Skip to content

Commit 322bdda

Browse files
committed
STAC API: fix ids POST mode handling
1 parent 04c7c7f commit 322bdda

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

pycsw/ogc/api/records.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,11 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
547547
query_parser = None
548548
sortby = None
549549
limit = None
550+
ids = []
550551
bbox = []
551552
facets_requested = False
552553
collections = []
554+
cql_ops_list = []
553555

554556
if collection not in self.get_all_collections():
555557
msg = 'Invalid collection'
@@ -644,7 +646,6 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
644646
query_parser = parse_ecql
645647

646648
elif json_post_data is not None:
647-
648649
if 'limit' in json_post_data:
649650
limit = json_post_data.pop('limit')
650651
if 'sortby' in json_post_data:
@@ -653,23 +654,36 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
653654
collections = json_post_data.pop('collections')
654655
if 'bbox' in json_post_data:
655656
bbox = json_post_data.pop('bbox')
657+
if 'ids' in json_post_data:
658+
ids = json_post_data.pop('ids')
656659
if not json_post_data:
657660
LOGGER.debug('No CQL specified, only query parameters')
658661
json_post_data = {}
662+
659663
if not json_post_data and collections and collections != ['metadata:main']:
660-
json_post_data = {'op': 'eq', 'args': [{'property': 'parentidentifier'}, collections[0]]}
661-
if bbox:
662-
json_post_data = {
663-
'op': 'and',
664-
'args': [{
665-
'op': 's_intersects',
666-
'args': [
667-
{'property': 'geometry2'},
668-
{'bbox': [bbox]}
669-
]},
670-
json_post_data
671-
]
672-
}
664+
cql_ops_list.append({'op': 'eq', 'args': [{'property': 'parentidentifier'}, collections[0]]})
665+
if bbox:
666+
cql_ops_list.append({
667+
'op': 's_intersects',
668+
'args': [
669+
{'property': 'geometry'},
670+
{'bbox': [bbox]}
671+
]}
672+
)
673+
674+
if ids:
675+
cql_ops_list.append({
676+
'op': 'in',
677+
'args': [{'property': 'identifier'}, ids]
678+
})
679+
680+
if len(cql_ops_list) > 1:
681+
json_post_data = {
682+
'op': 'and',
683+
'args': cql_ops_list
684+
}
685+
elif len(cql_ops_list) == 1:
686+
json_post_data = cql_ops_list[0]
673687

674688
cql_query = json_post_data
675689
LOGGER.debug('Detected CQL JSON; ignoring all other query predicates')

tests/functionaltests/suites/stac_api/test_stac_api_functional.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ def test_items(config):
239239
assert content['numberReturned'] == 1
240240
assert content['numberMatched'] == 30
241241

242+
# test ids
243+
ids = [
244+
'S2B_MSIL2A_20190910T095029_N0213_R079_T33UXQ_20190910T124513.SAFE',
245+
'S2B_MSIL2A_20190910T095029_N0213_R079_T33UXP_20190910T124513.SAFE'
246+
]
247+
content = json.loads(api.items({}, {'ids': ids}, {})[2])
248+
249+
assert content['numberReturned'] == 2
250+
assert content['numberMatched'] == 2
251+
252+
242253
def test_item(config):
243254
api = STACAPI(config)
244255
item = 'S2B_MSIL2A_20190910T095029_N0500_R079_T33TXN_20230430T083712.SAFE'

0 commit comments

Comments
 (0)