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 VCARD.hasURL property parsing/serialization #324

Merged
merged 13 commits into from
Dec 16, 2024
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ jobs:
ckan -c test.ini db init
ckan -c test.ini db pending-migrations --apply
- name: Run tests
run: pytest --ckan-ini=test.ini --cov=ckanext.dcat --cov-report=term-missing --cov-append --disable-warnings ckanext/dcat/tests
run: pytest --ckan-ini=test.ini --cov=ckanext.dcat --cov-report=term-missing --cov-append --disable-warnings ckanext/dcat/tests
17 changes: 6 additions & 11 deletions ckanext/dcat/harvesters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,12 @@ def _read_datasets_from_db(self, guid):
'''
Returns a database result of datasets matching the given guid.
'''
if toolkit.check_ckan_version(max_version="2.11"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was probably changed by mistake

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, when I revert this setting, the pipeline fails. Please refer to the following link for details: https://github.com/ckan/ckanext-dcat/actions/runs/12284575222. The tests seem to fail unexpectedly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something upstream changed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, the version check was wrong: 6bcf693

datasets = model.Session.query(model.Package.id) \
.join(model.PackageExtra) \
.filter(model.PackageExtra.key == 'guid') \
.filter(model.PackageExtra.value == guid) \
.filter(model.Package.state == 'active') \
.all()
else:
datasets = model.Session.query(model.Package.id) \
.filter(model.Package.extras['guid'] == f'"{guid}"') \
.all()
datasets = model.Session.query(model.Package.id) \
.join(model.PackageExtra) \
.filter(model.PackageExtra.key == 'guid') \
.filter(model.PackageExtra.value == guid) \
.filter(model.Package.state == 'active') \
.all()

return datasets

Expand Down
11 changes: 7 additions & 4 deletions ckanext/dcat/profiles/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,9 @@ def _agents_details(self, subject, predicate):
agent_details = {}
agent_details["uri"] = str(agent) if isinstance(agent, term.URIRef) else ""
agent_details["name"] = self._object_value(agent, FOAF.name)
agent_details["email"] = self._object_value(agent, FOAF.mbox)
agent_details["email"] = self._without_mailto(
self._object_value(agent, FOAF.mbox)
)
if not agent_details["email"]:
agent_details["email"] = self._without_mailto(
self._object_value(agent, VCARD.hasEmail)
Expand Down Expand Up @@ -573,6 +575,9 @@ def _contact_details(self, subject, predicate):
)

contact["identifier"] = self._get_vcard_property_value(agent, VCARD.hasUID)

contact["url"] = self._get_vcard_property_value(agent, VCARD.hasURL)

contacts.append(contact)

return contacts
Expand Down Expand Up @@ -818,9 +823,7 @@ def _add_spatial_value_to_graph(self, spatial_ref, predicate, value):
or object.
"""
spatial_formats = aslist(
config.get(
"ckanext.dcat.output_spatial_format", DEFAULT_SPATIAL_FORMATS
)
config.get("ckanext.dcat.output_spatial_format", DEFAULT_SPATIAL_FORMATS)
)

if isinstance(value, str):
Expand Down
4 changes: 2 additions & 2 deletions ckanext/dcat/profiles/euro_dcat_ap_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ def _parse_dataset_base(self, dataset_dict, dataset_ref):
contact = self._contact_details(dataset_ref, ADMS.contactPoint)
if contact:
contact = contact[0]
for key in ("uri", "name", "email", "identifier"):
for key in ("uri", "name", "email", "identifier", "url"):
if contact.get(key):
dataset_dict["extras"].append(
{
"key": "contact_{0}".format(key),
"value": contact.get(key)
"value": contact.get(key),
}
)

Expand Down
7 changes: 7 additions & 0 deletions ckanext/dcat/profiles/euro_dcat_ap_scheming.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ def _graph_from_dataset_v2_scheming(self, dataset_dict, dataset_ref):
"identifier",
_type=URIRefOrLiteral,
)
self._add_triple_from_dict(
item,
contact_details,
VCARD.hasURL,
"url",
_type=URIRef,
)

self._add_agents(dataset_ref, dataset_dict, "publisher", DCT.publisher)
self._add_agents(dataset_ref, dataset_dict, "creator", DCT.creator)
Expand Down
5 changes: 4 additions & 1 deletion ckanext/dcat/schemas/dcat_ap_full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ dataset_fields:
- field_name: identifier
label: Identifier
help_text: Unique identifier for the contact point. Such as a ROR ID.


- field_name: url
label: URL
help_text: A URL associated with the contact
help_text: Contact information for enquiries about the dataset.

- field_name: publisher
Expand Down
5 changes: 4 additions & 1 deletion ckanext/dcat/schemas/dcat_ap_multilingual.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ dataset_fields:
- field_name: identifier
label: Identifier
help_text: Unique identifier for the contact point. Such as a ROR ID.


- field_name: url
label: URL
help_text: A URL associated with the contact
help_text: Contact information for enquiries about the dataset.

- field_name: license_id
Expand Down
4 changes: 4 additions & 0 deletions ckanext/dcat/schemas/dcat_ap_recommended.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ dataset_fields:
- field_name: email
label: Email
display_snippet: email.html

- field_name: url
label: URL
help_text: A URL associated with the contact
help_text: Contact information for enquiries about the dataset.

- field_name: publisher
Expand Down
4 changes: 4 additions & 0 deletions ckanext/dcat/schemas/dcat_us_full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ dataset_fields:
- field_name: email
label: Email
display_snippet: email.html

- field_name: url
label: URL
help_text: A URL associated with the contact
help_text: Contact information for enquiries about the dataset.

- field_name: publisher
Expand Down
4 changes: 4 additions & 0 deletions ckanext/dcat/schemas/dcat_us_recommended.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ dataset_fields:
- field_name: email
label: Email
display_snippet: email.html

- field_name: url
label: URL
help_text: A URL associated with the contact
help_text: Contact information for enquiries about the dataset.

- field_name: publisher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def test_e2e_dcat_to_ckan(self):

assert dataset["contact"][0]["name"] == "Point of Contact"
assert dataset["contact"][0]["email"] == "[email protected]"
assert dataset["contact"][0]["url"] == "https://example.org"

assert (
dataset["publisher"][0]["name"] == "Publishing Organization for dataset 1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def test_e2e_ckan_to_dcat(self):
VCARD.hasUID,
dataset_dict["contact"][0]["identifier"],
)
assert self._triple(
g, contact_details[0][2], VCARD.hasURL, URIRef(dataset_dict["contact"][0]["url"])
)
assert self._triple(
g, contact_details[1][2], VCARD.fn, dataset_dict["contact"][1]["name"]
)
Expand Down
3 changes: 0 additions & 3 deletions ckanext/dcat/tests/shacl/test_shacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ def test_validate_dcat_us_3_graph():

graph = graph_from_dataset("ckan_full_dataset_dcat_us_vocabularies.json")

graph.serialize(destination="graph.ttl")

graph.serialize(destination="graph.xml")
path = _get_shacl_file_path("dcat-us_3.0_shacl_shapes.ttl")
r = validate(graph, shacl_graph=path)
conforms, results_graph, results_text = r
Expand Down
3 changes: 2 additions & 1 deletion examples/ckan/ckan_full_dataset_dcat_ap.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
{
"name": "Contact 1",
"email": "[email protected]",
"identifier": "123"
"identifier": "123",
"url": "https://example.org"
},
{
"name": "Contact 2",
Expand Down
1 change: 1 addition & 0 deletions examples/dcat/dataset.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<vcard:Organization>
<vcard:fn>Point of Contact</vcard:fn>
<vcard:hasEmail rdf:resource="mailto:[email protected]"/>
<vcard:hasURL rdf:resource="https://example.org"/>
</vcard:Organization>
</dcat:contactPoint>
<dct:publisher>
Expand Down
Loading