source: mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment.py @ 8221

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment.py@8221
Revision 8221, 26.3 KB checked in by mnagni, 8 years ago (diff)

Incomplete - # 22385: CEDA Observation - result
 http://team.ceda.ac.uk/trac/ceda/ticket/22385

Line 
1'''
2Created on 15 Nov 2011
3
4@author: mnagni
5'''
6from libs.migration.processor.commons import findMolesLineage,\
7    createMO_ResponsiblePartyInfo,\
8    DO_BADC, DO_NEODC, findAuthorsInResource, CEDA,\
9    createMD_Identifier, extractSummary, extractQuality, \
10    hasAtomDocumentSameHash, getAtomDocumentHashByMO, extractTitle,\
11        createCEDA_Result,\
12    createEX_GeographicBoundingBox, extractGeographicExtentInMigrationDocument, findDownloadLinksInMigrationDocument,\
13    findDOIInMigrationDocument, extractContent, createCI_Citation, createCI_Date, createDate,\
14    createTM_Position, createTM_Instant, extractMolesCreationDate,\
15    createDateTime, isoDateTimeStringToTimeDate, extractMolesProviderID,\
16    DO_UKSSDC, createMO_ResponsiblePartyInfo_, createMO_Organization,\
17    createCI_Contact, createCI_Address, createCI_OnlineResource,\
18    createCI_Telephone, extractMolesTemporalRange, isoDateStringToTimeDate,\
19    createTM_Period, createCI_Individual, findAccessLinksInMigrationDocument,\
20    findLinksInDeployment, createMD_LegalConstraints, extractMolesQuality,\
21    createDQ_Element, createDQ_ConformanceResult, findUpdatedDate,\
22    createMD_Metadata, createMO_OnlineResource
23from ea_model.moles3_4.utilities.mo_rolevalue import MO_RoleValue
24from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation
25from libs.migration.MigrationEPB import MigrationEPB
26from libs.epb import EPB
27from libs.migration.processor.deployment_data import DeploymentDataProcessor
28from ea_model.moles3_4.utilities.mo_publicationstatevalue import MO_PublicationStateValue
29from libs.migration.exception.exceptions import NoDataLineage,\
30    NoAssociatedAuthor
31from MolesManager.moles3epb import Moles3EPB
32from libs.migration.authors import authors
33from logging import StreamHandler
34import logging
35from datetime import date
36from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_onlinefunctioncode import CI_OnLineFunctionCode
37from libs.migration.processor.check.check import moles3Append
38from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_datetypecode import CI_DateTypeCode
39from ea_model.iso_19115_2006_metadata_corrigendum.constraint_information.md_restrictioncode import MD_RestrictionCode
40from copy import deepcopy
41import datetime
42from libs.migration.InfodbEPB import InfodbEPB
43from ea_model.ceda_metadatamodel.ceda_result import ceda_curationvalue
44
45class DeploymentProcessor(object):
46    '''
47        Migrates a deployment element in a CEDA_Observation entity
48    '''
49    publisherName = 'CEDA'
50   
51    log = logging.getLogger('DeploymentProcessor')
52    log.addHandler(StreamHandler())
53    log.setLevel(logging.DEBUG)   
54    def __init__(self, dataEntityMigration, deploymentMigration, migrationSessions):
55        '''
56            Initializes the class
57            @param dataEntityMigration: a DataEntityMigration instance
58            @param deploymentMigration: the DeploymentMigration instance
59            @param migrationSessions: a MigrationSessions instance   
60        '''             
61        self._dataEntityMigration = dataEntityMigration
62        self._deploymentMigration = deploymentMigration
63        self._dataEntityHasSameHash = hasAtomDocumentSameHash(self._dataEntityMigration) and self._dataEntityMigration.doc_hash is not None
64        self._deploymentHasSameHash = hasAtomDocumentSameHash(self._deploymentMigration) and self._deploymentMigration.doc_hash is not None
65       
66        self._migrationSessions = migrationSessions
67
68    def _existsCEDAasPublisher(self):
69        for rp in self._ceda_observation.relatedParty:
70            if rp.role == MO_RoleValue.cl_publisher:
71                for party in rp.parties:
72                    if party.name == DeploymentProcessor.publisherName:
73                        return True
74        return False
75                   
76    def _extractResponsiblePartyInfo(self, authors = None, parsedParties = []):
77        '''
78            @param authors: the deployment's authors
79            @param parsedParties: a list to fill with the created MO_ResponsiblePartyInfos
80        '''
81        #First is assumend to be the author
82        parsedParties.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_author, authors[:1]))   
83        parsedParties.append(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_coinvestigator, authors[1:]))           
84
85    def _addResponsiblePartyInfo(self, oldResponsiblePartyInfos, newResponsiblePartyInfo):
86        opi = None
87        for oldPartyInfo in oldResponsiblePartyInfos:
88            if oldPartyInfo.role == newResponsiblePartyInfo.role:
89                opi = oldPartyInfo
90                break
91           
92        if len(oldResponsiblePartyInfos) == 0 or opi is None:
93            oldResponsiblePartyInfos.append(newResponsiblePartyInfo)
94       
95        if opi is not None: 
96            for np in newResponsiblePartyInfo.party:
97                opi.party.append(np)
98
99    def _appendResponsibleParty(self, observation, names, creation_function, role):
100        for nm in names:
101            i_party = creation_function(name = nm)
102            observation.relatedParty.append(createMO_ResponsiblePartyInfo_(role, [i_party]))       
103
104    def _assignName(self, observation):       
105        '''
106            @param relatedPartyInfos: a MO_ResponsiblePartyInfo list
107            @return True if the documents changed, False otherwise
108        '''
109        whereAreAuthors = self._deploymentMigration       
110        doc_authors = findAuthorsInResource(self._deploymentMigration)       
111        if doc_authors['authors'] in [DO_BADC, DO_NEODC]:
112            doc_authors = findAuthorsInResource(self._dataEntityMigration)
113            whereAreAuthors = self._dataEntityMigration
114
115        i_party = createMO_Organization(name = CEDA)
116        observation.relatedParty.append(createMO_ResponsiblePartyInfo_(MO_RoleValue.cl_curator, [i_party]))                               
117       
118        if authors.has_key(doc_authors['authors']):
119            tmp_auth = authors[doc_authors['authors']]
120            ret = self._extractIndividualsAndOrganizations(tmp_auth, whereAreAuthors)
121            if len(ret['ind']) > 0:
122                self._appendResponsibleParty(observation, ret['ind'], createCI_Individual, MO_RoleValue.cl_author)               
123            if len(ret['org']) > 0:
124                self._appendResponsibleParty(observation, ret['org'], createMO_Organization, MO_RoleValue.cl_author)                               
125            if len(ret['co_ind']) > 0:
126                self._appendResponsibleParty(observation, ret['co_ind'], createCI_Individual, MO_RoleValue.cl_coinvestigator)               
127            if len(ret['co_org']) > 0:
128                self._appendResponsibleParty(observation, ret['co_org'], createMO_Organization, MO_RoleValue.cl_coinvestigator)                                                                                         
129        else:
130            raise NoAssociatedAuthor(doc_authors['authors'], migrationObject = whereAreAuthors)
131       
132        if doc_authors['contributors'] is None:
133            return
134       
135        if authors.has_key(doc_authors['contributors']):
136            tmp_auth = authors[doc_authors['contributors']]           
137            ret = self._extractIndividualsAndOrganizations(tmp_auth, whereAreAuthors)
138            if len(ret['ind']) > 0:
139                self._appendResponsibleParty(observation, ret['ind'], createCI_Individual, MO_RoleValue.cl_coinvestigator)
140            if len(ret['org']) > 0:
141                self._appendResponsibleParty(observation, ret['org'], createMO_Organization, MO_RoleValue.cl_coinvestigator)               
142            if len(ret['co_ind']) > 0:
143                self._appendResponsibleParty(observation, ret['co_ind'], createCI_Individual, MO_RoleValue.cl_coinvestigator)               
144            if len(ret['co_org']) > 0:
145                self._appendResponsibleParty(observation, ret['co_org'], createMO_Organization, MO_RoleValue.cl_coinvestigator)                                                       
146        else:
147            raise NoAssociatedAuthor(doc_authors['contributors'], migrationObject = whereAreAuthors)
148
149
150    def _extractIndividualsAndOrganizations(self, tmp_auth, whereAreAuthors):
151        if whereAreAuthors is None:
152            raise Exception("migrationObject is None")
153        try:
154            ret = {'ind': [], 'org': [], 'co_ind': [], 'co_org': []}
155            if tmp_auth['type'] == 'ind':
156                ret['ind'].append(tmp_auth['author'])
157            elif tmp_auth['type'] == 'org':
158                ret['org'].append(tmp_auth['author'])
159           
160            if tmp_auth['author'] == 'unknown':
161                DeploymentProcessor.log.info("%s %s %s has unknown author" \
162                                             % (whereAreAuthors.doc_status, whereAreAuthors.doc_owner, whereAreAuthors.doc_name))       
163                 
164            for item in tmp_auth['co_author_type']:
165                if item == 'ind':
166                    ret['ind'].append(tmp_auth['co_author'][tmp_auth['co_author_type'].index(item)])
167                elif item == 'org':
168                    ret['org'].append(tmp_auth['co_author'][tmp_auth['co_author_type'].index(item)])
169           
170                if (tmp_auth['co_author'][tmp_auth['co_author_type'].index(item)] == 'unknown'):
171                    DeploymentProcessor.log.info("%s %s %s has unknown author" \
172                                                 % (whereAreAuthors.doc_status, whereAreAuthors.doc_owner, whereAreAuthors.doc_name))
173        except Exception as e:
174            print e
175        return ret
176
177    def _assignLineage(self, observation):
178        data_lineage = findMolesLineage(self._dataEntityMigration)
179        if data_lineage is None:
180            raise NoDataLineage(self._dataEntityMigration)
181        Moles3EPB.addDataLineageToObservation(data_lineage, observation, self._migrationSessions.molesSession)       
182       
183    def _assignTitle(self, observation):       
184        doc_title = extractTitle(self._deploymentMigration)
185       
186        if doc_title.startswith('deployment_') or doc_title.startswith('Deployment_'):
187            doc_title = extractTitle(self._dataEntityMigration)           
188        auth = createCI_Citation(title = 'ceda_title')                 
189        Moles3EPB.addIdentifierToObservation(createMD_Identifier(code = doc_title, authority = auth), \
190                                             observation, self._migrationSessions.molesSession)
191
192    def _assignDescription(self, observation):
193        summary = extractSummary(self._deploymentMigration, self._dataEntityMigration)
194        Moles3EPB.addDescriptionToObservation(summary, observation, self._migrationSessions.molesSession)
195       
196    def _assignQuality(self, observation):
197        doc_quality = extractQuality(self._dataEntityMigration)
198        doc_date = findUpdatedDate(self._dataEntityMigration)
199        ci_dates = []           
200        if doc_date:
201            i_date = createDate(isoDateTimeStringToTimeDate(doc_date))               
202            ci_dates.append(createCI_Date(CI_DateTypeCode.cl_revision, date = i_date))           
203        else:
204            i_date = createDate(isoDateTimeStringToTimeDate(datetime.datetime.now()))
205            ci_dates.append(createCI_Date(CI_DateTypeCode.cl_creation, date = i_date))
206
207        i_specification = createCI_Citation(title = "CEDA Data Quality Statement", date=ci_dates)
208        i_dq_result = createDQ_ConformanceResult(doc_quality, True, i_specification)
209        i_quality_element = createDQ_Element(i_dq_result)       
210        observation.resultQuality = [i_quality_element]
211       
212    def updateObservation(self):
213        ceda_observation = EPB.searchOrCreate(CEDA_Observation, self._migrationSessions.molesSession, \
214                                              self._deploymentMigration.ceda_observation_id)
215        return ceda_observation
216
217    def _getcurationcategory(self, curationcategory):
218        """
219            Returns a CEDA_CurationValue code if the parameter match any CEDA_CurationValue code
220            @param curationcategory: a String
221        """
222        if curationcategory is None:
223            return None
224       
225        for code in ceda_curationvalue.CEDA_CurationValue.__dict__:
226            if code.startswith('cl_'):
227                if code.lower() == curationcategory.lower():
228                    return code
229        return None
230       
231
232    def _assignResult(self, observation):
233        # TDB - Check that if is an update or not!       
234        download = findDownloadLinksInMigrationDocument(self._deploymentMigration)
235        content = None
236        if len(download) == 0:
237            download = findDownloadLinksInMigrationDocument(self._dataEntityMigration)
238            content = extractContent(self._dataEntityMigration)
239        else:
240            content = extractContent(self._deploymentMigration) 
241        for dwn in download:
242            int_description = None
243            int_applicationProfile = None
244            if content.has_key('formats'):
245                #int_applicationProfile = content['formats']
246                pass
247            if dwn['href'].startswith('http://badc.nerc.ac.uk/browse') or dwn['href'].startswith('http://neodc.nerc.ac.uk/browse'):
248                int_description = "download directly from archive"   
249            i_source = createMO_OnlineResource(linkage = dwn['href'], name = dwn['title'], \
250                                                   function = CI_OnLineFunctionCode.cl_download, \
251                                                   description = int_description, applicationProfile = int_applicationProfile)
252            dataentity_id = '%s__ATOM__%s' % (self._dataEntityMigration.doc_owner, self._dataEntityMigration.doc_name)
253            dataentity_id = dataentity_id.replace('.atom', '')           
254            infodb_de = InfodbEPB.getCedaInfoApp_dataentityByDE_ID(dataentity_id)
255            i_logical_path = '/dummy'
256            if infodb_de['logical_path']:
257                i_logical_path = infodb_de['logical_path']
258           
259            i_category = ceda_curationvalue.CEDA_CurationValue.cl_a                           
260            if infodb_de['category']:
261                i_category = self._getcurationcategory(infodb_de['category'])
262               
263            observation.result = createCEDA_Result(i_category, i_logical_path, source = [i_source])                               
264
265
266    def _assignGeographicExtent(self, observation):
267        # TDB - Check that if is an update or not!
268        ge = extractGeographicExtentInMigrationDocument(self._deploymentMigration)
269        if not ge:
270            ge = extractGeographicExtentInMigrationDocument(self._dataEntityMigration)
271        if ge:
272            moles3Append(observation, 'geographicExtent', createEX_GeographicBoundingBox(ge['east'], ge['north'], ge['west'], ge['south']))
273
274    def _assignCreationDate(self, observation):
275        # TDB - Check that if is an update or not!
276        creation_date = extractMolesCreationDate(self._deploymentMigration)
277        py_datetime = isoDateTimeStringToTimeDate(creation_date)
278        date_time = createDateTime(py_datetime)   
279        tm_position = createTM_Position(dateTime8601 = date_time)
280        observation.resultTime = createTM_Instant(tm_position)
281
282    def _assignDOI(self, observation):
283        # TDB - Check that if is an update or not!
284        doi = findDOIInMigrationDocument(self._deploymentMigration) 
285        if not doi:
286            doi = findDOIInMigrationDocument(self._dataEntityMigration)
287        if doi:
288            identifier = createMD_Identifier(code = doi['href'])
289            ci_date = None
290            if doi['href'] == '10.5285/E8F43A51-0198-4323-A926-FE69225D57DD':
291                #dt = createDateTime('21', '11', '04', '01', '07', '25', '35')
292                py_date = date(2011, 4, 1)
293                dt = createDate(py_date)
294                ci_date = createCI_Date(CI_DateTypeCode.cl_publication, date = dt)
295            elif doi['href'] == '10.5285/78114093-E2BD-4601-8AE5-3551E62AEF2B':
296                #dt = createDateTime('21', '11', '11', '29', '11', '37', '11')
297                py_date = date(2011, 11, 29)               
298                dt = createDate(py_date)               
299                ci_date = createCI_Date(CI_DateTypeCode.cl_publication, date = dt)
300            if ci_date:               
301                identifier.authority = createCI_Citation("", date = ci_date)
302            moles3Append(observation, 'identifier', identifier)                 
303            #Moles3EPB.addIdentifierToObservation(identifier, observation, self._migrationSessions.molesSession)                   
304
305    def _assignPublisherCurator(self, observation):       
306        provider_id = extractMolesProviderID(self._deploymentMigration)
307        party = None
308        if provider_id == DO_BADC:
309            i_linkage = 'http://badc.rl.ac.uk'
310            i_onlineResources = createCI_OnlineResource(linkage = i_linkage, name = 'British Atmospheric Data Centre Website')
311            i_address = createCI_Address(deliveryPoint = ['British Atmospheric Data Centre, STFC Rutherford Appleton Laboratory'], \
312                                         electronicMailAddress=['badc@rl.ac.uk'], postalCode='OX11 0QX', country='UK', city='Harwell Oxford')                                   
313            i_phone = createCI_Telephone(voice=['+44(0)1235 446432'])                                   
314            contact = createCI_Contact(phone=i_phone, address=i_address, onlineResource=i_onlineResources)                       
315            party = createMO_Organization(name = "NERC - British Atmospheric Data Centre", contactInfo = [contact])
316        elif provider_id == DO_NEODC:
317            i_linkage = 'http://www.neodc.rl.ac.uk'
318            i_onlineResources = createCI_OnlineResource(linkage = i_linkage, name = 'NERC Earth Observation Data Centre website')
319            i_address = createCI_Address(deliveryPoint = ['NERC - Earth Observation Data Centre, STFC Rutherford Appleton Laboratory'], \
320                                         electronicMailAddress=['neodc@rl.ac.uk'], postalCode='OX11 0QX', country='UK', city='Harwell Oxford')                                   
321            i_phone = createCI_Telephone(voice=['+44(0)1235 446432'])                                 
322            contact = createCI_Contact(phone=i_phone, address=i_address, onlineResource=i_onlineResources)                       
323            party = createMO_Organization(name = 'NERC - British Atmospheric Data Centre', contactInfo = [contact])
324        elif provider_id == DO_UKSSDC:
325            i_linkage = 'http://www.ukssdc.rl.ac.uk'
326            i_onlineResources = createCI_OnlineResource(linkage = i_linkage, name = 'UK Solar System Data Centre website')
327            i_address = createCI_Address(deliveryPoint = ['UK Solar System Data Centre, STFC Rutherford Appleton Laboratory'], \
328                                         electronicMailAddress=['support@rl.ac.uk'], postalCode='OX11 0QX', country='UK', city='Harwell Oxford')                                   
329            i_phone = createCI_Telephone(voice=['+44(0)1235 445173'])                                 
330            contact = createCI_Contact(phone=i_phone, address=i_address, onlineResource=i_onlineResources)                       
331            party = createMO_Organization(name = 'NERC - UK Solar System Data Centre', contactInfo = [contact])
332       
333        if party:
334            observation.relatedParty.append(createMO_ResponsiblePartyInfo_(MO_RoleValue.cl_publisher, [party]))
335            observation.relatedParty.append(createMO_ResponsiblePartyInfo_(MO_RoleValue.cl_custodian, deepcopy([party])))
336            observation.relatedParty.append(createMO_ResponsiblePartyInfo_(MO_RoleValue.cl_distributor, deepcopy([party])))
337            observation.relatedParty.append(createMO_ResponsiblePartyInfo_(MO_RoleValue.cl_pointofcontact, deepcopy([party])))
338            observation.relatedParty.append(createMO_ResponsiblePartyInfo_(MO_RoleValue.cl_metadataowner, deepcopy([party])))
339            observation.relatedParty.append(createMO_ResponsiblePartyInfo_(MO_RoleValue.cl_curator, deepcopy([party])))                                                           
340
341    def _assignPhenomenonTime(self, observation):       
342        doc_phenomenon_time = extractMolesTemporalRange(self._deploymentMigration)
343       
344        if doc_phenomenon_time:
345            if '/' in doc_phenomenon_time:
346                period = doc_phenomenon_time.split('/')
347                begin_date = createDate(isoDateStringToTimeDate(period[0]))
348                begin_position = createTM_Position(date8601 = begin_date)
349                begin_tm_instant = createTM_Instant(begin_position)
350               
351                end_date = createDate(isoDateStringToTimeDate(period[1]))
352                end_position = createTM_Position(date8601 = end_date)
353                end_tm_instant = createTM_Instant(end_position)
354               
355                observation.phenomenonTime = createTM_Period(begin_tm_instant, end_tm_instant)
356            else:
357                observation.phenomenonTime = createTM_Position(date8601 = createDate(isoDateStringToTimeDate(doc_phenomenon_time)))         
358
359    def _assignPermission(self, observation):
360        access_link = findAccessLinksInMigrationDocument(self._deploymentMigration)
361        dwn_link = findDownloadLinksInMigrationDocument(self._deploymentMigration)
362        if len(access_link) == 0:
363            access_link = findAccessLinksInMigrationDocument(self._dataEntityMigration) 
364
365        i_accessConstraints = []
366        i_use_limitation = []
367        md_legal_constraints = None
368       
369        if len(access_link) == 0:
370            if len(dwn_link) == 0:
371                dwn_link = findDownloadLinksInMigrationDocument(self._dataEntityMigration)
372                if dwn_link and len(dwn_link) == 1:               
373                    i_use_limitation.append("These data are open access and available through %s." % (dwn_link[0]['href']) )
374                    #i_accessConstraints.append(MD_RestrictionCode.cl_)
375                    observation.permission = createMD_LegalConstraints(useLimitation = i_use_limitation, accessConstrains = i_accessConstraints)
376        else:
377            if access_link and len(access_link) == 1:
378                i_use_limitation.append("Access to these data is restricted. To obtain access please apply for access at: %s" % (access_link[0]['href']))
379                i_accessConstraints.append(MD_RestrictionCode.cl_restricted)
380                observation.permission = createMD_LegalConstraints(useLimitation = i_use_limitation, accessConstrains = i_accessConstraints)               
381                                   
382        '''                               
383        contentDict = extractContent(self._deploymentMigration)
384        if not contentDict.has_key('access-restricted'):
385            contentDict = extractContent(self._dataEntityMigration)
386        '''
387           
388    def _assignMoles2Link(self, ceda_observation):
389        i_code = 'http://badc.nerc.ac.uk/view/%s__ATOM__%s' % (self._deploymentMigration.doc_owner, self._deploymentMigration.doc_name)
390        i_code = i_code.replace('.atom', '')
391        #i_code = buildExistDocPath(self._deploymentMigration.doc_status, DT_DEPLOYMENTS, self._deploymentMigration.doc_owner, self._deploymentMigration.doc_name)
392        i_authority = createCI_Citation('moles2url')
393        identifier = createMD_Identifier(code = i_code, authority = i_authority)
394        moles3Append(ceda_observation, 'identifier', identifier)
395   
396    def _assignLanguage(self, ceda_observation):
397        i_date_stamp = createDate(isoDateStringToTimeDate(datetime.datetime.now()))
398        i_contact = createCI_Citation("", date = i_date_stamp)
399        ceda_observation.metadata = createMD_Metadata(date_stamp=i_date_stamp, contact = i_contact, language = "English")
400   
401    def createNewObservation(self):
402        ceda_observation = CEDA_Observation()
403        ceda_observation.publicationState = MO_PublicationStateValue.cl_working
404        self._assignQuality(ceda_observation)
405        self._assignLineage(ceda_observation)
406        self._assignDescription(ceda_observation)
407        self._assignName(ceda_observation)
408        self._assignTitle(ceda_observation)
409        self._assignResult(ceda_observation)   
410        self._assignGeographicExtent(ceda_observation)   
411        self._assignDOI(ceda_observation)       
412        self._assignCreationDate(ceda_observation)
413        self._assignPublisherCurator(ceda_observation)       
414        self._assignPhenomenonTime(ceda_observation)       
415        self._assignPermission(ceda_observation)       
416        self._assignMoles2Link(ceda_observation)
417        self._assignQuality(ceda_observation)               
418        #self._assignLanguage(ceda_observation)       
419        Moles3EPB.addCedaObject(ceda_observation, self._migrationSessions.molesSession, True)
420        MigrationEPB.associateObservationToDeployment(self._deploymentMigration, ceda_observation.id, self._migrationSessions.molesSession, True)
421        return ceda_observation
422
423    def _getObservation(self):
424        return EPB.search(CEDA_Observation, self._deploymentMigration.ceda_observation_id, self._migrationSessions.molesSession)
425           
426    def process(self):
427        ceda_observation = None
428        #Moles3 object exists...
429        if self._deploymentMigration.ceda_observation_id: 
430            # ...and the data entity document has not changed
431            if hasAtomDocumentSameHash(self._deploymentMigration):
432                ceda_observation = self._getObservation()
433            else:
434                ceda_observation = self.updateObservation()
435        else:
436            #... does not exist so create it
437            ceda_observation = self.createNewObservation()
438       
439        #process the CEDA_Observation.procedure
440        deploymentDataProcessor = DeploymentDataProcessor(self._deploymentMigration, self._migrationSessions)
441        links = findLinksInDeployment(self._deploymentMigration)
442        procedure = deploymentDataProcessor.createProcess(links)
443       
444        #Temporary commented because CEDA_Project.subProject is not correctly mapped to the DB
445        project = deploymentDataProcessor.createProject(links)       
446        if procedure:
447            ceda_observation.procedure = procedure
448           
449        if project:
450            ceda_observation.inSupportOf = project         
451           
452        if procedure or project:                       
453            self._migrationSessions.molesSession.commit()
454           
455        if not self._deploymentHasSameHash:
456            self._deploymentMigration.doc_hash = getAtomDocumentHashByMO(self._deploymentMigration)
457            self._commitMigration()
458             
459       
460        return ceda_observation
Note: See TracBrowser for help on using the repository browser.