Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pycsw/ogc/api/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,10 @@ def record2json(record, url, collection, mode='ogcapi-records'):
for rtp in record.topicategory:
tctheme['concepts'].append({'id': rtp})
elif isinstance(record.topicategory, str):
tctheme['concepts'].append({'id': record.topicategory})
# repositories store several topic categories comma-separated
for rtp in record.topicategory.split(','):
if rtp.strip():
tctheme['concepts'].append({'id': rtp.strip()})

record_dict['properties']['themes'] = [tctheme]

Expand Down
2 changes: 1 addition & 1 deletion pycsw/plugins/profiles/apiso/apiso.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def write_record(self, result, esn, outputschema, queryables, caps=None):
if val:
for v in val.split(','):
tmp = etree.SubElement(resident, util.nspath_eval('gmd:topicCategory', self.namespaces))
etree.SubElement(tmp, util.nspath_eval('gmd:MD_TopicCategoryCode', self.namespaces)).text = val
etree.SubElement(tmp, util.nspath_eval('gmd:MD_TopicCategoryCode', self.namespaces)).text = v.strip()

# bbox extent
val = util.getqattr(result, queryables['apiso:BoundingBox']['dbcol'])
Expand Down
2 changes: 1 addition & 1 deletion pycsw/plugins/profiles/iso19115p3/iso19115p3.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def write_record(self, result, esn, outputschema, queryables, caps=None):
topic_cat = build_path(resident, ['mri:topicCategory'], self.namespaces)
if val:
for v in val.split(','):
etree.SubElement(topic_cat, util.nspath_eval('mri:MD_TopicCategoryCode', self.namespaces)).text = val
etree.SubElement(topic_cat, util.nspath_eval('mri:MD_TopicCategoryCode', self.namespaces)).text = v.strip()

# Bbox and vertical extent
bbox = util.getqattr(result, queryables['mdb:BoundingBox']['dbcol'])
Expand Down
42 changes: 42 additions & 0 deletions tests/unittests/test_ogc_api_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Unit tests for OGC API - Records record generation."""

import pytest

from pycsw.ogc.api.records import record2json

pytestmark = pytest.mark.unit

TOPIC_SCHEME = 'https://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_TopicCategoryCode'


class Record:
identifier = 'record-1'
title = 'Title'
typename = 'gmd:MD_Metadata'
metadata_type = 'application/xml'
type = 'dataset'

def __init__(self, topicategory):
self.topicategory = topicategory

def __getattr__(self, name):
return None


def topic_concepts(topicategory):
record = record2json(Record(topicategory), 'http://localhost/pycsw', 'metadata:main')
themes = record['properties'].get('themes', [])
return [concept['id'] for theme in themes if theme['scheme'] == TOPIC_SCHEME
for concept in theme['concepts']]


@pytest.mark.parametrize('topicategory, expected', [
('environment', ['environment']),
# stored comma-separated by repositories: one concept each
('climatologyMeteorologyAtmosphere,environment',
['climatologyMeteorologyAtmosphere', 'environment']),
('oceans, environment,', ['oceans', 'environment']),
(['oceans', 'environment'], ['oceans', 'environment']),
])
def test_topic_categories_are_one_concept_each(topicategory, expected):
assert topic_concepts(topicategory) == expected
Loading