Changeset 8193 for mauRepo


Ignore:
Timestamp:
27/03/12 08:33:46 (8 years ago)
Author:
mnagni
Message:

Incomplete - # 22412: CEDA Observation - publisher, curator
 http://team.ceda.ac.uk/trac/ceda/ticket/22412

Location:
mauRepo/MolesManager/trunk/src/libs/migration/processor
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/commons.py

    r8187 r8193  
    3838from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_onlineresource import CI_OnlineResource 
    3939from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_telephone import CI_Telephone 
     40from ea_model.iso_19108_2006_temporal_schema.temporal_objects.tm_period import TM_Period 
    4041 
    4142base = '/exist/rest/atoms' 
     
    6566georssNS="{http://www.georss.org/georss/10}" 
    6667gmlNS="{http://www.opengis.net/gml}" 
    67 time_format = '%Y-%m-%dT%H:%M:%SZ' 
     68date_format = '%Y-%m-%d' 
     69datetime_format = date_format + 'T%H:%M:%SZ' 
    6870ihost = 'bora.badc.rl.ac.uk' 
    6971iport = '8080' 
     
    156158        @param timestring: a time string formatted as '%Y-%m-%dT%H:%M:%SZ' 
    157159    '''     
    158     return datetime.datetime.fromtimestamp(time.mktime(time.strptime(timestring, time_format))) 
     160    return datetime.datetime.fromtimestamp(time.mktime(time.strptime(timestring, datetime_format))) 
     161 
     162def isoDateStringToTimeDate(datestring): 
     163    ''' 
     164        Return a datatime.datatime instance. 
     165        @param datestring: a date string formatted as '%Y-%m-%d' 
     166    ''' 
     167    return datetime.datetime.strptime(datestring, date_format) 
    159168 
    160169def isoDateTimeStringToTimeDate(timestring): 
     
    163172        @param timestring: a time string formatted as '%Y-%m-%dT%H:%M:%SZ' 
    164173    ''' 
    165     return datetime.datetime.strptime(timestring, time_format) 
     174    return datetime.datetime.strptime(timestring, datetime_format) 
    166175 
    167176def _getDocument(source): 
     
    197206    provider_id = resourceXML.find('%sentity/%smolesISO/%sproviderID' % (molesNS, molesNS, molesNS)) 
    198207    return _returnNotNoneText(provider_id) 
     208 
     209def extractMolesTemporalRange(migrationObject): 
     210    resourceXML = getAtomDocumentByMO(migrationObject) 
     211    temporal_range = resourceXML.find('%stemporalRange' % (molesNS)) 
     212    return _returnNotNoneText(temporal_range) 
    199213 
    200214def extractMolesCreationDate(migrationObject): 
     
    470484    tm_instant.position = position 
    471485    return tm_instant 
     486 
     487def createTM_Period(begin, end): 
     488    ''' 
     489        Creates a new TM_Position instance 
     490        @param position: a TM_Position instance 
     491    ''' 
     492    tm_period = TM_Period() 
     493    tm_period.begin = begin 
     494    tm_period.end = end     
     495    return tm_period 
    472496 
    473497def createCI_Address(deliveryPoint = None, electronicMailAddress = None, city = None, country = None, postalCode = None): 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment.py

    r8187 r8193  
    1717    DO_UKSSDC, createMO_ResponsiblePartyInfo_, createMO_Organization,\ 
    1818    createCI_Contact, createCI_Address, createCI_OnlineResource,\ 
    19     createCI_Telephone 
     19    createCI_Telephone, extractMolesTemporalRange, isoDateStringToTimeDate,\ 
     20    createTM_Period 
    2021from ea_model.moles3_4.utilities.mo_rolevalue import MO_RoleValue 
    2122from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation 
     
    244245 
    245246    def _assignPublisherCurator(self, observation):         
    246         ''' 
    247             @param relatedPartyInfos: a MO_ResponsiblePartyInfo list 
    248             @return True if the documents changed, False otherwise 
    249         ''' 
    250247        provider_id = extractMolesProviderID(self._deploymentMigration) 
    251248        party = None 
     
    280277            Moles3EPB.addRelatedPartyInfoToObservation(createMO_ResponsiblePartyInfo_(MO_RoleValue.cl_curator, party), observation, self._migrationSessions.molesSession)                                                             
    281278 
     279    def _assignPhenomenonTime(self, observation):         
     280        doc_phenomenon_time = extractMolesTemporalRange(self._deploymentMigration) 
     281         
     282        if doc_phenomenon_time: 
     283            if '/' in doc_phenomenon_time: 
     284                period = doc_phenomenon_time.split('/') 
     285                begin_date = createDate(isoDateStringToTimeDate(period[0])) 
     286                begin_position = createTM_Position(date8601 = begin_date) 
     287                begin_tm_instant = createTM_Instant(begin_position) 
     288                 
     289                end_date = createDate(isoDateStringToTimeDate(period[1])) 
     290                end_position = createTM_Position(date8601 = end_date) 
     291                end_tm_instant = createTM_Instant(end_position) 
     292                 
     293                observation.phenomenonTime = createTM_Period(begin_tm_instant, end_tm_instant) 
     294            else: 
     295                observation.phenomenonTime = createTM_Position(date8601 = createDate(isoDateStringToTimeDate(doc_phenomenon_time)))          
     296 
    282297    def createNewObservation(self): 
    283298        ceda_observation = CEDA_Observation() 
     
    293308        self._assignCreationDate(ceda_observation) 
    294309        self._assignPublisherCurator(ceda_observation)         
     310        self._assignPhenomenonTime(ceda_observation)         
    295311        #self._migrationSessions.molesSession.commit() 
    296312        #self._commitMoles3() 
Note: See TracChangeset for help on using the changeset viewer.