Ignore:
Timestamp:
25/09/08 15:26:46 (12 years ago)
Author:
cbyrom
Message:

Improve the creation of new atom entries in eXist - generating unique
IDs, and checking these, where necessary + fix update date updates +
add methods to the vocab data class to retrieve lists of data categories
+ subtypes - for use in the UI dropdowns.

File:
1 edited

Legend:

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

    r4219 r4236  
    3636    FILE_BROWSER_TERM = 'FileBrowser'    
    3737    CSML_TERM = 'CSML' 
     38     
    3839    ACTIVITY_TERM = 'ACTIVITY' 
    3940    DPT_TERM = 'DPT' 
     
    8889    COMPUTER_TERM = "dgComputer" 
    8990 
     91    # provider types 
     92    BADC_TERM = 'badc.nerc.ac.uk' 
     93    NEODC_TERM = 'neodc.nerc.ac.uk' 
     94     
    9095    TERM_DATA = { 
    9196                 URI_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '3', title = 'Data Home Page'), 
     97                 BADC_TERM:VocabTermItem('NOT YET SET UP', BADC_TERM, title = 'British Atomspheric Data Centre'), 
     98                 NEODC_TERM:VocabTermItem('NOT YET SET UP', NEODC_TERM, title = 'NERC Earth Observation Data Centre'), 
    9299                 LOGO_TERM:VocabTermItem('LOGO', 'LOGO', title = 'Logo'), 
    93100                 NUM_SIM_TERM:VocabTermItem('http://vocab.ndg.nerc.ac.uk/term/N041', '7', title = 'NumSim description'), 
     
    149156                 } 
    150157 
    151  
     158    ATOM_TYPES = [ACTIVITY_TERM, DE_TERM, DPT_TERM, GRANULE_TERM, OBS_TERM] 
     159 
     160    PROVIDER_TYPES = [BADC_TERM, NEODC_TERM] 
     161 
     162    ATOM_CATEGORY = "atom" 
     163    PROVIDER_CATEGORY = "provider" 
    152164     
    153165    # A dictionary to group the various valid subtypes of atoms - grouped by their 
     
    185197                     } 
    186198              
    187  
    188  
    189      
    190199     
    191200    ONE_HOUR = 3600.0 
     
    224233        logging.error(errorMessage) 
    225234        raise ValueError(errorMessage) 
     235 
     236 
     237    def getValidTypes(self, category): 
     238        ''' 
     239        Return a list of the valid types available for a particular data category 
     240        @param category: type of term info to look up - e.g. atoms or providers  
     241        - this should be specified using the ..._CATEGORY instance variables 
     242        defined above 
     243        @return list of VocabTermInfo objects for the specified category 
     244        ''' 
     245        logging.debug("Lookup up list of valid %s types" %category) 
     246        catList = [] 
     247        if category == self.ATOM_CATEGORY: 
     248            catList = self.ATOM_TYPES 
     249        elif category == self.PROVIDER_CATEGORY: 
     250            catList = self.PROVIDER_TYPES 
     251        else: 
     252            errorMessage = "Unrecognised data category, '%s'" %category 
     253            logging.info(errorMessage) 
     254            raise ValueError(errorMessage) 
     255             
     256        types = [] 
     257        for st in catList: 
     258            types.append(self.TERM_DATA[st]) 
     259        return types 
     260 
     261 
     262    def getValidSubTypes(self, atomType): 
     263        ''' 
     264        Get list of subtypes that are valid wrt a specified atom type 
     265        @param atomType: term ID for the atom type whose subtypes need to  
     266        be looked up 
     267        @return: list of valid subtypes 
     268        ''' 
     269        logging.debug("Lookup up subtypes for atom type, '%s'" %atomType) 
     270        subTypes = self.SUBTYPE_TERMS.get(atomType) or [] 
     271        types = [] 
     272        for st in subTypes: 
     273            item = self.TERM_DATA[st] 
     274            # tidy up the title slightly, if need be 
     275            if item.title and item.title.startswith('dg'): 
     276                item.title = item.title[2:] 
     277                # and fix any camelcase - putting into words 
     278                item.title = re.sub('([A-Z])', r" \1", item.title).strip() 
     279            types.append(item) 
     280        logging.debug("Found subtypes: %s" %subTypes) 
     281        return types 
    226282 
    227283         
Note: See TracChangeset for help on using the changeset viewer.