Changeset 4782 for exist


Ignore:
Timestamp:
12/01/09 10:10:44 (10 years ago)
Author:
cbyrom
Message:

Add code to allow publishing of data to multiple feeds - to offer
different levels of granularity to subscribe to (with appropriate feed
titles) + add code to
allow feed publication to be done asynchronously + extend to
run atom to DIF transforms at point of publish for atom docs
in the published state (i.e. with state of 'published' or 'Published').
Add code to ingest required organisation data when setting up
the eXist DB - and provide cache of this data to avoid unecessary
lookups. Also extend the eXist DB setup code to initialise the
various new feeds added.
Add utility methods to check if an eXist collection is new and to
establish the publication state of an atom doc - and to change
the state of this doc (NB, need to do a doc delete and doc create
for this - can't see a doc 'move' function in eXist). Also add
code to do the atom to DIF transform direct in the eXist DB.
Improve error handling when publishing feed data.

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

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgUtils/eXistConnector.py

    r4757 r4782  
    5555    NDG_A_COLLECTION_PATH = "/db/ndg_A_metadata/" 
    5656    NDG_A_COLLECTION_PATH_BACKUP = "/db/ndg_A_metadata_backup/" 
     57    DIF_COLLECTION_PATH = "/db/DIF/" 
     58    PROVIDER_FEED_PATH = BASE_COLLECTION_PATH + "providerFeeds/" 
    5759 
    5860    """Access class for eXist""" 
  • exist/trunk/python/ndgUtils/lib/existdbclient.py

    r4758 r4782  
    88from ndgUtils.models.Atom import Atom 
    99from ndgUtils.eXistConnector import eXistConnector as ec 
    10 from ndgUtils.ndgXqueries import ndgXqueries 
    1110from ndgUtils import DocumentRetrieve as DR 
    1211from existdbfeedclient import eXistDBFeedClient as feedClient 
     12from ndgUtils.models import AtomState 
     13from ndgUtils.lib.atomutilities import * 
    1314 
    1415try: 
     
    4647       self.ec.createEXistFile(self.doc, self.collection, self.fileName) 
    4748       logging.info("- finished backing up file") 
     49 
     50class publishingThread(Thread): 
     51     
     52   def __init__ (self, edc, atom): 
     53       logging.info("Setting up thread to publish atom data for atom, '%s'" %atom.datasetID) 
     54       Thread.__init__(self) 
     55       self.edc = edc 
     56       self.atom = atom 
     57       logging.info("- finished setting up thread") 
     58       
     59   def run(self): 
     60       logging.info("Running thread to publish atom data for atom, '%s'" %self.atom.datasetID) 
     61       self.edc._eXistDBClient__publishAtom(self.atom) 
     62       logging.info("- finished publishing atom data") 
    4863         
    4964 
     
    104119            # add the schema required for atom validation 
    105120            self.__addAtomSchema() 
     121 
     122            # add common data missing from atoms - but used to create output DIF records 
     123            self.__uploadOrgData() 
    106124             
    107125            # set up the required atom feeds 
    108             self.feedClient.createAtomFeed(ec.BASE_COLLECTION_PATH,  
    109                                            self.feedClient.ATOM_FEED_TITLE) 
     126            self.feedClient.setupBasicFeeds() 
    110127         
    111128        self.collections = None 
    112129        if loadCollectionData: 
    113130            self.collections = self.getAllAtomCollections() 
     131 
     132        # dict to hold the data centre element info - used to augment atom info 
     133        # when doing atom->DIF translations - to avoid having to constantly 
     134        # look this up for the different provider IDs 
     135        self.dataCentres = {} 
    114136             
    115137        logging.info("eXist DB connection initialised") 
     
    120142        if not self.atomSchema: 
    121143            self.atomSchema = ec.BASE_COLLECTION_PATH + \ 
    122                 ndgXqueries.ATOM_MOLES_SCHEMA  + '.xsd' 
     144                self.xmldb.xq.ATOM_MOLES_SCHEMA  + '.xsd' 
    123145 
    124146        return self.atomSchema 
    125147 
    126148    AtomSchema = property(fget=__getSchema, doc="Atom schema path") 
     149 
     150 
     151    def __uploadOrgData(self): 
     152        '''         
     153        Upload the organisations DIF file to eXist - this is required for the atom->DIF output 
     154        ''' 
     155        logging.info("Uploading organisation data to eXist") 
     156        schemae = [self.xmldb.xq.ATOM_SCHEMA, self.xmldb.xq.MOLES_SCHEMA, self.xmldb.xq.ATOM_MOLES_SCHEMA] 
     157        for fileName, orgData in self.xmldb.xq.resources.items(): 
     158            self.createEXistFile(orgData, ec.BASE_COLLECTION_PATH, fileName) 
     159        logging.info("Data uploaded") 
    127160 
    128161 
     
    239272                self.xmldb.createCollection(col + type + ec.DEPLOYMENTS_COLLECTION_PATH) 
    240273                self.xmldb.createCollection(col + type + ec.GRANULE_COLLECTION_PATH) 
     274 
     275        self.xmldb.createCollection(ec.DIF_COLLECTION_PATH) 
     276        self.xmldb.createCollection(ec.PROVIDER_FEED_PATH) 
    241277        logging.info("Required collections available") 
    242278         
     
    248284        ''' 
    249285        logging.info("Adding atom schema to eXist") 
    250         xq = ndgXqueries() 
    251         schemae = [xq.ATOM_SCHEMA, xq.MOLES_SCHEMA, xq.ATOM_MOLES_SCHEMA] 
    252         for schema in schemae: 
    253             xml = xq.getSchema(schema) 
     286        schemata = [self.xmldb.xq.ATOM_SCHEMA, self.xmldb.xq.MOLES_SCHEMA, self.xmldb.xq.ATOM_MOLES_SCHEMA] 
     287        for schema in schemata: 
     288            xml = self.xmldb.xq.getSchema(schema) 
    254289            self.createEXistFile(xml, ec.BASE_COLLECTION_PATH, schema + '.xsd') 
    255290        logging.info("- schema added") 
     
    294329        logging.info("Found file - returning result ID") 
    295330        return id 
     331 
     332 
     333    def isNewEXistCollection(self, collectionPath): 
     334        ''' 
     335        Look up a collection in eXist using XPath 
     336        @param collectionPath: path to collection to look up 
     337        @return: False if collection exists, True otherwise 
     338        ''' 
     339        logging.info("Checking if collection, '%s', exists in eXist" %collectionPath) 
     340         
     341        id, doc = self.xmldb.executeQuery('collection("' + collectionPath + '")') 
     342        if doc['hits'] == 0: 
     343            logging.info("Collection does not exist in eXist DB") 
     344            return True 
     345        logging.info("Found collection") 
     346        return False 
    296347          
    297348 
     
    462513        ''' 
    463514        logging.info("Retrieving all atom ids") 
    464         xq = ndgXqueries().actual('atomList', '/db/atoms', '', '') 
     515        xq = self.xmldb.xq.actual('atomList', '/db/atoms', '', '') 
    465516        id, doc = self.xmldb.executeQuery(xq) 
    466517        if doc['hits'] == 0:  
     
    486537        ''' 
    487538        logging.info("Retrieving all atom collection paths") 
    488         xq = ndgXqueries().actual('atomList', '/db/atoms', '', '') 
     539        xq = self.xmldb.xq.actual('atomList', '/db/atoms', '', '') 
    489540        id, doc = self.xmldb.executeQuery(xq) 
    490541        if doc['hits'] == 0:  
     
    507558 
    508559 
     560    def getAtomPublicationState(self, atomID): 
     561        ''' 
     562        Retrieve the publication state of the specified atom - by  
     563        checking the collection it is in 
     564        @param atom: atom id to look up 
     565        @return: AtomState for the atom.  NB, if the ID is not found, assume 
     566        we're dealing with a new atom and set the state as the working state 
     567        ''' 
     568        logging.debug("Finding atom publication state") 
     569        path = self.getAtomFileCollectionPath(atomID) 
     570        for state in AtomState.allStates.values(): 
     571            if path.find('/%s' %state.collectionPath) > -1: 
     572                logging.debug("- state found: '%s'" %state.title) 
     573                return state 
     574         
     575        logging.debug("- state not found - returning WORKING state") 
     576        return AtomState.WORKING_STATE 
     577 
     578 
    509579    def getAtomFileCollectionPath(self, atomID): 
    510580        ''' 
     
    515585        ''' 
    516586        logging.info("Looking up collection path for atom ID, '%s'" %atomID) 
    517         xq = ndgXqueries()['atomFullPath'] 
     587        xq = self.xmldb.xq['atomFullPath'] 
    518588        xq = xq.replace('TargetCollection', ec.BASE_COLLECTION_PATH) 
    519589        xq = xq.replace('LocalID', atomID) 
     
    541611        self.deleteEXistFile(atomPath) 
    542612        logging.info("Atom deleted") 
     613 
     614 
     615    def changeAtomPublicationStateInExist(self, atom, newState): 
     616        ''' 
     617        Adjust the publication state of an atom in eXist 
     618        @param atom: the Atom data model of the atom whose publication state 
     619        needs to change 
     620        @param newState: an AtomState object representing the new publication 
     621        state of the atom 
     622        @return atom: atom data model with updated state 
     623        ''' 
     624        logging.info("Changing the publication state of atom - from '%s' to '%s'" \ 
     625                     %(atom.state.title, newState.title)) 
     626        oldState = atom.state 
     627        # firstly, create atom in new publication state collection - so data isn't 
     628        # lost if this fails 
     629        atom.state = newState 
     630        self.createEXistFile(atom.toPrettyXML(), atom.getDefaultCollectionPath(),  
     631                             atom.atomName) 
     632         
     633        # now delete atom in the old publication state 
     634        atom.state = oldState 
     635        self.deleteAtomInExist(atom) 
     636        logging.info("- atom created in new publication state and removed from old one") 
     637        atom.state = newState 
     638         
     639        # update feeds + create DIFs, if needed 
     640        if atom.isPublished(): 
     641            self.runAsynchAtomPublish(atom) 
     642         
     643        return atom 
     644         
    543645 
    544646             
     
    552654        asynchronously in a separate thread 
    553655        then raise a ValueError. 
    554          
    555656        ''' 
    556657        logging.info("Creating atom in eXist") 
     
    578679        if not eXistCollection: 
    579680            eXistCollection = atom.getDefaultCollectionPath() 
     681 
     682            # check if we need a new provider feed set up 
     683            providerCollection = ec.PROVIDER_FEED_PATH + atom.ME.providerID + '/' 
     684            if self.isNewEXistCollection(providerCollection): 
     685                logging.info("Creating feed for new provider ID") 
     686                self.createCollections([providerCollection]) 
     687                self.feedClient.createAtomFeed(providerCollection, 
     688                                               self.feedClient.PROVIDERLEVEL_ATOM_FEED_TITLE %atom.ME.providerID) 
     689             
    580690        elif isNew: 
    581691            # in this situation we're trying to create an atom with the same 
     
    601711        logging.info("Atom created in eXist") 
    602712         
    603         # lastly, update the feed to include an entry pointing to the atom 
    604         self.feedClient.createAtomFeedEntry(ec.BASE_COLLECTION_PATH, atom) 
     713        # lastly, if we're dealing with a published atom, update DIF records + 
     714        # feeds 
     715        if atom.isPublished(): 
     716            self.runAsynchAtomPublish(atom) 
     717            
    605718        return atom 
     719     
     720    def runAsynchAtomPublish(self, atom): 
     721        thread = publishingThread(self, atom) 
     722        thread.start() 
     723             
     724     
     725    def __publishAtom(self, atom): 
     726        ''' 
     727        Add atom info to the various feeds - and if it is a data entity, use  
     728        it to create a DIF document and add this to feeds, also 
     729        ''' 
     730        if atom.isDE(): 
     731            self.createDIFDocumentFromAtom(atom) 
     732         
     733        self.feedClient.addAtomToFeeds(atom) 
     734         
    606735     
    607736     
     
    631760        self.createEXistFile(doc, collection, fileName) 
    632761        logging.info("File restored") 
    633          
     762 
     763 
     764    def transformAtomIntoDIF(self, atom): 
     765        ''' 
     766        Transform an atom into a DIF document - using an XQuery transform ran 
     767        in eXist 
     768        @param atom: the Atom data model to convert 
     769        @return: the produced DIF document  
     770        ''' 
     771        logging.info("Creating DIF record from atom - using XQuery transform") 
     772         
     773        # get the query and set this up to use properly 
     774        targetCollection = atom.getPublicationStatePath() 
     775        providerID = atom.ME.providerID 
     776        # remove the trailing forward slash - otherwise the xquery won't work 
     777        if targetCollection.endswith('/'): 
     778            targetCollection = targetCollection[0:-1] 
     779        xquery = self.xmldb.xq.actual('atom2DIF', targetCollection, \ 
     780                                 providerID, atom.datasetID) 
     781 
     782        discovery_id,s = self.xmldb.executeQuery(xquery) 
     783        if s.has_key('hits') and not s['hits']: 
     784            raise Exception("XQuery produced no results - suggesting a problem with the query") 
     785        doc = self.xmldb.retrieve(discovery_id,0) 
     786         
     787        # add various missing info 
     788        # get the organisation data for the repository 
     789        # - NB, store for re-use to avoid multiple lookups of the same info 
     790        if self.dataCentres.has_key(providerID): 
     791            dataCentre = self.dataCentres[providerID] 
     792        else: 
     793            dataCentre = getDataCentreDIFElement(providerID, self.xmldb) 
     794            self.dataCentres[providerID] = dataCentre 
     795 
     796        # add various other data to atoms - to make up with the incomplete data spec there 
     797        doc = addOrgData(doc, targetCollection, dataCentre) 
     798        doc = expandParametersData(doc) 
     799        doc = addStandardKeywords(doc) 
     800 
     801        logging.info("Transform completed successfully - returning DIF doc") 
     802        return doc 
     803 
     804 
     805    def createDIFDocumentFromAtom(self, atom): 
     806        ''' 
     807        Transform an atom into a DIF document and store this in eXist 
     808        @param atom: the Atom data model to convert 
     809        ''' 
     810        logging.info("Creating and storing DIF document") 
     811        doc = self.transformAtomIntoDIF(atom) 
     812        fileName = atom.atomName.replace('.atom', '.dif') 
     813         
     814        # now add to eXist 
     815        providerID = atom.ME.providerID 
     816        collectionPath = ec.DIF_COLLECTION_PATH + providerID 
     817        # NB, check if provider collection exists; if not, add this with a feed 
     818        # NB, the collection will be created along with the DIF file - so set the 
     819        # feed up after the file has been created 
     820        setupFeed = False 
     821        if self.isNewEXistCollection(collectionPath): 
     822            setupFeed = True 
     823 
     824        self.createOrUpdateEXistFile(doc, collectionPath, 
     825                                     fileName)         
     826        if setupFeed: 
     827            logging.info("Creating feed for new provider ID") 
     828            self.createCollections([collectionPath]) 
     829            self.feedClient.createAtomFeed(collectionPath, 
     830                                           self.feedClient.PROVIDERLEVEL_DIF_FEED_TITLE %providerID + '/') 
     831        logging.info("DIF document created and stored") 
     832 
  • exist/trunk/python/ndgUtils/lib/existdbfeedclient.py

    r4758 r4782  
    77import logging, httplib 
    88import feedparser 
     9from ndgUtils.models.vocabtermdata import VocabTermData as VTD 
     10from ndgUtils.eXistConnector import eXistConnector as ec 
     11from ndgUtils import ndgObject 
    912 
    1013 
     
    1922class eXistDBFeedClient: 
    2023     
    21     ATOM_FEED_TITLE = 'Moles Atom Data' 
     24    TOPLEVEL_ATOM_FEED_TITLE = 'Moles Atom Data' 
     25    TOPLEVEL_DIF_FEED_TITLE = 'DIF Data' 
     26    ENTITYLEVEL_ATOM_FEED_TITLE = 'Moles %s Atom Data' 
     27    DEPLOYMENTS_ATOM_FEED_TITLE = 'Deployments Data (activities/observation stations/data production tools)' 
     28    PROVIDERLEVEL_ATOM_FEED_TITLE = 'Moles Atom Data - for provider, %s' 
     29    PROVIDERLEVEL_DIF_FEED_TITLE = 'Moles Atom Data - for provider, %s' 
     30     
    2231    REST_BASE_URL = '/exist/rest' 
    2332    FEED_ERROR_MSG = 'Failed to retrieve valid feed - error' 
     
    6776        logging.debug("Response retrieved") 
    6877 
    69         if response.status == 201: 
     78        if response.status == 204: 
     79            logging.info("No content returned => new feed set up") 
     80        elif response.status == 201: 
    7081            logging.info("Successfully posted atom to eXist feed") 
    7182        elif response.status == 401 and response.reason.find('+already+exists') > -1: 
     
    7687 
    7788 
     89    def setupBasicFeeds(self): 
     90        ''' 
     91        Set up the standard feeds expected of the eXist DB 
     92        - nb, provider feeds are set up when creating new atoms - when 
     93        their providers don't already have feeds available 
     94        ''' 
     95        self.createAtomFeed(ec.BASE_COLLECTION_PATH, 
     96                            self.TOPLEVEL_ATOM_FEED_TITLE) 
     97        self.VTD = VTD() 
     98        self.deName = VTD.TERM_DATA[VTD.DE_TERM].title 
     99        for type in [ec.PUBLISHED_COLLECTION_PATH, ec.SMALL_P_PUBLISHED_COLLECTION_PATH]: 
     100            self.createAtomFeed(ec.BASE_COLLECTION_PATH + type + ec.DE_COLLECTION_PATH, 
     101                                self.ENTITYLEVEL_ATOM_FEED_TITLE %VTD.TERM_DATA[VTD.DE_TERM].title), 
     102            self.createAtomFeed(ec.BASE_COLLECTION_PATH + type + ec.DEPLOYMENT_COLLECTION_PATH, 
     103                                self.ENTITYLEVEL_ATOM_FEED_TITLE %VTD.TERM_DATA[VTD.DEPLOYMENT_TERM].title), 
     104            self.createAtomFeed(ec.BASE_COLLECTION_PATH + type + ec.DEPLOYMENTS_COLLECTION_PATH, 
     105                                self.DEPLOYMENTS_ATOM_FEED_TITLE), 
     106            self.createAtomFeed(ec.BASE_COLLECTION_PATH + type + ec.GRANULE_COLLECTION_PATH, 
     107                                self.ENTITYLEVEL_ATOM_FEED_TITLE %VTD.TERM_DATA[VTD.GRANULE_TERM].title) 
     108 
     109        self.createAtomFeed(ec.DIF_COLLECTION_PATH, 
     110                            self.TOPLEVEL_DIF_FEED_TITLE) 
     111 
     112 
     113    def addAtomToFeeds(self, atom): 
     114        ''' 
     115        Add an entry to the different feeds associated with the specified atom 
     116        @param atom: an Atom object which should be linked to as an entry in the 
     117        eXist feeds 
     118        ''' 
     119        # add to top level feed 
     120        self.createAtomFeedEntry(ec.BASE_COLLECTION_PATH, atom) 
     121        # add to entity level feed 
     122        self.createAtomFeedEntry(atom.getDefaultEntityCollectionPath(), atom) 
     123         
     124        # add to provider level feed 
     125        self.createAtomFeedEntry(ec.PROVIDER_FEED_PATH + atom.ME.providerID + '/', atom) 
     126         
     127        # add to DIF feeds - if appropriate 
     128        if atom.isDE(): 
     129            self.createAtomFeedEntry(ec.DIF_COLLECTION_PATH, atom) 
     130            self.createAtomFeedEntry(ec.DIF_COLLECTION_PATH + atom.ME.providerID + '/',  
     131                                     atom) 
     132         
     133 
    78134    def createAtomFeed(self, collection, title): 
    79135        ''' 
     
    107163         
    108164 
    109     def createAtomFeedEntry(self, collection, atom): 
     165    def createAtomFeedEntry(self, collection, atom, isDIFRecord=False): 
    110166        ''' 
    111167        Add an entry to the specified collection (which should already have a 
     
    113169        @param collection: eXist collection with the atom feed to add the entry to 
    114170        @param atom: Atom to be referenced in the new entry 
    115         ''' 
    116         atomPath = atom.getDefaultCollectionPath() + atom.atomName 
    117         restfulLink = 'http://%s%s%s' %(self.hostAndPort, 
    118                                         self.REST_BASE_URL, atomPath) 
    119          
     171        @keyword isDIFRecord: if True, the entry contents are adjusted to 
     172        point to the DIF doc rather than the atom doc.  Default False.  
     173        ''' 
     174        titleString = '%s Atom' %atom.atomTypeName 
     175        browseURL = atom.atomBrowseURL 
     176        if isDIFRecord: 
     177            titleString = 'DIF Record' 
     178            browseURL = browseURL.replace('__%s__' %ndgObject.ATOM_DOC_TYPE,  
     179                                          '__%s__' %ndgObject.BROWSE_DIF_DOC_TYPE) 
     180             
    120181        entryXML = '<?xml version="1.0" ?>\ 
    121182<entry xmlns="http://www.w3.org/2005/Atom">\ 
    122 <title>%s Atom [%s]</title>\ 
     183<title>%s [%s]</title>\ 
     184<summary>%s</summary>\ 
    123185<content src="%s" type="application/atom+xml"/>\ 
    124 </entry>' %(atom.atomTypeName, atom.title, restfulLink) 
     186</entry>' %(titleString, atom.title, atom.Summary, browseURL) 
    125187        logging.info("Adding link to atom (%s) as entry in atom feed, %s" \ 
    126                      %(restfulLink, collection)) 
     188                     %(browseURL, collection)) 
    127189        self.__postEditAtomFeed(collection, entryXML) 
    128190        logging.info("Successfully added new feed entry") 
    129191 
    130192 
    131     def getRESTfulData(self, docPath): 
     193    def getRESTfulData(self, docPath, suppressPrefix = False): 
    132194        ''' 
    133195        Retrieve data using the REST interface 
    134196        @param docPath: path to the data to retrieve - NB, this should equal 
    135197        the DB path to the document in question 
     198        @keyword suppressPrefix: if True, the base, REST url, is not added to  
     199        the specified docPath  
    136200        @return document, if found, None, otherwise 
    137201        ''' 
    138202        logging.info("Retrieving document at, %s, using RESTful interface" %docPath) 
    139203        connection = httplib.HTTPConnection(self.hostAndPort) 
    140         connection.request("GET", '%s%s' %(self.REST_BASE_URL, docPath)) 
    141         response = connection.getresponse() 
    142         if response.status == 200: 
    143             logging.info("Document successfully retrieved - returning this now") 
    144             return response.read() 
     204        url = docPath 
     205        if not suppressPrefix: 
     206            url = self.REST_BASE_URL + docPath 
     207        try: 
     208            connection.request("GET", '%s' %(url)) 
     209            response = connection.getresponse() 
     210             
     211            if response.status == 200: 
     212                logging.info("Document successfully retrieved - returning this now") 
     213                return response.read() 
     214        except Exception, e: 
     215            import pdb 
     216            pdb.set_trace() 
    145217         
    146218        logging.info("- no document found at path, '%s'" %docPath) 
  • exist/trunk/python/ndgUtils/lib/utilities.py

    r4722 r4782  
     1''' 
     2Various helper methods for use across different applications  
     3@author: C Byrom 
     4''' 
    15import os, sys, logging, re, cgi, urlparse, httplib, time, urllib2, socket 
    26from ndgUtils import ndgObject 
    37import csml.csmlscan as CsmlScan 
    4 ''' 
    5 Various helper methods for use with the granulator command line tool  
    6 @author: C Byrom 
    7 ''' 
    88ISO8601_RE = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})([T\s]?([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" + \ 
    99    "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?" 
    1010 
    1111regExp = re.compile(ISO8601_RE) 
     12 
     13YEAR_FORMAT = '%Y-%m-%d'    # format to use when parsing dates 
    1214 
    1315# Regular expression string to allow months to be stripped out of parameters 
     
    522524       else:  
    523525           return ww,ee 
     526 
     527 
     528def findElementIndex(tree, elementName, isLast = False): 
     529    ''' 
     530    Given an elementree object and a name of an element, determine the index 
     531    of the element in the tree 
     532    @param tree: tree to search for the element in 
     533    @param elementName: name of element to find index of 
     534    @keyword isLast: if False get the index of the first occurance, otherwise get 
     535    the last occurance  
     536    @return: index value or -1 if not found 
     537    ''' 
     538    # not sure if there is a better way of doing this - seems to be no other way 
     539    # of determining the correct index - NB, order is important for DIF schema 
     540    # validation 
     541    logging.debug("Looking for index of element, '%s'" %elementName) 
     542    index = -1 
     543    for i, element in enumerate(tree): 
     544        if element.tag == elementName: 
     545            logging.debug("Element found (index = %s)" %i) 
     546            index = i 
     547            if not isLast: 
     548                break 
     549 
     550    if index < 0: 
     551        logging.debug("Element not found") 
     552    return index 
  • exist/trunk/python/ndgUtils/ndgObject.py

    r4696 r4782  
    1919    ATOM_DOC_TYPE = 'ATOM' 
    2020    ATOM_BACKUP_DOC_TYPE = 'ATOM-BACKUP' 
     21     
     22    # NB, DIF records are stored in local eXist DB to allow feeds to serve them 
     23    BROWSE_DIF_DOC_TYPE = 'BROWSE-DIF' 
    2124 
    2225        # various namespaces used in the docs 
     
    3538    BROWSE_SCHEMES = [MOLES_DOC_TYPE, NDGB1_DOC_TYPE, \ 
    3639                      NUMSIM_DOC_TYPE, ATOM_DOC_TYPE, \ 
    37                       ATOM_BACKUP_DOC_TYPE] 
     40                      ATOM_BACKUP_DOC_TYPE, BROWSE_DIF_DOC_TYPE] 
    3841     
    3942    def __init__(self,uri,config=None): 
  • exist/trunk/python/ndgUtils/ndgRetrieve.py

    r4663 r4782  
    99NUMSIM_COLLECTION = '/db/NumSim' 
    1010NDGA0_COLLECTION = '/db/ndg_A_metadata' 
     11DIF_COLLECTION = '/db/DIF' 
    1112 
    1213class NDGRetrieveError(Exception): 
Note: See TracChangeset for help on using the changeset viewer.