Changeset 4281 for exist


Ignore:
Timestamp:
06/10/08 09:51:40 (11 years ago)
Author:
cbyrom
Message:

Add activity deployment term to vocab data + add new error handling +
add new methods to retrieve vocab term items from their term ID and
their fully specified vocab url.

File:
1 edited

Legend:

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

    r4248 r4281  
    1616        self.termID = termID 
    1717        self.title = title 
     18 
     19 
     20class VocabTermDataError(ValueError): 
     21    """ 
     22    Exception handling for VocabTermData class. 
     23    """ 
     24    def __init__(self, msg): 
     25        logging.error(msg) 
     26        ValueError.__init__(self, msg) 
    1827 
    1928 
     
    8392    CRUISE_TERM = "dgCruise" 
    8493    FUNDING_PROGRAM_TERM = "dgFundingProgram" 
     94    DEPLOYMENT_TERM = "Deployment" 
     95    # NB, this is a specialised activity with the subtype deployment pre-set 
     96    ACTIVITY_DEPLOYMENT_TERM = "ActivityDeployment" 
    8597     
    8698    # obs subtypes 
     
    107119                 METADATA_SOURCE_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '6', title = 'Original Metadata Source'), 
    108120                 #URI_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '3URI', title = 'Data Home Page'), 
    109                  BADC_TERM:VocabTermItem('NOT YET SET UP', BADC_TERM, title = 'British Atomspheric Data Centre'), 
     121                  
     122                 BADC_TERM:VocabTermItem('NOT YET SET UP', BADC_TERM, title = 'British Atmospheric Data Centre'), 
    110123                 NEODC_TERM:VocabTermItem('NOT YET SET UP', NEODC_TERM, title = 'NERC Earth Observation Data Centre'), 
     124                  
    111125                 LOGO_TERM:VocabTermItem('LOGO', 'LOGO', title = 'Logo'), 
    112126                 NUM_SIM_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '7', title = 'NumSim description'), 
     
    121135                 CSML_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N021', '1'), 
    122136                 ACTIVITY_TERM:VocabTermItem('Activity - NOT YET SET UP', ACTIVITY_TERM, title = 'Activity'), 
     137                 ACTIVITY_DEPLOYMENT_TERM:VocabTermItem('Activity Deployment - NOT YET SET UP', ACTIVITY_DEPLOYMENT_TERM, title = 'Activity Deployment'), 
    123138                 DPT_TERM:VocabTermItem('DPT - NOT YET SET UP', DPT_TERM, title = 'Data Production Tool'), 
    124139                 OBS_TERM:VocabTermItem('OBS - NOT YET SET UP', OBS_TERM, title = 'Observation Station'), 
     
    126141                 DE_TERM:VocabTermItem('DE - NOT YET SET UP', DE_TERM, title = 'Data Entity'), 
    127142                  
    128                  LIDAR_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG02', title = LIDAR_TERM), 
    129                  RADAR_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG03', title = RADAR_TERM), 
    130                  SONDE_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG04', title = SONDE_TERM), 
    131                  NAVIGATION_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG05', title = NAVIGATION_TERM), 
    132                  GAS_CHROMATOGRAPH_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG06', title = GAS_CHROMATOGRAPH_TERM), 
     143                 LIDAR_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG02', title = "Lidar"), 
     144                 RADAR_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG03', title = "Radar"), 
     145                 SONDE_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG04', title = "Sonde"), 
     146                 NAVIGATION_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG05', title = "Navigation"), 
     147                 GAS_CHROMATOGRAPH_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG06', title = "Gas Chromatograph"), 
    133148                 SPECTROMETER_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG07', title = SPECTROMETER_TERM), 
    134149                 MASS_SPECTROMETER_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/C330', 'NG08', title = MASS_SPECTROMETER_TERM), 
     
    156171                 CRUISE_TERM:VocabTermItem('NOT YET SET UP', CRUISE_TERM, title = CRUISE_TERM), 
    157172                 FUNDING_PROGRAM_TERM:VocabTermItem('NOT YET SET UP', FUNDING_PROGRAM_TERM, title = FUNDING_PROGRAM_TERM), 
     173                 DEPLOYMENT_TERM:VocabTermItem('NOT YET SET UP', DEPLOYMENT_TERM, title = DEPLOYMENT_TERM), 
    158174                  
    159175                 STATIONARY_PLATFORM_TERM:VocabTermItem('NOT YET SET UP', STATIONARY_PLATFORM_TERM, title = STATIONARY_PLATFORM_TERM), 
     
    206222                        DATA_CAMPAIGN_TERM, DATA_INVESTIGATION_TERM, \ 
    207223                        FLIGHT_TERM, CRUISE_TERM, \ 
    208                         FUNDING_PROGRAM_TERM, 
     224                        FUNDING_PROGRAM_TERM, DEPLOYMENT_TERM 
    209225                        ], 
    210226                     OBS_TERM: [ 
     
    216232                        ] 
    217233                     } 
    218               
    219234     
    220235    ONE_HOUR = 3600.0 
     
    227242        logging.info("Setting up VocabTermData object") 
    228243        self.VOCAB_DATA_PAGE = None 
    229         self.REFRESH_TIME = time.time() 
     244        # introduce slight delay here 
     245        self.REFRESH_TIME = time.time() - 2.0 
    230246        self.latestTermVersion = {} 
    231247        logging.info("VocabTermData object set up") 
     
    444460        currentVersion = self._getURIVersion(uri) 
    445461        logging.debug("URI version looked up") 
    446         if currentVersion: 
     462        if currentVersion is not None: 
    447463            if not uri.endswith('/'): 
    448464                uri += '/' 
    449465            return uri + str(currentVersion) 
    450466        return uri 
     467     
     468    def getVTI(self, term): 
     469        ''' 
     470        Return the vocab term item for the specified term 
     471        @param term: term ID - one of the constants defined above 
     472        @return VocabTermItem corresponding to term 
     473        @raise VocabTermDataError if term not found 
     474        ''' 
     475        vti = self.TERM_DATA.get(term) 
     476        if not vti: 
     477            raise VocabTermDataError("No info for term, '%s', found" %term) 
     478     
     479        return vti 
     480         
     481     
     482     
     483    def getTermItemfromFullVocabURI(self, uri): 
     484        ''' 
     485        Given a full term id - i.e. with vocab uri + version + term ID 
     486        determine the correct vocab data term item 
     487        @param uri: full term ID with version + vocab uri 
     488        @return vocab term item corresponding to the input uri 
     489        @raise ValueError if term ID not found 
     490        ''' 
     491        logging.debug("Determining term ID for uri, '%s'" %uri) 
     492        termID = uri.split('/')[-1] 
     493        vti = None 
     494        if self.TERM_DATA.get(termID) and uri.startswith(self.TERM_DATA[termID].vocabURL): 
     495            vti = self.TERM_DATA[termID] 
     496        else: 
     497            for item in self.TERM_DATA.itervalues(): 
     498                if item.termID == termID and uri.startswith(item.vocabURL): 
     499                    vti = item 
     500                    break 
     501         
     502        if not vti: 
     503            raise VocabTermDataError("Unrecognised term URI: '%s'" %uri) 
     504 
     505        logging.debug("Found matching term - '%s'" %vti.termID) 
     506        return vti 
     507                 
Note: See TracChangeset for help on using the changeset viewer.