Changeset 8523


Ignore:
Timestamp:
17/08/12 09:20:13 (7 years ago)
Author:
mnagni
Message:

Requests, parse and display a fatcat atom feed

Location:
mauRepo/HPFos/trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/HPFos/trunk/hpfos/HPFos/osImpl/myimpl.py

    r8515 r8523  
    5252from ceda_markup.opensearch.os_param import OSParam 
    5353from hpfos import __version__, __revision__ 
     54from ceda_markup.atom.atom import ATOM_NAMESPACE 
     55from hpfos.HPFos.osImpl.commons import get_document, get_xml_document,\ 
     56    return_not_none_text 
     57from xml.etree.ElementTree import _ElementInterface, ElementTree 
     58from ceda_markup.opensearch.os_request import OpenSearchDescription, OS_NAMESPACE 
    5459 
    5560GUID = 'guid' 
     
    5964BBOX = 'bbox' 
    6065DUMMY_GUID = 'dummy_guid' 
     66 
     67FATCAT_HOST = 'citest1.jc.rl.ac.uk' 
     68FATCAT_ROOT_PATH = 'fatcatOS' 
    6169 
    6270CEDA_TITLE = 'ceda_title' 
     
    95103         
    96104        return 1 
     105     
     106    def _digest_fatcat_atom(self, context, results): 
     107        count, start_index, start_page = self._importCountAndPage(context) 
     108        subresults = results.findall('{%s}entry' % (ATOM_NAMESPACE)) 
     109        tot_results = int(results.find('{%s}totalResults' % (OS_NAMESPACE)).text.replace('\n','').strip()) 
     110        return Result(count, start_index, start_page, tot_results, subresult = subresults, title=HPFOS_TITLE)         
     111         
    97112 
    98113    def digest_search_results(self, results, context):  
     
    108123            #to be done 
    109124            filtered = filter_results(results.result, count, start_index, start_page) 
    110             tot_results = self._get_tot_results(results.result)         
     125            tot_results = self._get_tot_results(results.result) 
     126        elif type(results) == CEDA_Result: 
     127            filtered = filter_results(results.result, count, start_index, start_page) 
     128            tot_results = 1   
     129        elif isinstance(results, _ElementInterface): 
     130            return self._digest_fatcat_atom(context, results)                                  
    111131        else: 
    112132            filtered = filter_results(results, count, start_index, start_page) 
     
    118138        subresults = [] 
    119139        for result in filtered: 
    120             item = None 
    121             if type(result) != CEDA_Result:             
    122                 result_guid = context['moles3EPB'].retrieveGUIDFromInstance(result) 
    123                 if result_guid is None: 
    124                     continue 
    125                 ititle = self._extractTitle(result) 
    126                 item = Subresult(result_guid.id, ititle, datetime.now().isoformat(), description = result.description) 
    127             else:     
    128                 item = Subresult(DUMMY_GUID, 'dummy_resultTitle', datetime.now().isoformat(), description = 'dummy_resultDescription') 
     140            item = None           
     141            result_guid = context['moles3EPB'].retrieveGUIDFromInstance(result) 
     142            if result_guid is None: 
     143                continue 
     144            ititle = self._extractTitle(result) 
     145            item = Subresult(result_guid.id, ititle, datetime.now().isoformat(), description = result.description)                
    129146            subresults.append(item) 
    130147         
     
    137154 
    138155    def generate_entries(self, atomroot, subresults, path): 
     156        if isinstance(subresults, list) \ 
     157                and len(subresults) > 0 \ 
     158                and isinstance(subresults[0], _ElementInterface): 
     159            for entry in subresults: 
     160                atomroot.append(entry) 
     161            return 
     162         
    139163        entries = [] 
    140164         
     
    249273            return context['moles3EPB'].searchSelectiveLoadByInstance(obj, 'member') #need to add bbox & phenomTime 
    250274        elif type(obj) == CEDA_Observation: 
    251             return context['moles3EPB'].searchSelectiveLoadByInstance(obj, 'result') #need to add bbox & phenomTime 
     275            #return context['moles3EPB'].searchSelectiveLoadByInstance(obj, 'result') #need to add bbox & phenomTime 
     276            for source in obj.result.source: 
     277                if source.function == 'search': 
     278                    return self._extractFatcatEntities(source.description) 
     279 
     280         
     281    def _extractFatcatEntities(self, fc_resource_id): 
     282        path = '/%s/search/%s/atom/' % (FATCAT_ROOT_PATH, str(fc_resource_id)) 
     283        return find_fatcat_atom_entity(host = FATCAT_HOST, path = path) 
     284     
     285def find_fatcat_atom_entity(host = 'localhost', path = '', port = 80):     
     286    source = get_document(host, path, port) 
     287    return get_xml_document(source) 
  • mauRepo/HPFos/trunk/hpfos/tests/testos.py

    r8505 r8523  
    6666        response = ar.generate_response(result, queries, '', context) 
    6767        self.assertTrue('<link href="/search/atom/?startIndex=3" rel="self" type="application/atom+xml"/>' in response, "Error") 
     68        self.assertTrue('<link href="/search/atom/?startIndex=1" rel="prev" type="application/atom+xml"/>' in response, "Error")         
    6869        self.assertTrue('<link href="/search/atom/?startIndex=1" rel="first" type="application/atom+xml"/>' in response, "Error") 
    6970        self.assertTrue('<link href="/search/atom/?startIndex=10" rel="next" type="application/atom+xml"/>' in response, "Error") 
     
    7374        response = ar.generate_response(result, queries, '', context) 
    7475        self.assertTrue('<link href="/search/atom/?startIndex=5" rel="self" type="application/atom+xml"/>' in response, "Error") 
     76        self.assertTrue('<link href="/search/atom/?startIndex=1" rel="prev" type="application/atom+xml"/>' in response, "Error")         
    7577        self.assertTrue('<link href="/search/atom/?startIndex=1" rel="first" type="application/atom+xml"/>' in response, "Error") 
    7678        self.assertTrue('<link href="/search/atom/?startIndex=15" rel="next" type="application/atom+xml"/>' in response, "Error") 
     
    8082        response = ar.generate_response(result, queries, '', context) 
    8183        self.assertTrue('<link href="/search/atom/?startIndex=2" rel="self" type="application/atom+xml"/>' in response, "Error") 
     84        self.assertTrue('<link href="/search/atom/?startIndex=1" rel="prev" type="application/atom+xml"/>' in response, "Error")         
    8285        self.assertTrue('<link href="/search/atom/?startIndex=1" rel="first" type="application/atom+xml"/>' in response, "Error") 
    8386        self.assertTrue('<link href="/search/atom/?startIndex=4" rel="next" type="application/atom+xml"/>' in response, "Error") 
     
    8790        response = ar.generate_response(result, queries, '', context) 
    8891        self.assertTrue('<link href="/search/atom/?startIndex=18" rel="self" type="application/atom+xml"/>' in response, "Error") 
     92        self.assertTrue('<link href="/search/atom/?startIndex=17" rel="prev" type="application/atom+xml"/>' in response, "Error")         
    8993        self.assertTrue('<link href="/search/atom/?startIndex=1" rel="first" type="application/atom+xml"/>' in response, "Error") 
    9094        self.assertTrue('<link href="/search/atom/?startIndex=19" rel="next" type="application/atom+xml"/>' in response, "Error") 
  • mauRepo/HPFos/trunk/hpfos/tests/testsetup.py

    r8505 r8523  
    4141 
    4242    def get_host(self): 
    43         return self.environ['SERVER_NAME'] 
     43        return getattr(self, 'environ')['SERVER_NAME'] 
    4444 
    4545    def is_secure(self): 
    46         return self.host 
     46        return getattr(self, 'host') 
  • mauRepo/HPFos/trunk/resources/requirements.txt

    r8505 r8523  
    77# --extra-index-url http://ciprod1.cems.rl.ac.uk/pip 
    88# to your pip install  
    9 ceda-markup==0.0.7 
     9ceda-markup==0.0.8 
    1010ceda-moles-model==0.1.5 
    1111 
Note: See TracChangeset for help on using the changeset viewer.