1 | ''' |
---|
2 | Created on 13 Feb 2012 |
---|
3 | |
---|
4 | @author: mnagni |
---|
5 | ''' |
---|
6 | from libs.migration.processor.commons import findLinksInDeployment,\ |
---|
7 | findSubTypeInDPT, hasAtomDocumentSameHash, getAtomDocumentHashByMO,\ |
---|
8 | createCEDA_Processing, createCEDA_Instrument, createCEDA_Project,\ |
---|
9 | findSummary |
---|
10 | from libs.migration.MigrationEPB import MigrationEPB |
---|
11 | from MolesManager.moles3epb import Moles3EPB |
---|
12 | from ea_model.moles3_4.utilities.mo_publicationstatevalue import MO_PublicationStateValue |
---|
13 | |
---|
14 | class DeploymentDataProcessor(object): |
---|
15 | |
---|
16 | def __init__(self, deploymentMigration, migrationSessions): |
---|
17 | self._migrationSessions = migrationSessions |
---|
18 | self._deploymentMigration = deploymentMigration |
---|
19 | |
---|
20 | def _commitDeploymentMigration(self, associateWithCedaObservation, dataProductionTool, dataProductionToolField): |
---|
21 | Moles3EPB.addCedaObject(associateWithCedaObservation, self._migrationSessions.molesSession, True) |
---|
22 | setattr(dataProductionTool, dataProductionToolField, associateWithCedaObservation.id) |
---|
23 | self._migrationSessions.migrationSession.commit() |
---|
24 | |
---|
25 | def createProject(self, links): |
---|
26 | project = None |
---|
27 | if links.has_key('ACTIVITY'): |
---|
28 | for link in links['ACTIVITY']: |
---|
29 | activity = MigrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, link + '.atom', self._migrationSessions.migrationSession) |
---|
30 | i_abstract = findSummary(activity) |
---|
31 | project = createCEDA_Project(abstract=i_abstract, publication_state=MO_PublicationStateValue.cl_working) |
---|
32 | self._commitDeploymentMigration(project, activity, 'ceda_project_id') |
---|
33 | return project |
---|
34 | |
---|
35 | def createProcess(self, links): |
---|
36 | associateWithCedaObservation = None |
---|
37 | hasCedaProcessing = False |
---|
38 | hasCedaComposite = False |
---|
39 | hasCedaAcquisition = False |
---|
40 | for dpt in links['DPT']: |
---|
41 | dataProductionTool = MigrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, dpt + '.atom', self._migrationSessions.migrationSession) |
---|
42 | |
---|
43 | #has the document changed? |
---|
44 | #if hasAtomDocumentSameHash(dataProductionTool): |
---|
45 | # dataProductionTool.doc_hash = getAtomDocumentHashByMO(self._deploymentMigration) |
---|
46 | # self._migrationSessions.migrationSession.commit() |
---|
47 | # continue |
---|
48 | |
---|
49 | subType = findSubTypeInDPT(dataProductionTool) |
---|
50 | if subType == 'model': |
---|
51 | associateWithCedaObservation = createCEDA_Processing() |
---|
52 | self._commitDeploymentMigration(associateWithCedaObservation, dataProductionTool, 'ceda_processing_id') |
---|
53 | if not (hasCedaComposite or hasCedaProcessing): |
---|
54 | hasCedaProcessing = True |
---|
55 | hasCedaComposite = False |
---|
56 | hasCedaAcquisition = False |
---|
57 | else: |
---|
58 | associateWithCedaObservation = createCEDA_Instrument() |
---|
59 | self._commitDeploymentMigration(associateWithCedaObservation, dataProductionTool, 'ceda_instrument_id') |
---|
60 | |
---|
61 | |
---|
62 | #if not a DPT.subType == 'model' then.... |
---|
63 | for obs in links['OBS']: |
---|
64 | observationStation = MigrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, obs + '.atom', self._migrationSessions.migrationSession) |
---|
65 | |
---|
66 | #has the document changed? |
---|
67 | #if hasAtomDocumentSameHash(observationStation): |
---|
68 | # observationStation.doc_hash = getAtomDocumentHashByMO(self._deploymentMigration) |
---|
69 | # self._migrationSessions.migrationSession.commit() |
---|
70 | # continue |
---|
71 | |
---|
72 | subType = findSubTypeInDPT(observationStation) |
---|
73 | if subType == 'satellite': |
---|
74 | associateWithCedaObservation = createCEDA_Processing() |
---|
75 | self._commitDeploymentMigration(associateWithCedaObservation, dataProductionTool, 'ceda_compositeprocess_id') |
---|
76 | if not hasCedaComposite: |
---|
77 | hasCedaProcessing = True |
---|
78 | hasCedaComposite = False |
---|
79 | hasCedaAcquisition = False |
---|
80 | else: |
---|
81 | pass |
---|
82 | ''' |
---|
83 | associateWithCedaObservation = createCEDA_Acquisition() |
---|
84 | self._commitDeploymentMigration(associateWithCedaObservation, dataProductionTool, 'ceda_acquisition_id') |
---|
85 | ''' |
---|
86 | if not (hasCedaComposite or hasCedaProcessing or hasCedaAcquisition): |
---|
87 | hasCedaProcessing = True |
---|
88 | hasCedaComposite = False |
---|
89 | hasCedaAcquisition = True |
---|
90 | return associateWithCedaObservation |
---|
91 | |
---|