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

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

Complete - # 22386: CEDA Observation - title
 http://team.ceda.ac.uk/trac/ceda/ticket/22386

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(*[EPB.buildFilter('doc_owner', dataEntity.doc_owner)]).filter(DeploymentsMigration.doc_name.in_(deploymentNames)).order_by(asc("doc_creation"))       
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.