Skip to content

Commit

Permalink
adds the contactinfo from dedicated role fields (#1014)
Browse files Browse the repository at this point in the history
* adds the contactinfo from dedicated role fields, if the role does not already exists in contacts

* fix code to consider record as object, also refactor if/else

* remove print statement
  • Loading branch information
pvgenuchten authored Oct 5, 2024
1 parent 6bb4520 commit c532be3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pycsw/ogc/api/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,9 +1196,11 @@ def record2json(record, url, collection, mode='ogcapi-records'):

if record.contacts not in [None, '', 'null']:
rcnt = []
roles = []
try:
for cnt in json.loads(record.contacts):
try:
roles.append(cnt.get('role', '').lower())
rcnt.append({
'name': cnt['name'],
'organization': cnt.get('organization', ''),
Expand All @@ -1223,6 +1225,13 @@ def record2json(record, url, collection, mode='ogcapi-records'):
})
except Exception as err:
LOGGER.exception(f"failed to parse contact of {record.identifier}: {err}")
for r2 in "creator,publisher,contributor".split(","): # match role-fields with contacts
if r2 not in roles and hasattr(record,r2) and record[r2] not in [None,'']:
rcnt.append({
'organization': record[r2],
'roles': [r2]
})

except Exception as err:
LOGGER.exception(f"failed to parse contacts json of {record.identifier}: {err}")

Expand Down

0 comments on commit c532be3

Please sign in to comment.