Changeset 5098


Ignore:
Timestamp:
11/03/09 17:43:14 (10 years ago)
Author:
cbyrom
Message:

Add a new feed to represent all Published data - and ensure all atoms
with this state get added + extend the getFeed method to return
the feed as both a feedparser and the original xml object

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/common/src/clients/xmldb/eXist/feedclient.py

    r5018 r5098  
    1111import ndg.common.src.lib.utilities as utils 
    1212import ndg.common.src.clients.xmldb.eXist.dbconstants as dc 
     13from ndg.common.src.models import AtomState 
    1314 
    1415 
     
    2526    TOPLEVEL_ATOM_FEED_TITLE = 'Moles Atom Data' 
    2627    TOPLEVEL_DIF_FEED_TITLE = 'DIF Data' 
     28    TOPLEVEL_PUBLISHED_FEED_TITLE = 'All Published Data' 
    2729    ENTITYLEVEL_ATOM_FEED_TITLE = 'Moles %s Atom Data' 
    2830    DEPLOYMENTS_ATOM_FEED_TITLE = 'Deployments Data (activities/observation stations/data production tools)' 
     
    112114                                self.ENTITYLEVEL_ATOM_FEED_TITLE %VTD.TERM_DATA[VTD.GRANULE_TERM].title) 
    113115 
     116        self.createAtomFeed(dc.ATOM_COLLECTION_PATH + dc.PUBLISHED_COLLECTION_PATH, 
     117                            self.TOPLEVEL_PUBLISHED_FEED_TITLE) 
     118 
    114119        self.createAtomFeed(dc.DIF_COLLECTION_PATH, 
    115120                            self.TOPLEVEL_DIF_FEED_TITLE) 
     
    130135        # add to top level feed 
    131136        self.createAtomFeedEntry(dc.ATOM_COLLECTION_PATH, atom) 
     137 
    132138        # add to entity level feed 
    133139        self.createAtomFeedEntry(atom.getDefaultEntityCollectionPath(), atom) 
    134140         
     141        # add to Published top level feed, if apprpriate 
     142        if atom.state == AtomState.PUBLISHED_STATE: 
     143            self.createAtomFeedEntry(dc.ATOM_COLLECTION_PATH +  
     144                                     dc.PUBLISHED_COLLECTION_PATH, atom) 
     145 
    135146        # add to provider level feed 
    136147        self.createAtomFeedEntry(dc.PROVIDER_FEED_PATH + atom.ME.providerID + '/', atom) 
     
    160171        - in a feed parser object 
    161172        @param collection: eXist collection to retrieve the feed from 
    162         @return feed: feed in a feedparser object 
    163173        @keyword proxyServer: proxy server to use, if required  
     174        @return feed, xml: feed in a feedparser object and xml original data 
    164175        ''' 
    165176        logging.info("Retrieving content of atom feed for collection, '%s'" %collection) 
    166177         
     178        uri = 'http://%s/exist/atom/content/%s' %(self.hostAndPort, collection) 
     179 
    167180        proxy = {} 
    168         # NB, there is slightly unhelpful default behaviour here: if there is a 
    169         # proxy specified in the environment variables, this will be used regardless 
    170         # of whether it is specified here - to temporarily remove this if no proxy 
    171         # is specified 
    172         oldProxy = None 
    173181        if proxyServer: 
    174             proxy = urllib2.ProxyHandler( {"http": proxyServer} ) 
    175         elif os.environ.has_key(utils.PROXY_KEY): 
    176             oldProxy = os.environ[utils.PROXY_KEY] 
    177             del os.environ[utils.PROXY_KEY] 
    178              
    179         feed = feedparser.parse('http://%s/exist/atom/content/%s'  
    180                                 %(self.hostAndPort, collection),  
    181                                 handlers = [proxy]) 
    182  
    183         if oldProxy: 
    184             os.environ[utils.PROXY_KEY] = oldProxy 
    185              
     182            proxy = {'http':proxyServer} 
     183        xml = utils.openURLWithProxy(uri, proxy) 
     184         
     185        # NB, feedparser is not fussy when it comes to parsing XML docs - so won't  
     186        # detect if there's been an error here - so check for this in the XML 
     187        if xml.find('HTTP ERROR') > -1: 
     188            errorMessage = "Error returned when retrieving feed: '%s'" %xml 
     189            logging.error(errorMessage) 
     190            raise FeedClientError(errorMessage) 
     191 
     192        feed = feedparser.parse(xml) 
     193 
    186194        # check we've got something valid back 
    187195        if feed.bozo: 
    188196            errorMessage = "%s: '%s'" %(self.FEED_ERROR_MSG, feed.bozo_exception) 
     197            logging.error(errorMessage) 
    189198            raise FeedClientError(errorMessage) 
    190199         
    191         return feed 
     200        return feed, xml 
    192201         
    193202 
     
    222231    def createGenericFeedEntry(self, title, summary, path): 
    223232        ''' 
    224         Add an entry to the corrections collection (which should already have a 
     233        Add an entry to the specified collection (which should already have a 
    225234        feed set up on it) - with details of the corrections data submitted by 
    226235        users of the atom editor 
    227236        @param title: title to give the feed entry 
    228         @param body: content to add to the summary element 
     237        @param summary: content to add to the summary element 
     238        @param path: path to collection for the feed 
    229239        ''' 
    230240        entryXML = '<?xml version="1.0" ?>\ 
Note: See TracChangeset for help on using the changeset viewer.