From efddd6a683f8da812a407e5a675284b27b004d35 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Tue, 3 Sep 2024 15:34:15 -0400 Subject: [PATCH] fix CSW 2/3 distributed search hopcount handling (#1005) * fix CSW 2/3 distributed search hopcount handling --- pycsw/ogc/csw/csw2.py | 14 +++++++------- pycsw/ogc/csw/csw3.py | 20 +++++++------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/pycsw/ogc/csw/csw2.py b/pycsw/ogc/csw/csw2.py index e3182b362..084b7d8ce 100644 --- a/pycsw/ogc/csw/csw2.py +++ b/pycsw/ogc/csw/csw2.py @@ -823,13 +823,13 @@ def getrecords(self): dsresults = [] + hopcount = int(self.parent.kvp.get('hopcount', 2)) - 1 + if ('federatedcatalogues' in self.parent.config and - 'distributedsearch' in self.parent.kvp and 'hopcount' in self.parent.kvp and - self.parent.kvp['distributedsearch'] and int(self.parent.kvp['hopcount']) > 0): - # do distributed search + self.parent.kvp.get('distributedsearch') and + hopcount > 0): - LOGGER.debug('DistributedSearch specified (hopCount: %s).', - self.parent.kvp['hopcount']) + LOGGER.debug('DistributedSearch specified (hopCount: %s).', hopcount) from owslib.csw import CatalogueServiceWeb from owslib.ows import ExceptionReport @@ -1736,8 +1736,8 @@ def parse_postdata(self, postdata): if tmp is not None: request['distributedsearch'] = True hopcount = tmp.attrib.get('hopCount') - request['hopcount'] = int(hopcount)-1 if hopcount is not None \ - else 1 + request['hopcount'] = int(hopcount) if hopcount is not None \ + else 2 else: request['distributedsearch'] = False diff --git a/pycsw/ogc/csw/csw3.py b/pycsw/ogc/csw/csw3.py index 2438d3255..c5de29455 100644 --- a/pycsw/ogc/csw/csw3.py +++ b/pycsw/ogc/csw/csw3.py @@ -972,19 +972,13 @@ def getrecords(self): 'Record serialization failed: %s' % str(err)) return self.parent.response - if ('federatedcatalogues' in self.parent.config and - 'distributedsearch' in self.parent.kvp and 'hopcount' in self.parent.kvp and - self.parent.kvp['distributedsearch'] and int(self.parent.kvp['hopcount']) > 0): - # do distributed search + hopcount = int(self.parent.kvp.get('hopcount', 2)) - 1 -# if all(['federatedcatalogues' in self.parent.config, -# 'distributedsearch' in self.parent.kvp, -# self.parent.kvp['distributedsearch'], -# 'hopcount' in self.parent.kvp, -# int(self.parent.kvp['hopcount']) > 0]): # do distributed search + if ('federatedcatalogues' in self.parent.config and + self.parent.kvp.get('distributedsearch') and + hopcount > 0): - LOGGER.debug('DistributedSearch specified (hopCount: %s)', - self.parent.kvp['hopcount']) + LOGGER.debug('DistributedSearch specified (hopCount: %s).', hopcount) from owslib.csw import CatalogueServiceWeb from owslib.ows import ExceptionReport @@ -1812,8 +1806,8 @@ def parse_postdata(self, postdata): if tmp is not None: request['distributedsearch'] = True hopcount = tmp.attrib.get('hopCount') - request['hopcount'] = int(hopcount)-1 if hopcount is not None \ - else 1 + request['hopcount'] = int(hopcount) if hopcount is not None \ + else 2 else: request['distributedsearch'] = False