From 2ea8a5f6cb76fdfbec2e78fda416d443df449458 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Wed, 23 Sep 2020 21:01:32 -0400 Subject: [PATCH] Misc fixes 2020 09 23 (#540) * fix OACov output headers, safeguard coverage plugin loading * fix ref, add query debug logging * normalize mimetypes --- pygeoapi/api.py | 26 +++++++++++++++++--------- pygeoapi/provider/elasticsearch_.py | 4 +++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pygeoapi/api.py b/pygeoapi/api.py index ed21350..fd2e75d 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -511,9 +511,18 @@ class API: }) if dataset is not None: LOGGER.debug('Creating extended coverage metadata') - p = load_plugin('provider', get_provider_by_type( - self.config['resources'][dataset]['providers'], - 'coverage')) + try: + p = load_plugin('provider', get_provider_by_type( + self.config['resources'][dataset]['providers'], + 'coverage')) + except ProviderConnectionError: + exception = { + 'code': 'NoApplicableCode', + 'description': 'connection error (check logs)' + } + LOGGER.error(exception) + return headers_, 500, to_json(exception, + self.pretty_print) collection['crs'] = [p.crs] collection['domainset'] = p.get_coverage_domainset() @@ -1341,10 +1350,10 @@ class API: mt = collection_def['format']['name'] if format_ == mt: - headers_['Content-type'] = mt + headers_['Content-Type'] = collection_def['format']['mimetype'] return headers_, 200, data elif format_ == 'json': - headers_['Content-type'] = 'application/prs.coverage+json' + headers_['Content-Type'] = 'application/prs.coverage+json' return headers_, 200, to_json(data, self.pretty_print) else: exception = { @@ -1411,7 +1420,7 @@ class API: data['title'] = self.config['resources'][dataset]['title'] content = render_j2_template(self.config, 'domainset.html', data) - headers_['Content-type'] = 'text/html' + headers_['Content-Type'] = 'text/html' return headers_, 200, content else: exception = { @@ -1471,14 +1480,13 @@ class API: return headers_, 500, to_json(exception, self.pretty_print) if format_ == 'json': - return ({'Content-type': 'application/json'}, - 200, to_json(data, self.pretty_print)) + return (headers_, 200, to_json(data, self.pretty_print)) elif format_ == 'html': data['id'] = dataset data['title'] = self.config['resources'][dataset]['title'] content = render_j2_template(self.config, 'rangetype.html', data) - headers_['Content-type'] = 'text/html' + headers_['Content-Type'] = 'text/html' return headers_, 200, content else: exception = { diff --git a/pygeoapi/provider/elasticsearch_.py b/pygeoapi/provider/elasticsearch_.py index 990108e..163a1c8 100644 --- a/pygeoapi/provider/elasticsearch_.py +++ b/pygeoapi/provider/elasticsearch_.py @@ -28,6 +28,7 @@ # ================================================================= from collections import OrderedDict +import json import logging from elasticsearch import Elasticsearch, exceptions, helpers @@ -190,7 +191,7 @@ class ElasticsearchProvider(BaseProvider): filter_.append({'match': {time_field: datetime}}) LOGGER.debug(filter_) - query['query']['bool']['filter'].append(filter_) + query['query']['bool']['filter'].append(*filter_) if properties: LOGGER.debug('processing properties') @@ -238,6 +239,7 @@ class ElasticsearchProvider(BaseProvider): query['_source']['includes'].append('geometry') try: LOGGER.debug('querying Elasticsearch') + LOGGER.debug(json.dumps(query, indent=4)) LOGGER.debug('Setting ES paging zero-based') if startindex > 0: