Changeset 8015
- Timestamp:
- 12/12/11 14:22:25 (9 years ago)
- Location:
- mauRepo/MolesManager/trunk/src
- Files:
-
- 1 added
- 1 deleted
- 8 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
mauRepo/MolesManager/trunk/src/MolesManager/dataaccess.py
r8014 r8015 25 25 def getCEDA_ObservationById(id, session = None): 26 26 session = _checkSession(session) 27 res = session.query(CEDA_Observation).filter(*[_buildFilter(' mo_observation_id', id)])27 res = session.query(CEDA_Observation).filter(*[_buildFilter('ceda_observation_id', id)]) 28 28 print(res) 29 29 return res.all() -
mauRepo/MolesManager/trunk/src/MolesManager/urls.py
r7970 r8015 17 17 ) 18 18 19 urlpatterns += patterns('MolesManager.views. dateView',20 (r'^ date/$', 'dateView'),19 urlpatterns += patterns('MolesManager.views.cedaObservationView', 20 (r'^cov/$', 'coView'), 21 21 ) -
mauRepo/MolesManager/trunk/src/MolesManager/views/cedaObservationView.py
r7976 r8015 4 4 @author: mnagni 5 5 ''' 6 from MolesManager.dataaccess import get DateById6 from MolesManager.dataaccess import getCEDA_ObservationById 7 7 from MolesManager.forms.date import createForm 8 8 from django.shortcuts import render_to_response … … 18 18 return sampleForm 19 19 ''' 20 dp = get DateById(1)20 dp = getCEDA_ObservationById(1) 21 21 return createForm(dp[0]) 22 def dateView(request):22 def coView(request): 23 23 c = {} 24 24 form = __getSample(request) 25 c[' form'] = form25 c['coObs'] = form 26 26 27 27 c.update(csrf(request)) 28 return render_to_response(' date.html', c)28 return render_to_response('cedaObservation.html', c) -
mauRepo/MolesManager/trunk/src/libs/migration/client.py
r8014 r8015 24 24 ''' 25 25 26 26 ''' 27 27 lr = LoadResources(session) 28 28 lr.process() 29 ''' 30 31 sorted_data_ents = getObservationCollectionMigrationOrderByDate(session) 32 exs = [] 33 #loops over the sorted data entities 34 for de in sorted_data_ents: 35 de_path = '%s/%s' % (de.exist_path, de.data_ent_name) 36 dep = DataEntityProcessor(de_path, session) 37 exs.append(dep.process()) 38 session.commit() 39 print exs 29 40 30 41 31 sorted_data_ents = getObservationCollectionMigrationOrderByDate(session)32 #loops over the sorted data entities33 for de in sorted_data_ents:34 de_path = '%s/%s' % (de.exist_path, de.data_ent_name)35 dep = DataEntityProcessor(de_path, session)36 dep.process()37 session.commit()38 39 -
mauRepo/MolesManager/trunk/src/libs/migration/db/migrationTables.py
r8014 r8015 9 9 from libs.migration.db.classes import ObservationCollectionMigration,\ 10 10 ObservationMigration 11 11 12 ''' 13 Connects a dataEntity to its associated CEDA_Observation_Collection 14 ''' 12 15 obs_coll_migration = Table('obs_coll_migration', metadata, 13 16 Column('data_ent_id', TEXT, primary_key=True, nullable=False), … … 18 21 ) 19 22 23 ''' 24 Connects a deployment to its associated CEDA_Observation 25 ''' 20 26 observation_migration = Table('observation_migration', metadata, 21 27 Column('depl_id', TEXT, primary_key=True, nullable=False), -
mauRepo/MolesManager/trunk/src/libs/migration/processor/commons.py
r8014 r8015 103 103 104 104 105 def createMO_ResponsiblePartyInfoAsCI_Organization(role, name): 105 def createMO_ResponsiblePartyInfoAsCI_Organization(role, names): 106 ''' 107 @param role: a CI_RoleCode/MO_RoleValue assigned to this ResponsibleParty 108 @param names: the list of CI_Party names 109 ''' 106 110 mo_responsableInfo = MO_ResponsiblePartyInfo() 107 111 mo_responsableInfo.party = [] 108 112 mo_responsableInfo.role = role 109 ci_org = CI_Organisation() 110 ci_org.name = name 111 mo_responsableInfo.party.append(ci_org) 113 for name in names: 114 ci_org = CI_Organisation() 115 ci_org.name = name 116 mo_responsableInfo.party.append(ci_org) 112 117 return mo_responsableInfo 113 118 -
mauRepo/MolesManager/trunk/src/libs/migration/processor/dataEntity.py
r8014 r8015 82 82 83 83 def process(self): 84 self.resource = getXMLDocument(self._de_path) 84 exs = [] 85 #Retrieve the DataEntity 86 self.dataEntity = getXMLDocument(self._de_path) 85 87 #extracts the dataentity deployments 86 self._depls = findDeploymentsInDE(self. resource)88 self._depls = findDeploymentsInDE(self.dataEntity) 87 89 #loops over the deployments 88 90 for deplName in self._depls: … … 97 99 depl.process() 98 100 except NoDataLineage as ex: 101 exs.append(ex) 99 102 print ex 103 return exs; 104 -
mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment.py
r8014 r8015 5 5 ''' 6 6 from libs.migration.processor.commons import getXMLDocument,\ 7 createMO_ResponsiblePartyInfoAsCI_Organization, findMolesLineage 7 createMO_ResponsiblePartyInfoAsCI_Organization, findMolesLineage,\ 8 findAuthorInResource 8 9 from libs.migration.db.dbConnection import findCEDAObservationByDeplID 9 10 from ea_model.ceda_moles.ceda_observation.ceda_observation import CEDA_Observation … … 25 26 ''' 26 27 27 def __init__(self, deplObj, d ataEntity):28 def __init__(self, deplObj, deProcessor): 28 29 ''' 29 30 Initializes the class 30 31 @param deplObj: a ObservationMigration entity 31 @param d ataEntity: the associated DataEntityProcessor32 @param deProcessor: the associated DataEntityProcessor 32 33 ''' 33 34 self._deplObj = deplObj 34 self._dataEntity = dataEntity 35 36 ''' 37 def _createCEDA_Observation(self, resource): 38 self._de_path = '%s/%s' % (deplObj.exist_path, deplObj.depl_name) 39 author = findAuthorInResource(resource) 40 id = findDEorDepl_ID(resource) 41 ceda_observation = CEDA_Observation() 42 ceda_observation.relatedParty = [] 43 ceda_observation.identifier = [] 44 ceda_observation.relatedParty.append(createMO_ResponsiblePartyInfo(author)) 45 ceda_observation.identifier.append(createMD_Identifier(id)) 46 return ceda_observation 47 ''' 35 self._deProcessor = deProcessor 48 36 49 37 def _existsCEDAasPublisher(self): … … 55 43 return False 56 44 57 45 def _extractResponsiblePartyInfo(self, authors): 46 ''' 47 @param authors: a list of authors (after the first are considered co-authors) 48 ''' 49 if not authors: 50 return 51 52 parsedParties = [] 53 if (len(set(authors) & set(['badc.nerc.ac.uk', 'neodc.rl.ac.uk'])) > 0): 54 parsedParties.append(self._createResponsibleParty('Centre for Environmental Data Archive', MO_RoleValue.cl_curator)) 55 authorsCSV = findAuthorInResource(self._deProcessor.dataEntity) 56 if (authorsCSV): 57 authors = authorsCSV.split(',') 58 else: 59 return 60 #First is assumend to be the author 61 parsedParties.append(self._createResponsibleParty(authors[0], MO_RoleValue.cl_author)) 62 if (authors.remove(authors[0])): 63 for coauthor in authors.remove(authors[0]): 64 parsedParties.append(self._createResponsibleParty(coauthor, MO_RoleValue.cl_author)) 58 65 59 def _assignName(self): 66 return parsedParties 67 68 def _createResponsibleParty(self, name, role): 69 ''' 70 @param name: The CI_Party names 71 @param role: The assigned role 72 ''' 73 return createMO_ResponsiblePartyInfoAsCI_Organization(name, role) 74 75 def _assignName(self, relatedPartyInfos): 76 ''' 77 @param relatedPartyInfos: a MO_ResponsiblePartyInfo list 78 ''' 79 authorCSV = findAuthorInResource(self._deployment) 80 if (not authorCSV): 81 return 82 newResponsiblePartyInfos = self._extractResponsiblePartyInfo(authorCSV.split(',')) 83 #This methods check prepare the insert/update of the responsiblePartyInfos 84 self._checkResponsiblePartyExist(relatedPartyInfos, newResponsiblePartyInfos) 85 for newResponsiblePartyInfo in newResponsiblePartyInfos: 86 self._addResponsiblePartyInfo(relatedPartyInfos, newResponsiblePartyInfo) 87 88 ''' 60 89 if not self._existsCEDAasPublisher(): 61 print dir(self._ceda_observation.relatedParty)62 90 rp = self._ceda_observation.relatedParty 63 rp.append(createMO_ResponsiblePartyInfoAsCI_Organization(MO_RoleValue.cl_publisher, DeploymentProcessor.publisherName)) 91 rp.append(createMO_ResponsiblePartyInfoAsCI_Organization(MO_RoleValue.cl_publisher, DeploymentProcessor.publisherName)) 92 ''' 93 94 def _addResponsiblePartyInfo(self, oldResponsiblePartyInfos, newResponsiblePartyInfo): 95 for oldPartyInfo in oldResponsiblePartyInfos: 96 if oldPartyInfo.role == newResponsiblePartyInfo.role: 97 oldPartyInfo.party.append(newResponsiblePartyInfo.party) 98 99 100 def _checkResponsiblePartyExist(self, oldResponsiblePartyInfos, newResponsiblePartyInfos): 101 ''' 102 Compares two MO_ResponsiblePartyInfo lists. For each MO_ResponsiblePartyInfo in the oldResponsiblePartyInfos it 103 - deletes it from the oldResponsiblePartyInfos if it does NOT exists in the newResponsiblePartyInfos 104 - deletes it from the newResponsiblePartyInfos if it does exists in the newResponsiblePartyInfos 105 @param oldResponsiblePartyInfos: the old MO_ResponsiblePartyInfo list 106 @param newResponsiblePartyInfos: the new MO_ResponsiblePartyInfo list 107 ''' 108 for oldPartyInfo in oldResponsiblePartyInfos: 109 exists = False 110 for newPartyInfo in newResponsiblePartyInfos: 111 if oldPartyInfo.role == newPartyInfo.role: 112 exists = True 113 self._checkPartyExist(oldPartyInfo, newPartyInfo) 114 if not exists: 115 oldResponsiblePartyInfos.remove(oldPartyInfo) 116 117 def _checkPartyExist(self, oldPartyInfo, newPartyInfo): 118 ''' 119 Compares two MO_ResponsiblePartyInfo-s. For each CI_Party in the oldPartyInfo it 120 - deletes it from the oldPartyInfo if it does NOT exists in the newPartyInfo 121 - deletes it from the newPartyInfo if it does exists in the oldPartyInfo 122 @param oldPartyInfo: the old MO_ResponsiblePartyInfo 123 @param newPartyInfo: the new MO_ResponsiblePartyInfo 124 ''' 125 for oldParty in oldPartyInfo: 126 exists = False 127 for newParty in newPartyInfo: 128 if oldParty.name == newParty.name: 129 exists = True 130 newPartyInfo.remove(newParty) 131 oldPartyInfo.remove(oldParty) 64 132 65 133 def _assignLineage(self): 66 self._ceda_observation.dataLineage = findMolesLineage(self._d ataEntity.resource)134 self._ceda_observation.dataLineage = findMolesLineage(self._deProcessor.dataEntity) 67 135 if self._ceda_observation.dataLineage is None: 68 136 raise NoDataLineage(self._de_path) 69 137 70 138 71 def _processObj(self): 72 self._assignName() 139 def _processObj(self, cedaObservation): 140 ''' 141 @param cedaObservation: a relatedPartiesInfo instance 142 ''' 143 self._assignName(cedaObservation.relatedParty) 73 144 self._assignLineage() 74 145 … … 78 149 print self._de_path 79 150 #retrieves the deployment'd document 80 self._ resource= getXMLDocument(self._de_path)151 self._deployment = getXMLDocument(self._de_path) 81 152 self._ceda_observation = None 82 153 isUpdate = True 83 #Exists already an associated CEDA_Observation ?154 #Exists already an associated CEDA_Observation associated to this deployment? 84 155 if self._deplObj is not None and self._deplObj.obs_id is not None: 85 self._ceda_observation = findCEDAObservationByDeplID(self._deplObj.obs_id, self._d ataEntity.session)156 self._ceda_observation = findCEDAObservationByDeplID(self._deplObj.obs_id, self._deProcessor.session) 86 157 87 158 #If does not exist creates a new one … … 92 163 93 164 #fills/update the CEDA_Observation 94 self._processObj( )165 self._processObj(self._ceda_observation) 95 166 #insert/update the CEDA_Observation 96 doInsertOrUpdate([self._ceda_observation], self._d ataEntity.session, isUpdate)97 self._d ataEntity.session.commit()167 doInsertOrUpdate([self._ceda_observation], self._deProcessor.session, isUpdate) 168 self._deProcessor.session.commit() 98 169 self._deplObj.obs_id = self._ceda_observation.ceda_observation_id 99 doInsertOrUpdate([self._deplObj], self._d ataEntity.session, True)100 self._d ataEntity.session.commit()170 doInsertOrUpdate([self._deplObj], self._deProcessor.session, True) 171 self._deProcessor.session.commit() 101 172 return self._ceda_observation 102 173 -
mauRepo/MolesManager/trunk/src/libs/migration/processor/loadResources.py
r8014 r8015 104 104 105 105 def process(self): 106 ''' 107 docStatus = ('published', 'working', 'Published') 108 ''' 106 109 for status in docStatus: 107 110 baseStatus = '%s/%s' % (base, status)
Note: See TracChangeset
for help on using the changeset viewer.