source: mauRepo/MolesManager/trunk/src/libs/migration/processor/dataEntity.py @ 8015

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/src/libs/migration/processor/dataEntity.py@8015
Revision 8015, 3.6 KB checked in by mnagni, 9 years ago (diff)

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

Line 
1'''
2Created on 15 Nov 2011
3
4@author: mnagni
5'''
6from libs.migration.processor.deployment import DeploymentProcessor
7from libs.migration.exception.exceptions import NoAssociatedDeployments,\
8    NoDataLineage
9from libs.migration.processor.commons import getResource, findDeploymentsInDE,\
10    getResourceRefs, getDocument, getXMLDocument
11from libs.migration.db.dbConnection import getObservationMigrationByName
12
13class DataEntityProcessor(object):
14    '''
15        Processes a DataEntity item.
16        @var _de_path: the full eXist path
17        @var session: an sqlAlchemy Session
18        @var resource: an elementTree Element representing XML document processed by this instance
19        @var _depl: a list of Deployment items associated with this DataEntity   
20    '''   
21   
22    def __init__(self, de_path, session):
23        '''
24            Initializes the class
25            @param de_path: the full eXist path
26            @param session: an sqlAlchemy Session
27        '''         
28        self._de_path = de_path
29        self.session = session
30        self.resource = None
31        self._depls = 0       
32
33    def _createCEDA_Observation(self, resource):
34        '''
35        author = findAuthorInResource(resource)
36        id = findDEorDepl_ID(resource)
37        mo_obs_coll = CEDA_ObservationCollection()
38        mo_obs_coll.relatedParty = []
39        mo_obs_coll.identifier = []       
40        mo_obs_coll.relatedParty.append(createMO_ResponsiblePartyInfo(author))
41        mo_obs_coll.identifier.append(createMD_Identifier(id))
42        return mo_obs_coll
43        '''
44
45    def _getIfExists(self, resource):
46        '''
47        id = findDEorDepl_ID(resource)
48        '''
49
50    def _ingestDataEntity(self, base, owner):
51        resource = getResource(base, owner)
52       
53        self._getIfExists(resource)
54       
55        deplNames = findDeploymentsInDE(resource)
56        if len(deplNames) == 0:
57            raise NoAssociatedDeployments('%s/%s' % (base, owner))
58        ceda_observations = []
59        for deplName in deplNames:
60            deplProcessor = DeploymentProcessor(self._baseStatus, self._owner, deplName)
61            ceda_observations.append(deplProcessor.process())
62        mo_obs_coll = self._createCEDA_Observation(resource)
63        mo_obs_coll.member = ceda_observations
64        '''
65        Do Insert or doUpdate???
66        doInsert(mo_obs_coll, self._session)
67        '''
68       
69        print mo_obs_coll
70       
71
72    def _processDataEntity(self): 
73        baseOwner = '%s/%s' % (self._baseDE, self._owner)       
74        refs = getResourceRefs(baseOwner)
75        for ref in refs:
76            refName = ref.get('name')
77            try:
78                self._ingestDataEntity(baseOwner, refName)
79            except NoAssociatedDeployments as dee:
80                print dee
81           
82   
83    def process(self):
84        exs = []
85        #Retrieve the DataEntity
86        self.dataEntity = getXMLDocument(self._de_path)
87        #extracts the dataentity deployments
88        self._depls = findDeploymentsInDE(self.dataEntity)
89        #loops over the deployments
90        for deplName in self._depls:
91            #retrieve the deployment's path
92            deplObj = getObservationMigrationByName(deplName + '.atom', self.session)           
93            if deplObj is None:
94                print "cannot find deployment %s for resource %s" % (deplName, self._de_path)
95                continue                             
96            depl = DeploymentProcessor(deplObj, self)
97            try:
98                #Processes the deployment
99                depl.process()
100            except NoDataLineage as ex:
101                exs.append(ex)
102                print ex
103        return exs;       
104       
Note: See TracBrowser for help on using the repository browser.