Changeset 8185 for mauRepo


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

Incomplete - # 22404: CEDA Observation - dates for DOI entries
 http://team.ceda.ac.uk/trac/ceda/ticket/22404

Location:
mauRepo/MolesManager/trunk/src/libs/migration
Files:
4 edited

Legend:

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

    r8182 r8185  
    2828from ea_model.ceda_metadatamodel.ceda_observationprocess.ceda_compositeprocess import CEDA_CompositeProcess 
    2929from ea_model.ceda_metadatamodel.ceda_acquisition.ceda_acquisition import CEDA_Acquisition 
     30from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_date import CI_Date 
     31from ea_model.iso_19103_2005_schema_language.basic_types.primitive.date_and_time.datetime import DateTime 
     32from ea_model.iso_19103_2005_schema_language.basic_types.primitive.date_and_time.date import Date 
    3033 
    3134base = '/exist/rest/atoms' 
     
    385388    return XML(resourceDoc) 
    386389 
     390def createDateTime(century, year='', month='', day='', hour='', minute='', second='', time_zone=''): 
     391    ''' 
     392        Creates a new DateTime instance. Note that all the attributes are strings! 
     393    ''' 
     394    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         
     410    return dateTime         
     411         
     412def 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        
     425         
     426             
     427 
    387428def createMO_ResponsiblePartyInfoAsCI_Organization(role, names): 
    388429    ''' 
     
    416457    return mo_responsableInfo 
    417458 
    418 def createCI_Citation(title = ""): 
     459def createCI_Date(dateType, date = None): 
     460    """ 
     461        Creates a new CI_Date 
     462        @param dateType: a CI_DateTypeCode value 
     463        @param date: a timestamp 
     464    """ 
     465    ci_date = CI_Date() 
     466    ci_date.dateType = dateType 
     467    if date: 
     468        ci_date.date = date  
     469    return ci_date 
     470 
     471def createCI_Citation(title, date = None): 
     472    """ 
     473        Creates a new CI_Citation 
     474        @param titile: the CI_Citation title 
     475        @param date: a CI_Date instance 
     476    """     
    419477    ci_citation = CI_Citation() 
    420478    ci_citation.title = title 
     479    if date: 
     480        ci_citation.date = date  
    421481    return ci_citation 
    422482 
    423 def createMD_Identifier(title = "", code = ""): 
     483def createMD_Identifier(code, authority = None): 
    424484    """ 
    425485        Creates a new MD_Identifier 
    426486        @param title: the MD_Identifier.authority.title field 
    427487        @param code: the MD_Identifier.code field 
     488        @param date: the MD_Identifier.authority.date field 
    428489    """ 
    429490    md_identifier = MD_Identifier() 
    430491    md_identifier.code = code 
    431     md_identifier.authority = createCI_Citation(title) 
     492    if authority: 
     493        md_identifier.authority = authority 
    432494    return md_identifier 
    433495 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/dataEntity.py

    r8180 r8185  
    1313from libs.migration.processor.commons import findDeploymentsInDE,\ 
    1414    createMD_Identifier, extractContent, MD_CODE_MOLES2_CITATION,\ 
    15     hasAtomDocumentSameHash 
     15    hasAtomDocumentSameHash, createCI_Citation, createCI_Date 
    1616from libs.migration.processor.deployment import DeploymentProcessor 
    1717from ea_model.moles3_4.utilities.mo_publicationstatevalue import MO_PublicationStateValue 
    1818from logging import StreamHandler 
    1919import logging 
     20from libs.migration.processor.check.check import moles3Append 
     21from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_datetypecode import CI_DateTypeCode 
    2022 
    2123class DataEntityProcessor(object): 
     
    4244        if not contentDict.has_key('citation'): 
    4345            DataEntityProcessor.log.info("The migration object "+ _migrationObjectDescription(self._dataEntityMigration) + " has not associated cedacat:citation") 
    44         ceda_observationCollection.identifier.append(createMD_Identifier(title = contentDict['citation'], code = MD_CODE_MOLES2_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) 
    4549     
    4650    def _getObservationCollection(self): 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment.py

    r8183 r8185  
    1212        createMO_ResponsiblePartyInfoAsCI_Individual, createCEDA_Result,\ 
    1313    createEX_GeographicBoundingBox, extractGeographicExtentInMigrationDocument, findDownloadLinksInMigrationDocument,\ 
    14     findDOIInMigrationDocument, extractContent 
     14    findDOIInMigrationDocument, extractContent, createCI_Citation, createCI_Date,\ 
     15    createDateTime, createDate 
    1516from ea_model.moles3_4.utilities.mo_rolevalue import MO_RoleValue 
    1617from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation 
     
    2728from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_onlinefunctioncode import CI_OnLineFunctionCode 
    2829from libs.migration.processor.check.check import moles3Append 
     30from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_datetypecode import CI_DateTypeCode 
    2931 
    3032class DeploymentProcessor(object): 
     
    162164         
    163165        if doc_title.startswith('deployment_') or doc_title.startswith('Deployment_'): 
    164             doc_title = extractTitle(self._dataEntityMigration)         
    165         Moles3EPB.addIdentifierToObservation(createMD_Identifier(code = doc_title, title = 'ceda_title'), observation, self._migrationSessions.molesSession) 
     166            doc_title = extractTitle(self._dataEntityMigration)             
     167        auth = createCI_Citation(title = 'ceda_title')                   
     168        Moles3EPB.addIdentifierToObservation(createMD_Identifier(code = doc_title, authority = auth), observation, self._migrationSessions.molesSession) 
    166169 
    167170    def _assignDescription(self, observation): 
     
    211214            doi = findDOIInMigrationDocument(self._dataEntityMigration) 
    212215        if doi: 
    213             Moles3EPB.addIdentifierToObservation(createMD_Identifier(code = doi['href']), observation, self._migrationSessions.molesSession)                     
     216            identifier = createMD_Identifier(code = doi['href']) 
     217            ci_date = None 
     218            if doi['href'] == '10.5285/E8F43A51-0198-4323-A926-FE69225D57DD': 
     219                #dt = createDateTime('21', '11', '04', '01', '07', '25', '35') 
     220                dt = createDate('21', '11', '04', '01') 
     221                ci_date = createCI_Date(CI_DateTypeCode.cl_publication, date = dt) 
     222            elif doi['href'] == '10.5285/78114093-E2BD-4601-8AE5-3551E62AEF2B': 
     223                #dt = createDateTime('21', '11', '11', '29', '11', '37', '11') 
     224                dt = createDate('21', '11', '11', '29')                 
     225                ci_date = createCI_Date(CI_DateTypeCode.cl_publication, date = dt) 
     226            if ci_date:                 
     227                identifier.authority = createCI_Citation("", date = ci_date)  
     228            Moles3EPB.addIdentifierToObservation(identifier, observation, self._migrationSessions.molesSession)                     
    214229 
    215230    def createNewObservation(self): 
  • mauRepo/MolesManager/trunk/src/libs/migration/tests/moles3epbtests.py

    r8159 r8185  
    1515from sqlalchemy.exc import IntegrityError 
    1616from libs.migration.processor.check.check import moles3Append 
     17from libs.migration.processor.commons import createCI_Date, createDateTime,\ 
     18    createDate 
     19from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_datetypecode import CI_DateTypeCode 
     20from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_date import CI_Date 
    1721 
    1822 
     
    3640        self.checkObservation() 
    3741        self.checkObservationCollection() 
     42        self.checkCI_Date() 
    3843 
    3944    def checkEmptyObservationCollection(self): 
     
    121126        session.commit() 
    122127 
     128    def checkCI_Date(self): 
     129        session = Moles3EPB.getNewMolesSession(); 
     130        dt = createDate('21', '2011', '04', '01') 
     131        ci_date = createCI_Date(CI_DateTypeCode.cl_creation, dt) 
     132         
     133        self.logging.info('Stores an empty new CEDA_ObservationCollection') 
     134        Moles3EPB.addCedaObject(ci_date, session) 
     135        session.commit() 
     136         
     137        self.logging.info('Tries to retrieve it') 
     138        self.assertTrue(hasattr(ci_date, 'id'), "Cannot create  CI_Date")         
     139        res = Moles3EPB.search(CI_Date, ci_date.id, session) 
     140        self.assertNotEqual(res, None, "Cannot retrieve the stored instance") 
     141         
     142        self.logging.info('Deletes it') 
     143        session.delete(ci_date) 
     144        session.commit() 
     145 
    123146    def _createObservationCollection(self): 
    124147        observationCollection = CEDA_ObservationCollection() 
Note: See TracChangeset for help on using the changeset viewer.