Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix STAC POST, update CQL serialization #1055

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pycsw/ogc/api/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Expand All @@ -1239,15 +1239,15 @@ 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:
for theme in json.loads(record.themes):
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}")
Expand Down
19 changes: 10 additions & 9 deletions pycsw/wsgi_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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/<collection>/items/<path:item>',
Expand Down