Skip to content

Commit e5b4b22

Browse files
committed
support virtual collection filter by collection id
1 parent 38f9ac4 commit e5b4b22

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

pycsw/core/repository.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,18 @@ def query_ids(self, ids):
347347
query = self.session.query(self.dataset).filter(column.in_(ids))
348348
return self._get_repo_filter(query).all()
349349

350-
def query_collections(self, filters=None, limit=10):
350+
def query_collections(self, collection=None, filters=None, limit=10):
351351
''' Query for parent collections '''
352352

353353
column = getattr(self.dataset,
354354
self.context.md_core_model['mappings']['pycsw:ParentIdentifier'])
355355

356-
collections = self.session.query(column).distinct()
356+
if collection is not None:
357+
collections = self.session.query(column).filter(column==collection)
358+
else:
359+
collections = self.session.query(column)
357360

358-
results = self._get_repo_filter(collections).all()
361+
results = self._get_repo_filter(collections).distinct().all()
359362

360363
ids = [res[0] for res in results if res[0] is not None]
361364

pycsw/ogc/api/records.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def queryables(self, headers_, args, collection='metadata:main'):
518518
if 'json' in headers_['Content-Type']:
519519
headers_['Content-Type'] = 'application/schema+json'
520520

521-
if collection not in self.get_all_collections():
521+
if collection not in self.get_collections(collection=collection):
522522
msg = 'Invalid collection'
523523
LOGGER.exception(msg)
524524
return self.get_exception(400, headers_, 'InvalidParameterValue', msg)
@@ -599,7 +599,7 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
599599
collections = []
600600
cql_ops_list = []
601601

602-
if collection not in self.get_all_collections():
602+
if collection not in self.get_collections(collection=collection):
603603
msg = 'Invalid collection'
604604
LOGGER.exception(msg)
605605
return self.get_exception(400, headers_, 'InvalidParameterValue', msg)
@@ -968,7 +968,7 @@ def item(self, headers_, args, collection, item):
968968
record = None
969969
headers_['Content-Type'] = self.get_content_type(headers_, args)
970970

971-
if collection not in self.get_all_collections():
971+
if collection not in self.get_collections(collection=collection):
972972
msg = 'Invalid collection'
973973
LOGGER.exception(msg)
974974
return self.get_exception(400, headers_, 'InvalidParameterValue', msg)
@@ -1247,15 +1247,15 @@ def federated_catalogue(self, headers_, args, collection, catalogue):
12471247

12481248
return self.get_response(200, headers_, response, template)
12491249

1250-
def get_all_collections(self) -> list:
1250+
def get_collections(self, collection=None) -> list:
12511251
"""
12521252
Get all collections
12531253
12541254
:returns: `list` of collection identifiers
12551255
"""
12561256

12571257
default_collection = 'metadata:main'
1258-
virtual_collections = self.repository.query_collections(limit=self.limit)
1258+
virtual_collections = self.repository.query_collections(collection=collection, limit=self.limit)
12591259

12601260
return [default_collection] + [vc.identifier for vc in virtual_collections]
12611261

pycsw/stac/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def collections(self, headers_, args):
256256
filters = to_filter(ast, self.repository.dbtype, self.repository.query_mappings)
257257
LOGGER.debug(f'Filter: {filters}')
258258

259-
virtual_collections = self.repository.query_collections(filters, limit)
259+
virtual_collections = self.repository.query_collections(filters=filters, limit=limit)
260260

261261
for virtual_collection in virtual_collections:
262262
virtual_collection_info = self.get_collection_info(
@@ -432,7 +432,7 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
432432
distributed_search_args = deepcopy(args)
433433
distributed_search_args.pop('type', None)
434434

435-
if collection not in self.get_all_collections():
435+
if collection not in self.get_collections(collection=collection):
436436
msg = 'Invalid collection'
437437
LOGGER.exception(msg)
438438
return self.get_exception(400, headers_, 'InvalidParameterValue', msg)
@@ -689,7 +689,7 @@ def item(self, headers_, args, collection, item):
689689
:returns: tuple of headers, status code, content
690690
"""
691691

692-
if collection not in self.get_all_collections():
692+
if collection not in self.get_collections(collection=collection):
693693
msg = 'Invalid collection'
694694
LOGGER.exception(msg)
695695
return self.get_exception(400, headers_, 'InvalidParameterValue', msg)
@@ -773,7 +773,7 @@ def get_collection_info(self, collection_name: str = 'metadata:main',
773773
def manage_collection_item(self, headers_, action='create', item=None, data=None, collection=None):
774774
if action in ['create', 'update']:
775775
if (data is not None and data.get('type', '') == 'Feature' and
776-
collection not in self.get_all_collections()):
776+
collection not in self.get_collections(collection=collection)):
777777
msg = 'Invalid collection'
778778
LOGGER.exception(msg)
779779
return self.get_exception(400, headers_, 'InvalidParameterValue', msg)
8 KB
Binary file not shown.

0 commit comments

Comments
 (0)