Changeset 8186 for mauRepo


Ignore:
Timestamp:
23/03/12 16:52:41 (8 years ago)
Author:
mnagni
Message:

Incomplete - # 22392: citation migration from MOLES2
 http://team.ceda.ac.uk/trac/ceda/ticket/22392
Complete - # 22397: CEDA Observation geographicExtent
 http://team.ceda.ac.uk/trac/ceda/ticket/22397
Complete - # 22409: CEDA Observation - resultTime
 http://team.ceda.ac.uk/trac/ceda/ticket/22409

Location:
mauRepo/MolesManager/trunk/src/libs/migration
Files:
1 added
5 edited

Legend:

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

    r8185 r8186  
    3131from ea_model.iso_19103_2005_schema_language.basic_types.primitive.date_and_time.datetime import DateTime 
    3232from ea_model.iso_19103_2005_schema_language.basic_types.primitive.date_and_time.date import Date 
     33from ea_model.iso_19108_2006_temporal_schema.temporal_reference_system.tm_position import TM_Position 
     34from ea_model.iso_19108_2006_temporal_schema.temporal_objects.tm_instant import TM_Instant 
    3335 
    3436base = '/exist/rest/atoms' 
     
    145147 
    146148def stringToTimestamp(timestring): 
     149    ''' 
     150        Return a timestamp such as is returned by time.time(). 
     151        @param timestring: a time string formatted as '%Y-%m-%dT%H:%M:%SZ' 
     152    '''     
    147153    return datetime.datetime.fromtimestamp(time.mktime(time.strptime(timestring, time_format))) 
     154 
     155def isoDateTimeStringToTimeDate(timestring): 
     156    ''' 
     157        Return a datatime.datatime instance. 
     158        @param timestring: a time string formatted as '%Y-%m-%dT%H:%M:%SZ' 
     159    ''' 
     160    return datetime.datetime.strptime(timestring, time_format) 
    148161 
    149162def _getDocument(source): 
     
    174187        raise NoDataLineage(dataEntityMigration) 
    175188    return lineage.text 
     189 
     190def extractMolesCreationDate(migrationObject): 
     191    resourceXML = getAtomDocumentByMO(migrationObject) 
     192    return findMolesCreationDate(resourceXML) 
    176193 
    177194def extractQuality(dataEntityMigration): 
     
    388405    return XML(resourceDoc) 
    389406 
    390 def createDateTime(century, year='', month='', day='', hour='', minute='', second='', time_zone=''): 
    391     ''' 
    392         Creates a new DateTime instance. Note that all the attributes are strings! 
     407def createDateTime(datetime): 
     408    ''' 
     409        Creates a new DateTime instance. 
     410        @param datetime: a datetime.datetime instance         
    393411    ''' 
    394412    dateTime = DateTime() 
    395     datetime.century = century 
    396     if year: 
    397         datetime.year = year 
    398     if month: 
    399         datetime.month = month         
    400     if day: 
    401         datetime.day = day 
    402     if hour: 
    403         datetime.hour = hour 
    404     if minute: 
    405         dateTime.minute = minute 
    406     if second: 
    407         dateTime.second = second 
    408     if time_zone: 
    409         dateTime.timeZone = time_zone         
     413    dateTime.century = (datetime.year / 100) + 1 
     414    dateTime.year = datetime.year 
     415    dateTime.month = datetime.month         
     416    dateTime.day = datetime.day 
     417    dateTime.hour = datetime.hour 
     418    dateTime.minute = datetime.minute 
     419    dateTime.second = datetime.second 
     420    dateTime.timeZone = datetime.tzinfo         
    410421    return dateTime         
    411422         
    412 def createDate(century, year='', month='', day=''): 
    413     ''' 
    414         Creates a new Date instance. Note that all the attributes are strings! 
    415     ''' 
    416     date = Date() 
    417     date.century = century 
    418     if year: 
    419         date.year = year 
    420     if month: 
    421         date.month = month         
    422     if day: 
    423         date.day = day         
    424     return date        
     423def createDate(date): 
     424    ''' 
     425        Creates a new Date instance. 
     426        @param date: a datetime.date instance  
     427    ''' 
     428    idate = Date() 
     429    idate.century = (date.year / 100) + 1 
     430    idate.year = date.year 
     431    idate.month = date.month         
     432    idate.day = date.day         
     433    return idate        
    425434         
    426              
     435def createTM_Position(anyOther = None, date8601 = None, dateTime8601 = None, time8601 = None): 
     436    ''' 
     437        Creates a new TM_Position instance 
     438        @param anyOther: a TM_TemporalPosition instance 
     439        @param date8601: a Date instance 
     440        @param dateTime8601:a DateTime instance 
     441        @param time8601: a Time instance    
     442    ''' 
     443    tm_position = TM_Position() 
     444    if anyOther: 
     445        tm_position.anyOther = anyOther 
     446    if date8601: 
     447        tm_position.date8601 = date8601   
     448    if dateTime8601: 
     449        tm_position.dateTime8601 = dateTime8601 
     450    if time8601: 
     451        tm_position.time8601 = time8601 
     452    return tm_position             
     453 
     454def createTM_Instant(position): 
     455    ''' 
     456        Creates a new TM_Position instance 
     457        @param position: a TM_Position instance 
     458    ''' 
     459    tm_instant = TM_Instant() 
     460    tm_instant.position = position 
     461    return tm_instant 
    427462 
    428463def createMO_ResponsiblePartyInfoAsCI_Organization(role, names): 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/dataEntity.py

    r8185 r8186  
    4444        if not contentDict.has_key('citation'): 
    4545            DataEntityProcessor.log.info("The migration object "+ _migrationObjectDescription(self._dataEntityMigration) + " has not associated cedacat:citation") 
    46         auth = createCI_Citation(title = contentDict['citation']) 
    47         newIdentifier = createMD_Identifier(code = MD_CODE_MOLES2_CITATION, authority = auth) 
    48         moles3Append(ceda_observationCollection, 'identifier', newIdentifier) 
     46            newIdentifier = createMD_Identifier(code = contentDict['citation']) 
     47            moles3Append(ceda_observationCollection, 'identifier', newIdentifier) 
    4948     
    5049    def _getObservationCollection(self): 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment.py

    r8185 r8186  
    1212        createMO_ResponsiblePartyInfoAsCI_Individual, createCEDA_Result,\ 
    1313    createEX_GeographicBoundingBox, extractGeographicExtentInMigrationDocument, findDownloadLinksInMigrationDocument,\ 
    14     findDOIInMigrationDocument, extractContent, createCI_Citation, createCI_Date,\ 
    15     createDateTime, createDate 
     14    findDOIInMigrationDocument, extractContent, createCI_Citation, createCI_Date, createDate,\ 
     15    createTM_Position, createTM_Instant, extractMolesCreationDate,\ 
     16    createDateTime, isoDateTimeStringToTimeDate 
    1617from ea_model.moles3_4.utilities.mo_rolevalue import MO_RoleValue 
    1718from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation 
     
    2526from libs.migration.authors import authors 
    2627from logging import StreamHandler 
    27 import logging 
     28import logging, datetime 
    2829from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_onlinefunctioncode import CI_OnLineFunctionCode 
    2930from libs.migration.processor.check.check import moles3Append 
     
    208209            moles3Append(observation, 'geographicExtent', createEX_GeographicBoundingBox(ge['east'], ge['north'], ge['west'], ge['south'])) 
    209210 
     211    def _assignCreationDate(self, observation): 
     212        # TDB - Check that if is an update or not! 
     213        creation_date = extractMolesCreationDate(self._deploymentMigration) 
     214        py_datetime = isoDateTimeStringToTimeDate(creation_date) 
     215        date_time = createDateTime(py_datetime)     
     216        tm_position = createTM_Position(dateTime8601 = date_time) 
     217        observation.resultTime = createTM_Instant(tm_position) 
     218 
    210219    def _assignDOI(self, observation): 
    211220        # TDB - Check that if is an update or not! 
     
    218227            if doi['href'] == '10.5285/E8F43A51-0198-4323-A926-FE69225D57DD': 
    219228                #dt = createDateTime('21', '11', '04', '01', '07', '25', '35') 
    220                 dt = createDate('21', '11', '04', '01') 
     229                py_date = datetime.date(2011, 4, 1) 
     230                dt = createDate(py_date) 
    221231                ci_date = createCI_Date(CI_DateTypeCode.cl_publication, date = dt) 
    222232            elif doi['href'] == '10.5285/78114093-E2BD-4601-8AE5-3551E62AEF2B': 
    223233                #dt = createDateTime('21', '11', '11', '29', '11', '37', '11') 
    224                 dt = createDate('21', '11', '11', '29')                 
     234                py_date = datetime.date(2011, 11, 29)                 
     235                dt = createDate(py_date)                 
    225236                ci_date = createCI_Date(CI_DateTypeCode.cl_publication, date = dt) 
    226237            if ci_date:                 
     
    239250        self._assignGeographicExtent(ceda_observation)     
    240251        self._assignDOI(ceda_observation)         
     252        self._assignCreationDate(ceda_observation) 
    241253        #self._migrationSessions.molesSession.commit() 
    242254        #self._commitMoles3() 
  • mauRepo/MolesManager/trunk/src/libs/migration/tests/migrationprocess.py

    r8180 r8186  
    4646         
    4747        ex = mp.process(dataEntity) 
    48         #ex = mp.process() 
     48        ex = mp.process() 
    4949        for e in ex: 
    5050            print e 
  • mauRepo/MolesManager/trunk/src/libs/migration/tests/moles3epbtests.py

    r8185 r8186  
    1010from unittest import TestCase 
    1111from ea_model.ceda_metadatamodel.ceda_observationcollection.ceda_observationcollection import CEDA_ObservationCollection 
    12 import logging 
     12import logging, datetime 
    1313from logging import StreamHandler 
    1414from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation 
     
    1616from libs.migration.processor.check.check import moles3Append 
    1717from libs.migration.processor.commons import createCI_Date, createDateTime,\ 
    18     createDate 
     18    createDate, createTM_Position, createTM_Instant, isoDateTimeStringToTimeDate 
    1919from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_datetypecode import CI_DateTypeCode 
    2020from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_date import CI_Date 
     21from ea_model.iso_19108_2006_temporal_schema.temporal_objects.tm_instant import TM_Instant 
     22from ea_model.iso_19108_2006_temporal_schema.temporal_reference_system.tm_position import TM_Position 
    2123 
    2224 
     
    4143        self.checkObservationCollection() 
    4244        self.checkCI_Date() 
     45        self.checkTM_Instant() 
     46        self.checkTM_Position()         
    4347 
    4448    def checkEmptyObservationCollection(self): 
     
    128132    def checkCI_Date(self): 
    129133        session = Moles3EPB.getNewMolesSession(); 
    130         dt = createDate('21', '2011', '04', '01') 
     134        py_date = datetime.date(2011, 4, 1) 
     135        dt = createDate(py_date) 
    131136        ci_date = createCI_Date(CI_DateTypeCode.cl_creation, dt) 
    132137         
     
    142147        self.logging.info('Deletes it') 
    143148        session.delete(ci_date) 
     149        session.commit() 
     150 
     151    def checkTM_Position(self): 
     152        session = Moles3EPB.getNewMolesSession(); 
     153        tm_position = self._createTM_Position() 
     154         
     155        self.logging.info('Stores an empty new TM_Position') 
     156        Moles3EPB.addCedaObject(tm_position, session) 
     157        session.commit() 
     158         
     159        self.logging.info('Tries to retrieve it') 
     160        self.assertTrue(hasattr(tm_position, 'id'), "Cannot create  TM_Position")         
     161        res = Moles3EPB.search(TM_Position, tm_position.id, session) 
     162        self.assertNotEqual(res, None, "Cannot retrieve the stored instance") 
     163         
     164        self.logging.info('Deletes it') 
     165        session.delete(tm_position) 
     166        session.commit()         
     167 
     168 
     169    def checkTM_Instant(self): 
     170        session = Moles3EPB.getNewMolesSession();         
     171        tm_instant = self._createTM_Instant() 
     172 
     173        self.logging.info('Stores an empty new TM_Instant') 
     174        Moles3EPB.addCedaObject(tm_instant, session) 
     175        session.commit() 
     176         
     177        self.logging.info('Tries to retrieve it') 
     178        self.assertTrue(hasattr(tm_instant, 'id'), "Cannot create  TM_Instant")         
     179        res = Moles3EPB.search(TM_Instant, tm_instant.id, session) 
     180        self.assertNotEqual(res, None, "Cannot retrieve the stored instance") 
     181         
     182        self.logging.info('Deletes it') 
     183        session.delete(tm_instant) 
    144184        session.commit() 
    145185 
     
    152192        observation.dataLineage = "dataLineage" 
    153193        return observation 
     194     
     195    def _createDateTime(self): 
     196        py_date = datetime.datetime(2011, 4, 1, 00, 00, 00) 
     197        return createDateTime(py_date)     
     198     
     199    def _createCI_Date(self): 
     200        py_date = datetime.date(2011, 4, 1) 
     201        dt = createDate(py_date) 
     202        return createCI_Date(CI_DateTypeCode.cl_creation, dt) 
     203     
     204    def _createTM_Position(self): 
     205        newDateTime = self._createDateTime()                 
     206        return createTM_Position(dateTime8601 = newDateTime) 
     207 
     208    def _createTM_Instant(self): 
     209        tm_position = self._createTM_Position()         
     210        return createTM_Instant(tm_position) 
    154211 
    155212if __name__ == "__main__": 
Note: See TracChangeset for help on using the changeset viewer.