source: mauRepo/MolesManager/trunk/src/libs/migration/MigrationEPB.py @ 8269

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

Complete - # 22434: CEDA Observation - keywords (following Gemini method)
 http://team.ceda.ac.uk/trac/ceda/ticket/22434

Line 
1'''
2Created on 10 Jan 2012
3
4@author: mnagni
5'''
6from libs.migration.db.classes import DeploymentDataMigration, DataEntityMigration,\
7    DeploymentsMigration
8from sqlalchemy.sql.expression import asc
9from libs.epb import EPB
10from libs.migration.exception.exceptions import NoDBManager
11
12
13class MigrationEPB(EPB):
14   
15    _migrationDB = None
16   
17    @classmethod
18    def overrrideDBManager(self, dbManager):
19        """
20            Sets the MigrationEPB libs.commons_db.DbManager
21        """
22        MigrationEPB._migrationDB = dbManager
23
24    @classmethod
25    def associateObservationCollectionToDataEntity(self, dataEntityMigration, obs_coll_id, session = None, commit = False):
26        intSession = MigrationEPB._getSession(session)
27        dataEntityMigration.ceda_observation_coll_id = obs_coll_id
28        if commit:
29            intSession.commit()
30
31    @classmethod
32    def associateObservationToDeployment(self, deploymentMigration, obs_id, session = None, commit = False):
33        intSession = MigrationEPB._getSession(session)
34        deploymentMigration.ceda_observation_id = obs_id
35        if commit:
36            intSession.commit()         
37       
38    @classmethod
39    def addMigration(self, migrationObj, session = None):
40        intSession = MigrationEPB._getSession(session)
41        intSession.add(migrationObj)
42        EPB._closeSession(session)       
43
44    @classmethod
45    def getAllDataEntityMigration(self, session = None):
46        intSession = MigrationEPB._getSession(session)   
47        return EPB.getAllObjects(DataEntityMigration, intSession)
48
49    @classmethod       
50    def getDataEntityMigrationOrderByDate(self, session = None):
51        return MigrationEPB.getAllDataEntityMigration(session).order_by(asc("doc_creation"))     
52
53    @classmethod
54    def getAllDeploymentsMigrationByDataEntitySortedByDate(self, dataEntity, deploymentNames, session = None):
55        intSession = MigrationEPB._getSession(session)
56        return EPB.getAllObjects(DeploymentsMigration, intSession).filter(DeploymentsMigration.doc_name.in_(deploymentNames)).order_by(asc("doc_creation"))       
57        #return EPB.getAllObjects(DeploymentsMigration, intSession).filter(*[EPB.buildFilter('doc_owner', dataEntity.doc_owner)]).filter(DeploymentsMigration.doc_name.in_(deploymentNames)).order_by(asc("doc_creation"))       
58        #return EPB.getAllObjects(DeploymentsMigration, intSession).filter(*[EPB.buildFilter('doc_status', dataEntity.doc_status)]).filter(*[EPB.buildFilter('doc_owner', dataEntity.doc_owner)]).filter(DeploymentsMigration.doc_name.in_(deploymentNames)).order_by(asc("doc_creation"))
59
60    @classmethod
61    def _getMigrationObject(self, mo_type, doc_status, doc_owner, doc_name, session = None):
62        intSession = MigrationEPB._getSession(session)
63        return intSession.query(mo_type).filter(*[EPB.buildFilter('doc_name', doc_name)]).first()
64        #return intSession.query(mo_type).filter(*[EPB.buildFilter('doc_owner', doc_owner)]).filter(*[EPB.buildFilter('doc_name', doc_name)]).first()       
65        #return intSession.query(mo_type).filter(*[EPB.buildFilter('doc_status', doc_status)]).filter(*[EPB.buildFilter('doc_owner', doc_owner)]).filter(*[EPB.buildFilter('doc_name', doc_name)]).first()
66
67    @classmethod
68    def _getMigrationObjectByName(self, mo_type, migrationObject, doc_name, session = None):
69        return self._getMigrationObject(mo_type, migrationObject.doc_status, migrationObject.doc_owner, doc_name, session)             
70
71    @classmethod
72    def getDeploymentsMigrationByName(self, migrationObject, doc_name, session = None):
73        if migrationObject is None:
74            raise Exception("migrationObject is None")
75        return self._getMigrationObjectByName(DeploymentsMigration, migrationObject, doc_name, session)       
76
77    @classmethod
78    def getDeploymentDataMigrationByName(self, migrationObject, doc_name, session = None):
79        if migrationObject is None:
80            raise Exception("migrationObject is None")
81        return self._getMigrationObjectByName(DeploymentDataMigration, migrationObject, doc_name, session)
82
83    @classmethod
84    def getDataEntityMigrationbyPath(self, migrationObject, session = None):
85        if migrationObject is None:
86            raise Exception("migrationObject is None")
87        return self._getMigrationObjectByName(DataEntityMigration, migrationObject, migrationObject.doc_name, session)       
88
89    @classmethod
90    def getNewMigrationSession(self):
91        return MigrationEPB._getSession()
92
93    @classmethod
94    def _getSession(self, session = None):
95        if MigrationEPB._migrationDB is None:
96            raise NoDBManager("MigrationEPB")
97        return EPB._getSession(MigrationEPB._migrationDB, session)
Note: See TracBrowser for help on using the repository browser.