From 8bb94c849fb2c548766103ab14c640ef64ce291f Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Tue, 17 Dec 2024 10:08:51 -0500 Subject: [PATCH] fix STAC POST, update CQL serialization --- pycsw/ogc/api/records.py | 14 +++++++------- pycsw/wsgi_flask.py | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pycsw/ogc/api/records.py b/pycsw/ogc/api/records.py index c1224c2d0..a077e67c4 100644 --- a/pycsw/ogc/api/records.py +++ b/pycsw/ogc/api/records.py @@ -644,7 +644,7 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'): LOGGER.debug('No CQL specified, only query parameters') json_post_data = {} if not json_post_data and collections and collections != ['metadata:main']: - json_post_data = {'eq': [{'property': 'parentidentifier'}, collections[0]]} + json_post_data = {'op': 'eq', 'args': [{'property': 'parentidentifier'}, collections[0]]} cql_query = json_post_data LOGGER.debug('Detected CQL JSON; ignoring all other query predicates') @@ -1158,7 +1158,7 @@ def record2json(record, url, collection, mode='ogcapi-records'): tctheme['concepts'].append({'id': rtp}) elif isinstance(record.topicategory, str): tctheme['concepts'].append({'id': record.topicategory}) - + record_dict['properties']['themes'] = [tctheme] if record.otherconstraints: @@ -1197,7 +1197,7 @@ def record2json(record, url, collection, mode='ogcapi-records'): if record.contacts not in [None, '', 'null']: rcnt = [] - roles = [] + roles = [] try: for cnt in json.loads(record.contacts): try: @@ -1226,8 +1226,8 @@ def record2json(record, url, collection, mode='ogcapi-records'): }) except Exception as err: LOGGER.exception(f"failed to parse contact of {record.identifier}: {err}") - for r2 in "creator,publisher,contributor".split(","): # match role-fields with contacts - if r2 not in roles and hasattr(record,r2) and record[r2] not in [None,'']: + for r2 in "creator,publisher,contributor".split(","): # match role-fields with contacts + if r2 not in roles and hasattr(record, r2) and record[r2] not in [None, '']: rcnt.append({ 'organization': record[r2], 'roles': [r2] @@ -1239,7 +1239,7 @@ def record2json(record, url, collection, mode='ogcapi-records'): record_dict['properties']['contacts'] = rcnt if record.themes not in [None, '', 'null']: - ogcapi_themes = record_dict['properties'].get('themes', []) + ogcapi_themes = record_dict['properties'].get('themes', []) # For a scheme, prefer uri over label # OWSlib currently uses .keywords_object for keywords with url, see https://github.com/geopython/OWSLib/pull/765 try: @@ -1247,7 +1247,7 @@ def record2json(record, url, collection, mode='ogcapi-records'): try: ogcapi_themes.append({ 'scheme': theme['thesaurus'].get('url') or theme['thesaurus'].get('title'), - 'concepts': [{'id': c.get('name','')} for c in theme.get('keywords', []) if 'name' in c and c['name'] not in [None, '']] + 'concepts': [{'id': c.get('name', '')} for c in theme.get('keywords', []) if 'name' in c and c['name'] not in [None, '']] }) except Exception as err: LOGGER.exception(f"failed to parse theme of {record.identifier}: {err}") diff --git a/pycsw/wsgi_flask.py b/pycsw/wsgi_flask.py index ebef4c904..95e734135 100644 --- a/pycsw/wsgi_flask.py +++ b/pycsw/wsgi_flask.py @@ -220,6 +220,7 @@ def items(collection='metadata:main'): request.method == 'POST', request.content_type not in [None, 'application/json']]): + # OGC API Transaction - create data = None if request.content_type == 'application/geo+json': # JSON grammar data = request.get_json(silent=True) @@ -229,18 +230,18 @@ def items(collection='metadata:main'): return get_response(api_.manage_collection_item(dict(request.headers), 'create', data=data)) elif request.method == 'POST' and get_api_type(request.url_rule.rule) == 'stac-api': - data = request.get_json(silent=True) - return get_response(stacapi.manage_collection_item(dict(request.headers), - 'create', data=data, collection=collection)) - else: - if get_api_type(request.url_rule.rule) == 'stac-api': + if request.url_rule.rule.endswith('items'): # STAC API transaction - create + data = request.get_json(silent=True) + return get_response(stacapi.manage_collection_item(dict(request.headers), + 'create', data=data, collection=collection)) + else: # STAC API search return get_response(stacapi.items(dict(request.headers), request.get_json(silent=True), dict(request.args), collection)) - else: - return get_response(api_.items(dict(request.headers), - request.get_json(silent=True), dict(request.args), - collection)) + else: # OGC API - Records items search + return get_response(api_.items(dict(request.headers), + request.get_json(silent=True), dict(request.args), + collection)) @BLUEPRINT.route('/collections//items/',