Skip to content

Commit

Permalink
Make schema.org output group organisations for responsible parties
Browse files Browse the repository at this point in the history
The authors and points of contact attached to a record might have an
organisation they are affiliated with referenced.  If that
organisation also has an ROR identifier, there's no need to repeat its
definition for each author in the schema.org output, just to ensure
it's included at the end.

EMC-399
  • Loading branch information
jshholland committed Jan 30, 2025
1 parent c28a70d commit 9e7d65b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,23 @@ public List<OnlineResource> getInfoLinks() {
.collect(Collectors.toCollection(ArrayList::new));
}

@JsonIgnore
public List<ResponsibleParty> getAuthorPointOfContactWithRORs() {
val seenRORs = new HashSet<String>();
return getResponsibleParties()
.stream()
.filter(party -> {
val role = party.getRole();
val authorOrPOC = role.equalsIgnoreCase("author") || role.equalsIgnoreCase("pointOfContact");
if (!authorOrPOC || !party.isRor()) return false;
val ror = party.getOrganisationIdentifier();
if (seenRORs.contains(ror)) return false;
seenRORs.add(ror);
return true;
})
.toList();
}

private static @NonNull String convertEmail(@NonNull String email) {
return email.endsWith("@ceh.ac.uk") ? "enquiries@ceh.ac.uk" : email;
}
Expand Down
16 changes: 16 additions & 0 deletions templates/schema.org/macros.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<#if funding?has_content>,<@fundDetails/></#if>
<#if parts?has_content>,<@partDetails parts/></#if>
<#if downloads?has_content>,<@distributionDetails/></#if>
<#if authorPointOfContactWithRORs?has_content>,<@organisationRORs/></#if>
</#macro>

<#macro alternateTitlesList>
Expand Down Expand Up @@ -322,11 +323,15 @@
</#if>
<#if contact.organisationName?has_content>
,"affiliation":{
<#if contact.organisationIdentifier?matches("^https://ror\\.org/\\w{8,10}$")>
"@id": "${contact.organisationIdentifier}"
<#else>
"@type":"Organization",
"name":"${contact.organisationName}"
<#if contact.organisationIdentifier?has_content>
,"identifier":"${contact.organisationIdentifier}"
</#if>
</#if>
}
</#if>
<#else>
Expand Down Expand Up @@ -405,3 +410,14 @@
],
</#if>
</#macro>

<#macro organisationRORs>
<#list authorPointOfContactWithRORs as contact>
{
"@id": "${contact.organisationIdentifier}",
"@type": "Organization",
"name": "${contact.organisationName}",
"identifier": "${contact.organisationIdentifier}"
}<#sep>,
</#list>
</#macro>

0 comments on commit 9e7d65b

Please sign in to comment.