Ignore:
Timestamp:
22/12/08 09:53:07 (11 years ago)
Author:
cbyrom
Message:

Adjust Atom and MolesEntity? data models to properly use namespaces when
dealing with xpath queries - rather than having these stripped out. This
avoids problems when namespaces are given arbitrary names and is a more
exact, hence robust, approach.
Create new test class to put the xmlhandler2 tests separately in.
Add delete function to granulite - to allow data granules, and their
connections to data entities, to be removed + add 'roll back' functionality
to cope with scenarios when granulite replace/delete fails to complete
properly. Add new methods to the existdbclient to allow the restore/delete/backup
functionality.
Extend test suite to exercise new functionality.

File:
1 edited

Legend:

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

    r4679 r4696  
    1414        from ndgUtils.elementtree import cElementTree as ET 
    1515import sys, logging, re, datetime 
     16from ndgUtils import ndgObject 
    1617from ndgUtils.eXistConnector import eXistConnector 
    1718from ndgUtils.ETxmlView import et2text 
     
    7071         
    7172    def fromETElement(self, personTag): 
    72         self.name = personTag.findtext('name') or "" 
    73         self.role = personTag.findtext('role') or "" 
    74         self.uri = personTag.findtext(self.uriTagName) or "" 
     73        self.name = personTag.findtext('{%s}name' %ndgObject.ATOM_NS) or "" 
     74        self.role = personTag.findtext('{%s}role' %ndgObject.ATOM_NS) or "" 
     75        self.uri = personTag.findtext('{%s}%s' %(ndgObject.ATOM_NS, self.uriTagName)) or "" 
    7576        logging.debug("Added name: '%s', role: '%s', %s: '%s'" \ 
    7677                      %(self.name, self.role, self.uriTagName, self.uri)) 
     
    561562        logging.info("Creating formatted XML version of Atom") 
    562563        root = ET.Element("entry") 
    563         root.attrib["xmlns"] = "http://www.w3.org/2005/Atom" 
    564         root.attrib["xmlns:moles"] = "http://ndg.nerc.ac.uk/schema/moles2beta" 
    565         root.attrib["xmlns:georss"] = "http://www.georss.org/georss/10" 
    566         root.attrib["xmlns:gml"] = "http://www.opengis.net/gml" 
     564        root.attrib["xmlns"] = ndgObject.ATOM_NS 
     565        root.attrib["xmlns:moles"] = ndgObject.MOLES_NS 
     566        root.attrib["xmlns:georss"] = ndgObject.GEOSS_NS 
     567        root.attrib["xmlns:gml"] = ndgObject.GML_NS 
    567568        id = ET.SubElement(root, "id") 
    568569        id.text = self.atomID 
     
    598599            content.attrib["type"] = "xhtml" 
    599600            div = ET.SubElement(content, 'div') 
    600             div.attrib["xmlns"] = "http://www.w3.org/1999/xhtml" 
     601            div.attrib["xmlns"] = ndgObject.XHTML_NS 
    601602            div.text = self.Content 
    602603         
     
    678679        ''' 
    679680        logging.info("Ingesting data from XML string") 
    680          
    681         # firstly, remove any namespaces used - to avoid problems with elementtree 
    682         logging.debug("Stripping moles namespace from string to allow easy handling with elementtree") 
    683         xmlString = xmlString.replace('moles:', '') 
    684         xmlString = xmlString.replace('georss:', '') 
    685         xmlString = xmlString.replace('gml:', '') 
    686         xmlString = xmlString.replace('xmlns="http://www.w3.org/2005/Atom"', '') 
    687         xmlString = xmlString.replace('default:', '') 
    688         xmlString = xmlString.replace('xs:', '') 
    689  
    690         # now create elementtree with the XML string 
    691681        logging.debug("Create elementtree instance with XML string") 
    692682        tree = ET.fromstring(xmlString) 
    693          
    694         title = tree.findtext('title') 
     683        title = tree.findtext('{%s}title' %ndgObject.ATOM_NS) 
    695684        if title: 
    696685            logging.debug("Adding title data") 
    697686            self.title = title 
    698687 
    699         summary = tree.findtext('summary') 
     688        summary = tree.findtext('{%s}summary' %ndgObject.ATOM_NS) 
    700689        if summary: 
    701690            self.Summary = summary#.decode('unicode_escape') 
    702691 
    703         authorElement = tree.find('author') 
     692        authorElement = tree.find('{%s}author' %ndgObject.ATOM_NS) 
    704693        if authorElement: 
    705694            logging.debug("Adding author data") 
     
    708697            self.author = author 
    709698 
    710         contributorElements = tree.findall('contributor') 
     699        contributorElements = tree.findall('{%s}contributor' %ndgObject.ATOM_NS) 
    711700        for contributorElement in contributorElements: 
    712701            logging.debug("Adding contributor data") 
     
    715704            self.contributors.append(contributor) 
    716705 
    717         molesElement = tree.find('entity') 
     706        molesElement = tree.find('{%s}entity' %ndgObject.MOLES_NS) 
    718707        if molesElement: 
    719708            self.ME.fromET(molesElement) 
    720709                 
    721         self.atomID = tree.findtext('id') 
    722  
    723         self._parseCategoryData(tree.findall('category')) 
    724  
    725         self._parseLinksData(tree.findall('link')) 
    726              
    727         contentTag = tree.find('content') 
     710        self.atomID = tree.findtext('{%s}id' %ndgObject.ATOM_NS) 
     711 
     712        self._parseCategoryData(tree.findall('{%s}category' %ndgObject.ATOM_NS)) 
     713 
     714        self._parseLinksData(tree.findall('{%s}link' %ndgObject.ATOM_NS)) 
     715             
     716        contentTag = tree.find('{%s}content' %ndgObject.ATOM_NS) 
    728717        if contentTag != None: 
    729718            logging.debug("Found content tag - checking for CSML/CDML file data") 
     
    743732                self.Content = div.text 
    744733         
    745         range = tree.findtext('temporalRange') 
     734        range = tree.findtext('{%s}temporalRange' %ndgObject.MOLES_NS) 
    746735        if range: 
    747736            logging.debug("Adding temporal range data") 
     
    751740                self.t2 = timeData[1] 
    752741         
    753         # NB, this parser won't mind if we're dealing with Envelope or EnvelopeWithTimePeriod 
    754         minBBox = tree.findall('.//lowerCorner') 
    755         if minBBox: 
    756             logging.debug("Adding min spatial range data") 
    757             minBBox = minBBox[0] 
    758             spatialData = minBBox.text.split() 
    759             self.minX = spatialData[0] 
    760             if len(spatialData) > 1: 
    761                 self.minY = spatialData[1] 
    762          
    763         maxBBox = tree.findall('.//upperCorner') 
    764         if maxBBox: 
    765             maxBBox = maxBBox[0] 
    766             logging.debug("Adding max spatial range data") 
    767             spatialData = maxBBox.text.split() 
    768             self.maxX = spatialData[0] 
    769             if len(spatialData) > 1: 
    770                 self.maxY = spatialData[1] 
     742        where = tree.find('{%s}where' %ndgObject.GEOSS_NS) 
     743        if where: 
     744            # NB, this parser won't mind if we're dealing with Envelope or EnvelopeWithTimePeriod 
     745            minBBox = where.findall('.//{%s}lowerCorner' %ndgObject.GML_NS) 
     746            if minBBox: 
     747                logging.debug("Adding min spatial range data") 
     748                minBBox = minBBox[0] 
     749                spatialData = minBBox.text.split() 
     750                self.minX = spatialData[0] 
     751                if len(spatialData) > 1: 
     752                    self.minY = spatialData[1] 
     753             
     754            maxBBox = where.findall('.//{%s}upperCorner' %ndgObject.GML_NS) 
     755            if maxBBox: 
     756                maxBBox = maxBBox[0] 
     757                logging.debug("Adding max spatial range data") 
     758                spatialData = maxBBox.text.split() 
     759                self.maxX = spatialData[0] 
     760                if len(spatialData) > 1: 
     761                    self.maxY = spatialData[1] 
    771762                 
    772763        publishedDate = tree.findtext('published') 
     
    12461237        logging.info("Retrieving info from %s references" %type) 
    12471238        if type == VTD.DEPLOYMENT_TERM: 
     1239            logging.info("Extracting links data to deployment entitites") 
    12481240            self.deployments = [] 
    12491241            for link in links: 
     
    12641256            # for DE data, just store the title + link in a Link object 
    12651257            self.dataEntities = [] 
     1258            logging.info("Extracting links data to data entitites") 
    12661259            for data in links: 
    12671260                atom = Atom(xmlString=str(data)) 
     
    12691262                link.title = atom.title 
    12701263                link.href = atom.atomBrowseURL 
     1264                link.rel = atom.datasetID 
    12711265                 
    12721266                # NB, different deployments may be used by the same DE - so  
Note: See TracChangeset for help on using the changeset viewer.