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

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

Global commit. In future Mylyn should manage a better per-ticket commit policy

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    #_migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT)
17   
18    @classmethod
19    def overrrideDBManager(self, dbManager):
20        """
21            Sets the MigrationEPB libs.commons_db.DbManager
22        """
23        MigrationEPB._migrationDB = dbManager
24
25    @classmethod
26    def associateObservationCollectionToDataEntity(self, dataEntityMigration, obs_coll_id, session = None, commit = False):
27        intSession = MigrationEPB._getSession(session)
28        dataEntityMigration.ceda_observation_coll_id = obs_coll_id
29        if commit:
30            intSession.commit()
31
32    @classmethod
33    def associateObservationToDeployment(self, deploymentMigration, obs_id, session = None, commit = False):
34        intSession = MigrationEPB._getSession(session)
35        deploymentMigration.ceda_observation_id = obs_id
36        if commit:
37            intSession.commit()         
38       
39    @classmethod
40    def addMigration(self, migrationObj, session = None):
41        intSession = MigrationEPB._getSession(session)
42        intSession.add(migrationObj)
43        EPB._closeSession(session)       
44
45    @classmethod
46    def getAllDataEntityMigration(self, session = None):
47        intSession = MigrationEPB._getSession(session)   
48        return EPB.getAllObjects(DataEntityMigration, intSession)
49
50    @classmethod       
51    def getDataEntityMigrationOrderByDate(self, session = None):
52        return MigrationEPB.getAllDataEntityMigration(session).order_by(asc("doc_creation"))     
53
54    @classmethod
55    def getAllDeploymentsMigrationByDataEntitySortedByDate(self, dataEntity, deploymentNames, session = None):
56        intSession = MigrationEPB._getSession(session)
57        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"))
58
59    @classmethod
60    def _getMigrationObject(self, mo_type, doc_status, doc_owner, doc_name, session = None):
61        intSession = MigrationEPB._getSession(session)
62        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()
63
64    @classmethod
65    def _getMigrationObjectByName(self, mo_type, migrationObject, doc_name, session = None):
66        return self._getMigrationObject(mo_type, migrationObject.doc_status, migrationObject.doc_owner, doc_name, session)             
67
68    @classmethod
69    def getDeploymentsMigrationByName(self, migrationObject, doc_name, session = None):
70        if migrationObject is None:
71            raise Exception("migrationObject is None")
72        return self._getMigrationObjectByName(DeploymentsMigration, migrationObject, doc_name, session)       
73
74    @classmethod
75    def getDeploymentDataMigrationByName(self, migrationObject, doc_name, session = None):
76        if migrationObject is None:
77            raise Exception("migrationObject is None")
78        return self._getMigrationObjectByName(DeploymentDataMigration, migrationObject, doc_name, session)
79
80    @classmethod
81    def getDataEntityMigrationbyPath(self, migrationObject, session = None):
82        if migrationObject is None:
83            raise Exception("migrationObject is None")
84        return self._getMigrationObjectByName(DataEntityMigration, migrationObject, migrationObject.doc_name, session)       
85
86    @classmethod
87    def getNewMigrationSession(self):
88        return MigrationEPB._getSession()
89
90    @classmethod
91    def _getSession(self, session = None):
92        if MigrationEPB._migrationDB is None:
93            raise NoDBManager("MigrationEPB")
94        return EPB._getSession(MigrationEPB._migrationDB, session)
Note: See TracBrowser for help on using the repository browser.