Ignore:
Timestamp:
02/09/08 16:41:35 (12 years ago)
Author:
cbyrom
Message:

Fix a few bugs in DocumentRetrieve? + add support for Atom based docs
+ extend test suite for the DocumentRetrieve? class + improve error
handling and logging.

File:
1 edited

Legend:

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

    r3500 r4160  
    1 import ndgRetrieve,xmlHandler2 
     1import ndgRetrieve,xmlHandler2, logging 
    22 
    33class ndgObject: 
     
    88    def __init__(self,uri,config=None): 
    99        ''' Parse the uri and prepare for obtaining the actual content''' 
    10          
     10        logging.debug("Initialising ndgObject with uri: '%s'" %uri) 
    1111        #Dom had problem with unicode coming in here ... dunno why @@@@ 
    1212        uri=str(uri)  
     
    4141            # after all that, we don't think it's an NDG URI ... 
    4242            raise ValueError,'The identifier [%s] is not a valid NDG style URI'%uri 
    43         else: 
    44             # yes, it is an NDG URI ... 
    45             self.repository,self.schema,self.localID=repository,schema,localID 
    46          
     43 
     44        # yes, it is an NDG URI ... 
     45        self.repository,self.schema,self.localID=repository,schema,localID 
     46        logging.debug("Extracted valid NDG values from URI: repository: '%s', schema: '%s', localID: '%s'" \ 
     47                      %(repository, schema, localID)) 
    4748        self.setConfig(config) 
    4849         
    4950    def setConfig(self,config): 
    50         ''' Set up the configuration for retrieving this document ''' 
     51        '''  
     52        Set up the configuration for retrieving this document  
     53        ''' 
     54        logging.debug("Setting up configuration for retrieving document") 
    5155        self.config=config 
    5256        if config is None: 
    5357            self.discoveryURL,self.baseURL,self.xmlURL,self.printableURL=None,None,None,None 
    5458            self.BURL=None 
     59            return 
     60 
     61        self.server=self.config.get('DISCOVERY','default') 
     62        server=self.server 
     63        qs=None 
     64        # This NDG object may itself be a discovery record, which makes life easy, but 
     65        # it might not be, in which case we have to build up all the possible views upon it. 
     66        # But remember only data entity b records have discovery records ... 
     67        self.viewService='%s/view/'%server 
     68        discoveryBASE='%s%s__%s__%s'%(self.viewService,self.repository,self.schema,self.localID) 
     69        fmt=self.config.get('DISCOVERY','formatDefault','DIF') 
     70        self.BURL=None 
     71        # We'll build the following even if it can't be used (as would be the case for 
     72        # a non data entity B record or an A record) because it's a useful template. 
     73        if self.schema!=fmt: qs=('outputSchema',fmt) 
     74        self.discoveryURL=self.__buildURL(discoveryBASE,[qs]) 
     75        servicehost=self.config.get('NDG_B_SERVICE',self.repository,'unknown') 
     76        # If this record is itself a discovery record, then we don't have much more to do 
     77        if self.schema in ['DIF','DC','MDIP','ISO19139']: 
     78            self.xmlURL=self.__buildURL( 
     79                discoveryBASE.replace('/view/','/retrieve/'),[qs,('format','raw')]) 
     80            self.printableURL=self.__buildURL(discoveryBASE,[qs,('format','xml')]) 
     81            self.URL=self.discoveryURL 
     82            if servicehost!='unknown':self.gettable=1 
     83        elif self.schema in ['NDG-B0','NDG-B1','NumSim']: 
     84            # One day we'll use a service binding to get this 
     85            # This is a mapping from the ndg repository id to an actual repository id 
     86            # understood by the ndg exist interface 
     87            blank=self.config.get('NDG_B_SERVICE','instance') 
     88            url=blank.replace('SERVICEHOST',servicehost) 
     89            url=url.replace('URI',self.uri) 
     90            self.URL=url 
     91            self.xmlURL=url.replace('/view/','/retrieve/')+'?format=raw' 
     92            self.printableURL=url+'?format=xml' 
     93            if servicehost!='unknown': self.gettable=0 
    5594        else: 
    56             self.server=self.config.get('DISCOVERY','default') 
    57             server=self.server 
    58             qs=None 
    59             # This NDG object may itself be a discovery record, which makes life easy, but 
    60             # it might not be, in which case we have to build up all the possible views upon it. 
    61             # But remember only data entity b records have discovery records ... 
    62             self.viewService='%s/view/'%server 
    63             discoveryBASE='%s%s__%s__%s'%(self.viewService,self.repository,self.schema,self.localID) 
    64             fmt=self.config.get('DISCOVERY','formatDefault','DIF') 
    65             self.BURL=None 
    66             # We'll build the following even if it can't be used (as would be the case for 
    67             # a non data entity B record or an A record) because it's a useful template. 
    68             if self.schema!=fmt: qs=('outputSchema',fmt) 
    69             self.discoveryURL=self.__buildURL(discoveryBASE,[qs]) 
    70             servicehost=self.config.get('NDG_B_SERVICE',self.repository,'unknown') 
    71             # If this record is itself a discovery record, then we don't have much more to do 
    72             if self.schema in ['DIF','DC','MDIP','ISO19139']: 
    73                 self.xmlURL=self.__buildURL( 
    74                     discoveryBASE.replace('/view/','/retrieve/'),[qs,('format','raw')]) 
    75                 self.printableURL=self.__buildURL(discoveryBASE,[qs,('format','xml')]) 
    76                 self.URL=self.discoveryURL 
    77                 if servicehost!='unknown':self.gettable=1 
    78             elif self.schema in ['NDG-B0','NDG-B1','NumSim']: 
    79                 # One day we'll use a service binding to get this 
    80                 # This is a mapping from the ndg repository id to an actual repository id 
    81                 # understood by the ndg exist interface 
    82                 blank=self.config.get('NDG_B_SERVICE','instance') 
    83                 url=blank.replace('SERVICEHOST',servicehost) 
    84                 url=url.replace('URI',self.uri) 
    85                 self.URL=url 
    86                 self.xmlURL=url.replace('/view/','/retrieve/')+'?format=raw' 
    87                 self.printableURL=url+'?format=xml' 
    88                 if servicehost!='unknown': self.gettable=0 
    89             else: 
    90                 #currently we don't know how to get this one 
    91                 self.URL='unknown' 
    92                 self.discoveryURL,self.baseURL,self.xmlURL,self.printableURL=None,None,None,None 
    93                  
    94             #now, we'll build a stub-B url as well, in case that comes in handy  
    95             if self.schema!='NumSim' and self.gettable<>-1: 
    96                 self.BURL=discoveryBASE.replace(self.schema,'NDG-B1') 
    97                 self.BURL=self.BURL.replace(server,servicehost) 
     95            #currently we don't know how to get this one 
     96            self.URL='unknown' 
     97            self.discoveryURL,self.baseURL,self.xmlURL,self.printableURL=None,None,None,None 
     98 
     99        logging.debug("Set up URL: '%s'\ndiscoveryURL: '%s'" %(self.URL, self.discoveryURL)) 
     100             
     101        #now, we'll build a stub-B url as well, in case that comes in handy  
     102        if self.schema!='NumSim' and self.gettable<>-1: 
     103            self.BURL=discoveryBASE.replace(self.schema,'NDG-B1') 
     104            self.BURL=self.BURL.replace(server,servicehost) 
     105            logging.debug("Set up stub-B url: '%s'" %self.BURL) 
     106 
    98107 
    99108    def __buildURL(self,base,queryStuff): 
Note: See TracChangeset for help on using the changeset viewer.