Changeset 4931 for ndgCommon


Ignore:
Timestamp:
10/02/09 17:32:22 (11 years ago)
Author:
cbyrom
Message:

Update ndgDirecory to use new clients suite.

Location:
ndgCommon/trunk/ndg/common/src/dal
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/src/dal/ndgDirectory.py

    r4793 r4931  
    44 @author: B Lawrence? 
    55''' 
    6 from ndg.common.src.lib.ndgXqueries import ndgXqueries 
    7 from ndg.common.src.clients.xmldb.eXist.eXistInterface import ndg_eXist 
     6from ndg.common.src.clients.xmldb.eXist.searchclient import SearchClient 
    87from xml.etree import ElementTree as ET 
    98 
     
    3635                 'MDIP':'http://www.oceannet.org/mdip/xml',\ 
    3736                 'ATOM': 'http://www.w3.org/2005/Atom'}[docType] 
    38         #load all queries 
    39         queries = ndgXqueries() 
     37         
     38        #make sure we have a db available 
     39        self.searchClient = SearchClient(dbHostName = existHost,  
     40                                         configFileName = passwordFile) 
     41 
    4042        #select the right query according to the docType 
    4143        xqName={'DIF':'DIFList','MOLES':'molesList', \ 
     
    4345                'ATOM': 'atomList'}[docType] 
    4446        self.docType=docType 
    45         xq=queries[xqName] 
     47        xq = self.searchClient.resources.xq[xqName] 
    4648        # set the query up with the correct target collection 
    4749        self.xq=xq.replace('TargetCollection',self.targetCollection) 
    48          
    49         #make sure we have a db available 
    50         self.xmldb=ndg_eXist(db=existHost, **inputs) 
    5150       
    52         if not fast: m=self.getMembers() 
     51        if not fast:  
     52            m=self.getMembers() 
    5353 
    5454         
    5555    def getMembers(self): 
    56         ''' Build the membership of the directory by URI (based on the FILENAME) ''' 
    57         id,s=self.xmldb.executeQuery(self.xq) 
    58         if s['hits']==0: return [] 
    59         indices=range(s['hits']) 
    60          
    61         doc = self.xmldb.retrieve(id, 0) 
    62         et = ET.fromstring(doc) 
     56        '''  
     57        Build the membership of the directory by URI (based on the FILENAME)  
     58        ''' 
     59        doc = self.searchClient.client.runQuery(self.xq) 
     60        if not doc: 
     61            return [] 
     62 
     63        et = ET.fromstring(doc[0]) 
    6364        for member in et: 
    64             fn = member.findtext('{%s}fileName'%self.ns) 
    65             eid = member.findtext('{%s}repositoryID'%self.ns) 
    66             c = member.findtext('{%s}created'%self.ns) 
     65            #fn = member.findtext('{%s}fileName'%self.ns) 
     66            #eid = member.findtext('{%s}repositoryID'%self.ns) 
     67            #c = member.findtext('{%s}created'%self.ns) 
     68            fn = member.findtext('fileName') 
     69            eid = member.findtext('repositoryID') 
     70            c = member.findtext('created') 
    6771            self.members.append({'fileName':fn,'EntryID':eid,'created':c}) 
    6872         
    69         self.xmldb.release(id) 
    7073        self.files=[i['fileName'] for i in self.members] 
    7174        self.entries=[i['EntryID'] for i in self.members] 
     
    7376 
    7477    
    75     def get(self,fileName): 
     78    def get(self, fileName): 
    7679        ''' Return the actual document corresponding to uri in this directory ''' 
    7780        #Use the fact that we know its document name ... 
    78         return self.xmldb.getDoc(self.targetCollection,fileName) 
     81        # NB, atoms have a more structured collection directory - as a result 
     82        # AtomList.xq returns the full path to the listed docs - so avoid 
     83        # concat'ing the collectionName for these 
     84        if fileName.startswith(self.targetCollection): 
     85            name = fileName 
     86        else: 
     87            name='%s/%s'%(self.targetCollection, fileName) 
     88 
     89        results = self.searchClient.getDocs([name]) 
     90        return results[name] 
    7991 
    8092     
     
    94106                q+=",'%s'"%fileName 
    95107        xq="<created>{xmldb:created(%s)}</created>"%q 
    96         r=self.xmldb.executeChunkedQuery(xq,1,1) 
     108        r = self.searchClient.client.runQuery(xq)[0] 
    97109        e=ET.fromstring(str(r)) 
    98         return e.findtext('created') 
     110        return e.text 
    99111     
    100112 
Note: See TracChangeset for help on using the changeset viewer.