Ignore:
Timestamp:
30/08/12 08:40:42 (7 years ago)
Author:
mnagni
Message:

Complete - # 22528: Migration of FAtCat Open Search link for HPFeld
 http://team.ceda.ac.uk/trac/ceda/ticket/22528
Adds a ceda_timestamp column to the tm_instant table to simplify the search-by-time in cedamoles.
The code has been changed consequently to use the new parameter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/MolesManager/trunk/cedaMoles/MolesManager/moles3epb.py

    r8538 r8545  
    3232''' 
    3333from cedaMoles.libs.epb import EPB 
     34from cedaMoles.MolesManager.db.tm_instant import customize_tm_instant 
     35from cedaMoles.MolesManager.db.search_indexes import init_search_indexes 
     36from cedaMoles.MolesManager.db.ceda_guid import init_ceda_guid 
     37from cedaMoles.MolesManager.db.after_flush import after_flush 
    3438from ea_model.moles3_4.observationcollection.mo_observationcollection \ 
    3539    import MO_ObservationCollection 
    3640from ea_model.moles3_4.observation.mo_observation import MO_Observation 
    37 from sqlalchemy import Table, Column, ForeignKey, Integer, String, event 
    38 from sqlalchemy.orm import mapper 
     41from sqlalchemy import event 
    3942from cedaMoles.MolesManager.ceda_guid import CedaGUID 
    4043from sqlalchemy.orm.collections import InstrumentedList 
     
    5255from ea_model.ceda_metadatamodel.ceda_project.ceda_project import CEDA_Project 
    5356from cedaMoles.MolesManager.codelist import MM_RoleValue, getCLValue 
    54 from cedaMoles.libs.migration.processor.commons import from_pt_to_string 
    55 from datetime import datetime 
    5657from ascore.utils import synchAttributes 
    57 from cedaMoles.MolesManager.db.partyIndexes import associateMOParty_indexes 
    58 from cedaMoles.MolesManager.db.after_flush import afterFlush 
     58from cedaMoles.MolesManager.db.partyIndexes import associate_moparty_indexes 
    5959 
    6060class Moles3EPBFactory(EPB):    
     
    6464 
    6565    def _init_ceda_customization(self): 
    66         self._associate_ceda_guid() 
    67         associateMOParty_indexes(self._db_manager.metadata) 
    68         self._initSearchIndexes()   
    69          
    70     def _associate_ceda_guid(self): 
    71         guid_table = Table('ceda_guid', self._db_manager.metadata,  
    72                            Column('id', String, primary_key=True),  
    73                            Column('ceda_observationcollection',  
    74                                   Integer, ForeignKey('ceda_observationcollection.id')),  
    75                            Column('ceda_observation',  
    76                                   Integer, ForeignKey('ceda_observation.id')), 
    77                            Column('ceda_project',  
    78                                   Integer, ForeignKey('ceda_project.id'))) 
    79         mapper(CedaGUID, guid_table) 
    80         self._db_manager.metadata.create_all() 
    81  
    82     def _initSearchIndexes(self): 
    83         #To Be Done - CHECK IF THE COLUMN ALREADY EXISTS! 
    84         # We don't want sqlalchemy to know about this column so we add it externally. 
    85         try: 
    86             self._db_manager.engine.execute("alter table md_identifier \ 
    87                 add column code_search_vector tsvector")                  
    88  
    89             # This indexes the tsvector column 
    90  
    91             self._db_manager.engine.execute("create index \ 
    92                 md_identifier_code_search_index on md_identifier using gin(code_search_vector)") 
    93  
    94             # This sets up the trigger that keeps the tsvector column up to date. 
    95             self._db_manager.engine.execute("create trigger \ 
    96                 md_identifier_code_search_update \ 
    97                 before update or insert on md_identifier \ 
    98                 for each row execute procedure \ 
    99                 tsvector_update_trigger('code_search_vector', \ 
    100                                         'pg_catalog.english', code)")                         
    101         except Exception: 
    102             pass 
     66        init_ceda_guid(self._db_manager.metadata)         
     67        associate_moparty_indexes(self._db_manager.metadata) 
     68        init_search_indexes(self._db_manager.engine) 
     69        customize_tm_instant(self._db_manager.engine, self._db_manager.metadata) 
    10370         
    10471    def createEPB(self): 
    10572        session = self._get_session() 
    106         event.listen(session, 'after_flush', afterFlush) 
     73        event.listen(session, 'after_flush', after_flush)       
    10774        return Moles3EPB(session) 
    10875 
     
    137104             
    138105        **Returns** 
    139             An updated, session independent, object instance reflecting the new persisted object  
     106            An updated, session independent, object instance reflecting  
     107            the new persisted object  
    140108        """ 
    141109        EPB.persistInstance(instance, self._session)         
     
    225193            @param collection: an CEDA_ObservationColleciton instance   
    226194        """ 
     195        if not hasattr(collection, 'member'): 
     196            return None 
     197         
    227198        bboxes = [] 
    228         if not hasattr(collection, 'member'): 
    229             return bboxes 
    230199        for member in collection.member: 
    231200            for ge in member.geographicExtent: 
     
    428397    """ 
    429398    return "%s-%s-%s" % (dt.year, dt.month, dt.day) 
    430  
    431 def unify_observation_collection_phenomenon_time(collection): 
    432     """ 
    433         Returns the time period of the collections.member'a  phenomenonTime(s) 
    434         @param collection: an CEDA_ObservationColleciton instance  
    435         @return: a tuple (startDate, endDate) strings 
    436     """ 
    437     dateFormat = '%Y-%m-%d' 
    438     ptStart = [] 
    439     ptEnd = []       
    440     for member in collection.member: 
    441         if member.phenomenonTime is None: 
    442             continue 
    443              
    444         pt =  member.phenomenonTime 
    445         ptString = from_pt_to_string(pt) 
    446         if ptString[0] is not None:                     
    447             ptStart.append(datetime.strptime(ptString[0], dateFormat)) 
    448         if ptString[1] is not None:                     
    449             ptEnd.append(datetime.strptime(ptString[1], dateFormat)) 
    450     ptStart.sort()                     
    451     ptEnd.sort() 
    452     start = None 
    453     end = None 
    454     #takes the earlier date 
    455     if len(ptStart) > 0: 
    456         start = _tmpstrftime(ptStart[0])  
    457     #takes the latest date 
    458     if len(ptEnd) > 0: 
    459         end = _tmpstrftime(ptEnd[len(ptEnd) - 1])  
    460     return start, end  
Note: See TracChangeset for help on using the changeset viewer.