Merge pull request #1431 from geopython/edr-collections

provide EDR metadata and links also for collections endpoint
This commit is contained in:
Jo
2023-12-18 09:20:53 +00:00
committed by GitHub
2 changed files with 33 additions and 37 deletions
+28 -32
View File
@@ -1182,41 +1182,37 @@ class API:
try:
edr = get_provider_by_type(v['providers'], 'edr')
p = load_plugin('provider', edr)
except ProviderConnectionError:
msg = 'connection error (check logs)'
return self.get_exception(
HTTPStatus.INTERNAL_SERVER_ERROR, headers,
request.format, 'NoApplicableCode', msg)
except ProviderTypeError:
edr = None
if edr and dataset is not None:
if edr:
# TODO: translate
LOGGER.debug('Adding EDR links')
try:
p = load_plugin('provider', get_provider_by_type(
self.config['resources'][dataset]['providers'], 'edr'))
parameters = p.get_fields()
if parameters:
collection['parameter-names'] = {}
for f in parameters['field']:
collection['parameter-names'][f['id']] = f
parameters = p.get_fields()
if parameters:
collection['parameter_names'] = {}
for f in parameters['field']:
collection['parameter_names'][f['id']] = f
for qt in p.get_query_types():
collection['links'].append({
'type': 'application/json',
'rel': 'data',
'title': f'{qt} query for this collection as JSON',
'href': f'{self.get_collections_url()}/{k}/{qt}?f={F_JSON}' # noqa
})
collection['links'].append({
'type': FORMAT_TYPES[F_HTML],
'rel': 'data',
'title': f'{qt} query for this collection as HTML',
'href': f'{self.get_collections_url()}/{k}/{qt}?f={F_HTML}' # noqa
})
except ProviderConnectionError:
msg = 'connection error (check logs)'
return self.get_exception(
HTTPStatus.INTERNAL_SERVER_ERROR, headers,
request.format, 'NoApplicableCode', msg)
except ProviderTypeError:
pass
for qt in p.get_query_types():
collection['links'].append({
'type': 'application/json',
'rel': 'data',
'title': f'{qt} query for this collection as JSON',
'href': f'{self.get_collections_url()}/{k}/{qt}?f={F_JSON}' # noqa
})
collection['links'].append({
'type': FORMAT_TYPES[F_HTML],
'rel': 'data',
'title': f'{qt} query for this collection as HTML',
'href': f'{self.get_collections_url()}/{k}/{qt}?f={F_HTML}' # noqa
})
if dataset is not None and k == dataset:
fcm = collection
@@ -3768,8 +3764,8 @@ class API:
HTTPStatus.BAD_REQUEST, headers, request.format,
'InvalidParameterValue', msg)
LOGGER.debug('Processing parameter-name parameter')
parameternames = request.params.get('parameter-name') or []
LOGGER.debug('Processing parameter_names parameter')
parameternames = request.params.get('parameter_names') or []
if isinstance(parameternames, str):
parameternames = parameternames.split(',')
@@ -3845,7 +3841,7 @@ class API:
if parameternames and not any((fld['id'] in parameternames)
for fld in p.get_fields()['field']):
msg = 'Invalid parameter-name'
msg = 'Invalid parameter_names'
return self.get_exception(
HTTPStatus.BAD_REQUEST, headers, request.format,
'InvalidParameterValue', msg)
+5 -5
View File
@@ -1883,7 +1883,7 @@ def test_get_collection_edr_query(config, api_):
req = mock_request()
rsp_headers, code, response = api_.describe_collections(req, 'icoads-sst')
collection = json.loads(response)
parameter_names = list(collection['parameter-names'].keys())
parameter_names = list(collection['parameter_names'].keys())
parameter_names.sort()
assert len(parameter_names) == 4
assert parameter_names == ['AIRT', 'SST', 'UWND', 'VWND']
@@ -1905,9 +1905,9 @@ def test_get_collection_edr_query(config, api_):
req, 'icoads-sst', None, 'position')
assert code == HTTPStatus.BAD_REQUEST
# bad parameter-name parameter
# bad parameter_names parameter
req = mock_request({
'coords': 'POINT(11 11)', 'parameter-name': 'bad'
'coords': 'POINT(11 11)', 'parameter_names': 'bad'
})
rsp_headers, code, response = api_.get_collection_edr_query(
req, 'icoads-sst', None, 'position')
@@ -1938,7 +1938,7 @@ def test_get_collection_edr_query(config, api_):
# single parameter
req = mock_request({
'coords': 'POINT(11 11)', 'parameter-name': 'SST'
'coords': 'POINT(11 11)', 'parameter_names': 'SST'
})
rsp_headers, code, response = api_.get_collection_edr_query(
req, 'icoads-sst', None, 'position')
@@ -2055,7 +2055,7 @@ def test_get_collection_edr_query(config, api_):
# cube decreasing latitude coords and S3
req = mock_request({
'bbox': '-100,40,-99,45',
'parameter-name': 'tmn',
'parameter_names': 'tmn',
'datetime': '1994-01-01/1994-12-31',
})