From 3bf54e08180c3c39770714bd52e2d3fa310841b9 Mon Sep 17 00:00:00 2001 From: Stefano Maffei Date: Thu, 28 Sep 2023 18:03:46 +0200 Subject: [PATCH 1/2] [DSC-1271] orcid extras change --- .../content/authority/OrcidAuthority.java | 62 +++++++++++++++++-- .../org/dspace/app/rest/OrcidAuthorityIT.java | 4 +- dspace/config/modules/authority.cfg | 14 +++++ 3 files changed, 72 insertions(+), 8 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/content/authority/OrcidAuthority.java b/dspace-api/src/main/java/org/dspace/content/authority/OrcidAuthority.java index 4dfe09cdec6..8978c1f90fc 100644 --- a/dspace-api/src/main/java/org/dspace/content/authority/OrcidAuthority.java +++ b/dspace-api/src/main/java/org/dspace/content/authority/OrcidAuthority.java @@ -43,9 +43,9 @@ public class OrcidAuthority extends ItemAuthority { private static final Logger LOGGER = LoggerFactory.getLogger(OrcidAuthority.class); - public static final String ORCID_EXTRA = "data-person_identifier_orcid"; + public static final String DEFAULT_ORCID_KEY = "person_identifier_orcid"; - public static final String INSTITUTION_EXTRA = "institution-affiliation-name"; + public static final String DEFAULT_INSTITUTION_KEY = "institution-affiliation-name"; private ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); @@ -131,11 +131,24 @@ private String composeAuthorityValue(String orcid) { private Map composeExtras(ExpandedResult result) { Map extras = new HashMap<>(); - extras.put(ORCID_EXTRA, result.getOrcidId()); - + String orcidIdKey = getOrcidIdKey(); + String orcidId = result.getOrcidId(); + if (StringUtils.isNotBlank(orcidId)) { + if (useOrcidIDAsData()) { + extras.put("data-" + orcidIdKey, orcidId); + } + if (useOrcidIDForDisplaying()) { + extras.put(orcidIdKey, orcidId); + } + } + String institutionKey = getInstitutionKey(); String[] institutionNames = result.getInstitutionNames(); - if (ArrayUtils.isNotEmpty(institutionNames)) { - extras.put(INSTITUTION_EXTRA, String.join(", ", institutionNames)); + + if (ArrayUtils.isNotEmpty(institutionNames) && useInstitutionAsData()) { + extras.put("data-" + institutionKey, String.join(", ", institutionNames)); + } + if (ArrayUtils.isNotEmpty(institutionNames) && useInstitutionForDisplaying()) { + extras.put(institutionKey, String.join(", ", institutionNames)); } return extras; @@ -165,4 +178,41 @@ public static void setAccessToken(String accessToken) { OrcidAuthority.accessToken = accessToken; } + public String getOrcidIdKey() { + return configurationService.getProperty("cris.OrcidAuthority." + + getPluginInstanceName() + ".orcid-id.key", + DEFAULT_ORCID_KEY); + } + + public String getInstitutionKey() { + return configurationService.getProperty("cris.OrcidAuthority." + + getPluginInstanceName() + ".institution.key", + DEFAULT_INSTITUTION_KEY); + } + + public boolean useInstitutionAsData() { + return configurationService + .getBooleanProperty("cris.OrcidAuthority." + + getPluginInstanceName() + ".institution.as-data", true); + } + + public boolean useInstitutionForDisplaying() { + return configurationService + .getBooleanProperty("cris.OrcidAuthority." + + getPluginInstanceName() + ".institution.display", true); + } + + public boolean useOrcidIDAsData() { + return configurationService + .getBooleanProperty("cris.OrcidAuthority." + + getPluginInstanceName() + ".orcid-id.as-data", true); + } + + public boolean useOrcidIDForDisplaying() { + return configurationService + .getBooleanProperty("cris.OrcidAuthority." + + getPluginInstanceName() + ".orcid-id.display", true); + + } + } diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/OrcidAuthorityIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/OrcidAuthorityIT.java index 2eb9cae64ae..ab18851e798 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/OrcidAuthorityIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/OrcidAuthorityIT.java @@ -56,8 +56,8 @@ */ public class OrcidAuthorityIT extends AbstractControllerIntegrationTest { - private static final String ORCID_INFO = OrcidAuthority.ORCID_EXTRA; - private static final String ORCID_INSTITUTION = OrcidAuthority.INSTITUTION_EXTRA; + private static final String ORCID_INFO = OrcidAuthority.DEFAULT_ORCID_KEY; + private static final String ORCID_INSTITUTION = OrcidAuthority.DEFAULT_INSTITUTION_KEY; private static final String READ_PUBLIC_TOKEN = "062d9f30-7e11-47ef-bd95-eaa2f2452565"; diff --git a/dspace/config/modules/authority.cfg b/dspace/config/modules/authority.cfg index 790489d15d5..0b78af0d453 100644 --- a/dspace/config/modules/authority.cfg +++ b/dspace/config/modules/authority.cfg @@ -112,6 +112,20 @@ cris.ItemAuthority.FundingAuthority.entityType = Funding cris.ItemAuthority.PublicationAuthority.entityType = Publication cris.ItemAuthority.EquipmentAuthority.entityType = Equipment +## OrcidAuthority Extras configuration +# + +cris.OrcidAuthority.EditorAuthority.institution.key = oairecerif_editor_affiliation +cris.OrcidAuthority.AuthorAuthority.institution.key = oairecerif_author_affiliation + +#cris.OrcidAuthority.AuthorAuthority.institution.display = true +#cris.OrcidAuthority.AuthorAuthority.institution.as-data = true +# +#cris.OrcidAuthority.AuthorAuthority.orcid-id.key = person_identifier_orcid +#cris.OrcidAuthority.AuthorAuthority.orcid-id.display = true +#cris.OrcidAuthority.AuthorAuthority.orcid-id.as-data = true + + cris.SherpaAuthority.entityType = Journal cris.SherpaAuthority.local-item-choices-enabled = true From 29f91362fead28b52416a05b184989496eb4230a Mon Sep 17 00:00:00 2001 From: eskander Date: Mon, 2 Oct 2023 14:33:33 +0300 Subject: [PATCH 2/2] [DSC-1271] fixed broken ITs --- .../org/dspace/app/rest/OrcidAuthorityIT.java | 19 +++++++++++++------ .../rest/matcher/ItemAuthorityMatcher.java | 19 +++++++++++++++++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/OrcidAuthorityIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/OrcidAuthorityIT.java index ab18851e798..a92253e5443 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/OrcidAuthorityIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/OrcidAuthorityIT.java @@ -600,8 +600,8 @@ public void testWithAffiliationExtra() throws Exception { .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.entries", containsInAnyOrder( orcidEntry("Author From Orcid 1", REFERENCE, "0000-1111-2222-3333"), - orcidEntryWithInstitution("Author From Orcid 2", REFERENCE, "0000-2222-3333-4444", "Org1, Org2"), - orcidEntryWithInstitution("Author From Orcid 3", REFERENCE, "0000-5555-6666-7777", "Organization")))) + orcidEntryWithAffiliation("Author From Orcid 2", REFERENCE, "0000-2222-3333-4444", "Org1, Org2"), + orcidEntryWithAffiliation("Author From Orcid 3", REFERENCE, "0000-5555-6666-7777", "Organization")))) .andExpect(jsonPath("$.page.size", Matchers.is(20))) .andExpect(jsonPath("$.page.totalPages", Matchers.is(1))) .andExpect(jsonPath("$.page.totalElements", Matchers.is(3))); @@ -679,11 +679,18 @@ private Matcher orcidEntry(String title, String authorityPrefix, title, "vocabularyEntry", ORCID_INFO, orcid); } - private Matcher orcidEntryWithInstitution(String title, String authorityPrefix, - String orcid, String institutions) { + private Matcher orcidEntryWithAffiliation(String title, String authorityPrefix, + String orcid, String affiliation) { String authority = authorityPrefix + "ORCID::" + orcid; - return ItemAuthorityMatcher.matchItemAuthorityWithTwoMetadataInOtherInformations(authority, title, - title, "vocabularyEntry", ORCID_INFO, orcid, ORCID_INSTITUTION, institutions); + return ItemAuthorityMatcher.matchItemAuthorityWithTwoMetadataInOtherInformations( + authority, title, title, "vocabularyEntry", + Map.of( + "data-" + ORCID_INFO, orcid, + ORCID_INFO, orcid, + "data-oairecerif_author_affiliation", affiliation, + "oairecerif_author_affiliation", affiliation + ) + ); } private String id(Item item) { diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/ItemAuthorityMatcher.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/ItemAuthorityMatcher.java index df20e0f65e1..27e9ffafc1a 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/ItemAuthorityMatcher.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/ItemAuthorityMatcher.java @@ -42,8 +42,9 @@ public static Matcher matchItemAuthorityWithOtherInformations(St hasJsonPath("$.display", is(display)), hasJsonPath("$.value", is(value)), hasJsonPath("$.type", is(type)), - hasJsonPath("$.otherInformation", aMapWithSize(1)), - hasJsonPath("$.otherInformation['" + otherInfMetadata + "']", is(metadataValue)) + hasJsonPath("$.otherInformation", aMapWithSize(2)), + hasJsonPath("$.otherInformation['" + otherInfMetadata + "']", is(metadataValue)), + hasJsonPath("$.otherInformation['" + "data-" + otherInfMetadata + "']", is(metadataValue)) ); } @@ -73,4 +74,18 @@ public static Matcher matchItemAuthorityWithTwoMetadataInOtherIn ) ); } + + public static Matcher matchItemAuthorityWithTwoMetadataInOtherInformations(String authority, + String display, String value, String type, Map orcidAndAffiliation) { + return allOf( + hasJsonPath("$.authority", is(authority)), + hasJsonPath("$.display", is(display)), + hasJsonPath("$.value", is(value)), + hasJsonPath("$.type", is(type)), + hasJsonPath("$.otherInformation", aMapWithSize(4)), + allOf ( + hasJsonPath("$.otherInformation", is(orcidAndAffiliation)) + ) + ); + } }