Changeset 8325 for mauRepo/MolesManager
- Timestamp:
- 03/06/12 20:29:12 (8 years ago)
- Location:
- mauRepo/MolesManager/trunk/src
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
mauRepo/MolesManager/trunk/src/MolesManager/moles3epb.py
r8323 r8325 19 19 from ea_model.moles3_4.utilities.mo_rolevalue import MO_RoleValue 20 20 from sqlalchemy.orm.collections import InstrumentedList 21 from sqlalchemy.orm.util import identity_key 22 23 24 class Moles3EPB(EPB): 25 26 _molesDB = None 21 22 23 class Moles3EPBFactory(EPB): 27 24 28 @classmethod 29 def overrrideDBManager(self, dbManager): 30 """ 31 Sets the MigrationEPB libs.commons_db.DbManager 32 """ 33 Moles3EPB._molesDB = dbManager 34 Moles3EPB._initCEDA_Customization() 35 36 @classmethod 25 def __init__(self, dbManager): 26 self._dbManager = dbManager 27 self._initCEDA_Customization() 28 29 37 30 def _initCEDA_Customization(self): 38 Moles3EPB._associateCEDA_GUID() 39 Moles3EPB._initSearchIndexes() 40 41 @classmethod 31 self._associateCEDA_GUID() 32 self._initSearchIndexes() 33 42 34 def _associateCEDA_GUID(self): 43 guid_table = Table('ceda_guid', Moles3EPB._molesDB.metadata, \35 guid_table = Table('ceda_guid', self._dbManager.metadata, \ 44 36 Column('id', String, primary_key=True), \ 45 37 Column('ceda_observationcollection', Integer, ForeignKey('ceda_observationcollection.id')), 46 38 Column('ceda_observation', Integer, ForeignKey('ceda_observation.id'))) 47 39 mapper(CedaGUID, guid_table) 48 Moles3EPB._molesDB.metadata.create_all() 49 50 @classmethod 40 self._dbManager.metadata.create_all() 41 51 42 def _initSearchIndexes(self): 52 43 #To Be Done - CHECK IF THE COLUMN ALREADY EXISTS! 53 44 # We don't want sqlalchemy to know about this column so we add it externally. 54 45 try: 55 Moles3EPB._molesDB.engine.execute("alter table md_identifier add column code_search_vector tsvector")46 self._dbManager.engine.execute("alter table md_identifier add column code_search_vector tsvector") 56 47 57 48 # This indexes the tsvector column 58 49 59 Moles3EPB._molesDB.engine.execute("create index md_identifier_code_search_index on md_identifier using gin(code_search_vector)")50 self._dbManager.engine.execute("create index md_identifier_code_search_index on md_identifier using gin(code_search_vector)") 60 51 61 52 # This sets up the trigger that keeps the tsvector column up to date. 62 Moles3EPB._molesDB.engine.execute("create trigger md_identifier_code_search_update before update or insert on md_identifier \53 self._dbManager.engine.execute("create trigger md_identifier_code_search_update before update or insert on md_identifier \ 63 54 for each row execute procedure tsvector_update_trigger('code_search_vector', 'pg_catalog.english', code)") 64 55 except Exception as e: 65 56 pass 66 57 67 @classmethod 68 def searchEager(self, clazz, inst_id, session = None): 69 intSession = Moles3EPB._getSession(session) 70 ret = EPB.searchEager(clazz, inst_id, intSession) 71 if session is None: 72 intSession.close() 73 return ret 74 75 @classmethod 76 def persistInstance(self, instance, session = None): 58 def _getSession(self): 59 if self._dbManager is not None: 60 return self._dbManager.createDbSession() 61 return None 62 63 def createMoles3EPB(self): 64 return Moles3EPB(self._getSession()) 65 66 class Moles3EPB(object): 67 68 def __init__(self, session): 69 self._session = session 70 71 def close(self): 72 return self._session.close() 73 74 def searchEager(self, clazz, inst_id): 75 return EPB.searchEager(clazz, inst_id) 76 77 def persistInstance(self, instance): 77 78 """ 78 79 Adds a new migration object. … … 82 83 @return an updated, session independent, object instance reflecting the new persisted object 83 84 """ 84 intSession = Moles3EPB._getSession(session) 85 EPB.persistInstance(instance, intSession) 86 if session is None: 87 intSession.close() 88 #return ret 89 90 91 @classmethod 92 def updateCedaObject(self, ceda_object, cols_to_update, session = None): 85 EPB.persistInstance(instance, self._session) 86 87 88 def updateCedaObject(self, ceda_object, cols_to_update): 93 89 """ 94 90 Update and eventually commit a CEDA Object in MOLES3 db. … … 99 95 @return: the given instance with the updated attributes. 100 96 """ 101 intSession = Moles3EPB._getSession(session)102 97 coll = None 103 98 try: 104 coll = intSession.merge(ceda_object)99 coll = self._session.merge(ceda_object) 105 100 except Exception as e: 106 101 print e … … 110 105 val = None 111 106 try: 112 val = intSession.merge(v)107 val = self._session.merge(v) 113 108 except Exception: 114 109 val = v … … 123 118 else: 124 119 setattr(coll, k, val) 125 EPB.persistInstance(coll, intSession) 126 if session is None: 127 intSession.close() 128 129 @classmethod 130 def retrieveGUIDFromInstance(self, instance, session = None): 120 EPB.persistInstance(coll, self._session) 121 122 def retrieveGUIDFromInstance(self, instance): 131 123 """ 132 124 Returns the CedaGUID object associated with the given instance. 133 125 @param instance: an instance of CEDA_Observation os CEDA_ObservationCollection 134 126 """ 135 intSession = Moles3EPB._getSession(session)136 127 if instance is None: 137 128 return None 138 129 if type(instance) == CEDA_ObservationCollection: 139 return intSession.query(CedaGUID).filter(CedaGUID.ceda_observationcollection==instance.id).first()130 return self._session.query(CedaGUID).filter(CedaGUID.ceda_observationcollection==instance.id).first() 140 131 elif type(instance) == CEDA_Observation: 141 return intSession.query(CedaGUID).filter(CedaGUID.ceda_observation==instance.id).first() 142 if session is None: 143 intSession.close() 132 return self._session.query(CedaGUID).filter(CedaGUID.ceda_observation==instance.id).first() 144 133 145 @classmethod 146 def observationCollectionHasObservation(self, obs_coll_id, obs_id, session = None): 134 def observationCollectionHasObservation(self, obs_coll_id, obs_id): 147 135 """ 148 136 Checks if a CEDA_Collection contains a given CEDA_Observation. … … 151 139 @return: True if the collection contains the given observation, False otherwise 152 140 """ 153 intSession = Moles3EPB._getSession(session) 154 ret = intSession.query(CEDA_ObservationCollection, CEDA_Observation).filter(CEDA_ObservationCollection.id==obs_coll_id).filter(CEDA_Observation.id==obs_id).count() > 0 155 if session is None: 156 intSession.close() 141 ret = self._session.query(CEDA_ObservationCollection, CEDA_Observation).filter(CEDA_ObservationCollection.id==obs_coll_id).filter(CEDA_Observation.id==obs_id).count() > 0 157 142 return ret 158 143 159 @classmethod 160 def observationAuthor(self, obs_id, session = None): 144 def observationAuthor(self, obs_id): 161 145 """ 162 146 Lists the CEDA_Observation author. … … 164 148 @return: True if the collection contains the given observation, False otherwise 165 149 """ 166 intSession = Moles3EPB._getSession(session) 167 ret = intSession.query(MO_ResponsiblePartyInfo).join(MO_Observation). \ 150 ret = self._session.query(MO_ResponsiblePartyInfo).join(MO_Observation). \ 168 151 filter(MO_ResponsiblePartyInfo.role == MO_RoleValue.cl_author). \ 169 filter(MO_Observation.id == obs_id) 170 if session is None: 171 intSession.close() 152 filter(MO_Observation.id == obs_id) 172 153 return ret 173 154 174 @classmethod 175 def extractObservationByTitleKeywords(self, keywords, session = None): 155 def extractObservationByTitleKeywords(self, keywords): 176 156 """ 177 157 Loooks for CEDA_Observation containing a specific title (observation.identifier.code) … … 179 159 @return: a tuple containing a CEDA_Observation satisfying the queryllection.idenfitier element having the title 180 160 """ 181 intSession = Moles3EPB._getSession(session)182 161 # search_vector is a ts_vector column. To search for terms, you use the 183 162 # @@ operator. plainto_tsquery turns a string into a query that can be 184 163 # used with @@. So this adds a where clause like "WHERE search_vector 185 164 # @@ plaint_tsquery(<search string>)" 186 q = intSession.query(CEDA_Observation). \165 q = self._session.query(CEDA_Observation). \ 187 166 join(MO_Observation).join(MO_ObservationCollection.identifier). \ 188 167 filter('md_identifier.code_search_vector @@ to_tsquery(:terms)') … … 193 172 194 173 195 @classmethod 196 def extractCollectionIdentifierByTitle(self, i_title, session = None): 174 def extractCollectionIdentifierByTitle(self, i_title): 197 175 """ 198 176 Searches for an MD_Identifier from a CEDA_ObservationCollection contains a specific title (observation.identifier.code) … … 200 178 @return: a tuple containing a CEDA_ObservationCollection and the CEDA_ObservationCollection.idenfitier element having the title 201 179 """ 202 intSession = Moles3EPB._getSession(session) 203 return intSession.query(CEDA_ObservationCollection, MD_Identifier). \ 180 return self._session.query(CEDA_ObservationCollection, MD_Identifier). \ 204 181 join(MO_ObservationCollection).join(MO_ObservationCollection.identifier). \ 205 182 join(MD_Identifier.authority).filter(CI_Citation.title.like('%' + i_title + '%')) 206 183 207 @classmethod 208 def extractObservationsForProject(self, project, session = None): 184 def extractObservationsForProject(self, project): 209 185 """ 210 186 Searches for the CEDA_Observation associated with a CEDA_Project … … 212 188 @return: a tuple containing the associated CEDA_Observation 213 189 """ 214 intSession = Moles3EPB._getSession(session) 215 return intSession.query(CEDA_Observation). \ 190 return self._session.query(CEDA_Observation). \ 216 191 join(CEDA_Observation, MO_Observation.inSupportOf).filter(CEDA_Project.id == project.id) 217 192 218 @classmethod 219 def extractProjectObservationCollections(self, project, session = None): 193 def extractProjectObservationCollections(self, project): 220 194 """ 221 195 Searches for the Observation_Collections associated with a CEDA_Project … … 223 197 @return: a tuple containing the associated CEDA_ObservationCollection 224 198 """ 225 intSession = Moles3EPB._getSession(session) 226 mo_obs = intSession.query(MO_Observation).join(CEDA_Project).filter(CEDA_Project.id == project.id).subquery() 227 obsers = intSession.query(CEDA_Observation).join(mo_obs, CEDA_Observation.id == mo_obs.c.id).one() 199 mo_obs = self._session.query(MO_Observation).join(CEDA_Project).filter(CEDA_Project.id == project.id).subquery() 200 obsers = self._session.query(CEDA_Observation).join(mo_obs, CEDA_Observation.id == mo_obs.c.id).one() 228 201 #print "obsers: " + str(intSession.query(CEDA_Observation).join(mo_obs, CEDA_Observation.id == mo_obs.c.id).count()) 229 202 230 cos = intSession.query(CEDA_ObservationCollection).all()231 co = intSession.query(MO_ObservationCollection).join(MO_ObservationCollection.member).filter(MO_ObservationCollection.member.contains(obsers))232 233 observations = intSession.query(MO_ObservationCollection).join(CEDA_Observation). \203 cos = self._session.query(CEDA_ObservationCollection).all() 204 co = self._session.query(MO_ObservationCollection).join(MO_ObservationCollection.member).filter(MO_ObservationCollection.member.contains(obsers)) 205 206 observations = self._session.query(MO_ObservationCollection).join(CEDA_Observation). \ 234 207 filter(obsers.any(CEDA_Observation.id==obsers.c.id)) 235 208 print "observation:" + str(observations.count()) 236 209 return observations 237 210 238 @classmethod 239 def getNewMolesSession(self): 240 return Moles3EPB._getSession() 241 242 @classmethod 243 def search(self, clazz, inst_id, session = None): 244 intSession = Moles3EPB._getSession(session) 245 ret = EPB.search(clazz, inst_id, intSession) 246 if session is None: 247 intSession.close() 211 def search(self, clazz, inst_id): 212 ret = EPB.search(clazz, inst_id, self._session) 248 213 return ret 249 250 @classmethod 251 def searchSelectiveLoad(self, clazz, inst_id, attributes, session = None): 214 215 def searchSelectiveLoad(self, clazz, inst_id, attributes): 252 216 """ 253 217 Searches a required instance by id loading selectively \ … … 271 235 @return the required instance 272 236 """ 273 intSession = Moles3EPB._getSession(session) 274 ret = EPB.searchSelectiveLoad(clazz, inst_id, attributes, intSession) 275 if session is None: 276 intSession.close() 237 ret = EPB.searchSelectiveLoad(clazz, inst_id, attributes, self._session) 277 238 return ret 278 239 279 @classmethod 280 def loadAttributes(self, instance, attributes, session = None): 240 def loadAttributes(self, instance, attributes): 281 241 """ 282 242 Returns the attribute of an instance. The parameter "attributes" is a single string or a list of attributes … … 298 258 @return: the given instance filled with the required attributes. 299 259 """ 300 intSession = Moles3EPB._getSession(session) 301 instance = intSession.merge(instance) 302 EPB.loadAttributes(instance, attributes, intSession) 303 if session is None: 304 intSession.close() 260 instance = self._session.merge(instance) 261 EPB.loadAttributes(instance, attributes, self._session) 305 262 return instance 306 263 307 @classmethod 308 def executeNative(self, sqlNative, session = None): 309 intSession = Moles3EPB._getSession(session) 310 return EPB.executeNative(sqlNative, intSession) 311 312 @classmethod 313 def _getSession(self, session = None): 314 if Moles3EPB._molesDB is None: 315 raise NoDBManager("Moles3EPB") 316 return EPB._getSession(Moles3EPB._molesDB, session) 264 def executeNative(self, sqlNative): 265 return EPB.executeNative(sqlNative, self._session) -
mauRepo/MolesManager/trunk/src/MolesManager/molesSessionMiddleware.py
r8323 r8325 4 4 @author: mnagni 5 5 ''' 6 from MolesManager.moles3epb import Moles3EPB 6 from MolesManager.moles3epb import Moles3EPBFactory 7 7 from libs.migration.client import MigrationThread 8 8 from MolesManager.settings import RUN_MIGRATION, MIGRATION_INTERVAL,\ … … 10 10 MOLES3_DB_SCRIPT, EVENTS_DB, INFO_DB_CONNECTION 11 11 from libs.commons_db import DbManager 12 from libs.migration.MigrationEPB import MigrationEPB13 12 from libs.migration.InfodbEPB import InfodbEPB 14 import logging 13 from libs.migration.MigrationEPB import MigrationEPBFactory 15 14 16 15 … … 20 19 #This attribute should be not here. 21 20 #unfortunately I cannot find any start/stop signals from Django 22 _migrationThread = MigrationThread(interval = MIGRATION_INTERVAL)21 #_migrationThread = MigrationThread(interval = MIGRATION_INTERVAL) 23 22 _epbInitialized = False 24 25 def _getNewMolesSession(self): 26 session = Moles3EPB.getNewMolesSession() 27 return session 28 23 _moles3EPBFactory = None 24 _migrationEPBFactory = None 29 25 30 26 def _doInitialization(self): … … 33 29 34 30 migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT) 35 M igrationEPB.overrrideDBManager(migrationDB)31 MolesSessionMiddleware._migrationEPBFactory = MigrationEPBFactory(migrationDB) 36 32 37 33 molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT, session_event_manager=EVENTS_DB) 38 Moles3EPB.overrrideDBManager(molesDB) 34 MolesSessionMiddleware._moles3EPBFactory = Moles3EPBFactory(molesDB) 35 36 MolesSessionMiddleware._migrationThread = MigrationThread( \ 37 MolesSessionMiddleware._moles3EPBFactory.createMoles3EPB(), \ 38 MolesSessionMiddleware._migrationEPBFactory.createMigrationEPB(), \ 39 interval = MIGRATION_INTERVAL ) 39 40 MolesSessionMiddleware._epbInitialized = True 40 41 … … 70 71 @deprecated: request.moles_session is going to be removed from all GUI-related instances 71 72 ''' 72 #request.moles_session = self._getMolesSession()73 request.moles3EPB = MolesSessionMiddleware._moles3EPBFactory.createMoles3EPB() 73 74 74 75 75 76 def process_response(self, request, response): 76 """ 77 if hasattr(request, 'moles_session'): 78 request.moles_session.close() 79 """ 77 request.moles3EPB.close() 80 78 return response 81 79 -
mauRepo/MolesManager/trunk/src/MolesManager/views/cedaObservationView.py
r8323 r8325 32 32 if record: 33 33 c['coObs'] = mark_safe(DJEncoder().escapeForJSON(DJEncoder().encode(record))) 34 guid = Moles3EPB.retrieveGUIDFromInstance(record)34 guid = request.moles3EPB.retrieveGUIDFromInstance(record) 35 35 if guid: 36 36 c['guid'] = guid.id … … 46 46 'geographicExtent', 'phenomenonTime', 'keywords', 'description', \ 47 47 'inSupportOf.abstract', 'dataLineage'] 48 return Moles3EPB.searchSelectiveLoad(CEDA_Observation, obs_id, eagerloadthese)48 return request.moles3EPB.searchSelectiveLoad(CEDA_Observation, obs_id, eagerloadthese) 49 49 #return Moles3EPB.searchEager(CEDA_Observation, obs_id) -
mauRepo/MolesManager/trunk/src/libs/migration/MigrationEPB.py
r8323 r8325 8 8 from sqlalchemy.sql.expression import asc 9 9 from libs.epb import EPB 10 from libs.migration.exception.exceptions import NoDBManager11 from libs.migration.processor.commons import stringToTimestamp12 10 from sqlalchemy.orm.collections import InstrumentedList 13 from sqlalchemy.orm.util import identity_key14 11 15 12 16 class MigrationEPB (EPB):13 class MigrationEPBFactory(EPB): 17 14 18 _migrationDB = None 19 20 @classmethod 21 def overrrideDBManager(self, dbManager): 22 """ 23 Sets the MigrationEPB libs.commons_db.DbManager 24 """ 25 MigrationEPB._migrationDB = dbManager 15 def __init__(self, dbManager): 16 self._dbManager = dbManager 17 18 def _getSession(self): 19 if self._dbManager is not None: 20 return self._dbManager.createDbSession() 21 return None 26 22 27 @classmethod 28 def persistInstance(self, instance, session = None): 23 def createMigrationEPB(self): 24 return MigrationEPB(self._getSession()) 25 26 27 class MigrationEPB(object): 28 29 def __init__(self, session): 30 self._session = session 31 32 def close(self): 33 return self._session.close() 34 35 def persistInstance(self, instance): 29 36 """ 30 37 Adds a new migration object. … … 33 40 @return an updated, session independent, object instance reflecting the new persisted object 34 41 """ 35 intSession = MigrationEPB._getSession(session) 36 EPB.persistInstance(instance, intSession) 37 if session is None: 38 intSession.close() 42 EPB.persistInstance(instance, self._session) 39 43 #return ret 40 44 41 @classmethod42 45 def getAllDeploymentsMigrationByDataEntitySortedByDate(self, dataEntity, deploymentNames): 43 intSession = MigrationEPB._getSession(None) 44 res = EPB.getAllObjects(DeploymentsMigration, intSession).filter(DeploymentsMigration.doc_name.in_(deploymentNames)).order_by(asc("doc_creation")).all() 45 intSession.close() 46 return res 46 return EPB.getAllObjects(DeploymentsMigration, self._session).filter(DeploymentsMigration.doc_name.in_(deploymentNames)).order_by(asc("doc_creation")).all() 47 47 #return EPB.getAllObjects(DeploymentsMigration, intSession).filter(*[EPB.buildFilter('doc_owner', dataEntity.doc_owner)]).filter(DeploymentsMigration.doc_name.in_(deploymentNames)).order_by(asc("doc_creation")) 48 48 #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")) 49 49 50 @classmethod 51 def _getMigrationObject(self, mo_type, doc_status, doc_owner, doc_name, session = None): 52 intSession = MigrationEPB._getSession(session) 53 return intSession.query(mo_type).filter(*[EPB.buildFilter('doc_name', doc_name)]).first() 50 def _getMigrationObject(self, mo_type, doc_status, doc_owner, doc_name): 51 return self._session.query(mo_type).filter(*[EPB.buildFilter('doc_name', doc_name)]).first() 54 52 #return intSession.query(mo_type).filter(*[EPB.buildFilter('doc_owner', doc_owner)]).filter(*[EPB.buildFilter('doc_name', doc_name)]).first() 55 53 #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() 56 54 57 @classmethod 58 def _getMigrationObjectByName(self, mo_type, migrationObject, doc_name, session = None): 59 return self._getMigrationObject(mo_type, migrationObject.doc_status, migrationObject.doc_owner, doc_name, session) 55 def _getMigrationObjectByName(self, mo_type, migrationObject, doc_name): 56 return self._getMigrationObject(mo_type, migrationObject.doc_status, migrationObject.doc_owner, doc_name) 60 57 61 @classmethod 62 def getDeploymentsMigrationByName(self, migrationObject, doc_name, session = None): 58 def getDeploymentsMigrationByName(self, migrationObject, doc_name): 63 59 if migrationObject is None: 64 60 raise Exception("migrationObject is None") 65 return self._getMigrationObjectByName(DeploymentsMigration, migrationObject, doc_name , session)61 return self._getMigrationObjectByName(DeploymentsMigration, migrationObject, doc_name) 66 62 67 @classmethod 68 def getDeploymentDataMigrationByName(self, migrationObject, doc_name, session = None): 63 def getDeploymentDataMigrationByName(self, migrationObject, doc_name): 69 64 if migrationObject is None: 70 65 raise Exception("migrationObject is None") 71 return self._getMigrationObjectByName(DeploymentDataMigration, migrationObject, doc_name , session)66 return self._getMigrationObjectByName(DeploymentDataMigration, migrationObject, doc_name) 72 67 73 @classmethod 74 def getDataEntityMigrationbyPath(self, migrationObject, session = None): 68 def getDataEntityMigrationbyPath(self, migrationObject): 75 69 """ 76 70 Returns the DataEntityMigration associated with the given path 77 71 @param migrationObject: the migration object to look for. If None returns all the DataEntityMigration items 78 72 """ 79 intSession = MigrationEPB._getSession(session)80 73 if migrationObject: 81 ret = intSession.query(DataEntityMigration).filter(*[EPB.buildFilter('doc_name', migrationObject.doc_name)]).first()74 ret = self._session.query(DataEntityMigration).filter(*[EPB.buildFilter('doc_name', migrationObject.doc_name)]).first() 82 75 else: #then process all the DataEntities 83 ret = EPB.getAllObjects(DataEntityMigration, intSession) 84 if session is None: 85 intSession.close() 76 ret = EPB.getAllObjects(DataEntityMigration) 86 77 return ret 87 88 @classmethod 89 def updateMigrationObject(self, migration_object, cols_to_update, session = None): 78 79 def updateMigrationObject(self, migration_object, cols_to_update): 90 80 """ 91 81 Update and eventually commit a Migration Object in Migration db … … 94 84 @param session: the external session to use. If None a new session will be open to add and commit the object and then closed at the exit. The object is committed 95 85 """ 96 intSession = MigrationEPB._getSession(session)97 86 coll = None 98 87 try: 99 coll = intSession.merge(migration_object)88 coll = self._session.merge(migration_object) 100 89 except Exception as e: 101 90 print e … … 105 94 val = None 106 95 try: 107 val = intSession.merge(v)96 val = self._session.merge(v) 108 97 except Exception: 109 98 val = v … … 116 105 else: 117 106 setattr(coll, k, val) 118 EPB.persistInstance(coll, intSession) 119 #intSession.commit() 120 if session is None: 121 intSession.close() 122 #if coll: 123 # return coll 107 EPB.persistInstance(coll, self._session) 124 108 125 126 @classmethod 127 def getNewMigrationSession(self): 128 return MigrationEPB._getSession() 129 130 @classmethod 131 def loadAttributes(self, instance, attributes, session = None): 109 def loadAttributes(self, instance, attributes): 132 110 """ 133 111 Returns the attribute of an instance. The parameter "attributes" is a single string or a list of attributes … … 149 127 @return: a detached instance (or array of instances) of the required attribute. 150 128 """ 151 intSession = MigrationEPB._getSession(session) 152 instance = intSession.merge(instance) 153 EPB.loadAttributes(instance, attributes, session) 154 if session is None: 155 intSession.close() 129 instance = self._session.merge(instance) 130 EPB.loadAttributes(instance, attributes) 156 131 return instance 157 132 158 @classmethod 159 def search(self, clazz, inst_id, session = None): 133 def search(self, clazz, inst_id): 160 134 if clazz is None or inst_id is None: 161 135 return None 162 intSession = MigrationEPB._getSession(session) 163 ret = EPB.search(clazz, inst_id, intSession) 164 if session is None: 165 intSession.close() 136 ret = EPB.search(clazz, inst_id, self._session) 166 137 return ret 167 138 168 169 @classmethod170 def _getSession(self, session = None):171 if MigrationEPB._migrationDB is None:172 raise NoDBManager("MigrationEPB")173 return EPB._getSession(MigrationEPB._migrationDB, session) -
mauRepo/MolesManager/trunk/src/libs/migration/client.py
r8147 r8325 10 10 import time 11 11 from threading import Timer 12 from libs.migration.processor.EPBRepo import EPBRepo 12 13 13 14 class MigrationThread(threading.Thread): 14 15 """ 15 16 Constructs a scheduler for the Moles2 to Moles3 migration. 17 Only one instance should be running for each python interpreter 16 18 @param interval: define the minimal time, in seconds, between an execution and the successive. 17 19 If the current migration run takes more than the defined interval the next will starts 18 20 as soon the previous ends. 19 21 """ 20 def __init__(self, interval=600): 22 23 def __init__(self, moles3EPB, migrationEPB, interval=600): 24 EPBRepo.moles3EPB = moles3EPB 25 EPBRepo.migrationEPB = migrationEPB 26 21 27 threading.Thread.__init__(self) 22 28 self._doRun = True -
mauRepo/MolesManager/trunk/src/libs/migration/processor/dataEntity.py
r8323 r8325 23 23 from MolesManager.ceda_guid import CedaGUID 24 24 from ea_model.iso_19115_2006_metadata_corrigendum.maintenance_information.md_maintenancefrequencycode import MD_MaintenanceFrequencyCode 25 from libs.migration.processor.EPBRepo import EPBRepo 25 26 26 27 class DataEntityProcessor(object): … … 63 64 64 65 def _getObservationCollection(self): 65 return Moles3EPB.search(CEDA_ObservationCollection, self._dataEntityMigration.ceda_observation_coll_id)66 return EPBRepo.moles3EPB.search(CEDA_ObservationCollection, self._dataEntityMigration.ceda_observation_coll_id) 66 67 67 68 def _processObservationCollection(self): … … 105 106 ceda_observationCollection.publicationState = MO_PublicationStateValue.cl_working 106 107 107 Moles3EPB.persistInstance(ceda_observationCollection)108 109 MigrationEPB.updateMigrationObject(self._dataEntityMigration, {'ceda_observation_coll_id': ceda_observationCollection.id})108 EPBRepo.moles3EPB.persistInstance(ceda_observationCollection) 109 110 EPBRepo.migrationEPB.updateMigrationObject(self._dataEntityMigration, {'ceda_observation_coll_id': ceda_observationCollection.id}) 110 111 111 112 … … 114 115 ceda_guid.id = calculateHash(self._dataEntityMigration.data_ent_id) 115 116 ceda_guid.ceda_observationcollection = ceda_observationCollection.id 116 Moles3EPB.persistInstance(ceda_guid)117 EPBRepo.moles3EPB.persistInstance(ceda_guid) 117 118 DataEntityProcessor.log.info("GUID for this ObservationCollection: %s" % (ceda_guid.id)) 118 119 … … 120 121 121 122 def _processResultAccumulation(self, ceda_observation): 122 ceda_observation = Moles3EPB.loadAttributes(ceda_observation, "resultAccumulation")123 ceda_observation = EPBRepo.moles3EPB.loadAttributes(ceda_observation, "resultAccumulation") 123 124 if ceda_observation.resultAccumulation is None: 124 125 updateFrequency = extractUpdateFrequency(self._dataEntityMigration) 125 126 if updateFrequency: 126 127 resultAccumulation = MD_MaintenanceFrequencyCode.from_string(updateFrequency) 127 Moles3EPB.updateCedaObject(ceda_observation, {'resultAccumulation': resultAccumulation})128 EPBRepo.moles3EPB.updateCedaObject(ceda_observation, {'resultAccumulation': resultAccumulation}) 128 129 129 130 def _processDOI(self, deploymentMigration, ceda_observation, deProcessor, single_deployment): … … 154 155 if not hasAtomDocumentSameHash(deploymentMigration): 155 156 doc_hash = getAtomDocumentHash(deploymentMigration.docStatus, deploymentMigration.docType, deploymentMigration.docOwner, deploymentMigration.docName) 156 MigrationEPB.updateMigrationObject(deploymentMigration, {'doc_hash': doc_hash})157 EPBRepo.migrationEPB.updateMigrationObject(deploymentMigration, {'doc_hash': doc_hash}) 157 158 except NoAssociatedAuthor as ex: 158 159 raise ex … … 182 183 183 184 #retrieves the DataEntityMigration sorted by creation date 184 deploymentMigrations = MigrationEPB.getAllDeploymentsMigrationByDataEntitySortedByDate( \185 deploymentMigrations = EPBRepo.migrationEPB.getAllDeploymentsMigrationByDataEntitySortedByDate( \ 185 186 self._dataEntityMigration, deploymentsLinks) 186 187 howManydm = 0 … … 194 195 195 196 #Check if a doi has been already assigned 196 cedaObservationCollection = Moles3EPB.loadAttributes(cedaObservationCollection, 'member')197 cedaObservationCollection = EPBRepo.moles3EPB.loadAttributes(cedaObservationCollection, 'member') 197 198 member = cedaObservationCollection.member 198 199 if member and not (ceda_observation in member): 199 Moles3EPB.updateCedaObject(cedaObservationCollection, {'member': ceda_observation})200 EPBRepo.moles3EPB.updateCedaObject(cedaObservationCollection, {'member': ceda_observation}) 200 201 201 202 except Exception as ex: -
mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment.py
r8323 r8325 50 50 from ea_model.iso_19115_2006_metadata_corrigendum.maintenance_information.md_maintenancefrequencycode import MD_MaintenanceFrequencyCode 51 51 from ea_model.ceda_metadatamodel.ceda_result.ceda_curationvalue import CEDA_CurationValue 52 from libs.migration.processor.EPBRepo import EPBRepo 52 53 53 54 class DeploymentProcessor(object): … … 230 231 obsList = [] 231 232 for obs in links['OBS']: 232 observationStation = MigrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, obs + '.atom')233 observationStation = EPBRepo.migrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, obs + '.atom') 233 234 obsList.append((extractTitle(observationStation), findSubTypeInDPT(observationStation))) 234 235 … … 246 247 if links.has_key('ACTIVITY'): 247 248 for link in links['ACTIVITY']: 248 activity = MigrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, link + '.atom')249 activity = EPBRepo.migrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, link + '.atom') 249 250 250 251 projSubType = findSubTypeInDPT(activity) … … 347 348 348 349 #Check if a doi has been already assigned 349 observation = Moles3EPB.loadAttributes(observation, 'identifier')350 observation = EPBRepo.moles3EPB.loadAttributes(observation, 'identifier') 350 351 obs_identifier = observation.identifier 351 352 if obs_identifier: … … 371 372 i_authority = createCI_Citation("DOI", date = ci_date) 372 373 identifier = createMD_Identifier(code = doi, authority=i_authority) 373 Moles3EPB.updateCedaObject(observation, {'identifier': identifier})374 EPBRepo.moles3EPB.updateCedaObject(observation, {'identifier': identifier}) 374 375 DeploymentProcessor.log.info("DOI: %s" % (doi)) 375 376 … … 513 514 self._assignUpdateFrequency(ceda_observation) 514 515 self._assignName(ceda_observation) 515 Moles3EPB.persistInstance(ceda_observation)516 MigrationEPB.updateMigrationObject(self._deploymentMigration, {'ceda_observation_id': ceda_observation.id})516 EPBRepo.moles3EPB.persistInstance(ceda_observation) 517 EPBRepo.migrationEPB.updateMigrationObject(self._deploymentMigration, {'ceda_observation_id': ceda_observation.id}) 517 518 518 519 #Adds the CedaGUID … … 520 521 ceda_guid.id = calculateHash(self._deploymentMigration.depl_id) 521 522 ceda_guid.ceda_observation = ceda_observation.id 522 Moles3EPB.persistInstance(ceda_guid)523 EPBRepo.moles3EPB.persistInstance(ceda_guid) 523 524 DeploymentProcessor.log.info("GUID for this Observation: %s" % (ceda_guid.id)) 524 525 … … 531 532 #Temporary commented because CEDA_Project.subProject is not correctly mapped to the DB 532 533 project = deploymentDataProcessor.createProject(links) 533 Moles3EPB.updateCedaObject(ceda_observation, {'procedure': procedure, 'inSupportOf': project})534 EPBRepo.moles3EPB.updateCedaObject(ceda_observation, {'procedure': procedure, 'inSupportOf': project}) 534 535 535 536 return ceda_observation 536 537 537 538 def _getObservation(self): 538 return Moles3EPB.search(CEDA_Observation, self._deploymentMigration.ceda_observation_id)539 return EPBRepo.moles3EPB.search(CEDA_Observation, self._deploymentMigration.ceda_observation_id) 539 540 540 541 def _update(self): -
mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment_data.py
r8323 r8325 11 11 from MolesManager.moles3epb import Moles3EPB 12 12 from ea_model.moles3_4.utilities.mo_publicationstatevalue import MO_PublicationStateValue 13 from libs.migration.processor.EPBRepo import EPBRepo 13 14 14 15 class DeploymentDataProcessor(object): … … 18 19 19 20 def _commitDeploymentMigration(self, associateWithCedaObservation, dataProductionTool, dataProductionToolField): 20 Moles3EPB.persistInstance(associateWithCedaObservation)21 MigrationEPB.updateMigrationObject(dataProductionTool, {dataProductionToolField: associateWithCedaObservation.id})21 EPBRepo.moles3EPB.persistInstance(associateWithCedaObservation) 22 EPBRepo.migrationEPB.updateMigrationObject(dataProductionTool, {dataProductionToolField: associateWithCedaObservation.id}) 22 23 23 24 … … 26 27 if links.has_key('ACTIVITY'): 27 28 for link in links['ACTIVITY']: 28 activity = MigrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, link + '.atom')29 activity = EPBRepo.migrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, link + '.atom') 29 30 i_abstract = findSummary(activity) 30 31 doc_link = findDocumentationInMigrationDocument(activity) … … 45 46 hasCedaAcquisition = False 46 47 for dpt in links['DPT']: 47 dataProductionTool = MigrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, dpt + '.atom')48 dataProductionTool = EPBRepo.migrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, dpt + '.atom') 48 49 49 50 #has the document changed? … … 79 80 #if not a DPT.subType == 'model' then.... 80 81 for obs in links['OBS']: 81 observationStation = MigrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, obs + '.atom')82 observationStation = EPBRepo.migrationEPB.getDeploymentDataMigrationByName(self._deploymentMigration, obs + '.atom') 82 83 83 84 #has the document changed? -
mauRepo/MolesManager/trunk/src/libs/migration/processor/loadResources.py
r8323 r8325 11 11 from libs.migration.db.classes import DeploymentDataMigration,\ 12 12 DeploymentsMigration, DataEntityMigration 13 from libs.migration. MigrationEPB import MigrationEPB13 from libs.migration.processor.EPBRepo import EPBRepo 14 14 15 15 class LoadResources(object): 16 """17 Loads informations from the eXist database to populate reference table for the migrations18 """19 def __init__(self):20 pass21 16 22 17 def process(self): … … 51 46 migrationObject.doc_creation = stringToTimestamp(docCreation) 52 47 try: 53 MigrationEPB.persistInstance(migrationObject)48 EPBRepo.migrationEPB.persistInstance(migrationObject) 54 49 except Exception as e: 55 50 print e … … 93 88 94 89 #The document has been already classified 95 if doc_id is None or MigrationEPB.search(migrationClass, doc_id) is not None:90 if doc_id is None or EPBRepo.migrationEPB.search(migrationClass, doc_id) is not None: 96 91 return 97 92 -
mauRepo/MolesManager/trunk/src/libs/migration/processor/migrationProcess.py
r8323 r8325 8 8 import logging 9 9 from logging import StreamHandler 10 from libs.migration.processor.EPBRepo import EPBRepo 10 11 11 12 class MigrationProcess(): … … 31 32 exs = [] 32 33 data_ents = [] 33 data_ents.append( MigrationEPB.getDataEntityMigrationbyPath(dataEntityObject))34 data_ents.append(EPBRepo.migrationEPB.getDataEntityMigrationbyPath(dataEntityObject)) 34 35 """ 35 36 #Does the migrationObject exists? -
mauRepo/MolesManager/trunk/src/libs/migration/tests/migrationprocess.py
r8323 r8325 6 6 from unittest import TestCase 7 7 from libs.commons_db import DbManager 8 from libs.migration.MigrationEPB import MigrationEPB 8 from libs.migration.MigrationEPB import MigrationEPB, MigrationEPBFactory 9 9 from libs.migration.processor.loadResources import LoadResources 10 10 from libs.migration.db.classes import MigrationObject 11 11 from libs.migration.processor.commons import DO_BADC, DS_pUBLISHED, DS_PUBLISHED 12 from MolesManager.moles3epb import Moles3EPB 12 from MolesManager.moles3epb import Moles3EPB, Moles3EPBFactory 13 13 from libs.migration.processor.migrationProcess import MigrationProcess 14 14 from testconfig import MIGRATION_DB_CONNECTION,\ … … 16 16 from libs.migration.InfodbEPB import InfodbEPB 17 17 from MolesManager.settings import EVENTS_DB 18 from libs.migration.client import EPBRepo 18 19 19 20 class LoadResourceTest(TestCase): … … 21 22 classdocs 22 23 ''' 23 24 24 25 def setUp(self): 25 26 migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT, sql_echo=True) 26 27 #migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT) 27 MigrationEPB.overrrideDBManager(migrationDB)28 #MigrationEPB.overrrideDBManager(migrationDB) 28 29 29 30 molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT, sql_echo=True, session_event_manager=EVENTS_DB) 30 #molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT, session_event_manager=EVENTS_DB) 31 Moles3EPB.overrrideDBManager(molesDB)31 #molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT, session_event_manager=EVENTS_DB) 32 32 33 33 34 #infoDB = DbManager(INFO_DB_CONNECTION, sql_echo=True) 34 35 infoDB = DbManager(INFO_DB_CONNECTION) 35 36 InfodbEPB.overrrideDBManager(infoDB) 37 38 moles3Factory = Moles3EPBFactory(molesDB) 39 migrationFactory = MigrationEPBFactory(migrationDB) 40 41 EPBRepo.moles3EPB = moles3Factory.createMoles3EPB() 42 EPBRepo.migrationEPB = migrationFactory.createMigrationEPB() 36 43 37 44 lr = LoadResources()
Note: See TracChangeset
for help on using the changeset viewer.