Changeset 4506


Ignore:
Timestamp:
27/11/08 17:06:56 (11 years ago)
Author:
cbyrom
Message:

Force atom validator to specify a db config file on construction + tidy up how some particular errors are formatted and retrieved.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • MILK/trunk/milk_server/milk_server/config/milkMiddleware.py

    r4504 r4506  
    6565        self.globals.pwFile = cf.get('NDG_EXIST','passwordFile') 
    6666        # set up the validator for atoms - to allow re-use across the app 
    67         self.globals.validator = AtomValidator(None, dbConfigFile = self.globals.pwFile, \ 
     67        self.globals.validator = AtomValidator(None, self.globals.pwFile, \ 
    6868                                       raiseException = True, newLineChar="<br/>") 
    6969 
  • exist/trunk/python/ndgUtils/lib/atomvalidator.py

    r4495 r4506  
    5555 
    5656         
    57     def __init__(self, atom, dbConfigFile = None, raiseException = False, \ 
    58                  newLineChar= NEW_LINE): 
     57    def __init__(self, atom, dbConfigFile, raiseException = False, \ 
     58                 newLineChar= NEW_LINE, loadAllCollections = False): 
    5959        ''' 
    6060        Set up validator object - with atom to validate 
     
    6363        @keyword raiseException: if True, raise a ValidationException following a failed validation  
    6464        - NB, if not used, errors can be retrieved from the self.errors field 
     65        @keyword loadAllCollections: loads all collections info when initialising eXist 
     66        connection, if True 
    6567        ''' 
    6668        logging.info("Setting up atomValidation object") 
     
    7375        self._validVocabTerms = [] 
    7476         
    75         # set up connection to eXist and postgres DBs 
    76         if dbConfigFile: 
    77             self.setUpEXistDBConnection(dbConfigFile) 
     77        # set up connection to eXist 
     78        self.__setUpEXistDBConnection(dbConfigFile, loadAllCollections = loadAllCollections) 
    7879 
    7980        # setup the dictionary to store errors 
     
    8384 
    8485     
    85     def setUpEXistDBConnection(self, dbConfFile): 
     86    def __setUpEXistDBConnection(self, dbConfFile, loadAllCollections = False): 
    8687        ''' 
    8788        Get the default eXist DB connection - by reading in data from the db config file 
     89        @keyword dbConfigFile: config file to use with eXist DB connection 
     90        @keyword loadAllCollections: loads all collections info when initialising eXist 
    8891        ''' 
    8992        logging.info("Setting up connection to eXist DB") 
    90         self._eXist = edc.eXistDBClient(configFile = dbConfFile, loadCollectionData=True) 
     93        self._eXist = edc.eXistDBClient(configFile = dbConfFile,  
     94                                        loadCollectionData=loadAllCollections) 
    9195        logging.info("eXist DB connection now set up") 
    9296 
     
    109113        @param atomPath: path to the atom in the eXist DB 
    110114        ''' 
    111         if not self._atom: 
    112             logging.error("No atom specified to validate - skipping") 
    113115        logging.info("Validating atom, '%s'" %self._atom.atomID) 
    114116        # firstly, check the links point to valid uris 
     
    292294            error = e.message 
    293295            if not error: 
    294                 error = e.faultString 
     296                # strip out the exception type - NB, this is usually native library code 
     297                # and is of no real interest - and will just confuse viewers 
     298                error = e.faultString.split(':')[-1]  
    295299                 
    296300            errorMessage = "Problem experienced when validating against schema:%s'%s'" \ 
    297301                %(self._nl, error) 
    298             traceback.format_exc() 
     302 
    299303            logging.error(errorMessage) 
    300304            self.__addError(self.SCHEMA_VALIDATION_FAILURE, errorMessage) 
     
    321325    def logErrors(self): 
    322326        ''' 
    323         Outpus any errors caught during validation to log 
     327        Outputs any errors caught during validation to log 
    324328        ''' 
    325329        logging.info("The following errors were encountered when validating the atoms:") 
Note: See TracChangeset for help on using the changeset viewer.