Changeset 4430 for exist


Ignore:
Timestamp:
17/11/08 09:40:21 (11 years ago)
Author:
cbyrom
Message:

Fix getDIF() method + extend xquery to include Dataset_Publisher in DIF +
improve existdbclient methods to get all atom IDs and collections using
pre-defined xqueries - in one retrieval.

Location:
exist/trunk
Files:
4 edited

Legend:

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

    r4427 r4430  
    8484    def getDIF(self,entryID): 
    8585        ''' Get a specific DIF document from a repository by using the entryID ''' 
    86         xq='''for $DE in collection()/DIF[Entry_ID='%s'] return $DE'''%entryID 
     86        xq='''declare default element namespace 'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/'; \ 
     87            for $DE in collection()/DIF[Entry_ID='%s'] return $DE'''%entryID 
    8788        xquery='''for $DE in collection('/db/testdif1')/DIF[Entry_ID='%s'] return $DE'''%entryID 
    8889        id,summary=self.executeQuery(xq)#xquery) 
  • exist/trunk/python/ndgUtils/models/existdbclient.py

    r4419 r4430  
    275275        ''' 
    276276        logging.info("Retrieving all atom ids") 
    277         xq = "declare default element namespace 'http://www.w3.org/2005/Atom'; \ 
    278             for $ID in collection(/db/atoms)/entry/id return <id>{tokenize(string($ID), '__ATOM__')[2]}</id>"#<entry>$DE/entry/id</entry>"#for $d in $DE/entry/id return data($d)"#$DE/entry/id" 
    279                  
     277        xq = ndgXqueries()['atomList'] 
    280278        id, doc = self.xmldb.executeQuery(xq) 
     279        if doc['hits'] == 0:  
     280            return [] 
    281281         
    282282        indices = range(doc['hits']) 
     283         
     284        doc = self.xmldb.retrieve(id, 0) 
     285        et = ET.fromstring(doc) 
    283286        ids = [] 
    284         for i in indices: 
    285             doc = self.xmldb.retrieve(id,i,{}) 
    286             docET = ET.fromstring(doc) 
    287             ids.append(docET.text) 
     287        for member in et: 
     288            fn = member.findtext('{http://www.w3.org/2005/Atom}repositoryID') 
     289            ids.append(fn) 
    288290        logging.debug("Found ids, '%s'" %ids) 
    289291        return ids 
     
    297299        ''' 
    298300        logging.info("Retrieving all atom collection paths") 
    299                  
    300         # NB, we get all data back in one field here since otherwise eXist complains 
    301         # that the returned dataset is too large and falls over 
    302         xq = "declare default element namespace 'http://www.w3.org/2005/Atom'; \ 
    303             for $DE in collection('/db/atoms')/entry/id let $f:=util:document-name($DE) return \ 
    304             <fileName>{util:collection-name($DE)}/{$f}</fileName>" 
    305  
     301        xq = ndgXqueries()['atomList'] 
    306302        id, doc = self.xmldb.executeQuery(xq) 
     303        if doc['hits'] == 0:  
     304            return [] 
     305         
    307306        indices = range(doc['hits']) 
     307         
     308        doc = self.xmldb.retrieve(id, 0) 
     309        et = ET.fromstring(doc) 
    308310        colData = {} 
    309         for i in indices: 
    310             doc = self.xmldb.retrieve(id,i,{}) 
    311             docET = ET.fromstring(doc) 
    312             data = docET.text 
     311        for member in et: 
     312            col = member.findtext('{http://www.w3.org/2005/Atom}fileName') 
    313313            key = data.split('/')[-1] 
    314314            key = key.split('.')[0] 
    315315            val = '/'.join(data.split('/')[0:-1]) 
    316316            colData[key] = val 
     317 
    317318        logging.debug("Finished looking up atom paths") 
    318319        return colData 
  • exist/trunk/python/ndgUtils/ndgObject.py

    r4427 r4430  
    2222        # various namespaces used in the docs 
    2323    ATOM_NS = 'http://www.w3.org/2005/Atom' 
     24    DIF_NS = 'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/' 
    2425    MOLES_NS = 'http://ndg.nerc.ac.uk/schema/moles2beta' 
    2526    GEOSS_NS = 'http://www.georss.org/georss/10' 
  • exist/trunk/xquery/atom2DIF.xq

    r4425 r4430  
    4444            element Dataset_Creator {string($DE/atom:author/atom:name)}, 
    4545            element Dataset_Title {string($DE/atom:title)} 
     46            element Dataset_Publisher {string($DE/moles:entity/moles:molesISO/moles:providerID)} 
    4647        }, 
    4748        element Personnel { 
Note: See TracChangeset for help on using the changeset viewer.