Skip to content

Commit 69994a5

Browse files
committed
preload config to read namespace if necessary. Generalize metadata namespace and tag name so we can now harvest any kind of metadata (if validation is provided or ignored) ckan#209 ckan#210 ckan#219 ckan#258
1 parent bef67e7 commit 69994a5

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

ckanext/spatial/harvesters/csw.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ def fetch_stage(self,harvest_object):
160160
harvest_object)
161161
return False
162162

163+
if not self.source_config:
164+
self._set_source_config(harvest_object.source.config)
163165
namespace = self.source_config.get('output_schema',self.output_schema())
164166
identifier = harvest_object.guid
165167
try:

ckanext/spatial/lib/csw_client.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,17 @@ def getrecordbyid(self, ids=[], esn="full", outputschema="gmd", **kw):
197197
csw.exceptionreport.exceptions
198198
#log.error(err)
199199
raise CswError(err)
200-
if not csw.records:
200+
elif csw.records:
201+
record = self._xmd(list(csw.records.values())[0])
202+
elif csw.response:
203+
record = self._xmd(etree.fromstring(csw.response))
204+
else:
201205
return
202-
record = self._xmd(list(csw.records.values())[0])
203206

204207
## strip off the enclosing results container, we only want the metadata
205-
#md = csw._exml.find("/gmd:MD_Metadata")#, namespaces=namespaces)
206-
# Ordinary Python version's don't support the metadata argument
207-
md = csw._exml.find("/{http://www.isotc211.org/2005/gmd}MD_Metadata")
208+
# '/{schema}*' expression should be safe enough and is able to match the
209+
# desired schema followed by both MD_Metadata or MI_Metadata (iso19115[-2])
210+
md = csw._exml.find("/{{{schema}}}*".format(schema=output_schemas[outputschema]))
208211
mdtree = etree.ElementTree(md)
209212
try:
210213
record["xml"] = etree.tostring(mdtree, pretty_print=True, encoding=_enc)

0 commit comments

Comments
 (0)