From 1f547c24ddfc4788d72bba90d9f7e1dad4992c67 Mon Sep 17 00:00:00 2001 From: Felipe Carlos Date: Thu, 15 Feb 2024 14:24:59 -0300 Subject: [PATCH] schema: adding support for multiple location names --- invenio_geographic_identifiers/__init__.py | 2 +- .../contrib/geonames/datastreams.py | 18 ++++++++++++++---- .../geoidentifiers/geoidentifier-v1.0.0.json | 5 ++++- .../geoidentifiers/schema.py | 2 +- setup.cfg | 1 + 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/invenio_geographic_identifiers/__init__.py b/invenio_geographic_identifiers/__init__.py index 6d7a0e9..9b0f102 100644 --- a/invenio_geographic_identifiers/__init__.py +++ b/invenio_geographic_identifiers/__init__.py @@ -10,5 +10,5 @@ from .ext import InvenioGeographicIdentifiers -__version__ = "0.3.0" +__version__ = "0.4.0" __all__ = ("__version__", "InvenioGeographicIdentifiers") diff --git a/invenio_geographic_identifiers/contrib/geonames/datastreams.py b/invenio_geographic_identifiers/contrib/geonames/datastreams.py index b7aca6e..91afa1a 100644 --- a/invenio_geographic_identifiers/contrib/geonames/datastreams.py +++ b/invenio_geographic_identifiers/contrib/geonames/datastreams.py @@ -8,6 +8,8 @@ """Geonames datastreams.""" +from itertools import chain + from invenio_access.permissions import system_identity from invenio_vocabularies.datastreams.transformers import BaseTransformer from invenio_vocabularies.datastreams.writers import ServiceWriter @@ -26,10 +28,18 @@ def apply(self, stream_entry, *args, **kwargs): stream_entry.entry = { "id": f"geonames::{stream_entry.entry['geonameid']}", "scheme": "geonames", - "name": ( - stream_entry.entry.get("asciiname") - or stream_entry.entry.get("name") - or stream_entry.entry.get("alternativenames") + "name": list( + chain( + *list( + filter( + lambda x: x is not None, + map( + lambda y: stream_entry.entry.get(y), + ["asciiname", "name", "alternativenames"], + ), + ) + ) + ) ), "locations": [ { diff --git a/invenio_geographic_identifiers/geoidentifiers/jsonschemas/geoidentifiers/geoidentifier-v1.0.0.json b/invenio_geographic_identifiers/geoidentifiers/jsonschemas/geoidentifiers/geoidentifier-v1.0.0.json index 7b9591e..0cf53b4 100644 --- a/invenio_geographic_identifiers/geoidentifiers/jsonschemas/geoidentifiers/geoidentifier-v1.0.0.json +++ b/invenio_geographic_identifiers/geoidentifiers/jsonschemas/geoidentifiers/geoidentifier-v1.0.0.json @@ -21,7 +21,10 @@ }, "name": { "description": "Human readable label.", - "type": "string" + "type": "array", + "items": { + "type": "string" + } }, "locations": { "type": "array", diff --git a/invenio_geographic_identifiers/geoidentifiers/schema.py b/invenio_geographic_identifiers/geoidentifiers/schema.py index 1656581..f2f16d5 100644 --- a/invenio_geographic_identifiers/geoidentifiers/schema.py +++ b/invenio_geographic_identifiers/geoidentifiers/schema.py @@ -59,7 +59,7 @@ class GeographicIdentifiersSchema(BaseVocabularySchema): # (subjects)``, here the ``id`` is ``required`` id = SanitizedUnicode(required=True) scheme = SanitizedUnicode(required=True) - name = SanitizedUnicode(required=True) + name = fields.List(required=True, cls_or_instance=SanitizedUnicode(required=True)) locations = fields.List( required=True, cls_or_instance=fields.Nested(LocationSchema) ) diff --git a/setup.cfg b/setup.cfg index 33095d5..da12409 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,6 +42,7 @@ install_requires = docs = Sphinx>=4.5.0 tests = + black<=23.12.1 pytest-black>=0.3.0 invenio-app>=1.3.4,<2.0.0 invenio-db[postgresql,mysql]>=1.0.14,<2.0.0