Skip to content

Commit 855ab7d

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 33d9b70 commit 855ab7d

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

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
@@ -190,14 +190,17 @@ def getrecordbyid(self, ids=[], esn="full", outputschema="gmd", **kw):
190190
csw.exceptionreport.exceptions
191191
#log.error(err)
192192
raise CswError(err)
193-
if not csw.records:
193+
elif csw.records:
194+
record = self._xmd(list(csw.records.values())[0])
195+
elif csw.response:
196+
record = self._xmd(etree.fromstring(csw.response))
197+
else:
194198
return
195-
record = self._xmd(list(csw.records.values())[0])
196199

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

0 commit comments

Comments
 (0)