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

Improve the creation of new atom entries in eXist - generating unique
IDs, and checking these, where necessary + fix update date updates +
add methods to the vocab data class to retrieve lists of data categories
+ subtypes - for use in the UI dropdowns.

File:
1 edited

Legend:

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

    r4229 r4236  
    99from ndgUtils.eXistConnector import eXistConnector as ec 
    1010from ndgUtils.ndgXqueries import ndgXqueries 
     11import uuid 
    1112 
    1213try: 
     
    281282        Create an atom in the eXist DB 
    282283        @param atom: atom object to create in the DB 
     284        @return atom: atom object saved in eXist 
    283285        ''' 
    284286        logging.info("Creating atom in eXist") 
    285         eXistCollection = self.getAtomFileCollectionPath(atom.atomID) 
     287         
     288        # if the atom has no dataset ID, generate and add one 
     289        # NB, this should only be the case when the atom is being created 
     290        # via the web interface 
     291        isNew = False 
     292        if not atom.datasetID: 
     293            isNew = True 
     294            atom.setDatasetID(atom.atomTypeID + '_' + str(uuid.uuid1())) 
     295             
     296        eXistCollection = self.getAtomFileCollectionPath(atom.datasetID) 
    286297         
    287298        # if collection not found, assume we're dealing with a new atom; get its 
     
    289300        if not eXistCollection: 
    290301            eXistCollection = atom.getDefaultCollectionPath() 
     302        elif isNew: 
     303            # in this situation we're trying to create an atom with the same 
     304            # name via the web interface - this can't be allowed - so retry to 
     305            # generate a new ID 
     306            atom.datasetID = None 
     307            self.createAtomInExist(atom) 
     308            return 
    291309        # create backup of atom if it already exists 
    292310        else: 
    293311            self.backupEXistFile(eXistCollection, atom.atomName) 
    294312             
     313            # also change updated date to current time 
     314            atom.updatedDate = datetime.datetime.today().strftime("%Y-%m-%dT%H:%M:%SZ") 
     315             
    295316        self.createEXistFile(atom.toPrettyXML(), eXistCollection, atom.atomName) 
    296317             
    297318        logging.info("Atom created in eXist") 
     319        return atom 
Note: See TracChangeset for help on using the changeset viewer.