Changeset 4531 for exist


Ignore:
Timestamp:
04/12/08 09:49:45 (11 years ago)
Author:
cbyrom
Message:

Fix issue with adding author lists + add data entities container to
Atom to store associated DEs + extend method to lookup both associated
DEs and deployments + extend Deployment to store the browseURL for
deployments - for use with this new functionality.

Location:
exist/trunk/python/ndgUtils/models
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgUtils/models/Atom.py

    r4512 r4531  
    256256        self.content = [] 
    257257        # NB, this deployments data duplicates other atom data - and is only used for a  
    258         # convenient way to collect the info (by lookupDeploymentsInfo()) for use in templates 
    259         self.deployments = []     
     258        # convenient way to collect the info (by lookupAssociatedData()) for use in templates 
     259        self.deployments = [] 
     260        # ditto for the following field 
     261        self.dataEntities = [] 
     262             
    260263        self.csmlFile = None 
    261264        self.cdmlFile = None 
     
    928931                setattr(self, "contributors", attributeValue[1:]) 
    929932        elif attributeName == "atomAuthors": 
    930             self.ME.responsibleParties.append(attributeValue) 
     933            if isinstance(attributeValue, list): 
     934                for val in attributeValue: 
     935                    self.ME.responsibleParties.append(val) 
     936            else: 
     937                self.ME.responsibleParties.append(attributeValue) 
    931938        else: 
    932939            setattr(self, attributeName, attributeValue) 
     
    11461153 
    11471154 
    1148     def lookupDeploymentsInfo(self, dr, lookupIndirectReferences=False): 
    1149         ''' 
    1150         Check through the atom links and retrieve any associated deployments 
    1151         data 
     1155    def lookupAssociatedData(self, type, dr, lookupIndirectReferences=False): 
     1156        ''' 
     1157        Check through the atom links and retrieve any associated data of the  
     1158        specified type 
     1159        @param type: type of associated data to lookup - currently VTD.DEPLOYMENT_TERM 
     1160        or VTD.DE_TERM 
    11521161        @param dr: Instance of DocumentRetrieve object - NB, this requires eXist 
    11531162        config details which are not available to the Atom object 
     
    11561165        deployments data featured in the atom related links are processed  
    11571166        ''' 
    1158         logging.info("Looking up deployments info") 
     1167        logging.info("Looking up %s info" %type) 
    11591168        self.deployments = [] 
    11601169        self.allActivities = [] 
     
    11621171        self.allDpts = [] 
    11631172 
     1173        if type != VTD.DE_TERM and type != VTD.DEPLOYMENT_TERM: 
     1174            raise ValueError('Unrecognised associated data type: %s' %type) 
     1175         
     1176        # avoid duplicating lookup effort 
     1177        if type == VTD.DEPLOYMENT_TERM and self.deployments: 
     1178            logging.info("- this info has already been looked up - returning") 
     1179            return 
     1180 
     1181        # firstly, collect all the references to the info required 
    11641182        if lookupIndirectReferences: 
    1165             logging.info("Looking up references to this atom from other deployments") 
    1166             doc = dr.get(self.ME.providerID, dr.ATOM_DEPLOYMENTS, self.atomBrowseURL, \ 
    1167                                         targetCollection='/db/atoms/') 
    1168             # now need to turn this results set into actual atoms 
    1169             tree = ET.fromstring(doc) 
     1183             
     1184            # if we're looking up DE data for deployments data, need to have the 
     1185            # deployments info looked up first 
     1186            if type == VTD.DE_TERM and self.isDeployable() and not self.deployments: 
     1187                self.lookupAssociatedData(VTD.DEPLOYMENT_TERM, dr, lookupIndirectReferences) 
     1188             
     1189            logging.info("Looking up references to this atom from other %s" %type) 
     1190             
     1191            urls = [self.atomBrowseURL] 
     1192             
     1193            if type == VTD.DE_TERM and self.isDeployable(): 
     1194                urls = [] 
     1195                for dep in self.deployments: 
     1196                    urls.append(dep.browseURL) 
     1197                     
    11701198            links = [] 
    1171             for atom in tree: 
    1172                 logging.debug("- found reference in deployment") 
    1173                 links.append(ET.tostring(atom)) 
    1174              
     1199            for url in urls: 
     1200                doc = dr.get(type, dr.ATOM_TYPE, url, \ 
     1201                                            targetCollection='/db/atoms/') 
     1202                # now need to turn this results set into actual atoms 
     1203                tree = ET.fromstring(doc) 
     1204                for atom in tree: 
     1205                    logging.debug("- found reference in deployment") 
     1206                    links.append(ET.tostring(atom)) 
    11751207        else: 
    11761208            links = self.getLinksOfType(self.VTD.DEPLOYMENT_TERM) 
    11771209 
    1178         for link in links: 
    1179             if lookupIndirectReferences: 
    1180                 deploymentAtom = link 
    1181             else: 
    1182                 localID = link.href.split("__ATOM__")[-1] 
    1183                 deploymentAtom = dr.get(self.ME.providerID, 'ATOM', localID, \ 
    1184                                         targetCollection='/db/atoms/') 
    1185  
    1186             deployment = Deployment.Deployment(Atom(xmlString=str(deploymentAtom))) 
    1187             self.deployments.append(deployment) 
    1188              
    1189             self.addUniqueLinks(self.allActivities, deployment.activities) 
    1190             self.addUniqueLinks(self.allObs, deployment.obs) 
    1191             self.addUniqueLinks(self.allDpts, deployment.dpts) 
    1192          
    1193         logging.info("Finished looking up deployments info") 
     1210        # now retrieve the refererences and extract the required data 
     1211        if type == VTD.DEPLOYMENT_TERM: 
     1212            for link in links: 
     1213                if lookupIndirectReferences: 
     1214                    deploymentAtom = link 
     1215                else: 
     1216                    localID = link.href.split("__ATOM__")[-1] 
     1217                    deploymentAtom = dr.get(self.ME.providerID, 'ATOM', localID, \ 
     1218                                            targetCollection='/db/atoms/') 
     1219     
     1220                deployment = Deployment.Deployment(Atom(xmlString=str(deploymentAtom))) 
     1221                self.deployments.append(deployment) 
     1222                 
     1223                self.addUniqueLinks(self.allActivities, deployment.activities) 
     1224                self.addUniqueLinks(self.allObs, deployment.obs) 
     1225                self.addUniqueLinks(self.allDpts, deployment.dpts) 
     1226        else: 
     1227            # for DE data, just store the title + link in a Link object 
     1228            deLinks = [] 
     1229            for data in links: 
     1230                atom = Atom(xmlString=str(data)) 
     1231                link = Link() 
     1232                link.title = atom.title 
     1233                link.href = atom.atomBrowseURL 
     1234                deLinks.append(link) 
     1235             
     1236            self.dataEntities = deLinks 
     1237         
     1238        logging.info("Finished looking up %s info" %type) 
    11941239 
    11951240 
  • exist/trunk/python/ndgUtils/models/Deployment.py

    r4440 r4531  
    2222        self.obs = [] 
    2323        self.dpts = [] 
     24        self.browseURL = None 
    2425         
    2526        # add the deployment info appropriately 
     
    4748        elif deploymentLink.rel.startswith(VTD.TERM_DATA[VTD.DPT_TERM].vocabURL): 
    4849            deploymentType = self.dpts 
     50        elif deploymentLink.rel == "self": 
     51            logging.debug("Found self referencing link - extract href") 
     52            self.browseURL = deploymentLink.href 
     53            return 
    4954        else: 
    5055            logging.debug("Not a valid deployment type (%s) - ignoring" \ 
Note: See TracChangeset for help on using the changeset viewer.