Changeset 8158


Ignore:
Timestamp:
13/03/12 13:05:55 (8 years ago)
Author:
mnagni
Message:

Fixes small bugs

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

Legend:

Unmodified
Added
Removed
  • mauRepo/MolesManager/trunk/src/libs/migration/exception/exceptions.py

    r8147 r8158  
    5555        super(NoAssociatedAuthor, self).__init__(migrationObject, comment = '') 
    5656    def __str__(self): 
    57         return "The MigrationObject %s has no author mapping for %s" % (_migrationObjectDescription(self.migrationObject), self.author)         
     57        return "The MigrationObject %s has no author mapping for %s" % (_migrationObjectDescription(self.migrationObject), self.author)             
    5858 
    5959class NoAssociatedDeployments(Exception): 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/commons.py

    r8147 r8158  
    364364 
    365365def createMD_Identifier(title = "", code = ""): 
     366    """ 
     367        Creates a new MD_Identifier 
     368        @param title: the MD_Identifier.authority.title field 
     369        @param code: the MD_Identifier.code field 
     370    """ 
    366371    md_identifier = MD_Identifier() 
    367372    md_identifier.code = code 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/dataEntity.py

    r8147 r8158  
    99from libs.epb import EPB 
    1010from libs.migration.MigrationEPB import MigrationEPB 
    11 from libs.migration.exception.exceptions import NoDataLineage,\ 
    12     MigrationObjectException, NoAssociatedAuthor 
    13 from libs.migration.processor.check.check import checkObservationCollection 
     11from libs.migration.exception.exceptions import MigrationObjectException, NoAssociatedAuthor,\ 
     12    _migrationObjectDescription 
    1413from libs.migration.processor.commons import findDeploymentsInDE,\ 
    1514    createMD_Identifier, extractContent, MD_CODE_MOLES2_CITATION,\ 
     
    1716from libs.migration.processor.deployment import DeploymentProcessor 
    1817from ea_model.moles3_4.utilities.mo_publicationstatevalue import MO_PublicationStateValue 
     18from logging import StreamHandler 
     19import logging 
    1920 
    2021class DataEntityProcessor(object): 
    21      
     22    log = logging.getLogger('DataEntityProcessor') 
     23    log.addHandler(StreamHandler()) 
     24    log.setLevel(logging.DEBUG)   
    2225    ''' 
    2326        Processes a DataEntityMigration item. Note that each DataEntity is associated to a "dataent_xxxx" file in Moles2 
     
    3639    def _processCitation(self, ceda_observationCollection): 
    3740        # TDB - Check that if is an update or not! 
    38         contentDict = extractContent(self._dataEntityMigration)        
     41        contentDict = extractContent(self._dataEntityMigration) 
     42        if not contentDict.has_key('citation'): 
     43            DataEntityProcessor.log.info("The migration object "+ _migrationObjectDescription(self._dataEntityMigration) + " has not associated cedacat:citation") 
    3944        ceda_observationCollection.identifier.append(createMD_Identifier(title = contentDict['citation'], code = MD_CODE_MOLES2_CITATION)) 
    4045     
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment.py

    r8147 r8158  
    66from libs.migration.processor.commons import findMolesLineage,\ 
    77    createMO_ResponsiblePartyInfo,\ 
    8     DO_BADC, DO_NEODC, findAuthorsInResource, CEDA, extractTitle,\ 
     8    DO_BADC, DO_NEODC, findAuthorsInResource, CEDA,\ 
    99    createMD_Identifier, extractSummary, extractQuality, \ 
    1010    hasAtomDocumentSameHash, getAtomDocumentHashByMO, extractTitle,\ 
     
    8383            @return True if the documents changed, False otherwise 
    8484        ''' 
    85         whereAreAuthors = self._deploymentMigration 
    86          
    87         doc_authors = findAuthorsInResource(self._deploymentMigration) 
    88          
    89         if (len(set(doc_authors['authors']) & set([DO_BADC, DO_NEODC])) > 0): 
     85        whereAreAuthors = self._deploymentMigration         
     86        doc_authors = findAuthorsInResource(self._deploymentMigration)         
     87        if doc_authors['authors'] in [DO_BADC, DO_NEODC]: 
    9088            doc_authors = findAuthorsInResource(self._dataEntityMigration) 
    9189            whereAreAuthors = self._dataEntityMigration 
     90                        
    9291        Moles3EPB.addRelatedPartyInfoToObservation(createMO_ResponsiblePartyInfo(MO_RoleValue.cl_curator, [CEDA]), observation, self._migrationSessions.molesSession) 
    93         tmp_auth = None 
     92         
    9493        if authors.has_key(doc_authors['authors']): 
    95             tmp_auth = authors[doc_authors['authors']] 
     94            tmp_auth = authors[doc_authors['authors']]             
    9695            ret = self._extractIndividualsAndOrganizations(tmp_auth, whereAreAuthors) 
    9796            if len(ret['ind']) > 0: 
    98                 createMO_ResponsiblePartyInfoAsCI_Individual(MO_RoleValue.cl_author, [ret['ind']]) 
     97                Moles3EPB.addRelatedPartyInfoToObservation(createMO_ResponsiblePartyInfoAsCI_Individual(MO_RoleValue.cl_author, [ret['ind']]), observation, self._migrationSessions.molesSession) 
    9998            if len(ret['org']) > 0: 
    100                 createMO_ResponsiblePartyInfoAsCI_Organization(MO_RoleValue.cl_author, [ret['org']]) 
     99                Moles3EPB.addRelatedPartyInfoToObservation(createMO_ResponsiblePartyInfoAsCI_Organization(MO_RoleValue.cl_author, [ret['org']]), observation, self._migrationSessions.molesSession)                 
    101100            if len(ret['co_ind']) > 0: 
    102                 createMO_ResponsiblePartyInfoAsCI_Individual(MO_RoleValue.cl_author, [ret['co_ind']]) 
     101                Moles3EPB.addRelatedPartyInfoToObservation(createMO_ResponsiblePartyInfoAsCI_Individual(MO_RoleValue.cl_coinvestigator, [ret['co_ind']]), observation, self._migrationSessions.molesSession) 
    103102            if len(ret['co_org']) > 0: 
    104                 createMO_ResponsiblePartyInfoAsCI_Organization(MO_RoleValue.cl_author, [ret['co_org']])                                                          
     103                Moles3EPB.addRelatedPartyInfoToObservation(createMO_ResponsiblePartyInfoAsCI_Organization(MO_RoleValue.cl_coinvestigator, [ret['co_org']]), observation, self._migrationSessions.molesSession)                                                           
    105104        else: 
    106105            raise NoAssociatedAuthor(doc_authors['authors'], migrationObject = whereAreAuthors) 
    107  
    108  
    109     def _extractIndividualsAndOrganizations(self, tmp_auth, whereAreAuthors):    
    110         ret = {'ind': [], 'org': [], 'co_ind': [], 'co_org': []} 
    111         if tmp_auth['type'] == 'ind': 
    112             ret['ind'].append(tmp_auth['author']) 
    113         elif tmp_auth['type'] == 'org': 
    114             ret['org'].append(tmp_auth['author']) 
    115          
    116         if tmp_auth['author'] == 'unknown': 
    117             DeploymentProcessor.log.info("%s %s %s has unknown author" % (whereAreAuthors.doc_status, whereAreAuthors.doc_owner, whereAreAuthors.doc_name))         
    118    
    119         for item in tmp_auth['co_author_type']: 
    120             if item == 'ind': 
    121                 ret['ind'].append(tmp_auth['co_author'].index(item)) 
    122             elif item == 'org': 
    123                 ret['org'].append(tmp_auth['co_author'].index(item)) 
    124          
    125             if (tmp_auth['co_author'].index(item) == 'unknown'): 
    126                 DeploymentProcessor.log.info("%s %s %s has unknown author" % (whereAreAuthors.doc_status, whereAreAuthors.doc_owner, whereAreAuthors.doc_name)) 
     106         
     107        if doc_authors['contributors'] is None: 
     108            return 
     109         
     110        if authors.has_key(doc_authors['contributors']): 
     111            tmp_auth = authors[doc_authors['contributors']]             
     112            ret = self._extractIndividualsAndOrganizations(tmp_auth, whereAreAuthors) 
     113            if len(ret['ind']) > 0: 
     114                Moles3EPB.addRelatedPartyInfoToObservation(createMO_ResponsiblePartyInfoAsCI_Individual(MO_RoleValue.cl_coinvestigator, [ret['ind']]), observation, self._migrationSessions.molesSession) 
     115            if len(ret['org']) > 0: 
     116                Moles3EPB.addRelatedPartyInfoToObservation(createMO_ResponsiblePartyInfoAsCI_Organization(MO_RoleValue.cl_coinvestigator, [ret['org']]), observation, self._migrationSessions.molesSession)                 
     117            if len(ret['co_ind']) > 0: 
     118                Moles3EPB.addRelatedPartyInfoToObservation(createMO_ResponsiblePartyInfoAsCI_Individual(MO_RoleValue.cl_coinvestigator, [ret['co_ind']]), observation, self._migrationSessions.molesSession) 
     119            if len(ret['co_org']) > 0: 
     120                Moles3EPB.addRelatedPartyInfoToObservation(createMO_ResponsiblePartyInfoAsCI_Organization(MO_RoleValue.cl_coinvestigator, [ret['co_org']]), observation, self._migrationSessions.molesSession)                                         
     121        else: 
     122            raise NoAssociatedAuthor(doc_authors['contributors'], migrationObject = whereAreAuthors) 
     123 
     124 
     125    def _extractIndividualsAndOrganizations(self, tmp_auth, whereAreAuthors): 
     126        try: 
     127            ret = {'ind': [], 'org': [], 'co_ind': [], 'co_org': []} 
     128            if tmp_auth['type'] == 'ind': 
     129                ret['ind'].append(tmp_auth['author']) 
     130            elif tmp_auth['type'] == 'org': 
     131                ret['org'].append(tmp_auth['author']) 
     132             
     133            if tmp_auth['author'] == 'unknown': 
     134                DeploymentProcessor.log.info("%s %s %s has unknown author" % (whereAreAuthors.doc_status, whereAreAuthors.doc_owner, whereAreAuthors.doc_name))         
     135                   
     136            for item in tmp_auth['co_author_type']: 
     137                if item == 'ind': 
     138                    ret['ind'].append(tmp_auth['co_author'][tmp_auth['co_author_type'].index(item)]) 
     139                elif item == 'org': 
     140                    ret['org'].append(tmp_auth['co_author'][tmp_auth['co_author_type'].index(item)]) 
     141             
     142                if (tmp_auth['co_author'][tmp_auth['co_author_type'].index(item)] == 'unknown'): 
     143                    DeploymentProcessor.log.info("%s %s %s has unknown author" % (whereAreAuthors.doc_status, whereAreAuthors.doc_owner, whereAreAuthors.doc_name)) 
     144        except Exception as e: 
     145            print e 
    127146        return ret 
    128147 
     
    138157        if doc_title.startswith('deployment_'): 
    139158            doc_title = extractTitle(self._dataEntityMigration)         
    140         Moles3EPB.addDataLineageToObservation(createMD_Identifier(title = "Data from %s" % (doc_title)), observation, self._migrationSessions.molesSession) 
     159        Moles3EPB.addIdentifierToObservation(createMD_Identifier(code = "Data from %s" % (doc_title), title = 'ceda_title'), observation, self._migrationSessions.molesSession) 
    141160 
    142161    def _assignDescription(self, observation): 
  • mauRepo/MolesManager/trunk/src/libs/migration/tests/migrationprocess.py

    r8147 r8158  
    3131        lr = LoadResources() 
    3232        ex = [] 
    33         #ex = lr.process() 
     33        ex = lr.process() 
    3434        for e in ex: 
    3535            print e 
     
    4343        dataEntity.doc_owner = DO_BADC 
    4444        dataEntity.doc_name = 'dataent_csip.atom' 
     45        #dataEntity.doc_name = 'DE_dcaa78b2-4008-11e0-88c9-00e081470265.atom' 
    4546         
    46         ex = mp.process(dataEntity) 
     47        #ex = mp.process(dataEntity) 
     48        ex = mp.process() 
    4749        for e in ex: 
    4850            print e 
Note: See TracChangeset for help on using the changeset viewer.