Changeset 4935


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

Update the models to use the new client suite + add new ndgObject var:
ASSOCIATED_ATOM_DOC_TYPE - to cope with the looking up of associated metadata.

Location:
ndgCommon/trunk/ndg/common/src/models
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/src/models/Atom.py

    r4842 r4935  
    77from xml.etree import cElementTree as ET 
    88import csml.parser as CsmlParser 
    9 from ndg.common.src.clients.xmldb.eXist.eXistConnector import eXistConnector 
     9import ndg.common.src.clients.xmldb.eXist.dbconstants as dc 
    1010from ndg.common.src.lib.ETxmlView import et2text 
    1111import ndg.common.src.lib.utilities as utilities 
     
    410410        ''' 
    411411        logging.debug("Getting collection path for atom publication state") 
    412         collectionPath = eXistConnector.BASE_COLLECTION_PATH + self.state.collectionPath 
     412        collectionPath = dc.ATOM_COLLECTION_PATH + self.state.collectionPath 
    413413        logging.debug("Returning publication state collection, '%s'" %collectionPath) 
    414414        return collectionPath 
     
    424424         
    425425        if self.atomTypeID == VTD.DE_TERM: 
    426             collectionPath += eXistConnector.DE_COLLECTION_PATH 
     426            collectionPath += dc.DE_COLLECTION_PATH 
    427427        elif self.atomTypeID == VTD.GRANULE_TERM: 
    428             collectionPath += eXistConnector.GRANULE_COLLECTION_PATH 
     428            collectionPath += dc.GRANULE_COLLECTION_PATH 
    429429        elif self.atomTypeID == VTD.ACTIVITY_TERM and \ 
    430430            self.subtypeID == VTD.DEPLOYMENT_TERM: 
    431             collectionPath += eXistConnector.DEPLOYMENTS_COLLECTION_PATH 
     431            collectionPath += dc.DEPLOYMENTS_COLLECTION_PATH 
    432432        else: 
    433             collectionPath += eXistConnector.DEPLOYMENT_COLLECTION_PATH 
     433            collectionPath += dc.DEPLOYMENT_COLLECTION_PATH 
    434434         
    435435        logging.debug("Returning entity collection, '%s'" %collectionPath) 
     
    12301230 
    12311231 
    1232     def lookupAssociatedData(self, type, dr, lookupIndirectReferences=False): 
     1232    def lookupAssociatedData(self, type, searchClient, lookupIndirectReferences=False): 
    12331233        ''' 
    12341234        Check through the atom links and retrieve any associated data of the  
     
    12361236        @param type: type of associated data to lookup - currently VTD.DEPLOYMENT_TERM 
    12371237        or VTD.DE_TERM 
    1238         @param dr: Instance of DocumentRetrieve object - NB, this requires eXist 
    1239         config details which are not available to the Atom object 
     1238        @param searchClient: Client implementing the AbstractSearchXMLDBClient class 
    12401239        @keyword lookupIndirectReferences: if True, the atom ID is used to search 
    12411240        defined deployments to find those which reference it, otherwise only  
     
    12631262            # deployments info looked up first 
    12641263            if type == VTD.DE_TERM and self.isDeployable() and not self.deployments: 
    1265                 self.lookupAssociatedData(VTD.DEPLOYMENT_TERM, dr, lookupIndirectReferences) 
     1264                self.lookupAssociatedData(VTD.DEPLOYMENT_TERM, searchClient,  
     1265                                          lookupIndirectReferences = lookupIndirectReferences) 
    12661266             
    12671267            logging.info("Looking up references to this atom from other %s" %type) 
     
    12791279            links = [] 
    12801280            for url in urls: 
    1281                 doc = dr.get(type, dr.ATOM_TYPE, url, \ 
    1282                              targetCollection = eXistConnector.BASE_COLLECTION_PATH) 
     1281                doc = searchClient.getNDGDoc(type, ndgObject.ASSOCIATED_ATOM_DOC_TYPE, url, 
     1282                                             targetCollection = dc.ATOM_COLLECTION_PATH) 
    12831283                # now need to turn this results set into actual atoms 
    12841284                tree = ET.fromstring(doc) 
     
    13011301                else: 
    13021302                    localID = link.href.split("__ATOM__")[-1] 
    1303                     deploymentAtom = dr.get(self.ME.providerID, 'ATOM', localID, \ 
    1304                                             targetCollection = eXistConnector.BASE_COLLECTION_PATH) 
     1303                    deploymentAtom = searchClient.getNDGDoc(self.ME.providerID,  
     1304                                                            'ATOM', localID,  
     1305                                                            targetCollection = dc.ATOM_COLLECTION_PATH) 
    13051306     
    13061307                deployment = Deployment.Deployment(Atom(xmlString=str(deploymentAtom))) 
  • ndgCommon/trunk/ndg/common/src/models/AtomState.py

    r4793 r4935  
    55''' 
    66import logging 
    7 from ndg.common.src.clients.xmldb.eXist.eXistConnector import eXistConnector as ec 
     7import ndg.common.src.clients.xmldb.eXist.dbconstants as dc 
    88 
    99# flags to specify published state of atom 
     
    6161        return False 
    6262 
    63 OLD_STATE = AtomState(OLD_STATE_FLAG, 'Old', ec.OLD_COLLECTION_PATH) 
    64 WORKING_STATE = AtomState(WORKING_STATE_FLAG, 'Working', ec.WORKING_COLLECTION_PATH) 
     63OLD_STATE = AtomState(OLD_STATE_FLAG, 'Old', dc.OLD_COLLECTION_PATH) 
     64WORKING_STATE = AtomState(WORKING_STATE_FLAG, 'Working', dc.WORKING_COLLECTION_PATH) 
    6565SMALL_P_PUBLISHED_STATE = AtomState(SMALL_P_PUBLISHED_STATE_FLAG, 'published',  
    66                                     ec.SMALL_P_PUBLISHED_COLLECTION_PATH) 
     66                                    dc.SMALL_P_PUBLISHED_COLLECTION_PATH) 
    6767PUBLISHED_STATE = AtomState(PUBLISHED_STATE_FLAG, 'Published', 
    68                             ec.PUBLISHED_COLLECTION_PATH) 
     68                            dc.PUBLISHED_COLLECTION_PATH) 
  • ndgCommon/trunk/ndg/common/src/models/Deployment.py

    r4837 r4935  
    5151        else: 
    5252            logging.debug("Not a valid deployment type (%s) - ignoring" \ 
    53                           %deploymentLink.vocabUrl) 
     53                          %deploymentLink.rel) 
    5454            return 
    5555 
  • ndgCommon/trunk/ndg/common/src/models/ndgObject.py

    r4793 r4935  
    55                (2) a printable xml representation  
    66''' 
    7 from ndg.common.src.lib import xmlHandler2 
    87import logging 
    98 
     
    2625    ATOM_DOC_TYPE = 'ATOM' 
    2726    ATOM_BACKUP_DOC_TYPE = 'ATOM-BACKUP' 
     27    # NB, this is used to look up associated atoms - e.g. when the type is Deployment, 
     28    # the lookup will return all deployment data atoms listed in the deployment 
     29    ASSOCIATED_ATOM_DOC_TYPE = 'ASSOCIATED-ATOM' 
    2830     
    2931    # NB, DIF records are stored in local eXist DB to allow feeds to serve them 
     
    4648                      NUMSIM_DOC_TYPE, ATOM_DOC_TYPE, \ 
    4749                      ATOM_BACKUP_DOC_TYPE, BROWSE_DIF_DOC_TYPE] 
     50 
     51    discoveryURL = None 
     52    baseURL = None 
     53    xmlURL = None 
     54    printableURL = None 
     55    useDiscoveryService = 1 
     56    BURL=None 
    4857     
    49     def __init__(self,uri,config=None): 
    50         ''' Parse the uri and prepare for obtaining the actual content''' 
     58    def __init__(self, uri, config=None): 
     59        '''  
     60        Parse the uri and prepare for obtaining the actual content 
     61        @param uri: ndgURI to set up object with 
     62        @keyword config: config object to use for retrieving the underlying doc 
     63        ''' 
    5164        logging.debug("Initialising ndgObject with uri: '%s'" %uri) 
    5265        #Dom had problem with unicode coming in here ... dunno why @@@@ 
     
    89102        self.setConfig(config) 
    90103 
    91     def setDefaultProperties(self): 
    92         ''' 
    93         Set default properties for object 
    94         ''' 
    95         self.discoveryURL,self.baseURL,self.xmlURL,\ 
    96             self.printableURL =None,None,None,None 
    97         self.useDiscoveryService = 1 
    98         self.BURL=None 
    99  
    100          
     104 
    101105    def setConfig(self, config): 
    102106        '''  
     
    105109        logging.debug("Setting up configuration for retrieving document") 
    106110        self.config=config 
    107         if config is None: 
    108             self.setDefaultProperties() 
     111        if not config: 
    109112            return 
     113         
    110114 
    111115        self.server=self.config.get('DISCOVERY','default') 
     
    122126        logging.info("Default discovery format set to: %s" %fmt) 
    123127             
    124         self.BURL=None 
    125128        # We'll build the following even if it can't be used (as would be the case for 
    126129        # a non data entity B record or an A record) because it's a useful template. 
     
    159162            #currently we don't know how to get this one 
    160163            self.URL='unknown' 
    161             self.setDefaultProperties() 
     164            self.discoveryURL = None 
    162165 
    163166        logging.debug("Set up URL: '%s', discoveryURL: '%s'" %(self.URL, self.discoveryURL)) 
     
    187190            return None 
    188191        from ndg.common.src.dal.ndgRetrieve import ndgRetrieve 
    189         status,xmlh = ndgRetrieve(self,self.config, \ 
    190                                             discovery = self.useDiscoveryService) 
     192        status,xmlh = ndgRetrieve(self, self.config,  
     193                                  discovery = self.useDiscoveryService) 
    191194        if status: 
    192             x=xmlHandler2.xmlHandler(xmlh,string=1) 
    193             return x.xmls 
     195            return xmlh 
    194196        else: 
    195197            return status 
Note: See TracChangeset for help on using the changeset viewer.