source: mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment_data.py @ 8091

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

The migration process now includes
1) deployment_data files
2) XML document hash
3) full Dojo support


Line 
1'''
2Created on 13 Feb 2012
3
4@author: mnagni
5'''
6from libs.migration.processor.commons import findLinksInDeployment,\
7    findSubTypeInDPT, hasAtomDocumentSameHash, getAtomDocumentHashByMO
8from libs.migration.MigrationEPB import MigrationEPB
9from ea_model.ceda_metadatamodel.ceda_computation.ceda_processing import CEDA_Processing
10from ea_model.ceda_metadatamodel.ceda_acquisition.ceda_instrument import CEDA_Instrument
11from ea_model.ceda_metadatamodel.ceda_observationprocess.ceda_compositeprocess import CEDA_CompositeProcess
12from ea_model.ceda_metadatamodel.ceda_acquisition.ceda_acquisition import CEDA_Acquisition
13from libs.epb import EPB
14from MolesManager.moles3epb import Moles3EPB
15
16class DeploymentDataProcessor(object):
17   
18    def __init__(self, deploymentMigration, migrationSessions):
19        self._migrationSessions = migrationSessions
20        self._deploymentMigration = deploymentMigration
21       
22    def _processCEDA_Processing(self, dataProductionTool):
23        if dataProductionTool and hasattr(dataProductionTool, 'ceda_processing_id'):
24            return EPB.searchOrCreate(CEDA_Processing, self._migrationSessions.molesSession, dataProductionTool.ceda_processing_id)
25
26    def _processCEDA_Instrument(self, dataProductionTool):
27        if dataProductionTool and hasattr(dataProductionTool, 'ceda_instrument_id'):       
28            return EPB.searchOrCreate(CEDA_Instrument, self._migrationSessions.molesSession, dataProductionTool.ceda_instrument_id)
29   
30    def _processCEDA_CompositeProcess(self, observationStation):
31        if observationStation and hasattr(observationStation, 'ceda_compositeprocess_id'):       
32            return EPB.searchOrCreate(CEDA_CompositeProcess, self._migrationSessions.molesSession, observationStation.ceda_compositeprocess_id)       
33
34    def _processCEDA_Acquisition(self, observationStation):
35        if observationStation and hasattr(observationStation, 'ceda_acquisition_id'):       
36            return EPB.searchOrCreate(CEDA_Acquisition, self._migrationSessions.molesSession, observationStation.ceda_acquisition_id)       
37       
38    def _assignProcess(self):
39        links = findLinksInDeployment(self._deploymentMigration)
40        associateWithCedaObservation = None
41        hasCedaProcessing = False
42        hasCedaComposite = False
43        hasCedaAcquisition = False
44        for dpt in links['DPT']:
45            dataProductionTool = MigrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, dpt + '.atom', self._migrationSessions.migrationSession)
46           
47            #has the document changed?           
48            if hasAtomDocumentSameHash(dataProductionTool):
49                dataProductionTool.doc_hash = getAtomDocumentHashByMO(self._deploymentMigration)
50                self._migrationSessions.migrationSession.commit()
51                continue
52           
53            subType = findSubTypeInDPT(dataProductionTool)
54            if subType == 'model':
55                ret = self._processCEDA_Processing(dataProductionTool)
56                Moles3EPB.addCedaObject(ret, self._migrationSessions.molesSession, True)
57                dataProductionTool.ceda_processing_id = ret.id
58                self._migrationSessions.migrationSession.commit()               
59                if not (hasCedaComposite or hasCedaProcessing):
60                    associateWithCedaObservation = ret
61                    hasCedaProcessing = True
62                    hasCedaComposite = False
63                    hasCedaAcquisition = False 
64            else:
65                ret = self._processCEDA_Instrument(dataProductionTool)
66                Moles3EPB.addCedaObject(ret, self._migrationSessions.molesSession, True)
67                dataProductionTool.ceda_instrument_id = ret.id
68                self._migrationSessions.migrationSession.commit() 
69               
70               
71        #if not a DPT.subType == 'model' then....
72        for obs in links['OBS']:
73            observationStation = MigrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, obs + '.atom', self._migrationSessions.migrationSession)
74 
75            #has the document changed?           
76            if hasAtomDocumentSameHash(observationStation):
77                observationStation.doc_hash = getAtomDocumentHashByMO(self._deploymentMigration)
78                self._migrationSessions.migrationSession.commit()
79                continue                       
80           
81            subType = findSubTypeInDPT(observationStation)
82            if subType == 'satellite':
83                ret = self._processCEDA_CompositeProcess(observationStation)
84                Moles3EPB.addCedaObject(ret, self._migrationSessions.molesSession, True)               
85                observationStation.ceda_compositeprocess_id = ret.id
86                self._migrationSessions.migrationSession.commit()                               
87                if not hasCedaComposite:
88                    associateWithCedaObservation = ret
89                    hasCedaProcessing = True
90                    hasCedaComposite = False
91                    hasCedaAcquisition = False                   
92            else:
93                ret = self._processCEDA_Acquisition(observationStation)
94                Moles3EPB.addCedaObject(ret, self._migrationSessions.molesSession, True)
95                observationStation.ceda_acquisition_id = ret.id
96                self._migrationSessions.migrationSession.commit()               
97                if not (hasCedaComposite or hasCedaProcessing or hasCedaAcquisition):
98                    associateWithCedaObservation = ret
99                    hasCedaProcessing = True
100                    hasCedaComposite = False
101                    hasCedaAcquisition = True
102       
103        return associateWithCedaObservation                   
104       
105    def process(self):
106        return self._assignProcess()         
107       
Note: See TracBrowser for help on using the repository browser.