Skip to content

Commit

Permalink
preload config to read namespace if necessary. Generalize metadata na…
Browse files Browse the repository at this point in the history
…mespace 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
  • Loading branch information
ccancellieri committed Oct 22, 2021
1 parent 33d9b70 commit 855ab7d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions ckanext/spatial/harvesters/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def fetch_stage(self,harvest_object):
harvest_object)
return False

if not self.source_config:
self._set_source_config(harvest_object.source.config)
namespace = self.source_config.get('output_schema',self.output_schema())
identifier = harvest_object.guid
try:
Expand Down
13 changes: 8 additions & 5 deletions ckanext/spatial/lib/csw_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,17 @@ def getrecordbyid(self, ids=[], esn="full", outputschema="gmd", **kw):
csw.exceptionreport.exceptions
#log.error(err)
raise CswError(err)
if not csw.records:
elif csw.records:
record = self._xmd(list(csw.records.values())[0])
elif csw.response:
record = self._xmd(etree.fromstring(csw.response))
else:
return
record = self._xmd(list(csw.records.values())[0])

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

0 comments on commit 855ab7d

Please sign in to comment.