Changeset 4964 for ndgCommon/trunk/ndg/common/src
- Timestamp:
- 12/02/09 17:32:22 (12 years ago)
- Location:
- ndgCommon/trunk/ndg/common/src/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ndgCommon/trunk/ndg/common/src/lib/atomvalidator.py
r4934 r4964 55 55 56 56 57 def __init__(self, atom, dbConfigFile, raiseException = True, \ 58 newLineChar= NEW_LINE, loadAllCollections = False, \ 59 isDebug = False, dbHostName = 'chinook.badc.rl.ac.uk'): 57 def __init__(self, atom, atomClient = None, 58 dbHostName = 'chinook.badc.rl.ac.uk', 59 dbConfigFile = None, 60 raiseException = True, 61 newLineChar= NEW_LINE, loadAllCollections = False, 62 isDebug = False): 60 63 ''' 61 64 Set up validator object - with atom to validate 62 65 @param atom: Atom object to validate 66 @keyword atomClient: an eXist client implementing the InterfaceXMLDBAtomClient interface 63 67 @keyword dbConfigFile: config file to use with eXist DB connection 64 68 @keyword raiseException: if True, raise a ValidationException following a failed validation … … 81 85 82 86 # set up connection to eXist 83 self.__setUpEXistDBConnection(dbConfigFile, 84 loadAllCollections = loadAllCollections, 85 dbHostName = dbHostName) 87 if atomClient: 88 self._atomClient = atomClient 89 else: 90 self.__setUpEXistDBConnection(dbConfigFile, 91 loadAllCollections = loadAllCollections, 92 dbHostName = dbHostName) 86 93 87 94 # setup the dictionary to store errors … … 333 340 ''' 334 341 logging.info("Validating schema compliance") 335 atomPath = self._atom.get DefaultCollectionPath() + self._atom.atomName342 atomPath = self._atom.getFullPath() 336 343 try: 337 344 errors = self._atomClient.checkAtomSchemaCompliance(atomPath, atom = self._atom, -
ndgCommon/trunk/ndg/common/src/lib/granulite.py
r4934 r4964 10 10 from ndg.common.src.models import Atom 11 11 import ndg.common.src.lib.utilities as utilities 12 from ndg.common.src.lib.atomvalidator import AtomValidator 12 13 from ndg.common.src.models.vocabtermdata import VocabTermData as VTD 13 14 from ndg.common.src.clients.xmldb.eXist.atomclient import AtomClient … … 132 133 self._cdmlTimeAxis = timeAxis 133 134 self._datasetID = datasetID 135 136 # AtomValidator to use for validation - only load when needed 137 self.validator = None 134 138 135 139 logging.info("Granulite data model set up") … … 362 366 logging.info("Adding granule info to data entities") 363 367 if not self._dataEntityIDs: 364 logging.info("No data entity IDs were specified in granulite - so will not add granule data to cedarmolesDB")368 logging.info("No data entity IDs were specified in granulite - so will not add granule data to eXist DB") 365 369 return 366 370 … … 405 409 providerID, 406 410 dataEntityID) 411 412 if not doc: 413 errorMessage = "Could not find data entity, %s - please retry with valid data" %dataEntityID 414 logging.error(errorMessage) 415 raise ValueError(errorMessage) 407 416 logging.debug("DE retrieved") 408 417 … … 589 598 590 599 else: 600 # validate the newly created atom - before importing it 601 self.__validateGranuleAtom() 602 591 603 # add the granule to eXist - if this exists already a DuplicationError 592 604 # will be thrown if backups are not allowed … … 610 622 errorMessage = "Exception thrown whilst updating data entities - detail: " + \ 611 623 str(e.message) + \ 612 " Will now roll back changes to granule atom to leave system in original state"624 "\n - will now roll back changes to granule atom to leave system in original state" 613 625 logging.error(errorMessage) 614 626 self.deleteGranuleAndDEReferences() … … 623 635 return self._atom 624 636 637 638 def __validateGranuleAtom(self): 639 ''' 640 Validate the granule atom created, using the standard AtomValidator 641 @raise atomvlaidator.ValidationError if any errors are found 642 ''' 643 if not self.validator: 644 self.validator = AtomValidator(None, 645 atomClient = self._eXist, 646 newLineChar="<br/>") 647 648 self.validator.setAtom(self._atom) 649 self.validator.validateAtom() 650 625 651 626 652 def deleteGranuleAndDEReferences(self):
Note: See TracChangeset
for help on using the changeset viewer.