Skip to content

Commit

Permalink
feat(feat) Revert multiple contact points
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans-Chrstian committed Aug 13, 2024
1 parent 9b1f888 commit cd80c80
Show file tree
Hide file tree
Showing 6 changed files with 777 additions and 925 deletions.
33 changes: 8 additions & 25 deletions ckanext/fairdatapoint/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ 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 @@ -115,37 +114,21 @@ def parse_dataset(self, dataset_dict: Dict, dataset_ref: URIRef) -> Dict:

return dataset_dict

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

for agent in self.g.objects(subject, predicate):
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['uri'] = (str(agent) if isinstance(agent, URIRef)
else self._get_vcard_property_value(agent, VCARD.hasUID))

contact_list.append(contact)
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)

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
return contact

def _parse_creator(self, dataset_dict: Dict, dataset_ref: URIRef) -> Dict:
graph = self.g
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit cd80c80

Please sign in to comment.