Changeset 4585 for exist


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

Restructure granulite, creating smaller methods, to allow the bulk of the
granulite data to override or augment that in the CSML/CDML files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgUtils/lib/granulite.py

    r4582 r4585  
    140140 
    141141 
    142     def _getGranuliteDetails(self): 
     142    def __getGranuliteDetails(self): 
    143143        ''' 
    144144        Load the granulite config file and extract the required data   
     
    216216                     
    217217        logging.info("Finished parsing granulite file") 
    218  
    219         logging.info("Setting up input data") 
    220         # add the single value attributes to the granule 
    221         for attribute in self.singleVals: 
    222             if attribute in granulite_data: 
    223                 self._atom.setAttribute(self.singleVals[attribute], granulite_data[attribute][0]) 
    224  
    225         # NB, explicitly set the related links before running the arrayVals loop, since 
    226         # this will replace any file Links created if it occurs after these have been 
    227         # created (was originally in arrayVals, but this doesn't enforce any specific ordering) 
    228         if self.RELATED_LINKS_SECTION in granulite_data: 
    229             self._atom.setAttribute('relatedLinks', \ 
    230                                     granulite_data[self.RELATED_LINKS_SECTION]) 
    231  
    232         # now add the arrays data 
    233         for attribute in self.arrayVals: 
    234             if attribute in granulite_data: 
    235                 self._atom.setAttribute(self.arrayVals[attribute], granulite_data[attribute]) 
    236  
     218        logging.info("- returning dict of ingested data") 
     219        return granulite_data 
     220         
     221         
     222    def __applyCoreGranuliteDetails(self, granulite_data): 
     223        ''' 
     224        Apply the essential data read in from the granulite file to the atom data model 
     225        being processed by the granulite 
     226        @param granulite_data: the dict produced by __getGranuliteDetails 
     227        ''' 
    237228        # add the general granule info 
    238229        if self.GRANULE_INFO_SECTION not in granulite_data: 
     
    246237        self._atom.setDatasetID(data[1]) 
    247238        self._atom.title = data[2] 
    248          
    249         if self.LOGO_SECTION in granulite_data: 
    250             for logo in granulite_data[self.LOGO_SECTION]: 
    251                 self._atom.addRelatedLinks(logo + " | Logo | " + \ 
    252                                            self.VTD.getTermCurrentVocabURL(VTD.LOGO_TERM)) 
    253  
    254         # add the parameters data via the method - since this does some tidying up of the data 
    255         if self.PARAMETERS_SECTION in granulite_data: 
    256             self._atom.addParameters(granulite_data[self.PARAMETERS_SECTION]) 
    257239 
    258240        # NB, if running from the web, ignore the CSML/CDML files specified in the granulite 
     
    274256                    self._datasetID = data[1] 
    275257                    self._cdmlTimeAxis = data[2] 
     258         
     259         
     260    def __applyGranuliteDetails(self, granulite_data): 
     261        ''' 
     262        Apply the data read in from the granulite file to the atom data model 
     263        being processed by the granulite 
     264        @param granulite_data: the dict produced by __getGranuliteDetails 
     265        ''' 
     266        logging.info("Applying granulite data to atom") 
     267        # add the single value attributes to the granule 
     268        for attribute in self.singleVals: 
     269            if attribute in granulite_data: 
     270                self._atom.setAttribute(self.singleVals[attribute], \ 
     271                                        granulite_data[attribute][0]) 
     272 
     273        # NB, explicitly set the related links before running the arrayVals loop, since 
     274        # this will replace any file Links created if it occurs after these have been 
     275        # created (was originally in arrayVals, but this doesn't enforce any specific ordering) 
     276        if self.RELATED_LINKS_SECTION in granulite_data: 
     277            self._atom.setAttribute('relatedLinks', \ 
     278                                    granulite_data[self.RELATED_LINKS_SECTION]) 
     279 
     280        # now add the arrays data 
     281        for attribute in self.arrayVals: 
     282            if attribute in granulite_data: 
     283                self._atom.setAttribute(self.arrayVals[attribute], \ 
     284                                        granulite_data[attribute]) 
     285         
     286        if self.LOGO_SECTION in granulite_data: 
     287            for logo in granulite_data[self.LOGO_SECTION]: 
     288                self._atom.addRelatedLinks(logo + " | Logo | " + \ 
     289                                           self.VTD.getTermCurrentVocabURL(VTD.LOGO_TERM)) 
     290 
     291        # add the parameters data via the method - since this does some tidying up of the data 
     292        if self.PARAMETERS_SECTION in granulite_data: 
     293            self._atom.addParameters(granulite_data[self.PARAMETERS_SECTION]) 
    276294             
    277295        if self.DATA_ENTITY_SECTION in granulite_data: 
     
    514532        logging.info("Processing granulite data") 
    515533        # load in the granulite details 
    516         self._getGranuliteDetails() 
     534        inputs = self.__getGranuliteDetails() 
     535         
     536        # apply the basic, essential data 
     537        self.__applyCoreGranuliteDetails(inputs) 
    517538         
    518539        # check for CSML or CDML file and load details 
    519540        self.processCSMLOrCDMLFile() 
     541 
     542        # apply any granulite data; NB, this overrides/augments the  
     543        # CSML/CDML data by default 
     544        self.__applyGranuliteDetails(inputs) 
    520545         
    521546        # add the granule to eXist 
Note: See TracChangeset for help on using the changeset viewer.