Changeset 8523
- Timestamp:
- 17/08/12 09:20:13 (8 years ago)
- Location:
- mauRepo/HPFos/trunk
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
mauRepo/HPFos/trunk/hpfos/HPFos/osImpl/myimpl.py
r8515 r8523 52 52 from ceda_markup.opensearch.os_param import OSParam 53 53 from hpfos import __version__, __revision__ 54 from ceda_markup.atom.atom import ATOM_NAMESPACE 55 from hpfos.HPFos.osImpl.commons import get_document, get_xml_document,\ 56 return_not_none_text 57 from xml.etree.ElementTree import _ElementInterface, ElementTree 58 from ceda_markup.opensearch.os_request import OpenSearchDescription, OS_NAMESPACE 54 59 55 60 GUID = 'guid' … … 59 64 BBOX = 'bbox' 60 65 DUMMY_GUID = 'dummy_guid' 66 67 FATCAT_HOST = 'citest1.jc.rl.ac.uk' 68 FATCAT_ROOT_PATH = 'fatcatOS' 61 69 62 70 CEDA_TITLE = 'ceda_title' … … 95 103 96 104 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 97 112 98 113 def digest_search_results(self, results, context): … … 108 123 #to be done 109 124 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) 111 131 else: 112 132 filtered = filter_results(results, count, start_index, start_page) … … 118 138 subresults = [] 119 139 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) 129 146 subresults.append(item) 130 147 … … 137 154 138 155 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 139 163 entries = [] 140 164 … … 249 273 return context['moles3EPB'].searchSelectiveLoadByInstance(obj, 'member') #need to add bbox & phenomTime 250 274 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 285 def 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 66 66 response = ar.generate_response(result, queries, '', context) 67 67 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") 68 69 self.assertTrue('<link href="/search/atom/?startIndex=1" rel="first" type="application/atom+xml"/>' in response, "Error") 69 70 self.assertTrue('<link href="/search/atom/?startIndex=10" rel="next" type="application/atom+xml"/>' in response, "Error") … … 73 74 response = ar.generate_response(result, queries, '', context) 74 75 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") 75 77 self.assertTrue('<link href="/search/atom/?startIndex=1" rel="first" type="application/atom+xml"/>' in response, "Error") 76 78 self.assertTrue('<link href="/search/atom/?startIndex=15" rel="next" type="application/atom+xml"/>' in response, "Error") … … 80 82 response = ar.generate_response(result, queries, '', context) 81 83 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") 82 85 self.assertTrue('<link href="/search/atom/?startIndex=1" rel="first" type="application/atom+xml"/>' in response, "Error") 83 86 self.assertTrue('<link href="/search/atom/?startIndex=4" rel="next" type="application/atom+xml"/>' in response, "Error") … … 87 90 response = ar.generate_response(result, queries, '', context) 88 91 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") 89 93 self.assertTrue('<link href="/search/atom/?startIndex=1" rel="first" type="application/atom+xml"/>' in response, "Error") 90 94 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 41 41 42 42 def get_host(self): 43 return self.environ['SERVER_NAME']43 return getattr(self, 'environ')['SERVER_NAME'] 44 44 45 45 def is_secure(self): 46 return self.host46 return getattr(self, 'host') -
mauRepo/HPFos/trunk/resources/requirements.txt
r8505 r8523 7 7 # --extra-index-url http://ciprod1.cems.rl.ac.uk/pip 8 8 # to your pip install 9 ceda-markup==0.0. 79 ceda-markup==0.0.8 10 10 ceda-moles-model==0.1.5 11 11
Note: See TracChangeset
for help on using the changeset viewer.