Changeset 4677


Ignore:
Timestamp:
17/12/08 17:22:52 (11 years ago)
Author:
cbyrom
Message:

Add keyword, 'replaceAtom' to determine whether atoms should be
replaced if a 'save atom' type operation is done with an atom with an
ID that already exists. Add new DuplicateError? to be raised when this
is not allowed.

Location:
exist/trunk/python/ndgUtils/lib
Files:
2 edited

Legend:

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

    r4655 r4677  
    2020 
    2121from threading import Thread 
     22 
     23 
     24class DuplicateError(Exception): 
     25    """ 
     26    Exception handling for when a duplicated atom doc is discovered 
     27    """ 
     28    def __init__(self, msg): 
     29        logging.error(msg) 
     30        Exception.__init__(self, msg) 
    2231 
    2332class backingUpThread(Thread): 
     
    496505 
    497506             
    498     def createAtomInExist(self, atom): 
     507    def createAtomInExist(self, atom, replaceAtom = 'True'): 
    499508        ''' 
    500509        Create an atom in the eXist DB - using the atom contents to work out 
    501510        the location + data set ID 
    502511        @param atom: atom object to create in the DB 
     512        @keyword replaceAtom: if 'False' and the atom is already available in eXist 
     513        then raise a ValueError.  NB, use strings not bools. 
    503514        ''' 
    504515        logging.info("Creating atom in eXist") 
     
    535546        # create backup of atom if it already exists 
    536547        else: 
     548            if replaceAtom == 'False': 
     549                raise DuplicateError('An atom with the specified ID (%s) already exists in eXist' \ 
     550                                     %atom.datasetID) 
    537551            self.backupEXistFile(eXistCollection, atom.atomName) 
    538552             
  • exist/trunk/python/ndgUtils/lib/granulite.py

    r4663 r4677  
    521521 
    522522         
    523     def processGranulite(self): 
     523    def processGranulite(self, replaceAtom = False): 
    524524        ''' 
    525525        Complete the required granulite actions 
     
    529529        - add granule atom to eXist 
    530530        - add references to granule atom to specified data entity atoms 
    531          
     531        @keyword replaceAtom: if True, allow granule atoms to replace existing 
     532        atoms with the same ID - if False, throw a DuplicationError 
     533        @raise DumplicationError: if allowBackups = False and an atom is found 
     534        with the same ID as that to be created   
    532535        @return atom: Atom object of created data granule 
    533536        ''' 
     
    546549        self.__applyGranuliteDetails(inputs) 
    547550         
    548         # add the granule to eXist 
    549         # check if we've got a valid datasetid at this point - otherwise we won't have a valid filename or DB PK to use 
    550         if not self._atom.datasetID: 
    551             errorMessage = "No dataset ID specified for the granule - this needs " + \ 
    552                 "to be set in the granulite file or in \nthe CSML/CDML files.  " + \ 
    553                 "NB, without this cannot create valid entry in the eXist " + \ 
    554                 "DB - so escaping now" 
    555             logging.error(errorMessage) 
    556             raise ValueError(errorMessage) 
    557  
     551        # add the granule to eXist - if this exists already a DuplicationError 
     552        # will be thrown if backups are not allowed 
    558553        logging.info("Creating granule atom, '%s', in eXist DB" %self._atom.atomName) 
    559         self._eXist.createOrUpdateEXistFile(self._atom.toPrettyXML(), \ 
    560                                             self._atom.getDefaultCollectionPath(), \ 
    561                                             self._atom.atomName) 
     554        self._eXist.createAtomInExist(self._atom, replaceAtom = replaceAtom) 
    562555 
    563556        # now add the granule data to the data entity in eXist 
Note: See TracChangeset for help on using the changeset viewer.