Changeset 8236


Ignore:
Timestamp:
14/04/12 09:22:37 (8 years ago)
Author:
mnagni
Message:

Incomplete - # 22428: CEDA Project - observationCollection
 http://team.ceda.ac.uk/trac/ceda/ticket/22428
Complete - # 22433: CEDA Observation - GUID
 http://team.ceda.ac.uk/trac/ceda/ticket/22433
Incomplete - # 22385: CEDA Observation - result
 http://team.ceda.ac.uk/trac/ceda/ticket/22385

Location:
mauRepo/MolesManager/trunk/src
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/MolesManager/trunk/src/MolesManager

    • Property svn:ignore set to
      My_settings.py
      myUrls.py
  • mauRepo/MolesManager/trunk/src/MolesManager/moles3epb.py

    r8217 r8236  
    88from ea_model.ceda_metadatamodel.ceda_observationcollection.ceda_observationcollection import CEDA_ObservationCollection 
    99from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation 
    10 from libs.migration.processor.check.check import moles3Append 
    11 from libs.migration.processor.commons import createDQ_Element 
    1210from ea_model.iso_19115_2006_metadata_corrigendum.reference_system_information.md_identifier import MD_Identifier 
    1311from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_citation import CI_Citation 
     
    1513from ea_model.moles3_4.observation.mo_observation import MO_Observation 
    1614from ea_model.ceda_metadatamodel.ceda_project.ceda_project import CEDA_Project 
    17  
    18 #molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT) 
     15from sqlalchemy import Table, Column, ForeignKey, Integer, String 
     16from sqlalchemy.orm import mapper 
     17from MolesManager.ceda_guid import CedaGUID 
     18 
    1919 
    2020class Moles3EPB(EPB): 
    2121 
    2222    _molesDB = None 
    23     #_migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT) 
    24      
     23    
    2524    @classmethod 
    2625    def overrrideDBManager(self, dbManager): 
     
    2928        """ 
    3029        Moles3EPB._molesDB = dbManager 
     30        Moles3EPB._initCEDA_Customization() 
     31 
     32    @classmethod 
     33    def _initCEDA_Customization(self): 
     34        Moles3EPB._associateCEDA_GUID() 
     35        Moles3EPB._initSearchIndexes()         
     36         
     37    @classmethod 
     38    def _associateCEDA_GUID(self): 
     39        guid_table = Table('ceda_guid', Moles3EPB._molesDB.metadata, \ 
     40                           Column('id', String, primary_key=True), \ 
     41                           Column('ceda_observationcollection', Integer, ForeignKey('ceda_observationcollection.id')),  
     42                           Column('ceda_observation', Integer, ForeignKey('ceda_observation.id'))) 
     43        mapper(CedaGUID, guid_table) 
     44        Moles3EPB._molesDB.metadata.create_all() 
     45 
     46    @classmethod 
     47    def _initSearchIndexes(self): 
     48        #To Be Done - CHECK IF THE COLUMN ALREADY EXISTS! 
     49        # We don't want sqlalchemy to know about this column so we add it externally. 
     50        try: 
     51            Moles3EPB._molesDB._engine.execute("alter table md_identifier add column code_search_vector tsvector")                  
     52 
     53            # This indexes the tsvector column 
     54 
     55            Moles3EPB._molesDB._engine.execute("create index md_identifier_code_search_index on md_identifier using gin(code_search_vector)") 
     56 
     57            # This sets up the trigger that keeps the tsvector column up to date. 
     58            Moles3EPB._molesDB._engine.execute("create trigger md_identifier_code_search_update before update or insert on md_identifier \ 
     59                for each row execute procedure tsvector_update_trigger('code_search_vector', 'pg_catalog.english', 'code')")                         
     60        except Exception as e: 
     61            pass 
    3162 
    3263    @classmethod         
     
    143174        intSession = Moles3EPB._getSession(session) 
    144175        if not self.observationCollectionHasObservation(observationCollection.id, observation.id, intSession): 
    145             moles3Append(observationCollection, 'member', observation) 
     176            observationCollection.member.append(observation) 
    146177            if commit: 
    147178                intSession.commit() 
     
    204235        intSession = Moles3EPB._getSession(session) 
    205236        if not identifier in observation.identifier: 
    206             #observation.identifier.append(identifier) 
    207             moles3Append(observation, 'identifier', identifier) 
     237            observation.identifier.append(identifier) 
    208238        if commit: 
    209239            intSession.commit() 
  • mauRepo/MolesManager/trunk/src/MolesManager/molesSessionMiddleware.py

    r8229 r8236  
    2424     
    2525 
    26     def _initSearchIndexes(self, db_manager): 
    27         #To Be Done - CHECK IF THE COLUMN ALREADY EXISTS! 
    28         # We don't want sqlalchemy to know about this column so we add it externally. 
    29         try: 
    30             db_manager._engine.execute("alter table md_identifier add column code_search_vector tsvector")                  
    3126 
    32             # This indexes the tsvector column 
    33  
    34             db_manager._engine.execute("create index md_identifier_code_search_index on md_identifier using gin(code_search_vector)") 
    35  
    36             # This sets up the trigger that keeps the tsvector column up to date. 
    37             db_manager._engine.execute("create trigger md_identifier_code_search_update before update or insert on md_identifier \ 
    38                 for each row execute procedure tsvector_update_trigger('code_search_vector', 'pg_catalog.english', 'code')")                         
    39         except Exception as e: 
    40             pass 
    4127 
    4228    def _getNewMolesSession(self): 
     
    5541        Moles3EPB.overrrideDBManager(molesDB) 
    5642        MolesSessionMiddleware._epbInitialized = True             
    57         self._initSearchIndexes(molesDB) 
     43        #self._initSearchIndexes(molesDB) 
     44        #Moles3EPB.associateCEDA_GUID() 
    5845     
    5946    def _getMolesSession(self): 
  • mauRepo/MolesManager/trunk/src/MolesManager/urls.py

    r8211 r8236  
    1 from django.conf.urls.defaults import patterns, url 
    2 from MolesManager.settings import STATIC_ROOT 
     1from django.conf.urls.defaults import patterns 
    32 
    43# Uncomment the next two lines to enable the admin: 
     
    2120 
    2221    (r'cov/$', 'coView'), 
     22) 
     23 
     24urlpatterns += patterns('MolesManager.views.splash', 
     25 
     26    (r'splash/(\w{32})$', 'splash'), 
    2327) 
    2428 
  • mauRepo/MolesManager/trunk/src/MolesManager/views/cedaObservationView.py

    r8211 r8236  
    66from django.shortcuts import render_to_response 
    77from django.core.context_processors import csrf 
    8 from MolesManager.forms.commons import ObjectById 
    98from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation 
    109from MolesManager.moles3epb import Moles3EPB 
     
    1312 
    1413 
    15 def __getSample(request, c): 
    16     ''' 
    17     @param request: an HttpRequest 
    18     @param objectId: an instance of ObjectById   
    19     ''' 
     14def coView(request): 
     15    obs_id = None 
    2016    if request.POST.has_key('obs_id'): 
    21         dp = Moles3EPB.searchEager(CEDA_Observation, request.POST['obs_id'], request.moles_session) 
    22         c['records'] = dp 
     17        obs_id = request.POST['obs_id']         
     18    return splash(request, obs_id)    
    2319 
    24  
    25 def coView(request): 
     20def splash(request, obs_id): 
     21    """ 
     22        Processes and display a given CEDA_Observation id 
     23        @param request: an HTTP request 
     24        @param obs_id: the CEDA_Observation id 
     25        @return: an HTTPResponse   
     26    """ 
     27    record = None 
     28    if obs_id: 
     29        record = _getCedaObservation(request, obs_id) 
     30    return _finalizeResponse(request, record) 
     31     
     32def _finalizeResponse(request, record): 
    2633    c = {} 
    27     __getSample(request, c) 
    28     if c.has_key('records'): 
    29         c['coObs'] = mark_safe(DJEncoder().escapeForJSON(DJEncoder().encode(c['records']))) 
     34    if record: 
     35        c['coObs'] = mark_safe(DJEncoder().escapeForJSON(DJEncoder().encode(record))) 
    3036        print c['coObs']  
    3137     
    3238    c.update(csrf(request)) 
    3339    return render_to_response('cedaObservation.html', c) 
     40 
     41def _getCedaObservation(request, obs_id): 
     42    return Moles3EPB.searchEager(CEDA_Observation, obs_id, request.moles_session)     
  • mauRepo/MolesManager/trunk/src/libs/commons_db.py

    r8228 r8236  
    3131          @param sql_echo: sets the SQLalchemy create_engine.echo param. Default is False       
    3232        """ 
    33         self._metadata = MetaData() 
    3433        self._connection = connection 
    3534        self._script = script 
    36         self._engine = create_engine(self._connection, echo=sql_echo) 
     35        self.engine = create_engine(self._connection, echo=sql_echo) 
     36        self.metadata = MetaData(bind=self.engine)         
    3737        self._session = None 
    3838        if self._script: 
    39             self._script(self._metadata) 
    40             self._metadata.create_all(bind=self._engine) 
    41             self._session = scoped_session(sessionmaker(bind=self._engine)) 
     39            self._script(self.metadata) 
     40            self.metadata.create_all(bind=self.engine) 
     41            self._session = scoped_session(sessionmaker()) 
    4242             
    43   
    4443    def createDbSession(self): 
    4544        """ 
     
    4948        if self._session: 
    5049            return self._session() 
    51         if self._engine: 
    52             return self._engine.connect() 
     50        if self.engine: 
     51            return self.engine.connect() 
    5352 
    5453    def closeDbSession(self, dbSession): 
     
    7574        session.add_all(items) 
    7675 
    77 def getObjectId(clazz, id, session):   
     76def getObjectId(clazz, obj_id, session):   
    7877    ''' 
    7978        Retrieves an entity 
    8079        @param clazz: the entity type 
    81         @param id: the entity id   
     80        @param obj_id: the entity id   
    8281    '''        
    83     res = session.query(clazz).get(id) 
     82    res = session.query(clazz).get(obj_id) 
    8483    if res is None: 
    8584        return None 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/dataEntity.py

    r8202 r8236  
    1414    createMD_Identifier, extractContent, MD_CODE_MOLES2_CITATION,\ 
    1515    hasAtomDocumentSameHash, createCI_Citation, createCI_Date, findPublishedDate,\ 
    16     isoDateTimeStringToTimeDate, findUpdatedDate, createDate, createDateTime 
     16    isoDateTimeStringToTimeDate, findUpdatedDate, createDate,\ 
     17    calculateHash 
    1718from libs.migration.processor.deployment import DeploymentProcessor 
    1819from ea_model.moles3_4.utilities.mo_publicationstatevalue import MO_PublicationStateValue 
    1920from logging import StreamHandler 
    2021import logging 
    21 from libs.migration.processor.check.check import moles3Append 
    2222from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_datetypecode import CI_DateTypeCode 
     23from MolesManager.ceda_guid import CedaGUID 
    2324 
    2425class DataEntityProcessor(object): 
     
    6061            i_citation = createCI_Citation(title = 'ceda_moles2_citation', date=ci_dates) 
    6162            newIdentifier = createMD_Identifier(code = contentDict['citation'], authority=i_citation) 
    62             moles3Append(ceda_observationCollection, 'identifier', newIdentifier) 
     63            ceda_observationCollection.identifier.append(newIdentifier) 
    6364     
    6465    def _getObservationCollection(self): 
     
    99100                   
    100101        Moles3EPB.addCedaObject(ceda_observationCollection, self.migrationSessions.molesSession, True) 
     102         
     103        #Adds the CedaGUID 
     104        ceda_guid = CedaGUID() 
     105        ceda_guid.id = calculateHash(self._dataEntityMigration.data_ent_id) 
     106        ceda_guid.ceda_observationcollection = ceda_observationCollection.id 
     107        Moles3EPB.addCedaObject(ceda_guid, self.migrationSessions.molesSession, True) 
     108         
    101109        MigrationEPB.associateObservationCollectionToDataEntity(self._dataEntityMigration, ceda_observationCollection.id, True) 
    102110        return ceda_observationCollection 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment.py

    r8227 r8236  
    1818    createCI_Telephone, extractMolesTemporalRange, isoDateStringToTimeDate,\ 
    1919    createTM_Period, createCI_Individual, findAccessLinksInMigrationDocument,\ 
    20     findLinksInDeployment, createMD_LegalConstraints, extractMolesQuality,\ 
     20    findLinksInDeployment, createMD_LegalConstraints,\ 
    2121    createDQ_Element, createDQ_ConformanceResult, findUpdatedDate,\ 
    22     createMD_Metadata, createMO_OnlineResource, createCEDA_Review 
     22    createMD_Metadata, createMO_OnlineResource, createCEDA_Review, calculateHash 
    2323from ea_model.moles3_4.utilities.mo_rolevalue import MO_RoleValue 
    2424from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation 
     
    3535from datetime import date 
    3636from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_onlinefunctioncode import CI_OnLineFunctionCode 
    37 from libs.migration.processor.check.check import moles3Append 
    3837from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_datetypecode import CI_DateTypeCode 
    3938from ea_model.iso_19115_2006_metadata_corrigendum.constraint_information.md_restrictioncode import MD_RestrictionCode 
     
    4443from ea_model.ceda_metadatamodel.ceda_utilities.ceda_reviewfrequencyvalue import CEDA_ReviewFrequencyValue 
    4544from ea_model.ceda_metadatamodel.ceda_utilities.ceda_reviewstatusvalue import CEDA_ReviewStatusValue 
    46 from ea_model.iso_19115_2006_metadata_corrigendum.citation_and_responsible_party_information.ci_rolecode import CI_RoleCode 
     45from MolesManager.ceda_guid import CedaGUID 
    4746 
    4847class DeploymentProcessor(object): 
     
    218217        i_dq_result = createDQ_ConformanceResult(doc_quality, True, i_specification) 
    219218        i_quality_element = createDQ_Element(i_dq_result)         
    220         observation.resultQuality = [i_quality_element] 
     219        observation.resultQuality.append(i_quality_element) 
    221220         
    222221    def updateObservation(self): 
     
    280279            ge = extractGeographicExtentInMigrationDocument(self._dataEntityMigration) 
    281280        if ge: 
    282             moles3Append(observation, 'geographicExtent', createEX_GeographicBoundingBox(ge['east'], ge['north'], ge['west'], ge['south'])) 
     281            observation.geographicExtent.append(createEX_GeographicBoundingBox(ge['east'], ge['north'], ge['west'], ge['south'])) 
    283282 
    284283    def _assignCreationDate(self, observation): 
     
    310309            if ci_date:                 
    311310                identifier.authority = createCI_Citation("", date = ci_date) 
    312             moles3Append(observation, 'identifier', identifier)                  
    313             #Moles3EPB.addIdentifierToObservation(identifier, observation, self._migrationSessions.molesSession)                     
     311            observation.identifier.append(identifier)                                      
    314312 
    315313    def _assignPublisherCurator(self, observation):         
     
    375373        i_accessConstraints = [] 
    376374        i_use_limitation = [] 
    377         md_legal_constraints = None 
    378375         
    379376        if len(access_link) == 0: 
     
    402399        i_authority = createCI_Citation('moles2url') 
    403400        identifier = createMD_Identifier(code = i_code, authority = i_authority) 
    404         moles3Append(ceda_observation, 'identifier', identifier) 
     401        ceda_observation.identifier.append(identifier) 
    405402     
    406403    def _assignLanguage(self, ceda_observation): 
     
    436433        #self._assignLanguage(ceda_observation)         
    437434        Moles3EPB.addCedaObject(ceda_observation, self._migrationSessions.molesSession, True) 
     435         
     436        #Adds the CedaGUID         
     437        ceda_guid = CedaGUID() 
     438        ceda_guid.id = calculateHash(self._deploymentMigration.depl_id) 
     439        ceda_guid.ceda_observation = ceda_observation.id 
     440        Moles3EPB.addCedaObject(ceda_guid, self._migrationSessions.molesSession, True) 
     441         
    438442        MigrationEPB.associateObservationToDeployment(self._deploymentMigration, ceda_observation.id, self._migrationSessions.molesSession, True) 
    439443        return ceda_observation 
  • mauRepo/MolesManager/trunk/src/libs/migration/tests/migrationprocess.py

    r8221 r8236  
    2424        #self._dropAllTables() 
    2525         
    26         migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT) 
     26        migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT, sql_echo=True) 
    2727        MigrationEPB.overrrideDBManager(migrationDB)         
    2828 
    29         molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT) 
     29        molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT, sql_echo=True) 
    3030        Moles3EPB.overrrideDBManager(molesDB) 
    3131         
    32         infoDB = DbManager(INFO_DB_CONNECTION) 
     32        infoDB = DbManager(INFO_DB_CONNECTION, sql_echo=True) 
    3333        InfodbEPB.overrrideDBManager(infoDB) 
    3434         
  • mauRepo/MolesManager/trunk/src/libs/migration/tests/moles3epbtests.py

    r8217 r8236  
    106106        self.logging.info('Adds two CEDA_Observations') 
    107107        firstObservation = self._createObservation() 
    108         moles3Append(observationCollection, 'member', firstObservation) 
     108        observationCollection.member.append(firstObservation) 
    109109        secondObservation = self._createObservation() 
    110         moles3Append(observationCollection, 'member', secondObservation)      
     110        observationCollection.member.append(secondObservation)      
    111111        session.commit() 
    112112         
Note: See TracChangeset for help on using the changeset viewer.