Changeset 4313


Ignore:
Timestamp:
09/10/08 09:32:22 (11 years ago)
Author:
cbyrom
Message:

Improve error handling - using user defined exception + include better
searching for items with matching term IDs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgUtils/vocabtermdata.py

    r4301 r4313  
    258258        @param subType: term ID of the subtype of the data 
    259259        @return: True if the subtype is valid 
    260         @raise ValueError: if the mainType is not recognised or the subType is not valid  
     260        @raise VocabTermDataError: if the mainType is not recognised or the subType is not valid  
    261261        ''' 
    262262        if not self.SUBTYPE_TERMS.has_key(mainType): 
     
    270270        errorMessage = "Error: subtype, '%s' is not valid for data type, '%s'" \ 
    271271            %(subType, mainType) 
    272         logging.error(errorMessage) 
    273         raise ValueError(errorMessage) 
     272        raise VocabTermDataError(errorMessage) 
    274273 
    275274 
     
    281280        defined above 
    282281        @return list of VocabTermInfo objects for the specified category 
     282        @raise VocabTermDataError: if unrecognised data category  
    283283        ''' 
    284284        logging.debug("Lookup up list of valid %s types" %category) 
     
    294294        else: 
    295295            errorMessage = "Unrecognised data category, '%s'" %category 
    296             logging.info(errorMessage) 
    297             raise ValueError(errorMessage) 
     296            raise VocabTermDataError(errorMessage) 
    298297             
    299298        types = [] 
     
    338337        Given a term title/label, get back the related term id 
    339338        @param title: title/label of term id to retrieve 
    340         @raise ValueError: if more than one title or no title is returned   
     339        @raise VocabTermDataError: if more than one title or no title is returned   
    341340        ''' 
    342341        termID = [] 
     
    348347            errorMessage = "Error: could not accurately determine the vocab term \ 
    349348                ID for the label, '%s' - %s values returned" %(title, len(termID)) 
    350             logging.error(errorMessage) 
    351             raise ValueError(errorMessage) 
     349            raise VocabTermDataError(errorMessage) 
    352350 
    353351        return termID[0] 
     
    408406        Parse the server data for a specified uri and return the latest version number of it 
    409407        @param uri: uri to look for 
    410         @raise ValueError: if specified uri not found in vocab server  
     408        @raise VocabTermDataError: if specified uri not found in vocab server  
    411409        @return version of vocab uri, '' if uri contains latest version and None if uri not found 
    412410        ''' 
     
    440438            logging.error(errorMessage) 
    441439            # TODO: uncomment the ValueError once all the vocab terms have been defined 
    442             #raise ValueError(errorMessage) 
     440            #raise VocabTermDataError(errorMessage) 
    443441 
    444442        return currentVersion 
     
    449447        Get the current URL on the vocab server to the specified term 
    450448        @param termName: name of term whose URL to return 
     449        @raise VocabTermDataError: if term not found 
    451450        ''' 
    452451        logging.debug("Looking up vocab data for term: '%s'" %termName) 
    453452         
    454453        if termName not in self.TERM_DATA: 
    455             errorMessage = "Could not find term, '%s' in defined list of valid vocab terms - exiting" %termName 
    456             logging.error(errorMessage) 
    457             raise ValueError(errorMessage) 
     454             
     455            # NB, some item term IDs are different from their item name; this was 
     456            # to allow the import of historical data and should be fixed at some 
     457            # point 
     458            foundTerm = False 
     459            for key, item in self.TERM_DATA.items(): 
     460                if termName == item.termID: 
     461                    termName = key 
     462                    foundTerm = True 
     463                    break 
     464                     
     465            if not foundTerm: 
     466                raise VocabTermDataError("Could not find term, '%s' in \ 
     467                    defined list of valid vocab terms - exiting" %termName) 
    458468         
    459469        if termName not in self.latestTermVersion: 
     
    500510        @param uri: full term ID with version + vocab uri 
    501511        @return vocab term item corresponding to the input uri 
    502         @raise ValueError if term ID not found 
     512        @raise VocabTermDataError if term ID not found 
    503513        ''' 
    504514        logging.debug("Determining term ID for uri, '%s'" %uri) 
Note: See TracChangeset for help on using the changeset viewer.