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

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