Changeset 4930 for ndgCommon/trunk


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

Remove main DocumentRetrieve? functionality - since this is now fully
handled by the various new clients created. Retain the http objects
incase they are actually needed.

File:
1 edited

Legend:

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

    r4834 r4930  
    44 @author: B Lawrence? 
    55''' 
    6 from ndg.common.src.clients.xmldb.eXist.eXistInterface import ndg_eXist 
    7 from ndg.common.src.lib.ndgXqueries import ndgXqueries 
    8 from ndg.common.src.models.ndgObject import ndgObject as no 
    96from xml.etree import ElementTree as ET 
    107import urllib2, logging, socket 
     
    1815        url = 'http://' + url 
    1916    return url 
    20      
    21          
    22 class DocumentRetrieve(ndg_eXist): 
    23     '''  
    24     This class provides a document retrieval service via the NDG exist interfaces  
    25     ''' 
    26  
    27     ATOM_TYPE = 'ATOM-TYPE' 
    28     ATOM_BACKUP_TYPE = 'ATOM-BACKUP' 
    29     ATOM = 'ATOM' 
    30     def __init__(self, repository, pwfile='passwords.txt'): 
    31         logging.info("Using repository, '%s'" %repository) 
    32  
    33         ndg_eXist.__init__(self, db=repository, passwordFile=pwfile) 
    34         logging.info("DB connection initialised") 
    35         self.repository=repository 
    36         self.xq=ndgXqueries() 
    37         self.knownQueries={'DIF':'moles2dif','DC':'moles2DC','ISO19139':'moles2iso19139', \ 
    38                            'NDG-B0':'moles','NDG-B1':'molesObjectType','MDIP':'moles2mdip', \ 
    39                            'NDG-A0':'csml','NumSim':'numsim', self.ATOM:'atom', \ 
    40                            self.ATOM_BACKUP_TYPE:'atom', self.ATOM_TYPE:'atomTypeList', 
    41                            no.BROWSE_DIF_DOC_TYPE:'dif'} 
    42  
    43     def _retrieveDoc(self, schema, xqtype, targetCollection, repository, localID): 
    44         ''' 
    45         Retrieve doc using specified XQuery type 
    46         @return: docName, docContents 
    47         ''' 
    48         logging.debug("Retrieving doc - type, '%s', coll, '%s', rep:'%s', localID:'%s'" \ 
    49                       %(xqtype,targetCollection,repository,localID)) 
    50         xquery=self.xq.actual(xqtype,targetCollection,repository,localID) 
    51  
    52         id,summary=self.executeQuery(xquery) 
    53         # NB, backups will inevitably return lots of docs - only retrieve the top one 
    54         # for the moment - since this is not really needed atm 
    55         if summary['hits'] != 1 and schema != self.ATOM_BACKUP_TYPE: 
    56             raise ValueError('Unable to obtain single %s document [%s] (hits=%s)'\ 
    57                              %(schema,localID,summary['hits'])) 
    58  
    59         docName = summary['documents'][0][0] 
    60         r=self.retrieve(id,0,{}) 
    61         self.sessionRelease(id) 
    62         return docName, r 
    63  
    64  
    65     def get(self,repository,schema,localID,targetCollection='/db/discovery/moles', \ 
    66             includeDocNameData=False): 
    67         ''' 
    68         @keyword includeDocNameData: if True, a dictionary is returned, instead of the dataset, with the key 
    69         being the name of the document and the entry being the dataset 
    70         ''' 
    71         logging.debug("Get called with rep:'%s', schema:'%s', localID:'%s', collection:'%s'" \ 
    72                       %(repository,schema,localID,targetCollection)) 
    73         docName = "" 
    74         if schema not in self.knownQueries: 
    75             raise TypeError('Unknown Schema "%s" in URI'%schema) 
    76  
    77         xqtype=self.knownQueries[schema] 
    78  
    79         if schema == 'NDG-B1': 
    80             # this is a general moles object - so need to further establish the type of moles doc  
    81             # it is to get the correct XQUery to use 
    82             name, xml = self._retrieveDoc(schema, xqtype, targetCollection, \ 
    83                                           repository, localID) 
    84             xml=ET.fromstring(xml) 
    85             otype=int(xml.text or 0) 
    86              
    87             xqtype={4:'stubB_dataEntity', 
    88                     3:'stubB_observationStation', 
    89                     2:'stubB_DPT', 
    90                     1:'stubB_activity'}[otype] 
    91  
    92         docName, r = self._retrieveDoc(schema, xqtype, targetCollection,  
    93                                        repository, localID) 
    94         if includeDocNameData: 
    95             return {docName: r} 
    96         return r 
    97      
    98      
    99     def error(self,string,t,r,s,l): 
    100         raise ValueError,string+' for %s:%s:%s in %s'%(r,s,l,t) 
    10117 
    10218             
     
    14763        from ndg.common.src.models.ndgObject import ndgObject 
    14864        n = ndgObject(uri) 
    149         return self.get(n.repository,n.schema,n.localID) 
     65        return self.getNDGDoc(n.repository,n.schema,n.localID) 
    15066 
    151     def get(self,repository,schema,localID,**kw): 
     67    def getNDGDoc(self,repository,schema,localID,**kw): 
    15268        ''' Return a remote ndg document ''' 
    15369        #TODO what about security? Probably means we need to get the headers of our responses sorted ... 
Note: See TracChangeset for help on using the changeset viewer.