Commit 091ea022 authored by BODERE's avatar BODERE
Browse files

fix: engine

parent 5ab55ffa
......@@ -4,7 +4,7 @@
from typing import Dict, List, Optional, Tuple
from urllib.parse import parse_qs, quote, urlencode, urlsplit, urlunsplit
from xml.etree.ElementTree import Element
from xml.etree import ElementTree as Element
import httpx
from starlette.responses import Response
......@@ -42,12 +42,12 @@ class OpensearchEngine:
opensearch_response.header, opensearch_response.entries = self._process_response(raw_response)
except httpx.ReadTimeout:
opensearch_response.errors = ["Timeout occurred"]
# except Exception as e:
# print(str(e.with_traceback()))
# opensearch_response.errors = str(e).split('\n')
except Exception as e:
print(str(e))
opensearch_response.errors = str(e).split('\n')
finally:
if opensearch_response.header is None and not opensearch_response.errors:
opensearch_response.errors.append("Not a valid response")
# if opensearch_response.header is None and not opensearch_response.errors:
# opensearch_response.errors.append("Not a valid response")
return opensearch_response
def _build_search_url(self, params: OpensearchQueryParameters) -> str:
......@@ -150,12 +150,16 @@ class JPLOpensearchEngine(OpensearchAtomEngine):
"""JPL opensearch engine"""
def _prepare_query_parameters(self, params: OpensearchQueryParameters) -> Dict:
params_as_dict = super()._prepare_query_parameters(params)
# to use bbox format
params_as_dict["spatial_type"] = "bbox"
# cursor start to 1, instead of 0
params_as_dict["cursor"] = params.startPage + 1
return params_as_dict
return {
"parentIdentifier": params.datasetId,
"startTime": params.timeStart.strftime("%Y-%m-%dT%H:%M:%SZ"),
"endTime": params.timeEnd.strftime("%Y-%m-%dT%H:%M:%SZ"),
"spatial_type": "bbox",
"boundingBox": params.geoBox,
"numberOfResults": params.count,
"cursor": params.startPage + 1,
"commit": "Search"
}
def _parse_entry_metadata(self, entry_elt: Element) -> OpensearchResponseEntry:
entry = super()._parse_entry_metadata(entry_elt)
......
......@@ -9,9 +9,9 @@
xmlns:gml="http://www.opengis.net/gml"
xmlns:cwic="http://cwic.wgiss.ceos.org/opensearch/extensions/1.0/">
<title>{{response.header.title}}</title>
<id>{{response.header.id}}</id>
<opensearch:totalResults>{{response.header.total_results}}</opensearch:totalResults>
<title>{{response.header.title}}</title>
<id>{{response.header.id}}</id>
<opensearch:totalResults>{{response.header.total_results}}</opensearch:totalResults>
<opensearch:startIndex>{{response.header.start_index}}</opensearch:startIndex>
<opensearch:itemsPerPage>{{response.header.items_per_page}}</opensearch:itemsPerPage>
<opensearch:Query role="request"
......@@ -21,7 +21,7 @@
geo:box="{{response.query.geoBox}}"
time:start="{{response.query.timeStart}}"
time:end="{{response.query.timeEnd}}" />
{% for entry in response.entries -%}
{% for entry in response.entries -%}
<entry>
<title>{{entry.title}}</title>
<id>{{entry.id}}</id>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment