source: mauRepo/MolesManager/trunk/src/libs/migration/processor/migrationProcess.py @ 8147

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

Implementation of tickets #22390

Line 
1'''
2Created on 10 Jan 2012
3
4@author: mnagni
5'''
6from libs.migration.processor.dataEntity import DataEntityProcessor
7from libs.migration.MigrationEPB import MigrationEPB
8from MolesManager.moles3epb import Moles3EPB
9from libs.migration.migration_sessions import MigrationSessions
10import logging
11from logging import StreamHandler
12
13class MigrationProcess():
14    log = logging.getLogger('MigrationProcess')
15    log.addHandler(StreamHandler())
16    log.setLevel(logging.DEBUG)
17   
18    """
19        Manages the migration process from Moles2 to Moles3.
20    """
21    def __init__(self):
22        '''
23            Because this is usually the starting point of a migration
24            process, it initialize the necessaries DB sessions 
25        '''
26        self.migrationSessions = MigrationSessions(MigrationEPB.getNewMigrationSession(), Moles3EPB.getNewMolesSession())
27   
28    def process(self, dataEntityObject = None):
29        """
30            Starts the migration. If no DataEntityMigration instance is given then all the DataEntityMigration objects in the
31            data_entity_migration table are processed
32            1) each DataEntityMigration is associated to a "dataent_xxxx" file, called "data entity" in Moles2
33            2) each "data entity" is associated with a CEDA_ObservationCollection
34            @param dataEntityObject: a DataEntityMigration instance to process.
35            @return: a list of collected exceptions
36        """
37        exs = []
38        data_ents = []
39       
40        #Does the migrationObject exists?
41        if dataEntityObject:
42            data_ents.append(MigrationEPB.getDataEntityMigrationbyPath(dataEntityObject, session = self.migrationSessions.migrationSession))
43        else: #then process all the DataEntities
44            data_ents = MigrationEPB.getAllDataEntityMigration(session = self.migrationSessions.migrationSession)
45           
46        #loops over the data entities
47        for dataEntityMigration in [f for f in data_ents if f != None]:             
48            dep = DataEntityProcessor(dataEntityMigration, self.migrationSessions)
49            exs.extend(dep.process())
50        return exs
51       
52    def commitAll(self):
53        self._migrationSession.commit()
54        self._molesSession.commit()
55
56    def rollbackAll(self):
57        self._migrationSession.rollback()
58        self._molesSession.rollback()
Note: See TracBrowser for help on using the repository browser.