Changeset 4983


Ignore:
Timestamp:
16/02/09 17:11:08 (11 years ago)
Author:
cbyrom
Message:

Add a new feed for collecting corrections info submitted by users of
the atom editor + create new method on client to do this + add new
tests and tidy up some code.

Location:
ndgCommon/trunk
Files:
6 edited

Legend:

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

    r4919 r4983  
    111111        providerID = atom.ME.providerID 
    112112         
    113         # remove the trailing forward slash - otherwise the xquery won't work 
    114         if targetCollection.endswith('/'): 
    115             targetCollection = targetCollection[0:-1] 
     113        # add a trailing forward slash - otherwise the xquery won't work 
     114        if not targetCollection.endswith('/'): 
     115            targetCollection = targetCollection + '/' 
    116116             
    117117        # NB, using the query() method (via the useChunked keyword) here results 
  • ndgCommon/trunk/ndg/common/src/clients/xmldb/eXist/dbconstants.py

    r4926 r4983  
    3535# collection for storing misc files - e.g. the org data snippets 
    3636RESOURCES_COLLECTION_PATH = ATOM_COLLECTION_PATH + "resources" 
     37CORRECTIONS_COLLECTION_PATH = ATOM_COLLECTION_PATH + "corrections" 
    3738EXIST_CONFIG_PATH = "/db/system/config/" 
    3839 
  • ndgCommon/trunk/ndg/common/src/clients/xmldb/eXist/feedclient.py

    r4976 r4983  
    2020        Exception.__init__(self, msg) 
    2121 
    22 class FeedClient: 
     22class FeedClient(object): 
    2323     
    2424    TOPLEVEL_ATOM_FEED_TITLE = 'Moles Atom Data' 
     
    2929    PROVIDERLEVEL_ATOM_FEED_TITLE = TOPLEVEL_ATOM_FEED_TITLE + PROVIDER_SUFFIX 
    3030    PROVIDERLEVEL_DIF_FEED_TITLE = TOPLEVEL_DIF_FEED_TITLE + PROVIDER_SUFFIX 
     31    CORRECTIONS_FEED_TITLE = 'Corrections data submitted by atom editor users' 
    3132    DIF_ENTRY_TITLE = 'DIF Record' 
    3233     
     
    111112        self.createAtomFeed(dc.DIF_COLLECTION_PATH, 
    112113                            self.TOPLEVEL_DIF_FEED_TITLE) 
     114 
     115        self.createAtomFeed(dc.CORRECTIONS_COLLECTION_PATH, 
     116                            self.CORRECTIONS_FEED_TITLE) 
    113117 
    114118 
     
    191195        self.__postEditAtomFeed(collection, entryXML) 
    192196        logging.info("Successfully added new feed entry") 
    193  
    194  
    195     def getRESTfulData(self, docPath, suppressPrefix = False): 
    196         ''' 
    197         Retrieve data using the REST interface 
    198         @param docPath: path to the data to retrieve - NB, this should equal 
    199         the DB path to the document in question 
    200         @keyword suppressPrefix: if True, the base, REST url, is not added to  
    201         the specified docPath  
    202         @return document, if found, None, otherwise 
    203         ''' 
    204         logging.info("Retrieving document at, %s, using RESTful interface" %docPath) 
    205         connection = httplib.HTTPConnection(self.hostAndPort) 
    206         url = docPath 
    207         if not suppressPrefix: 
    208             url = self.REST_BASE_URL + docPath 
    209  
    210         connection.request("GET", '%s' %(url)) 
    211         response = connection.getresponse() 
    212          
    213         if response.status == 200: 
    214             logging.info("Document successfully retrieved - returning this now") 
    215             return response.read() 
    216          
    217         logging.info("- no document found at path, '%s'" %docPath) 
    218         return None 
    219          
     197         
     198 
     199    def createCorrectionsFeedEntry(self, title, summary): 
     200        ''' 
     201        Add an entry to the corrections collection (which should already have a 
     202        feed set up on it) - with details of the corrections data submitted by 
     203        users of the atom editor 
     204        @param title: title to give the feed entry 
     205        @param body: content to add to the summary element 
     206        ''' 
     207        entryXML = '<?xml version="1.0" ?>\ 
     208<entry xmlns="http://www.w3.org/2005/Atom">\ 
     209<title>%s</title>\ 
     210<content>%s</content>\ 
     211</entry>' %(title, summary) 
     212        logging.info("Adding corrections data to atom feed") 
     213        self.__postEditAtomFeed(dc.CORRECTIONS_COLLECTION_PATH, entryXML) 
     214        logging.info("Successfully added new feed entry") 
  • ndgCommon/trunk/ndg/common/src/models/Atom.py

    r4970 r4983  
    699699        logging.debug("Adding content data") 
    700700        self.content = [] 
     701        if not content: 
     702            return 
     703         
    701704        for content_line in content.split('\n'): 
    702705            self.content.append(content_line) 
     
    762765            else: 
    763766                logging.debug("No file data - adding contents of element instead") 
    764                 div = contentTag.findtext('{%s}div'%ndgObject.ATOM_NS) 
     767                div = contentTag.findtext('{%s}div'%ndgObject.XHTML_NS) 
    765768                self.Content = div 
    766769         
  • ndgCommon/trunk/ndg/common/unittests/clients/xmldb/eXist/testfeedclient.py

    r4978 r4983  
    4444            self.fail("Should not have thrown an exception") 
    4545 
     46    def testCreateCorrectionsFeedEntry(self): 
     47        try: 
     48            self.feedClient.createCorrectionsFeedEntry('some title info', 
     49                                                       'some body info') 
     50        except: 
     51            self.fail("Should not have thrown an exception") 
     52 
     53 
     54 
    4655    def testInvalidCollectionCreateAtomFeed(self): 
    4756        try: 
     
    5362        except Exception, e: 
    5463            self.fail("Should have thrown a FeedClientError exception") 
    55          
    56     def testValidGetRESTfulData(self): 
    57         atom = self.utils.createAtomInEXist(tc.xmlString) 
    58         self.createdAtoms.append(atom.getFullPath()) 
    59         doc = self.feedClient.getRESTfulData(atom.getFullPath()) 
    60         self.assertNotEquals(None, doc) 
    61          
    62     def testInvalidGetRESTfulData(self): 
    63         self.assertEquals(None, self.feedClient.getRESTfulData(self.VALID_FILE_PATH)) 
    6464 
    6565    def testGetAtomFeed(self): 
  • ndgCommon/trunk/setup.py

    r4978 r4983  
    66    packages=find_packages(), 
    77        test_suite='nose.collector', 
    8     install_requires=["ZSI", "feedparser", "httplib2"], # for Discovery Service Client 
     8    install_requires=["ZSI", "feedparser", "httplib2"], # ZSI for Discovery Service Client 
    99    package_data={'ndg': ['common/xmldb/indexing/*/*.xconf',  
    1010                                                  'common/xmldb/resources/*', 
Note: See TracChangeset for help on using the changeset viewer.