Changeset 8434


Ignore:
Timestamp:
04/07/12 14:25:18 (7 years ago)
Author:
mnagni
Message:

Incomplete - # 22416: CEDA MOLES3 - search function - by title keyword
 http://team.ceda.ac.uk/trac/ceda/ticket/22416

Location:
mauRepo/MolesManager/trunk/src
Files:
3 edited

Legend:

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

    r8433 r8434  
    223223        # @@ plaint_tsquery(<search string>)" 
    224224        q = self._session.query(CEDA_Observation). \ 
    225             join(MO_Observation).join(MO_ObservationCollection.identifier). \ 
     225            join(MO_Observation).join(MO_Observation.identifier). \ 
    226226            filter('md_identifier.code_search_vector @@ to_tsquery(:terms)') 
    227227        # This binds the :terms placeholder to the searchterms string. User input  
  • mauRepo/MolesManager/trunk/src/MolesManager/views/cedaSearch.py

    r8430 r8434  
    2020        @return: the first Observation or None  
    2121        ''' 
    22     if not keywords.startswith("'"): 
    23         keywords = "'" + keywords 
    24     if not keywords.endswith("'"): 
    25         keywords = keywords + "'" 
    2622    obsevations = request.moles3EPB.extractObservationByTitleKeywords(keywords)  
    2723    titles = [] 
     
    3127    for o in obsevations: 
    3228        a = "".join([baseCov, str(o.id)]) 
    33         responsibleAuthors = request.moles3EPB.observationAuthor(o) 
    34         list_list.append((a, o.description, _appendAuthors(responsibleAuthors)))  
     29        try: 
     30            responsibleAuthors = request.moles3EPB.observationAuthor(o) 
     31            if responsibleAuthors is not None: 
     32                list_list.append((a, o.description, _appendAuthors(responsibleAuthors))) 
     33        except Exception as e: 
     34            print e 
    3535    return list_list 
    3636 
     
    3838    res = None 
    3939    for item in party: 
    40          res = ("%s%s,") % (res, item.name) 
     40        res = ("%s%s,") % (res, item.name) 
    4141    if len(res) > 1: 
    4242        return res[:len(res)-1] 
  • mauRepo/MolesManager/trunk/src/libs/migration/tests/moles3epbmothods.py

    r8409 r8434  
    66import unittest 
    77from testconfig import MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT 
    8 from MolesManager.moles3epb import Moles3EPB 
     8from MolesManager.moles3epb import Moles3EPB, Moles3EPBFactory 
    99from libs.commons_db import DbManager 
    1010from unittest import TestCase 
     
    1212from logging import StreamHandler 
    1313from test_utils import createObservationCollection, createObservation, createProject 
    14 from ea_model.moles3_4.observationcollection.mo_observationcollection import MO_ObservationCollection 
    15 from ea_model.moles3_4.utilities.mo_responsiblepartyinfo import MO_ResponsiblePartyInfo 
    16 from ea_model.moles3_4.observation.mo_observation import MO_Observation 
    17 from ea_model.moles3_4.utilities.mo_rolevalue import MO_RoleValue 
    18 from sqlalchemy.orm import subqueryload_all, subqueryload, joinedload,\ 
    19     joinedload_all, contains_eager 
    20 from ea_model.iso_19115_2006_metadata_corrigendum.reference_system_information.md_identifier import MD_Identifier 
    21 from sqlalchemy.orm.util import aliased 
     14from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation 
    2215 
    2316 
     
    2518 
    2619    def setUp(self):     
    27         Moles3EPBTest.molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT) 
    28         #Moles3EPBTest.molesDB = DbManager(TESTMOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT) 
    29         Moles3EPB.overrrideDBManager(Moles3EPBTest.molesDB) 
    30         self._initSearchIndexes(Moles3EPBTest.molesDB)         
     20        molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT)  
     21        self._mole3EPB = Moles3EPBFactory(molesDB).createEPB()                 
     22        self._initSearchIndexes(molesDB)         
    3123        self.logging = logging.getLogger('Moles3EPBTest') 
    3224        self.logging.addHandler(StreamHandler()) 
     
    3931    def runTest(self): 
    4032        #self.checkExtractCollectionIdentifierByTitle()    
    41         #self.checkExtractObservationByTitleKeywords()  
     33        self.checkExtractObservationByTitleKeywords()  
    4234        #self.checkExtractProjectObservationCollections() 
    4335        #self.checkExtractObservationCollectionsForObservation() 
    4436        #self.checkObservationAuthors() 
    45         self.checkSubqueryload() 
     37        #self.checkSubqueryload() 
    4638 
    4739    def checkSubqueryload(self): 
    4840        eagerloadthese = ['identifier', 'resultTime', 'relatedParty.party'] 
    4941        obs_id = 1 
    50         ret = Moles3EPB.searchSelectiveEager(CEDA_Observation, obs_id, eagerloadthese) 
     42        ret = self._mole3EPB.searchSelectiveEager(CEDA_Observation, obs_id, eagerloadthese) 
    5143        print ret.relatedParty[0].party 
    5244 
     
    6961 
    7062    def checkObservationAuthors(self): 
    71         session = Moles3EPB.getNewMolesSession(); 
    72         coll = Moles3EPB.observationAuthor(1, session) 
    73         colls = coll.all() 
    74         print colls 
    75  
    76     def checkExtractObservationCollectionsForObservation(self): 
    77         session = Moles3EPB.getNewMolesSession(); 
    78         #coll = session.query(CEDA_ObservationCollection). \ 
    79         #    join(MO_ObservationCollection).join(MO_ObservationCollection.member) 
    80         coll = session.query(CEDA_ObservationCollection) 
     63        coll = self._mole3EPB.observationAuthor(1) 
    8164        colls = coll.all() 
    8265        print colls 
    8366 
    8467    def checkExtractCollectionIdentifierByTitle(self): 
    85         session = Moles3EPB.getNewMolesSession(); 
    8668        observationCollection = createObservationCollection() 
    8769         
    8870        self.logging.info('Stores an new CEDA_ObservationCollection') 
    89         Moles3EPB.persistInstance(observationCollection) 
     71        self._mole3EPB.persistInstance(observationCollection) 
    9072 
    91         my_identifier = Moles3EPB.extractCollectionIdentifierByTitle('test_title', session)             
     73        my_identifier = self._mole3EPB.extractCollectionIdentifierByTitle('test_title')             
    9274        self.assertTrue(my_identifier.count() > 0, "Cannot find MD_Identifier") 
    93         my_identifier = Moles3EPB.extractCollectionIdentifierByTitle('fake_title', session)         
     75        my_identifier = self._mole3EPB.extractCollectionIdentifierByTitle('fake_title')         
    9476        self.assertTrue(my_identifier.count() == 0, "Cannot find MD_Identifier")             
    9577         
    9678        self.logging.info('Deletes it') 
    97         session.delete(observationCollection) 
    98         session.commit() 
     79        #session.delete(observationCollection) 
     80        #session.commit() 
    9981 
    10082    def checkExtractObservationByTitleKeywords(self): 
    101         session = Moles3EPB.getNewMolesSession(); 
    102         observation = createObservation() 
     83        #observation = createObservation() 
    10384         
    104         self.logging.info('Stores an new CEDA_Observation') 
    105         Moles3EPB.persistInstance(observation) 
     85        #self.logging.info('Stores an new CEDA_Observation') 
     86        #self._mole3EPB.persistInstance(observation) 
    10687         
    107         obs = Moles3EPB.extractObservationByTitleKeywords('test_code', session) 
    108         self.assertTrue(obs.count() > 1, "Cannot find a CEDA_Observation") 
    109         obs = Moles3EPB.extractObservationByTitleKeywords('dummy_code', session) 
    110         self.assertTrue(obs.count() == 0, "Should NOT find a CEDA_Observation") 
    111         session.delete(observation) 
    112         session.commit()            
    113  
     88        obs = self._mole3EPB.extractObservationByTitleKeywords('ECMWF') 
     89        print len(obs) 
     90        #self.assertTrue(obs.count() > 1, "Cannot find a CEDA_Observation") 
     91        #obs = self._mole3EPB.extractObservationByTitleKeywords('dummy_code') 
     92        #self.assertTrue(obs.count() == 0, "Should NOT find a CEDA_Observation") 
     93        #session.delete(observation) 
     94        #session.commit()            
     95    ''' 
    11496    def checkExtractProjectObservationCollections(self): 
    115         session = Moles3EPB.getNewMolesSession(); 
    11697 
    11798        p_1 = createProject() 
     
    166147            self.assertTrue(True==False, "Error!") 
    167148        self._delete(objects, session)                 
    168  
     149    ''' 
    169150                     
    170151    def _initSearchIndexes(self, db_manager): 
     
    183164            pass 
    184165 
    185     def _create(self, objects, session): 
     166    def _create(self, objects): 
    186167        for item in objects: 
    187             Moles3EPB.persistInstance(item) 
     168            self._mole3EPB.persistInstance(item) 
    188169 
    189170    def _delete(self, objects, session): 
Note: See TracChangeset for help on using the changeset viewer.