Ignore:
Timestamp:
12/12/11 14:22:25 (8 years ago)
Author:
mnagni
Message:

implemented a prototype for the cedaObservation.
Further implementation for the Moles2 migration

Location:
mauRepo/MolesManager/trunk/src
Files:
1 added
1 deleted
8 edited
1 moved

Legend:

Unmodified
Added
Removed
  • mauRepo/MolesManager/trunk/src/MolesManager/dataaccess.py

    r8014 r8015  
    2525def getCEDA_ObservationById(id, session = None):      
    2626    session = _checkSession(session) 
    27     res = session.query(CEDA_Observation).filter(*[_buildFilter('mo_observation_id', id)]) 
     27    res = session.query(CEDA_Observation).filter(*[_buildFilter('ceda_observation_id', id)]) 
    2828    print(res) 
    2929    return res.all() 
  • mauRepo/MolesManager/trunk/src/MolesManager/urls.py

    r7970 r8015  
    1717) 
    1818 
    19 urlpatterns += patterns('MolesManager.views.dateView', 
    20     (r'^date/$', 'dateView'), 
     19urlpatterns += patterns('MolesManager.views.cedaObservationView', 
     20    (r'^cov/$', 'coView'), 
    2121) 
  • mauRepo/MolesManager/trunk/src/MolesManager/views/cedaObservationView.py

    r7976 r8015  
    44@author: mnagni 
    55''' 
    6 from MolesManager.dataaccess import getDateById 
     6from MolesManager.dataaccess import getCEDA_ObservationById 
    77from MolesManager.forms.date import createForm 
    88from django.shortcuts import render_to_response 
     
    1818    return sampleForm 
    1919    ''' 
    20     dp = getDateById(1) 
     20    dp = getCEDA_ObservationById(1) 
    2121    return createForm(dp[0]) 
    22 def dateView(request): 
     22def coView(request): 
    2323    c = {} 
    2424    form = __getSample(request) 
    25     c['form'] = form 
     25    c['coObs'] = form 
    2626     
    2727    c.update(csrf(request)) 
    28     return render_to_response('date.html', c) 
     28    return render_to_response('cedaObservation.html', c) 
  • mauRepo/MolesManager/trunk/src/libs/migration/client.py

    r8014 r8015  
    2424''' 
    2525 
    26  
     26''' 
    2727lr = LoadResources(session) 
    2828lr.process() 
     29''' 
     30 
     31sorted_data_ents = getObservationCollectionMigrationOrderByDate(session) 
     32exs = [] 
     33#loops over the sorted data entities 
     34for de in sorted_data_ents:     
     35    de_path = '%s/%s' % (de.exist_path, de.data_ent_name) 
     36    dep = DataEntityProcessor(de_path, session) 
     37    exs.append(dep.process())     
     38    session.commit() 
     39print exs     
    2940 
    3041 
    31 sorted_data_ents = getObservationCollectionMigrationOrderByDate(session) 
    32 #loops over the sorted data entities 
    33 for de in sorted_data_ents: 
    34     de_path = '%s/%s' % (de.exist_path, de.data_ent_name) 
    35     dep = DataEntityProcessor(de_path, session) 
    36     dep.process()     
    37     session.commit() 
    38  
    39  
  • mauRepo/MolesManager/trunk/src/libs/migration/db/migrationTables.py

    r8014 r8015  
    99from libs.migration.db.classes import ObservationCollectionMigration,\ 
    1010    ObservationMigration 
    11          
     11 
     12''' 
     13Connects a dataEntity to its associated CEDA_Observation_Collection 
     14'''         
    1215obs_coll_migration = Table('obs_coll_migration', metadata, 
    1316            Column('data_ent_id', TEXT, primary_key=True, nullable=False), 
     
    1821        ) 
    1922 
     23''' 
     24Connects a deployment to its associated CEDA_Observation 
     25''' 
    2026observation_migration = Table('observation_migration', metadata, 
    2127            Column('depl_id', TEXT, primary_key=True, nullable=False), 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/commons.py

    r8014 r8015  
    103103 
    104104 
    105 def createMO_ResponsiblePartyInfoAsCI_Organization(role, name): 
     105def createMO_ResponsiblePartyInfoAsCI_Organization(role, names): 
     106    ''' 
     107        @param role: a CI_RoleCode/MO_RoleValue assigned to this ResponsibleParty 
     108        @param names: the list of CI_Party names 
     109    ''' 
    106110    mo_responsableInfo = MO_ResponsiblePartyInfo() 
    107111    mo_responsableInfo.party = []     
    108112    mo_responsableInfo.role = role 
    109     ci_org = CI_Organisation() 
    110     ci_org.name = name 
    111     mo_responsableInfo.party.append(ci_org) 
     113    for name in names: 
     114        ci_org = CI_Organisation() 
     115        ci_org.name = name 
     116        mo_responsableInfo.party.append(ci_org) 
    112117    return mo_responsableInfo 
    113118 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/dataEntity.py

    r8014 r8015  
    8282     
    8383    def process(self): 
    84         self.resource = getXMLDocument(self._de_path) 
     84        exs = [] 
     85        #Retrieve the DataEntity 
     86        self.dataEntity = getXMLDocument(self._de_path) 
    8587        #extracts the dataentity deployments  
    86         self._depls = findDeploymentsInDE(self.resource) 
     88        self._depls = findDeploymentsInDE(self.dataEntity) 
    8789        #loops over the deployments  
    8890        for deplName in self._depls: 
     
    9799                depl.process() 
    98100            except NoDataLineage as ex: 
     101                exs.append(ex) 
    99102                print ex 
     103        return exs;         
     104         
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment.py

    r8014 r8015  
    55''' 
    66from libs.migration.processor.commons import getXMLDocument,\ 
    7     createMO_ResponsiblePartyInfoAsCI_Organization, findMolesLineage 
     7    createMO_ResponsiblePartyInfoAsCI_Organization, findMolesLineage,\ 
     8    findAuthorInResource 
    89from libs.migration.db.dbConnection import findCEDAObservationByDeplID 
    910from ea_model.ceda_moles.ceda_observation.ceda_observation import CEDA_Observation 
     
    2526    '''     
    2627     
    27     def __init__(self, deplObj, dataEntity): 
     28    def __init__(self, deplObj, deProcessor): 
    2829        ''' 
    2930            Initializes the class 
    3031            @param deplObj: a ObservationMigration entity 
    31             @param dataEntity: the associated DataEntityProcessor 
     32            @param deProcessor: the associated DataEntityProcessor 
    3233        '''               
    3334        self._deplObj = deplObj 
    34         self._dataEntity = dataEntity 
    35  
    36     ''' 
    37     def _createCEDA_Observation(self, resource): 
    38             self._de_path = '%s/%s' % (deplObj.exist_path, deplObj.depl_name) 
    39         author = findAuthorInResource(resource) 
    40         id = findDEorDepl_ID(resource) 
    41         ceda_observation = CEDA_Observation() 
    42         ceda_observation.relatedParty = [] 
    43         ceda_observation.identifier = []         
    44         ceda_observation.relatedParty.append(createMO_ResponsiblePartyInfo(author)) 
    45         ceda_observation.identifier.append(createMD_Identifier(id)) 
    46         return ceda_observation 
    47     ''' 
     35        self._deProcessor = deProcessor 
    4836 
    4937    def _existsCEDAasPublisher(self): 
     
    5543        return False 
    5644                     
    57              
     45    def _extractResponsiblePartyInfo(self, authors): 
     46        ''' 
     47            @param authors: a list of authors (after the first are considered co-authors) 
     48        ''' 
     49        if not authors: 
     50            return 
     51         
     52        parsedParties = [] 
     53        if (len(set(authors) & set(['badc.nerc.ac.uk', 'neodc.rl.ac.uk'])) > 0): 
     54            parsedParties.append(self._createResponsibleParty('Centre for Environmental Data Archive', MO_RoleValue.cl_curator)) 
     55            authorsCSV = findAuthorInResource(self._deProcessor.dataEntity) 
     56            if (authorsCSV): 
     57                authors = authorsCSV.split(',') 
     58            else: 
     59                return         
     60        #First is assumend to be the author  
     61        parsedParties.append(self._createResponsibleParty(authors[0], MO_RoleValue.cl_author)) 
     62        if (authors.remove(authors[0])): 
     63            for coauthor in authors.remove(authors[0]): 
     64                parsedParties.append(self._createResponsibleParty(coauthor, MO_RoleValue.cl_author)) 
    5865 
    59     def _assignName(self):         
     66        return parsedParties             
     67 
     68    def _createResponsibleParty(self, name, role): 
     69        ''' 
     70            @param name: The CI_Party names 
     71            @param role: The assigned role             
     72        ''' 
     73        return createMO_ResponsiblePartyInfoAsCI_Organization(name, role) 
     74 
     75    def _assignName(self, relatedPartyInfos): 
     76        ''' 
     77            @param relatedPartyInfos: a MO_ResponsiblePartyInfo list 
     78        '''         
     79        authorCSV = findAuthorInResource(self._deployment) 
     80        if (not authorCSV): 
     81            return 
     82        newResponsiblePartyInfos = self._extractResponsiblePartyInfo(authorCSV.split(',')) 
     83        #This methods check prepare the insert/update of the responsiblePartyInfos 
     84        self._checkResponsiblePartyExist(relatedPartyInfos, newResponsiblePartyInfos) 
     85        for newResponsiblePartyInfo in newResponsiblePartyInfos: 
     86            self._addResponsiblePartyInfo(relatedPartyInfos, newResponsiblePartyInfo) 
     87         
     88        ''' 
    6089        if not self._existsCEDAasPublisher(): 
    61             print dir(self._ceda_observation.relatedParty) 
    6290            rp = self._ceda_observation.relatedParty 
    63             rp.append(createMO_ResponsiblePartyInfoAsCI_Organization(MO_RoleValue.cl_publisher, DeploymentProcessor.publisherName))     
     91            rp.append(createMO_ResponsiblePartyInfoAsCI_Organization(MO_RoleValue.cl_publisher, DeploymentProcessor.publisherName)) 
     92        ''' 
     93 
     94    def _addResponsiblePartyInfo(self, oldResponsiblePartyInfos, newResponsiblePartyInfo): 
     95        for oldPartyInfo in oldResponsiblePartyInfos: 
     96            if oldPartyInfo.role == newResponsiblePartyInfo.role: 
     97                oldPartyInfo.party.append(newResponsiblePartyInfo.party) 
     98 
     99 
     100    def _checkResponsiblePartyExist(self, oldResponsiblePartyInfos, newResponsiblePartyInfos): 
     101        ''' 
     102            Compares two MO_ResponsiblePartyInfo lists. For each MO_ResponsiblePartyInfo in the oldResponsiblePartyInfos it 
     103            - deletes it from the oldResponsiblePartyInfos if it does NOT exists in the newResponsiblePartyInfos 
     104            - deletes it from the newResponsiblePartyInfos if it does exists in the newResponsiblePartyInfos 
     105            @param oldResponsiblePartyInfos: the old MO_ResponsiblePartyInfo list 
     106            @param newResponsiblePartyInfos: the new MO_ResponsiblePartyInfo list 
     107        '''                        
     108        for oldPartyInfo in oldResponsiblePartyInfos: 
     109            exists = False 
     110            for newPartyInfo in newResponsiblePartyInfos: 
     111                if oldPartyInfo.role == newPartyInfo.role: 
     112                    exists = True 
     113                    self._checkPartyExist(oldPartyInfo, newPartyInfo) 
     114            if not exists: 
     115                oldResponsiblePartyInfos.remove(oldPartyInfo)             
     116                             
     117    def _checkPartyExist(self, oldPartyInfo, newPartyInfo): 
     118        ''' 
     119            Compares two MO_ResponsiblePartyInfo-s. For each CI_Party in the oldPartyInfo it 
     120            - deletes it from the oldPartyInfo if it does NOT exists in the newPartyInfo 
     121            - deletes it from the newPartyInfo if it does exists in the oldPartyInfo 
     122            @param oldPartyInfo: the old MO_ResponsiblePartyInfo 
     123            @param newPartyInfo: the new MO_ResponsiblePartyInfo   
     124        ''' 
     125        for oldParty in oldPartyInfo: 
     126            exists = False 
     127            for newParty in newPartyInfo:                 
     128                if oldParty.name == newParty.name: 
     129                    exists = True                     
     130                    newPartyInfo.remove(newParty) 
     131            oldPartyInfo.remove(oldParty)  
    64132 
    65133    def _assignLineage(self): 
    66         self._ceda_observation.dataLineage = findMolesLineage(self._dataEntity.resource) 
     134        self._ceda_observation.dataLineage = findMolesLineage(self._deProcessor.dataEntity) 
    67135        if self._ceda_observation.dataLineage is None: 
    68136            raise NoDataLineage(self._de_path) 
    69137         
    70138         
    71     def _processObj(self): 
    72         self._assignName() 
     139    def _processObj(self, cedaObservation): 
     140        ''' 
     141            @param  cedaObservation: a relatedPartiesInfo instance  
     142        ''' 
     143        self._assignName(cedaObservation.relatedParty) 
    73144        self._assignLineage() 
    74145         
     
    78149        print    self._de_path 
    79150        #retrieves the deployment'd document          
    80         self._resource = getXMLDocument(self._de_path) 
     151        self._deployment = getXMLDocument(self._de_path) 
    81152        self._ceda_observation = None 
    82153        isUpdate = True 
    83         #Exists already an associated CEDA_Observation? 
     154        #Exists already an associated CEDA_Observation associated to this deployment? 
    84155        if self._deplObj is not None and self._deplObj.obs_id is not None: 
    85             self._ceda_observation = findCEDAObservationByDeplID(self._deplObj.obs_id, self._dataEntity.session) 
     156            self._ceda_observation = findCEDAObservationByDeplID(self._deplObj.obs_id, self._deProcessor.session) 
    86157 
    87158        #If does not exist creates a new one             
     
    92163 
    93164        #fills/update the CEDA_Observation                         
    94         self._processObj() 
     165        self._processObj(self._ceda_observation) 
    95166        #insert/update the CEDA_Observation 
    96         doInsertOrUpdate([self._ceda_observation], self._dataEntity.session, isUpdate) 
    97         self._dataEntity.session.commit() 
     167        doInsertOrUpdate([self._ceda_observation], self._deProcessor.session, isUpdate) 
     168        self._deProcessor.session.commit() 
    98169        self._deplObj.obs_id = self._ceda_observation.ceda_observation_id 
    99         doInsertOrUpdate([self._deplObj], self._dataEntity.session, True) 
    100         self._dataEntity.session.commit() 
     170        doInsertOrUpdate([self._deplObj], self._deProcessor.session, True) 
     171        self._deProcessor.session.commit() 
    101172        return self._ceda_observation 
    102173 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/loadResources.py

    r8014 r8015  
    104104             
    105105    def process(self): 
     106        ''' 
     107            docStatus = ('published', 'working', 'Published')  
     108        ''' 
    106109        for status in docStatus:            
    107110            baseStatus = '%s/%s' % (base, status) 
Note: See TracChangeset for help on using the changeset viewer.