Changeset 5135 for ndgCommon/trunk


Ignore:
Timestamp:
23/03/09 16:08:17 (11 years ago)
Author:
cbyrom
Message:

Add new method for vocab server client to allow vocab terms to be searched.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/src/clients/http/vocabserverclient.py

    r5117 r5135  
    1010from ndg.common.src.lib.utilities import httpify 
    1111from ndg.common.src.models.codetabletype import CodeTableType 
     12from ndg.common.src.models.codetablerecord import CodeTableRecord 
    1213 
    1314class VocabServerClient(GenericHTTPClient): 
     
    1819    GET_LIST_QUERY = '%sgetList?recordKey=%s' 
    1920    WHAT_LISTS_QUERY = '%swhatLists' 
     21    SEARCH_VOCAB_QUERY = '%ssearchVocab?listKey=%s&searchTerm=%s' 
    2022     
    2123    def __init__(self,  
     
    103105        error = et.findtext('{%s}error' %ndgObject.VOCAB_NS) 
    104106        if error != 'false': 
    105             raise SystemError("Problem occurred whilst looking up vocab data: %s" %list.error) 
     107            raise SystemError("Problem occurred whilst looking up vocab list: %s" %error) 
    106108 
    107109        recordElements = et.findall('{%s}codeTableType' %ndgObject.VOCAB_NS) 
    108110         
    109         self.records = [] 
    110111        for record in recordElements: 
    111112            ctr = CodeTableType(et = record) 
     
    117118         
    118119         
     120    def searchVocabTerm(self, vocabListKey, searchTerm): 
     121        ''' 
     122        Search the specified vocab list for terms matching the input searchTerm 
     123        @param vocabListKey: url of the vocab list 
     124        @param searchTerm: term to search on - NB, accepts '*' wildcard for any character 
     125        @return list of CodeTableRecords matching the search criteria 
     126        ''' 
     127        logging.debug("Searching for vocab terms matching the input filter, '%s' in vocab list, '%s'"  
     128                      %(searchTerm, vocabListKey)) 
     129        url = self.SEARCH_VOCAB_QUERY %(self.path, vocabListKey, searchTerm) 
     130        doc = self.readURL(url) 
     131        et = ET.fromstring(doc) 
     132 
     133        error = et.findtext('{%s}error' %ndgObject.VOCAB_NS) 
     134        if error != 'false': 
     135            raise SystemError("Problem occurred whilst searching vocab data: %s" %error) 
     136 
     137        recordElements = et.findall('{%s}codeTableRecord' %ndgObject.VOCAB_NS) 
     138         
     139        self.records = [] 
     140        for record in recordElements: 
     141            self.records.append(CodeTableRecord(et = record)) 
     142         
     143        logging.debug("- returning %s results" %len(self.records)) 
     144        return self.records 
Note: See TracChangeset for help on using the changeset viewer.