1 | ''' |
---|
2 | Created on 13 Feb 2012 |
---|
3 | |
---|
4 | @author: mnagni |
---|
5 | ''' |
---|
6 | from libs.migration.processor.commons import findSubTypeInDPT,\ |
---|
7 | createCEDA_Processing, createCEDA_Instrument, createCEDA_Project,\ |
---|
8 | findSummary, findDocumentationInMigrationDocument, createCI_Citation,\ |
---|
9 | createMO_OnlineResource |
---|
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', \ |
---|
30 | self._migrationSessions.migrationSession) |
---|
31 | i_abstract = findSummary(activity) |
---|
32 | doc_link = findDocumentationInMigrationDocument(activity) |
---|
33 | i_documentation = None |
---|
34 | i_resource = None |
---|
35 | if doc_link and len(doc_link) == 1: |
---|
36 | i_documentation = createCI_Citation("Documentation resource") |
---|
37 | i_resource = createMO_OnlineResource(doc_link[0]['href']) |
---|
38 | project = createCEDA_Project(abstract=i_abstract, publication_state=MO_PublicationStateValue.cl_working, \ |
---|
39 | documentation=i_documentation, project_resource=i_resource) |
---|
40 | self._commitDeploymentMigration(project, activity, 'ceda_project_id') |
---|
41 | return project |
---|
42 | |
---|
43 | def createProcess(self, links): |
---|
44 | associateWithCedaObservation = None |
---|
45 | hasCedaProcessing = False |
---|
46 | hasCedaComposite = False |
---|
47 | hasCedaAcquisition = False |
---|
48 | for dpt in links['DPT']: |
---|
49 | dataProductionTool = MigrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, dpt + \ |
---|
50 | '.atom', self._migrationSessions.migrationSession) |
---|
51 | |
---|
52 | #has the document changed? |
---|
53 | #if hasAtomDocumentSameHash(dataProductionTool): |
---|
54 | # dataProductionTool.doc_hash = getAtomDocumentHashByMO(self._deploymentMigration) |
---|
55 | # self._migrationSessions.migrationSession.commit() |
---|
56 | # continue |
---|
57 | |
---|
58 | subType = findSubTypeInDPT(dataProductionTool) |
---|
59 | if subType == 'model': |
---|
60 | associateWithCedaObservation = createCEDA_Processing() |
---|
61 | self._commitDeploymentMigration(associateWithCedaObservation, dataProductionTool, 'ceda_processing_id') |
---|
62 | if not (hasCedaComposite or hasCedaProcessing): |
---|
63 | hasCedaProcessing = True |
---|
64 | hasCedaComposite = False |
---|
65 | hasCedaAcquisition = False |
---|
66 | else: |
---|
67 | associateWithCedaObservation = createCEDA_Instrument() |
---|
68 | self._commitDeploymentMigration(associateWithCedaObservation, dataProductionTool, 'ceda_instrument_id') |
---|
69 | |
---|
70 | |
---|
71 | #if not a DPT.subType == 'model' then.... |
---|
72 | for obs in links['OBS']: |
---|
73 | observationStation = MigrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, obs + \ |
---|
74 | '.atom', self._migrationSessions.migrationSession) |
---|
75 | |
---|
76 | #has the document changed? |
---|
77 | #if hasAtomDocumentSameHash(observationStation): |
---|
78 | # observationStation.doc_hash = getAtomDocumentHashByMO(self._deploymentMigration) |
---|
79 | # self._migrationSessions.migrationSession.commit() |
---|
80 | # continue |
---|
81 | |
---|
82 | subType = findSubTypeInDPT(observationStation) |
---|
83 | if subType == 'satellite': |
---|
84 | associateWithCedaObservation = createCEDA_Processing() |
---|
85 | self._commitDeploymentMigration(associateWithCedaObservation, dataProductionTool, 'ceda_compositeprocess_id') |
---|
86 | if not hasCedaComposite: |
---|
87 | hasCedaProcessing = True |
---|
88 | hasCedaComposite = False |
---|
89 | hasCedaAcquisition = False |
---|
90 | else: |
---|
91 | pass |
---|
92 | ''' |
---|
93 | associateWithCedaObservation = createCEDA_Acquisition() |
---|
94 | self._commitDeploymentMigration(associateWithCedaObservation, dataProductionTool, 'ceda_acquisition_id') |
---|
95 | ''' |
---|
96 | if not (hasCedaComposite or hasCedaProcessing or hasCedaAcquisition): |
---|
97 | hasCedaProcessing = True |
---|
98 | hasCedaComposite = False |
---|
99 | hasCedaAcquisition = True |
---|
100 | return associateWithCedaObservation |
---|
101 | |
---|