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

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

Major refactoring about migration (now handles better create/update, even if the single updates have to be quite fully implemented)
Added the connection pool from SQLAlchemy

Line 
1'''
2BSD Licence
3Copyright (c) 2012, Science & Technology Facilities Council (STFC)
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without modification,
7are permitted provided that the following conditions are met:
8
9    * Redistributions of source code must retain the above copyright notice,
10        this list of conditions and the following disclaimer.
11    * Redistributions in binary form must reproduce the above copyright notice,
12        this list of conditions and the following disclaimer in the documentation
13        and/or other materials provided with the distribution.
14    * Neither the name of the Science & Technology Facilities Council (STFC)
15        nor the names of its contributors may be used to endorse or promote
16        products derived from this software without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29Created on 13 Feb 2012
30
31@author: Maurizio Nagni
32'''
33from libs.migration.processor.commons import findSubTypeInDPT,\
34    createCEDA_Processing, createCEDA_Instrument, createCEDA_Project,\
35    findSummary, findDocumentationInMigrationDocument, createCI_Citation,\
36    createMO_OnlineResource, findLinksInDeployment
37from ea_model.moles3_4.utilities.mo_publicationstatevalue import MO_PublicationStateValue
38
39class DeploymentDataProcessor(object):
40   
41    def __init__(self, deploymentMigration, epbRepo):
42        '''
43            @param epbRepo: an instance of EPBRepo
44        '''       
45        self._deploymentMigration = deploymentMigration
46        self.epbRepo = epbRepo       
47        self._links = findLinksInDeployment(self._deploymentMigration)
48       
49    def _commitDeploymentMigration(self, associateWithCedaObservation, dataProductionTool, dataProductionToolField):
50        self.epbRepo.moles3EPB.persistInstance(associateWithCedaObservation)
51        self.epbRepo.migrationEPB.updateMigrationObject(dataProductionTool, {dataProductionToolField: associateWithCedaObservation.id})
52                                   
53       
54    def createProject(self):
55        project = None
56        if self._links.has_key('ACTIVITY'):
57            for link in self._links['ACTIVITY']:
58                activity = self.epbRepo.migrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, link + '.atom')
59                i_abstract = findSummary(activity)
60                doc_link = findDocumentationInMigrationDocument(activity)
61                i_documentation = None
62                i_resource = None
63                if doc_link and len(doc_link) == 1:
64                    i_documentation = createCI_Citation("Documentation resource")
65                    i_resource = createMO_OnlineResource(doc_link[0]['href'])
66                project = createCEDA_Project(abstract=i_abstract, publication_state=MO_PublicationStateValue.cl_working, \
67                                             documentation=i_documentation, project_resource=i_resource)
68                self._commitDeploymentMigration(project, activity, 'ceda_project_id')
69        return project
70       
71    def createProcess(self):
72        associateWithCedaObservation = None
73        hasCedaProcessing = False
74        hasCedaComposite = False
75        hasCedaAcquisition = False
76        for dpt in self._links['DPT']:
77            dataProductionTool = self.epbRepo.migrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, dpt + '.atom')
78           
79            #has the document changed?           
80            #if hasMOSameHash(dataProductionTool):
81            #    dataProductionTool.doc_hash = getAtomDocumentHashByMO(self._deploymentMigration)
82            #    self._migrationSessions.migrationSession.commit()
83            #    continue
84           
85            subType = findSubTypeInDPT(dataProductionTool)
86           
87            if subType == 'model':
88                #MigrationEPB.loadAttributes(dataProductionTool, 'ceda_processing_id')
89                if dataProductionTool.ceda_processing_id is None:
90                    associateWithCedaObservation = createCEDA_Processing()
91                    self._commitDeploymentMigration(associateWithCedaObservation, dataProductionTool, 'ceda_processing_id')
92                    if not (hasCedaComposite or hasCedaProcessing):
93                        hasCedaProcessing = True
94                        hasCedaComposite = False
95                        hasCedaAcquisition = False
96                else:
97                    #should update
98                    pass 
99            else: 
100                #MigrationEPB.loadAttributes(dataProductionTool, 'ceda_instrument_id')
101                if dataProductionTool.ceda_instrument_id is None:
102                    associateWithCedaObservation = createCEDA_Instrument()
103                    self._commitDeploymentMigration(associateWithCedaObservation, dataProductionTool, 'ceda_instrument_id')
104                else:
105                    #should update
106                    pass
107               
108               
109        #if not a DPT.subType == 'model' then....
110        for obs in self._links['OBS']:
111            observationStation = self.epbRepo.migrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, obs + '.atom')
112 
113            #has the document changed?           
114            #if hasMOSameHash(observationStation):
115            #    observationStation.doc_hash = getAtomDocumentHashByMO(self._deploymentMigration)
116            #    self._migrationSessions.migrationSession.commit()
117            #    continue                       
118           
119            subType = findSubTypeInDPT(observationStation)
120            if subType == 'satellite':
121                #MigrationEPB.loadAttributes(dataProductionTool, 'ceda_compositeprocess_id')               
122                if dataProductionTool.ceda_compositeprocess_id is None:
123                    associateWithCedaObservation = createCEDA_Processing()
124                    self._commitDeploymentMigration(associateWithCedaObservation, dataProductionTool, 'ceda_compositeprocess_id')   
125                    if not hasCedaComposite:
126                        hasCedaProcessing = True
127                        hasCedaComposite = False
128                        hasCedaAcquisition = False
129                else:
130                    #should update
131                    pass
132            else:
133                #MigrationEPB.loadAttributes(dataProductionTool, 'ceda_acquisition_id')               
134                if dataProductionTool.ceda_acquisition_id is None:
135                    pass
136                    '''
137                    associateWithCedaObservation = createCEDA_Acquisition()
138                    self._commitDeploymentMigration(associateWithCedaObservation, dataProductionTool, 'ceda_acquisition_id')
139                    '''               
140                else:
141                    #should update
142                    pass
143                    if not (hasCedaComposite or hasCedaProcessing or hasCedaAcquisition):
144                        hasCedaProcessing = True
145                        hasCedaComposite = False
146                        hasCedaAcquisition = True                           
147        return associateWithCedaObservation                           
148       
Note: See TracBrowser for help on using the repository browser.