Skip to content

Commit 55da2ca

Browse files
author
mohamed eskander
committed
[DSC-1497] refactoring and adding more ITs
1 parent 135be84 commit 55da2ca

File tree

6 files changed

+153
-87
lines changed

6 files changed

+153
-87
lines changed

dspace-api/src/main/java/org/dspace/content/authority/ItemAuthority.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class ItemAuthority implements ChoiceAuthority, LinkableEntityAuthority {
7979
// map of field key to presentation type
8080
protected Map<String, String> externalSource = new HashMap<String, String>();
8181

82-
private String source;
82+
public static final String DEFAULT = "local";
8383

8484
// punt! this is a poor implementation..
8585
@Override
@@ -176,7 +176,7 @@ private List<Choice> getChoiceListFromQueryResults(SolrDocumentList results, Str
176176
Map<String, String> extras = ItemAuthorityUtils.buildExtra(getPluginInstanceName(), doc);
177177
return new Choice((String) doc.getFieldValue("search.resourceid"),
178178
title,
179-
title, extras, getSource());
179+
title, extras, DEFAULT);
180180
}).collect(Collectors.toList());
181181
}
182182

@@ -299,9 +299,9 @@ private Context getContext() {
299299
return context != null ? context : new Context();
300300
}
301301

302-
public String getSource() {
302+
protected String getSource() {
303303
return configurationService.getProperty(
304-
"cris.ItemAuthority." + authorityName + ".source", "local");
304+
"cris.ItemAuthority." + authorityName + ".source", DEFAULT);
305305
}
306306

307307
}

dspace-server-webapp/src/test/java/org/dspace/app/rest/ItemAuthorityIT.java

+4-78
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.dspace.builder.ItemBuilder;
3030
import org.dspace.content.Collection;
3131
import org.dspace.content.Item;
32+
import org.dspace.content.authority.ItemAuthority;
3233
import org.dspace.content.authority.service.ChoiceAuthorityService;
3334
import org.dspace.core.service.PluginService;
3435
import org.dspace.eperson.EPerson;
@@ -265,7 +266,7 @@ public void singleItemAuthorityWithoutOrgUnitTest() throws Exception {
265266
Map.of("data-oairecerif_author_affiliation", "", "oairecerif_author_affiliation", "",
266267
"data-person_identifier_orcid", "",
267268
"person_identifier_orcid", ""),
268-
"local")
269+
ItemAuthority.DEFAULT)
269270
)))
270271
.andExpect(jsonPath("$.page.totalElements", Matchers.is(1)));
271272
}
@@ -889,81 +890,6 @@ public void authorCoarseAuthorityTests() throws Exception {
889890
person4Id, "Cortese, Claudio", "Cortese, Claudio", "vocabularyEntry"))));
890891
}
891892

892-
@Test
893-
public void orcidAuthoritySourceReferenceTest() throws Exception {
894-
context.turnOffAuthorisationSystem();
895-
896-
configurationService.setProperty("plugin.named.org.dspace.content.authority.ChoiceAuthority",
897-
new String[] {
898-
"org.dspace.content.authority.OrcidAuthority=AuthorAuthority"
899-
});
900-
901-
configurationService.setProperty("solr.authority.server", "${solr.server}/authority");
902-
configurationService.setProperty("choices.plugin.dc.contributor.author", "AuthorAuthority");
903-
configurationService.setProperty("choices.presentation.dc.contributor.author", "suggest");
904-
configurationService.setProperty("authority.controlled.dc.contributor.author", "true");
905-
906-
// set authority source reference
907-
configurationService.setProperty("cris.ItemAuthority.AuthorAuthority.source", "ORCID");
908-
909-
// These clears have to happen so that the config is actually reloaded in those classes. This is needed for
910-
// the properties that we're altering above and this is only used within the tests
911-
pluginService.clearNamedPluginClasses();
912-
choiceAuthorityService.clearCache();
913-
914-
parentCommunity = CommunityBuilder.createCommunity(context).build();
915-
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).build();
916-
917-
Item orgUnit_1 = ItemBuilder.createItem(context, col1)
918-
.withTitle("OrgUnit_1")
919-
.withEntityType("orgunit")
920-
.build();
921-
922-
Item orgUnit_2 = ItemBuilder.createItem(context, col1)
923-
.withTitle("OrgUnit_2")
924-
.withEntityType("orgunit")
925-
.build();
926-
927-
Item author_1 = ItemBuilder.createItem(context, col1)
928-
.withTitle("Author 1")
929-
.withPersonMainAffiliation(orgUnit_1.getName(), orgUnit_1.getID().toString())
930-
.withEntityType("person")
931-
.build();
932-
933-
Item author_2 = ItemBuilder.createItem(context, col1)
934-
.withTitle("Author 2")
935-
.withPersonMainAffiliation(orgUnit_2.getName(), orgUnit_2.getID().toString())
936-
.withEntityType("person")
937-
.build();
938-
939-
context.restoreAuthSystemState();
940-
941-
String token = getAuthToken(eperson.getEmail(), password);
942-
getClient(token).perform(get("/api/submission/vocabularies/AuthorAuthority/entries")
943-
.param("metadata", "dc.contributor.author")
944-
.param("collection", col1.getID().toString())
945-
.param("filter", "author"))
946-
.andExpect(status().isOk())
947-
.andExpect(jsonPath("$._embedded.entries", Matchers.containsInAnyOrder(
948-
// filled with AuthorAuthority extra metadata generator
949-
ItemAuthorityMatcher.matchItemAuthorityWithOtherInformations(author_1.getID().toString(),
950-
"Author 1", "Author 1", "vocabularyEntry",
951-
Map.of("data-oairecerif_author_affiliation", "OrgUnit_1::" + orgUnit_1.getID(),
952-
"oairecerif_author_affiliation", "OrgUnit_1::" + orgUnit_1.getID(),
953-
"data-person_identifier_orcid", "",
954-
"person_identifier_orcid", ""),
955-
"ORCID"),
956-
ItemAuthorityMatcher.matchItemAuthorityWithOtherInformations(author_2.getID().toString(),
957-
"Author 2", "Author 2", "vocabularyEntry",
958-
Map.of("data-oairecerif_author_affiliation", "OrgUnit_2::" + orgUnit_2.getID(),
959-
"oairecerif_author_affiliation", "OrgUnit_2::" + orgUnit_2.getID(),
960-
"data-person_identifier_orcid", "",
961-
"person_identifier_orcid", ""),
962-
"ORCID")
963-
)))
964-
.andExpect(jsonPath("$.page.totalElements", Matchers.is(2)));
965-
}
966-
967893
@Test
968894
public void itemAuthoritySourceReferenceTest() throws Exception {
969895
context.turnOffAuthorisationSystem();
@@ -1012,8 +938,8 @@ public void itemAuthoritySourceReferenceTest() throws Exception {
1012938
.andExpect(status().isOk()).andExpect(jsonPath("$.page.totalElements", Matchers.is(1)))
1013939
.andExpect(jsonPath("$._embedded.entries",
1014940
Matchers.containsInAnyOrder(ItemAuthorityMatcher.matchItemAuthorityWithOtherInformations(
1015-
person1.getID().toString(), "Person 1", "Person 1", "vocabularyEntry", Map.of(), "ORCID"))));
1016-
941+
person1.getID().toString(), "Person 1", "Person 1", "vocabularyEntry", Map.of(),
942+
ItemAuthority.DEFAULT))));
1017943
}
1018944

1019945
@Override

dspace-server-webapp/src/test/java/org/dspace/app/rest/OrcidAuthorityIT.java

+107
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.dspace.builder.ItemBuilder;
3232
import org.dspace.content.Collection;
3333
import org.dspace.content.Item;
34+
import org.dspace.content.authority.ItemAuthority;
3435
import org.dspace.content.authority.OrcidAuthority;
3536
import org.dspace.orcid.client.OrcidClient;
3637
import org.dspace.orcid.client.OrcidConfiguration;
@@ -712,6 +713,101 @@ public void testWithAffiliationExtra() throws Exception {
712713
verifyNoMoreInteractions(orcidClientMock);
713714
}
714715

716+
@Test
717+
public void testSourceReference() throws Exception {
718+
719+
List<ExpandedResult> orcidSearchResults = List.of(
720+
expandedResult("Author", "From Orcid 1", "0000-1111-2222-3333"),
721+
expandedResult("AUTHOR", "FROM ORCID 2", "0000-2222-3333-4444"));
722+
723+
String expectedQuery = "(given-names:author+OR+family-name:author+OR+other-names:author)";
724+
725+
when(orcidClientMock.expandedSearch(READ_PUBLIC_TOKEN, expectedQuery, 0, 20))
726+
.thenReturn(expandedSearch(2, orcidSearchResults));
727+
728+
String token = getAuthToken(eperson.getEmail(), password);
729+
getClient(token).perform(get("/api/submission/vocabularies/AuthorAuthority/entries")
730+
.param("filter", "author"))
731+
.andExpect(status().isOk())
732+
.andExpect(jsonPath("$._embedded.entries", containsInAnyOrder(
733+
orcidEntry("From Orcid 1 Author", REFERENCE, "0000-1111-2222-3333", getSource()),
734+
orcidEntry("From Orcid 2 Author", REFERENCE, "0000-2222-3333-4444", getSource()))))
735+
.andExpect(jsonPath("$.page.size", Matchers.is(20)))
736+
.andExpect(jsonPath("$.page.totalPages", Matchers.is(1)))
737+
.andExpect(jsonPath("$.page.totalElements", Matchers.is(2)));
738+
739+
verify(orcidClientMock).getReadPublicAccessToken();
740+
verify(orcidClientMock).expandedSearch(READ_PUBLIC_TOKEN, expectedQuery, 0, 20);
741+
verifyNoMoreInteractions(orcidClientMock);
742+
}
743+
744+
@Test
745+
public void testMultipleSourcesReferences() throws Exception {
746+
context.turnOffAuthorisationSystem();
747+
748+
List<ExpandedResult> orcidSearchResults = List.of(
749+
expandedResult("Author", "From Orcid 1", "0000-1111-2222-3333"),
750+
expandedResult("AUTHOR", "FROM ORCID 2", "0000-2222-3333-4444"));
751+
752+
String expectedQuery = "(given-names:author+OR+family-name:author+OR+other-names:author)";
753+
754+
when(orcidClientMock.expandedSearch(READ_PUBLIC_TOKEN, expectedQuery, 0, 18))
755+
.thenReturn(expandedSearch(2, orcidSearchResults));
756+
757+
parentCommunity = CommunityBuilder.createCommunity(context).build();
758+
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).build();
759+
760+
Item orgUnit_1 = ItemBuilder.createItem(context, col1)
761+
.withTitle("OrgUnit_1")
762+
.withEntityType("orgunit")
763+
.build();
764+
765+
Item orgUnit_2 = ItemBuilder.createItem(context, col1)
766+
.withTitle("OrgUnit_2")
767+
.withEntityType("orgunit")
768+
.build();
769+
770+
Item author_1 = ItemBuilder.createItem(context, col1)
771+
.withTitle("Author 1")
772+
.withPersonMainAffiliation(orgUnit_1.getName(), orgUnit_1.getID().toString())
773+
.withEntityType("person")
774+
.build();
775+
776+
Item author_2 = ItemBuilder.createItem(context, col1)
777+
.withTitle("Author 2")
778+
.withPersonMainAffiliation(orgUnit_2.getName(), orgUnit_2.getID().toString())
779+
.withEntityType("person")
780+
.build();
781+
782+
context.restoreAuthSystemState();
783+
784+
String token = getAuthToken(eperson.getEmail(), password);
785+
getClient(token).perform(get("/api/submission/vocabularies/AuthorAuthority/entries")
786+
.param("filter", "author"))
787+
.andExpect(status().isOk())
788+
.andExpect(jsonPath("$._embedded.entries", Matchers.containsInAnyOrder(
789+
// source should be local
790+
ItemAuthorityMatcher.matchItemAuthorityWithOtherInformations(author_1.getID().toString(),
791+
"Author 1", "Author 1", "vocabularyEntry",
792+
Map.of("data-oairecerif_author_affiliation", "OrgUnit_1::" + orgUnit_1.getID(),
793+
"oairecerif_author_affiliation", "OrgUnit_1::" + orgUnit_1.getID(),
794+
"data-person_identifier_orcid", "",
795+
"person_identifier_orcid", ""),
796+
ItemAuthority.DEFAULT),
797+
ItemAuthorityMatcher.matchItemAuthorityWithOtherInformations(author_2.getID().toString(),
798+
"Author 2", "Author 2", "vocabularyEntry",
799+
Map.of("data-oairecerif_author_affiliation", "OrgUnit_2::" + orgUnit_2.getID(),
800+
"oairecerif_author_affiliation", "OrgUnit_2::" + orgUnit_2.getID(),
801+
"data-person_identifier_orcid", "",
802+
"person_identifier_orcid", ""),
803+
ItemAuthority.DEFAULT),
804+
// source should be orcid as configured
805+
orcidEntry("From Orcid 1 Author", REFERENCE, "0000-1111-2222-3333", getSource()),
806+
orcidEntry("From Orcid 2 Author", REFERENCE, "0000-2222-3333-4444", getSource())
807+
)))
808+
.andExpect(jsonPath("$.page.totalElements", Matchers.is(4)));
809+
}
810+
715811
private ExpandedSearch buildExpandedSearchFromSublist(List<ExpandedResult> totalResults, int start, int rows) {
716812
int total = totalResults.size();
717813
if (start > total) {
@@ -783,6 +879,12 @@ private Matcher<? super Object> orcidEntry(String title, String authorityPrefix,
783879
title, "vocabularyEntry", ORCID_INFO, orcid);
784880
}
785881

882+
private Matcher<? super Object> orcidEntry(String title, String authorityPrefix, String orcid, String source) {
883+
String authority = authorityPrefix + "ORCID::" + orcid;
884+
return ItemAuthorityMatcher.matchItemAuthorityWithOtherInformations(authority, title,
885+
title, "vocabularyEntry", ORCID_INFO, orcid, source);
886+
}
887+
786888
private Matcher<? super Object> orcidEntryWithAffiliation(String title, String authorityPrefix,
787889
String orcid, String affiliation) {
788890
String authority = authorityPrefix + "ORCID::" + orcid;
@@ -800,4 +902,9 @@ private Matcher<? super Object> orcidEntryWithAffiliation(String title, String a
800902
private String id(Item item) {
801903
return item.getID().toString();
802904
}
905+
906+
private String getSource() {
907+
return configurationService.getProperty(
908+
"cris.ItemAuthority.AuthorAuthority.source", ItemAuthority.DEFAULT);
909+
}
803910
}

dspace-server-webapp/src/test/java/org/dspace/app/rest/ZDBAuthorityIT.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313

1414
import org.dspace.app.rest.matcher.ItemAuthorityMatcher;
1515
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
16+
import org.dspace.content.authority.ItemAuthority;
17+
import org.dspace.services.ConfigurationService;
1618
import org.hamcrest.Matchers;
1719
import org.junit.Test;
20+
import org.springframework.beans.factory.annotation.Autowired;
1821

1922
/**
2023
* This class handles ZDBAuthority related IT.
@@ -23,6 +26,9 @@
2326
*/
2427
public class ZDBAuthorityIT extends AbstractControllerIntegrationTest {
2528

29+
@Autowired
30+
private ConfigurationService configurationService;
31+
2632
@Test
2733
public void zdbAuthorityTest() throws Exception {
2834
String token = getAuthToken(eperson.getEmail(), password);
@@ -35,21 +41,21 @@ public void zdbAuthorityTest() throws Exception {
3541
"will be generated::zdb::1447228-4", "Acta mathematica et informatica",
3642
"Acta mathematica et informatica", "vocabularyEntry", "data-dc_relation_ispartof",
3743
"Acta mathematica et informatica::will be generated::zdb::1447228-4",
38-
"data-dc_relation_issn", ""),
44+
"data-dc_relation_issn", "", getSource()),
3945
ItemAuthorityMatcher.matchItemAuthorityWithTwoMetadataInOtherInformations(
4046
"will be generated::zdb::1194912-0",
4147
"Acta mathematica Universitatis Ostraviensis",
4248
"Acta mathematica Universitatis Ostraviensis", "vocabularyEntry",
4349
"data-dc_relation_ispartof",
4450
"Acta mathematica Universitatis Ostraviensis::will be generated::zdb::1194912-0",
45-
"data-dc_relation_issn", "1211-4774"),
51+
"data-dc_relation_issn", "1211-4774", getSource()),
4652
ItemAuthorityMatcher.matchItemAuthorityWithTwoMetadataInOtherInformations(
4753
"will be generated::zdb::2618143-5",
4854
"Acta mathematica Universitatis Ostraviensis",
4955
"Acta mathematica Universitatis Ostraviensis", "vocabularyEntry",
5056
"data-dc_relation_ispartof",
5157
"Acta mathematica Universitatis Ostraviensis::will be generated::zdb::2618143-5",
52-
"data-dc_relation_issn", ""))))
58+
"data-dc_relation_issn", "", getSource()))))
5359
.andExpect(jsonPath("$.page.totalElements", Matchers.is(3)));
5460
}
5561

@@ -67,4 +73,9 @@ public void zdbAuthorityUnauthorizedTest() throws Exception {
6773
.param("filter", "Mathematica AND informatica"))
6874
.andExpect(status().isUnauthorized());
6975
}
76+
77+
private String getSource() {
78+
return configurationService.getProperty(
79+
"cris.ItemAuthority.ZDBAuthority.source", ItemAuthority.DEFAULT);
80+
}
7081
}

dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/ItemAuthorityMatcher.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ public static Matcher<? super Object> matchItemAuthorityWithOtherInformations(St
4848
);
4949
}
5050

51+
public static Matcher<? super Object> matchItemAuthorityWithOtherInformations(String authority, String display,
52+
String value, String type, String otherInfMetadata, String metadataValue, String source) {
53+
return allOf(
54+
hasJsonPath("$.authority", is(authority)),
55+
hasJsonPath("$.display", is(display)),
56+
hasJsonPath("$.value", is(value)),
57+
hasJsonPath("$.type", is(type)),
58+
hasJsonPath("$.source", is(source)),
59+
hasJsonPath("$.otherInformation", aMapWithSize(2)),
60+
hasJsonPath("$.otherInformation['" + otherInfMetadata + "']", is(metadataValue)),
61+
hasJsonPath("$.otherInformation['" + "data-" + otherInfMetadata + "']", is(metadataValue))
62+
);
63+
}
64+
5165
public static Matcher<? super Object> matchItemAuthorityWithOtherInformations(String authority, String display,
5266
String value, String type, Map<String, String> otherInformation) {
5367
return allOf(
@@ -73,12 +87,13 @@ public static Matcher<? super Object> matchItemAuthorityWithOtherInformations(St
7387

7488
public static Matcher<? super Object> matchItemAuthorityWithTwoMetadataInOtherInformations(String authority,
7589
String display, String value, String type, String firstOtherMetadata, String firstOtherValue,
76-
String secondOtherMetadata, String secondOtherValue) {
90+
String secondOtherMetadata, String secondOtherValue, String source) {
7791
return allOf(
7892
hasJsonPath("$.authority", is(authority)),
7993
hasJsonPath("$.display", is(display)),
8094
hasJsonPath("$.value", is(value)),
8195
hasJsonPath("$.type", is(type)),
96+
hasJsonPath("$.source", is(source)),
8297
hasJsonPath("$.otherInformation", aMapWithSize(2)),
8398
allOf (
8499
hasJsonPath("$.otherInformation." + firstOtherMetadata, is(firstOtherValue)),

0 commit comments

Comments
 (0)