Changeset 8482 for mauRepo/MolesManager


Ignore:
Timestamp:
03/08/12 15:17:55 (7 years ago)
Author:
mnagni
Message:

Complete - # 22489: CEDA Observation Collection - phenomenonTime
 http://team.ceda.ac.uk/trac/ceda/ticket/22489
Incomplete - # 22531: CedaMoles3 MO_Party
 http://team.ceda.ac.uk/trac/ceda/ticket/22531

Many more unitests
Better structure for database operation (see MolesManager?.db.after_flux and moles3epb)
Documented many method but not updated docs folder

Location:
mauRepo/MolesManager/trunk
Files:
9 added
4 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/MolesManager/trunk/src/MolesManager/djencoder.py

    r8480 r8482  
    2121 
    2222    def default(self, obj): 
     23        if obj is not None and id(obj) in self.__markers: 
     24            return 
     25         
    2326        # Convert objects to a dictionary of their representation 
    2427        d = { '__module__':obj.__module__, 
  • mauRepo/MolesManager/trunk/src/MolesManager/moles3epb.py

    r8481 r8482  
    3434from ea_model.moles3_4.observationcollection.mo_observationcollection import MO_ObservationCollection 
    3535from ea_model.moles3_4.observation.mo_observation import MO_Observation 
    36 from sqlalchemy import Table, Column, ForeignKey, Integer, String 
     36from sqlalchemy import Table, Column, ForeignKey, Integer, String, event 
    3737from sqlalchemy.orm import mapper 
    3838from MolesManager.ceda_guid import CedaGUID 
     
    4141from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_citation import CI_Citation 
    4242from ea_model.iso_19115_2006_metadata_corrigendum.extent_information.ex_geographicboundingbox import EX_GeographicBoundingBox 
    43 from libs.postgisutil import unifyGeometries, create_st_setSRID, getBox2D,\ 
    44     unifyGeometriesAsBBox 
     43from libs.postgisutil import create_st_setSRID, unifyGeometriesAsBBox 
    4544from ea_model.ceda_metadatamodel.ceda_observationcollection.ceda_observationcollection import CEDA_ObservationCollection 
    4645from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation 
    4746from ea_model.ceda_metadatamodel.ceda_project.ceda_project import CEDA_Project 
    48 from ea_model.moles3_4.utilities.mo_responsiblepartyinfo import MO_ResponsiblePartyInfo 
    49 from ea_model.moles3_4.utilities.ceda_rolevalue import CEDA_RoleValue 
    5047from MolesManager.codelist import MM_RoleValue, getCLValue 
    5148from libs.migration.processor.commons import fromPhenomenonTimeToString 
    5249from datetime import datetime 
    5350from ascore.utils import synchAttributes 
     51from MolesManager.db.partyIndexes import associateMOParty_indexes 
     52from MolesManager.db.after_flush import afterFlush 
    5453 
    5554class Moles3EPBFactory(EPB): 
     
    6261    def _initCEDA_Customization(self): 
    6362        self._associateCEDA_GUID() 
    64         self._initSearchIndexes()         
     63        associateMOParty_indexes(self._dbManager.metadata) 
     64        self._initSearchIndexes()   
    6565         
    6666    def _associateCEDA_GUID(self): 
     
    9595         
    9696    def createEPB(self): 
    97         return Moles3EPB(self._getSession()) 
     97        session = self._getSession() 
     98        event.listen(session, 'after_flush', afterFlush) 
     99        return Moles3EPB(session) 
    98100 
    99101class Moles3EPB(object): 
     
    113115        except Exception as e: 
    114116            print e 
     117 
     118    def rollback(self): 
     119        """ 
     120        Rolls back the session and one a new transaction  
     121        """ 
     122        EPB.rollback(self._session)  
    115123      
    116124    def persistInstance(self, instance): 
    117125        """ 
    118             Adds a new migration object. 
    119             @param migrationObj: the migration object to add 
    120             @param session: an SQLAlchemy Session object. If not None the session IS NOT closed at the exit,  
    121             If None (default) a new Session is created from the underlying EPB and closed at the exit. 
    122             @return an updated, session independent, object instance reflecting the new persisted object  
     126        Adds a new migration object. 
     127        **Parameters** 
     128            * instance: the object to add 
     129             
     130        **Returns** 
     131            An updated, session independent, object instance reflecting the new persisted object  
    123132        """ 
    124133        EPB.persistInstance(instance, self._session)         
     134 
     135    def mergeInstance(self, instance): 
     136        """ 
     137        Copy the state an instance onto the persistent instance with the same identifier. 
     138        **Parameters** 
     139            * instance: the object to add 
     140             
     141        **Returns** 
     142            An updated object instance reflecting the new persisted object  
     143        """ 
     144        return EPB.mergeInstance(instance, self._session)   
     145 
     146    def refresh(self, instance): 
     147        """ 
     148        Expires and refresh the attributes on the given instance. 
     149        **Parameters** 
     150            * instance: the object to refresh  
     151        """ 
     152        EPB.refresh(instance, self._session)  
     153 
     154 
     155    def deleteInstance(self, instance): 
     156        """ 
     157        Deletes a new migration object. 
     158        **Parameters** 
     159            * instance: the object to delete  
     160        """ 
     161        EPB.deleteInstance(instance, self._session)  
     162 
     163    def expunge(self, instance): 
     164        """ 
     165        Expunges an object from the session 
     166        **Parameters** 
     167            * instance: the object to expunge  
     168        """ 
     169        EPB.expunge(instance, self._session)  
    125170 
    126171    def _mergeOrAddInSession(self, ceda_object): 
  • mauRepo/MolesManager/trunk/src/MolesManager/molesSessionMiddleware.py

    r8425 r8482  
    5959        infoDB = DbManager(INFO_DB_CONNECTION) 
    6060        MolesSessionMiddleware._infodbEPBFactory = InfodbEPBFactory(infoDB) 
    61         #InfodbEPB.overrrideDBManager(infoDB) 
    6261            
    6362        migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT) 
     
    7473        MolesSessionMiddleware._epbInitialized = True       
    7574             
    76         _migration()       
     75        _migration() 
    7776    
    7877    def process_request(self, request):   
  • mauRepo/MolesManager/trunk/src/libs/epb.py

    r8480 r8482  
    159159 
    160160    @classmethod 
     161    def rollback(cls, session): 
     162        """ 
     163        Rolls back the session and one a new transaction  
     164        """ 
     165        session.rollback()   
     166 
     167    @classmethod 
     168    def mergeInstance(cls, instance, session): 
     169        """ 
     170            Copy the state an instance onto the persistent instance with the same identifier. 
     171            @param instance: the migration object to add 
     172            @param session: an sqlalchemy Session object. If None (default) the method creates 
     173            @return an updated, session independant, object instance reflecting the new persisted object  
     174        """         
     175        return session.merge(instance) 
     176 
     177    @classmethod 
     178    def refresh(cls, instance, session): 
     179        """ 
     180            Expire and refresh the attributes on the given instance. 
     181            @param instance: the migration object to add 
     182            @param session: an sqlalchemy Session object. If None (default) the method creates 
     183            @return an updated, session independant, object instance reflecting the new persisted object  
     184        """         
     185        session.refresh(instance) 
     186 
     187    @classmethod 
    161188    def persistInstance(cls, instance, session): 
    162189        """ 
    163             Adds a new migration object. 
    164             @param migrationObj: the migration object to add 
     190            Adds a new object. 
     191            @param instance: the migration object to add 
    165192            @param session: an sqlalchemy Session object. If None (default) the method creates 
    166193            @return an updated, session independant, object instance reflecting the new persisted object  
     
    171198        instance = EPB.search(id_key[0], id_key[1], session) 
    172199        #instance = ret 
     200 
     201    @classmethod 
     202    def deleteInstance(cls, instance, session): 
     203        """ 
     204            Deletes a new object. 
     205            @param instance: the migration object to be deleted 
     206            @param session: an sqlalchemy Session object. If None (default) the method creates  
     207        """         
     208        session.delete(instance) 
     209        session.commit() 
     210 
     211    @classmethod 
     212    def expunge(cls, instance, session): 
     213        """ 
     214            Expunges an object from the session. 
     215            @param instance: the migration object to expunge 
     216            @param session: an sqlalchemy Session object. If None (default) the method creates  
     217        """         
     218        session.expunge(instance) 
    173219 
    174220    @classmethod 
Note: See TracChangeset for help on using the changeset viewer.