Changeset 4627


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

Improve input parameter checking + improve scoping of methods + add more structure to validator.

Location:
exist/trunk/python/ndgUtils
Files:
4 edited

Legend:

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

    r4555 r4627  
    2424    LINE_SEPARATOR = "-----------------------------" 
    2525     
    26     # constants to use as error dict keys 
    27     BROKEN_LINKS = 1 
    28     INVALID_VOCAB_TERM = 2 
    29     SCHEMA_VALIDATION_FAILURE = 4 
    30  
    31     VALID_RELS = ["self", "related"] 
    32      
    33  
    3426    def __validateAtom(self, atomPath): 
    3527        ''' 
     
    8476 
    8577 
    86  
    8778    def _setUpOptions(self): 
    8879        ''' 
     
    130121        self._setUpOptions() 
    131122 
    132         self.validator = AtomValidator(None, self.DBCONFIG_FILE, loadAllCollections=True) 
     123        self.validator = AtomValidator(None, self.DBCONFIG_FILE, loadAllCollections=True, \ 
     124                                       raiseException = False) 
    133125         
    134126        # setup the dictionary to store errors 
    135127        self._errors = {} 
     128         
     129         
     130    def validateCollection(self): 
    136131        # NB, we've loaded all the atom collection data so now step through this 
    137132        for atom, collection in self.validator._eXist.collections.items(): 
     
    146141if __name__=="__main__": 
    147142    opts, args = getopt.getopt(sys.argv[1:], '-vd') 
    148     eXistAtomValidator() 
    149      
     143    validator = eXistAtomValidator() 
     144    validator.validateCollection() 
  • exist/trunk/python/ndgUtils/lib/existdbclient.py

    r4590 r4627  
    55 @author: C Byrom - Tessella 08 
    66''' 
    7 import os, sys, logging, datetime 
     7import os, sys, logging, datetime, uuid 
     8from ndgUtils.models.Atom import Atom 
    89from ndgUtils.eXistConnector import eXistConnector as ec 
    910from ndgUtils.ndgXqueries import ndgXqueries 
    1011from ndgUtils import DocumentRetrieve as DR 
    11 import uuid 
    1212 
    1313try: 
     
    487487    def createAtomInExist(self, atom): 
    488488        ''' 
    489         Create an atom in the eXist DB 
     489        Create an atom in the eXist DB - using the atom contents to work out 
     490        the location + data set ID 
    490491        @param atom: atom object to create in the DB 
    491492        ''' 
    492493        logging.info("Creating atom in eXist") 
     494        if not atom: 
     495            raise ValueError("Input is not an object - cannot create in eXist") 
     496        if not isinstance(atom, Atom): 
     497            raise ValueError("Input object is not an Atom object - cannot create in eXist") 
    493498         
    494499        # if the atom has no dataset ID, generate and add one 
  • exist/trunk/python/ndgUtils/lib/granulite.py

    r4591 r4627  
    119119        else: 
    120120            # create a skeleton granule 
    121             self._initialiseGranule() 
     121            self.__initialiseGranule() 
    122122 
    123123        self.useCSMLID = useCSMLID 
     
    128128 
    129129         
    130     def _getSectionName(self, str): 
     130    def __getSectionName(self, str): 
    131131        ''' 
    132132        Checks an input string to see if it contains a section title; if so 
     
    186186                continue 
    187187             
    188             section = self._getSectionName(line) 
     188            section = self.__getSectionName(line) 
    189189 
    190190            # if a section name is returned, we're at a new section of the file - so change the dictionary key 
     
    347347      
    348348     
    349     def _addGranuleToDataEntityRecords(self): 
     349    def __addGranuleToDataEntityRecords(self): 
    350350        ''' 
    351351        Augment any data entity records, specified in the granulite, with a reference to 
     
    380380        ''' 
    381381        logging.debug("Retrieving data entity atom - to attach granule to") 
    382         doc = self._eXist.getAtom('dataent_' + dataEntityID) 
     382#        doc = self._eXist.getAtom('dataent_' + dataEntityID) 
     383        doc = self._eXist.getAtom(dataEntityID) 
    383384        logging.debug("DE retrieved - now adding link to granule") 
    384385        de = Atom.Atom(xmlString=str(doc)) 
     
    398399 
    399400 
    400     def _initialiseGranule(self): 
     401    def __initialiseGranule(self): 
    401402        ''' 
    402403        Create an Atom object ready to populate with data 
     
    561562 
    562563        # now add the granule data to the data entity in eXist 
    563         self._addGranuleToDataEntityRecords() 
     564        self.__addGranuleToDataEntityRecords() 
    564565         
    565566        logging.info("granulite processing complete") 
  • exist/trunk/python/ndgUtils/models/Atom.py

    r4605 r4627  
    324324             
    325325            # also pass any moles data up to the moles entity object 
    326             if inputs.get('providerID'): 
     326            if inputs.has_key('providerID'): 
    327327                self.ME.providerID = inputs.get('providerID') 
    328328                 
    329             if inputs.get('abbreviation'): 
     329            if inputs.has_key('abbreviation'): 
    330330                self.ME.abbreviation = inputs.get('abbreviation') 
    331331 
     
    846846        ''' 
    847847        self.atomName = datasetID + ".atom" 
     848        if not self.ME.providerID: 
     849            raise ValueError("Provider ID has not been specified for atom - please add this and retry") 
    848850        self.ndgURI = self.ME.providerID + "__ATOM__" + datasetID  
    849851        self.atomBrowseURL = VTD.BROWSE_ROOT_URL + self.ndgURI 
Note: See TracChangeset for help on using the changeset viewer.