Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geoDCAT-AP schema option to CswDcatBackend #3027

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion js/components/harvest/feature-field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export default {
},
computed: {
checked() {
return this.key in this.features ? this.features[this.key] : this.feature.default;
if (this.key in this.features)
return this.features[this.key]
if (this.feature.default === "False")
return false
return this.feature.default
},
features() {
return this.config.features || {};
Expand Down
20 changes: 16 additions & 4 deletions udata/harvest/backends/dcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
DCAT, DCT, HYDRA, SPDX, namespace_manager, guess_format, url_from_rdf
)
from udata.core.dataset.rdf import dataset_from_rdf
from udata.i18n import gettext as _
from udata.storage.s3 import store_as_json, get_from_json
from udata.harvest.models import HarvestItem

from .base import BaseBackend
from .base import BaseBackend, HarvestFeature

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -190,12 +191,23 @@ def next_record_if_should_continue(self, start, search_results):
class CswDcatBackend(DcatBackend):
display_name = 'CSW-DCAT'

DCAT_SCHEMA = 'http://www.w3.org/ns/dcat#'
features = (
HarvestFeature('geodcat_ap', _('Use GeoDCAT-AP schema (experimental)'),
_('If enabled, use GeoDCAT-AP schema instead of default.'), default=False),
)

DEFAULT_CSW_SCHEMA = 'http://www.w3.org/ns/dcat#'

def walk_graph(self, url: str, fmt: str) -> Generator[tuple[int, Graph], None, None]:
"""
Yield all RDF pages as `Graph` from the source
"""

if self.has_feature('geodcat_ap'):
schema = 'http://data.europa.eu/930/'
else:
schema = self.DEFAULT_CSW_SCHEMA

body = '''<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"
xmlns:gmd="http://www.isotc211.org/2005/gmd"
service="CSW" version="2.0.2" resultType="results"
Expand All @@ -216,7 +228,7 @@ def walk_graph(self, url: str, fmt: str) -> Generator[tuple[int, Graph], None, N
page_number = 0
start = 1

response = self.post(url, data=body.format(start=start, schema=self.DCAT_SCHEMA),
response = self.post(url, data=body.format(start=start, schema=schema),
headers=headers)
response.raise_for_status()
content = response.content
Expand Down Expand Up @@ -244,7 +256,7 @@ def walk_graph(self, url: str, fmt: str) -> Generator[tuple[int, Graph], None, N
page_number += 1

tree = ET.fromstring(
self.post(url, data=body.format(start=start, schema=self.DCAT_SCHEMA),
self.post(url, data=body.format(start=start, schema=schema),
headers=headers).content)


Expand Down
20 changes: 14 additions & 6 deletions udata/translations/udata.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: udata 7.0.7.dev0\n"
"Project-Id-Version: udata 8.0.1.dev0\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-04-15 12:06+0200\n"
"PO-Revision-Date: 2024-04-15 12:06+0200\n"
"POT-Creation-Date: 2024-04-25 17:58+0200\n"
"PO-Revision-Date: 2024-04-25 17:58+0200\n"
"Last-Translator: Open Data Team <[email protected]>\n"
"Language: en\n"
"Language-Team: Open Data Team <[email protected]>\n"
Expand Down Expand Up @@ -132,17 +132,17 @@ msgstr ""
msgid "Confirm change of email instructions"
msgstr ""

#: udata/auth/views.py:72
#: udata/auth/views.py:73
msgid ""
"You did not confirm your change of email within {email_within}. New "
"instructions to confirm your change of email have been sent to {new_email}."
msgstr ""

#: udata/auth/views.py:82
#: udata/auth/views.py:83
msgid "Thank you. Your change of email has been confirmed."
msgstr ""

#: udata/auth/views.py:97
#: udata/auth/views.py:98
msgid ""
"Thank you. Confirmation instructions for changing your email have been sent "
"to {new_email}."
Expand Down Expand Up @@ -1162,6 +1162,14 @@ msgstr ""
msgid "Archived"
msgstr ""

#: udata/harvest/backends/dcat.py:212
msgid "Use GeoDCAT-AP schema (experimental)"
msgstr ""

#: udata/harvest/backends/dcat.py:213
msgid "If enabled, use GeoDCAT-AP schema instead of default."
msgstr ""

#: udata/templates/admin.html:7
msgid "Admin"
msgstr ""
Expand Down