Skip to content

Commit

Permalink
Revert "feat(feat) Revert multiple contact points"
Browse files Browse the repository at this point in the history
This reverts commit cd80c80.
  • Loading branch information
Hans-Chrstian committed Aug 14, 2024
1 parent cd80c80 commit a0291a4
Show file tree
Hide file tree
Showing 6 changed files with 925 additions and 777 deletions.
33 changes: 25 additions & 8 deletions ckanext/fairdatapoint/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class FAIRDataPointDCATAPProfile(EuropeanDCATAP2Profile):

def parse_dataset(self, dataset_dict: Dict, dataset_ref: URIRef) -> Dict:
super(FAIRDataPointDCATAPProfile, self).parse_dataset(dataset_dict, dataset_ref)
dataset_dict = self._parse_contact_point(dataset_dict, dataset_ref)

dataset_dict = self._parse_creator(dataset_dict, dataset_ref)

Expand All @@ -114,21 +115,37 @@ def parse_dataset(self, dataset_dict: Dict, dataset_ref: URIRef) -> Dict:

return dataset_dict

def _contact_details(self, subject, predicate):
def _contact_point_details(self, subject, predicate) -> List:
"""
Overrides RDFProfile._contact_details so uri is taken from hasUID for VCard
"""
contact = {}
contact_list = []

for agent in self.g.objects(subject, predicate):
contact['uri'] = (str(agent) if isinstance(agent, URIRef)
else self._get_vcard_property_value(agent, VCARD.hasUID))
contact = {
'contact_uri': (str(agent) if isinstance(agent, URIRef)
else self._get_vcard_property_value(agent, VCARD.hasUID)),
'contact_name': self._get_vcard_property_value(agent, VCARD.hasFN, VCARD.fn),
'contact_email': self._without_mailto(self._get_vcard_property_value(agent, VCARD.hasEmail))}

contact['name'] = self._get_vcard_property_value(agent, VCARD.hasFN, VCARD.fn)
contact['email'] = self._without_mailto(self._get_vcard_property_value(agent, VCARD.hasEmail))
contact['phone'] = self._get_vcard_property_value(agent, VCARD.hasTelephone)
contact_list.append(contact)

return contact
return contact_list

def _parse_contact_point(self, dataset_dict: Dict, dataset_ref: URIRef) -> Dict:
"""
ckan-dcat extension implies there can be just one contact point and in case a list is provided by source only
last value is taken. Besides it never solves uri from a VCard object. This function parses DCAT.contactPoint
information to a list of `pontact_point` dictionaries and replaces ckan-dcat values
"""
contact_point = self._contact_point_details(subject=dataset_ref, predicate=DCAT.contactPoint)
dcat_profile_contact_fields = ['contact_name', 'contact_email', 'contact_uri']
if contact_point:
dataset_dict['extras'].append({'key': 'contact_point', 'value': contact_point})
# Remove the extras contact_ fields if they were parsed by dcat extension
dataset_dict['extras'] = \
[item for item in dataset_dict['extras'] if item.get('key') not in dcat_profile_contact_fields]
return dataset_dict

def _parse_creator(self, dataset_dict: Dict, dataset_ref: URIRef) -> Dict:
graph = self.g
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-FileCopyrightText: 2024 Stichting Health-RI
#
# SPDX-License-Identifier: AGPL-3.0-only

@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ldp: <http://www.w3.org/ns/ldp#> .
@prefix v: <http://www.w3.org/2006/vcard/ns#> .

<https://health-ri.sandbox.semlab-leiden.nl/dataset/d7129d28-b72a-437f-8db0-4f0258dd3c25>
a dcat:Resource, dcat:Dataset;
<http://www.w3.org/2000/01/rdf-schema#label> "Example";
dcterms:title "Example";
<https://w3id.org/fdp/fdp-o#metadataIssued> "2023-09-05T12:00:36.276171042Z"^^xsd:dateTime;
<https://w3id.org/fdp/fdp-o#metadataModified> "2024-05-02T13:01:35.716385359Z"^^xsd:dateTime;
dcterms:license <http://rdflicense.appspot.com/rdflicense/cc-by-nc-nd3.0>;
dcterms:description "This is an example description.";
dcat:contactPoint [ a v:VCard ;
v:fn "Marc Bonten" ;
v:hasUID <https://orcid.org/0000-0002-9095-9201> ;
v:hasEmail <mailto:marc.bonten@example.com> ] ,
[ a v:VCard ;
v:fn "Frits Rosendaal" ;
v:hasUID <https://orcid.org/0000-0003-2558-7496> ;
v:hasEmail <mailto:frits.rosendaal@example.com> ] .
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: 2024 Stichting Health-RI
#
# SPDX-License-Identifier: AGPL-3.0-only

@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ldp: <http://www.w3.org/ns/ldp#> .

<https://health-ri.sandbox.semlab-leiden.nl/dataset/d7129d28-b72a-437f-8db0-4f0258dd3c25>
a dcat:Resource, dcat:Dataset;
<http://www.w3.org/2000/01/rdf-schema#label> "Example";
dcterms:title "Example";
<https://w3id.org/fdp/fdp-o#metadataIssued> "2023-09-05T12:00:36.276171042Z"^^xsd:dateTime;
<https://w3id.org/fdp/fdp-o#metadataModified> "2024-05-02T13:01:35.716385359Z"^^xsd:dateTime;
dcterms:license <http://rdflicense.appspot.com/rdflicense/cc-by-nc-nd3.0>;
dcterms:description "This is an example description.";
dcat:contactPoint <https://orcid.org/0000-0002-9095-9201>, <https://orcid.org/0000-0003-2558-7496> .
Loading

0 comments on commit a0291a4

Please sign in to comment.