diff --git a/ckanext/spatial/lib/csw_client.py b/ckanext/spatial/lib/csw_client.py index d4e2403..a052072 100644 --- a/ckanext/spatial/lib/csw_client.py +++ b/ckanext/spatial/lib/csw_client.py @@ -65,13 +65,19 @@ class CswService(OwsService): Perform various operations on a CSW service """ from owslib.csw import CatalogueServiceWeb as _Implementation + from owslib.fes import PropertyIsEqualTo def getrecords(self, qtype=None, keywords=[], typenames="csw:Record", esn="brief", skip=0, count=10, outputschema="gmd", **kw): from owslib.csw import namespaces + constraints = [] csw = self._ows(**kw) + + if qtype is not None: + constraints.append(PropertyIsEqualTo("dc:type", qtype)) + kwa = { - "qtype": qtype, + "constraints": constraints, "keywords": keywords, "typenames": typenames, "esn": esn, @@ -79,8 +85,8 @@ class CswService(OwsService): "maxrecords": count, "outputschema": namespaces[outputschema], } - log.info('Making CSW request: getrecords %r', kwa) - csw.getrecords(**kwa) + log.info('Making CSW request: getrecords2 %r', kwa) + csw.getrecords2(**kwa) if csw.exceptionreport: err = 'Error getting records: %r' % \ csw.exceptionreport.exceptions @@ -92,9 +98,14 @@ class CswService(OwsService): keywords=[], limit=None, page=10, outputschema="gmd", startposition=0, **kw): from owslib.csw import namespaces + constraints = [] csw = self._ows(**kw) + + if qtype is not None: + constraints.append(PropertyIsEqualTo("dc:type", qtype)) + kwa = { - "qtype": qtype, + "constraints": constraints, "keywords": keywords, "typenames": typenames, "esn": esn, @@ -105,9 +116,9 @@ class CswService(OwsService): i = 0 matches = 0 while True: - log.info('Making CSW request: getrecords %r', kwa) + log.info('Making CSW request: getrecords2 %r', kwa) - csw.getrecords(**kwa) + csw.getrecords2(**kwa) if csw.exceptionreport: err = 'Error getting identifiers: %r' % \ csw.exceptionreport.exceptions diff --git a/ckanext/spatial/tests/test_csw_client.py b/ckanext/spatial/tests/test_csw_client.py index d64214b..5a6ef85 100644 --- a/ckanext/spatial/tests/test_csw_client.py +++ b/ckanext/spatial/tests/test_csw_client.py @@ -4,6 +4,7 @@ from urllib2 import urlopen import os from owslib.csw import CatalogueServiceWeb +from owslib.fes import PropertyIsEqualTo from owslib.iso import MD_Metadata from pylons import config from nose.plugins.skip import SkipTest @@ -137,7 +138,7 @@ class TestCswClient(CkanProcess): # NB: This test fails because no records have been setup... raise SkipTest() # therefore skip csw = CatalogueServiceWeb(service) - csw.getrecords(outputschema=GMD, startposition=1, maxrecords=5) + csw.getrecords2(outputschema=GMD, startposition=1, maxrecords=5) nrecords = len(csw.records) #print csw.response[:1024] assert nrecords == 5, nrecords @@ -147,19 +148,20 @@ class TestCswClient(CkanProcess): def test_GetRecords_dataset(self): csw = CatalogueServiceWeb(service) - csw.getrecords(qtype="dataset", outputschema=GMD, startposition=1, maxrecords=5) + constraints = [PropertyIsEqualTo("dc:type", "dataset")] + csw.getrecords2(constraints=constraints, outputschema=GMD, startposition=1, maxrecords=5) nrecords = len(csw.records) # TODO def test_GetRecords_brief(self): csw = CatalogueServiceWeb(service) - csw.getrecords(outputschema=GMD, startposition=1, maxrecords=5, esn="brief") + csw.getrecords2(outputschema=GMD, startposition=1, maxrecords=5, esn="brief") nrecords = len(csw.records) # TODO def test_GetRecords_summary(self): csw = CatalogueServiceWeb(service) - csw.getrecords(outputschema=GMD, startposition=1, maxrecords=5, esn="summary") + csw.getrecords2(outputschema=GMD, startposition=1, maxrecords=5, esn="summary") nrecords = len(csw.records) # TODO