From a6992efd45d72a3cc1ee515ad7af88047d8ddf70 Mon Sep 17 00:00:00 2001 From: Samuel Date: Tue, 7 Dec 2021 11:21:21 +0100 Subject: [PATCH 1/6] taskid 85555 Custom DSpaceControlledVocabulary for WB syntax --- .../WbDSpaceControlledVocabulary.java | 30 ++++ .../test/data/dspaceFolder/config/local.cfg | 2 +- .../DSpaceControlledVocabularyTest.java | 2 +- ...aryEntryDetailsChildrenLinkRepository.java | 2 +- ...ularyEntryDetailsParentLinkRepository.java | 2 +- .../VocabularyEntryDetailsRestRepository.java | 4 +- .../app/rest/WbVocabularyEntryDetailsIT.java | 52 +++++++ .../app/rest/VocabularyEntryDetailsIT.java | 136 +++++++++--------- .../app/rest/VocabularyRestRepositoryIT.java | 4 +- dspace/config/dspace.cfg | 2 +- 10 files changed, 159 insertions(+), 77 deletions(-) create mode 100644 dspace-api/src/main/java/com/atmire/dspace/content/authority/WbDSpaceControlledVocabulary.java create mode 100644 dspace-server-webapp/src/test/java/com/atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java diff --git a/dspace-api/src/main/java/com/atmire/dspace/content/authority/WbDSpaceControlledVocabulary.java b/dspace-api/src/main/java/com/atmire/dspace/content/authority/WbDSpaceControlledVocabulary.java new file mode 100644 index 0000000000..ed05325ace --- /dev/null +++ b/dspace-api/src/main/java/com/atmire/dspace/content/authority/WbDSpaceControlledVocabulary.java @@ -0,0 +1,30 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package com.atmire.dspace.content.authority; + +import org.dspace.content.authority.DSpaceControlledVocabulary; +import org.w3c.dom.Node; + +public class WbDSpaceControlledVocabulary extends DSpaceControlledVocabulary { + + @Override + protected void init() { + super.init(); + hierarchyDelimiter = " " + hierarchyDelimiter + " "; + } + + protected String buildString(Node node) { + if (node.getNodeType() == Node.DOCUMENT_NODE || ( + node.getParentNode() != null && + node.getParentNode().getNodeType() == Node.DOCUMENT_NODE)) { + return (""); + } else { + return super.buildString(node); + } + } +} diff --git a/dspace-api/src/test/data/dspaceFolder/config/local.cfg b/dspace-api/src/test/data/dspaceFolder/config/local.cfg index 3c19a68e9f..74e3e14d6a 100644 --- a/dspace-api/src/test/data/dspaceFolder/config/local.cfg +++ b/dspace-api/src/test/data/dspaceFolder/config/local.cfg @@ -97,7 +97,7 @@ event.dispatcher.exclude-discovery.consumers = versioning, eperson # (This overrides default, commented out settings in dspace.cfg) plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \ org.dspace.content.authority.DCInputAuthority, \ - org.dspace.content.authority.DSpaceControlledVocabulary + com.atmire.dspace.content.authority.WbDSpaceControlledVocabulary # Configure some more Plugins for PluginTest class # NOTE: Plugins are just *interfaces*. So, here we are defining some plugins diff --git a/dspace-api/src/test/java/org/dspace/content/authority/DSpaceControlledVocabularyTest.java b/dspace-api/src/test/java/org/dspace/content/authority/DSpaceControlledVocabularyTest.java index 7ade9c582d..255b070e5e 100644 --- a/dspace-api/src/test/java/org/dspace/content/authority/DSpaceControlledVocabularyTest.java +++ b/dspace-api/src/test/java/org/dspace/content/authority/DSpaceControlledVocabularyTest.java @@ -86,7 +86,7 @@ public class DSpaceControlledVocabularyTest extends AbstractDSpaceTest { CoreServiceFactory.getInstance().getPluginService().getNamedPlugin(Class.forName(PLUGIN_INTERFACE), "farm"); assertNotNull(instance); Choices result = instance.getMatches(text, start, limit, locale); - assertEquals("the farm::north 40", result.values[0].value); + assertEquals("north 40", result.values[0].value); } /** diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsChildrenLinkRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsChildrenLinkRepository.java index 044710d25b..1788fa893b 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsChildrenLinkRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsChildrenLinkRepository.java @@ -45,7 +45,7 @@ public class VocabularyEntryDetailsChildrenLinkRepository extends AbstractDSpace @Autowired private AuthorityUtils authorityUtils; - @PreAuthorize("hasAuthority('AUTHENTICATED')") + @PreAuthorize("permitAll()") public Page getChildren(@Nullable HttpServletRequest request, String name, @Nullable Pageable optionalPageable, Projection projection) { diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsParentLinkRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsParentLinkRepository.java index 379928d9cc..d7a1ff85c3 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsParentLinkRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsParentLinkRepository.java @@ -40,7 +40,7 @@ public class VocabularyEntryDetailsParentLinkRepository extends AbstractDSpaceRe @Autowired private AuthorityUtils authorityUtils; - @PreAuthorize("hasAuthority('AUTHENTICATED')") + @PreAuthorize("permitAll()") public VocabularyEntryDetailsRest getParent(@Nullable HttpServletRequest request, String name, @Nullable Pageable optionalPageable, Projection projection) { Context context = obtainContext(); diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsRestRepository.java index c206721361..911a4ae49b 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsRestRepository.java @@ -60,13 +60,13 @@ public class VocabularyEntryDetailsRestRepository extends DSpaceRestRepository findAll(Context context, Pageable pageable) { throw new RepositoryMethodNotImplementedException(ResourcePolicyRest.NAME, "findAll"); } - @PreAuthorize("hasAuthority('AUTHENTICATED')") + @PreAuthorize("permitAll()") @Override public VocabularyEntryDetailsRest findOne(Context context, String name) { String[] parts = StringUtils.split(name, ":", 2); diff --git a/dspace-server-webapp/src/test/java/com/atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java b/dspace-server-webapp/src/test/java/com/atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java new file mode 100644 index 0000000000..cd7baae915 --- /dev/null +++ b/dspace-server-webapp/src/test/java/com/atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java @@ -0,0 +1,52 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package com.atmire.dspace.app.rest; + +import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath; +import static org.hamcrest.Matchers.everyItem; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.startsWith; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.dspace.app.rest.test.AbstractControllerIntegrationTest; +import org.junit.Test; + +public class WbVocabularyEntryDetailsIT extends AbstractControllerIntegrationTest { + + @Test + public void testCustomWbSyntax() throws Exception { + + String token = getAuthToken(eperson.getEmail(), password); + + getClient(token) + .perform(get("/api/submission/vocabularyEntryDetails/topics:Information_Technology")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.value", is( + "Information and Communication Technologies :: Information Technology" + ))); + + getClient(token) + .perform(get("/api/submission/vocabularies/topics/entries") + .param("filter", "Information and Communication Technologies :: Information Technology") + .param("exact", "true")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$._embedded.entries[0].value", is( + "Information and Communication Technologies :: Information Technology" + ))); + + getClient(token) + .perform(get("/api/submission/vocabularyEntryDetails/search/top?vocabulary=topics")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$._embedded.vocabularyEntryDetails", everyItem( + hasJsonPath("$.value", not(startsWith("Topics:"))) + ))); + } +} diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyEntryDetailsIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyEntryDetailsIT.java index 4962e1aef2..a580c28c92 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyEntryDetailsIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyEntryDetailsIT.java @@ -57,12 +57,12 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(status().isOk()) .andExpect(jsonPath("$", VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB110", "Religion/Theology", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology"))) + "HUMANITIES and RELIGION :: Religion/Theology"))) .andExpect(jsonPath("$.selectable", is(true))) .andExpect(jsonPath("$.otherInformation.id", is("SCB110"))) .andExpect(jsonPath("$.otherInformation.note", is("Religionsvetenskap/Teologi"))) .andExpect(jsonPath("$.otherInformation.parent", - is("Research Subject Categories::HUMANITIES and RELIGION"))) + is("HUMANITIES and RELIGION"))) .andExpect(jsonPath("$._links.parent.href", endsWith("api/submission/vocabularyEntryDetails/srsc:SCB110/parent"))) .andExpect(jsonPath("$._links.children.href", @@ -73,7 +73,7 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest public void findOneUnauthorizedTest() throws Exception { String idAuthority = "srsc:SCB110"; getClient().perform(get("/api/submission/vocabularyEntryDetails/" + idAuthority)) - .andExpect(status().isUnauthorized()); + .andExpect(status().isOk()); } @Test @@ -102,30 +102,30 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.vocabularyEntryDetails", Matchers.containsInAnyOrder( VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB11", "HUMANITIES and RELIGION", - "Research Subject Categories::HUMANITIES and RELIGION"), + "HUMANITIES and RELIGION"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB12", "LAW/JURISPRUDENCE", - "Research Subject Categories::LAW/JURISPRUDENCE"), + "LAW/JURISPRUDENCE"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB13", "SOCIAL SCIENCES", - "Research Subject Categories::SOCIAL SCIENCES"), + "SOCIAL SCIENCES"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB14", "MATHEMATICS", - "Research Subject Categories::MATHEMATICS"), + "MATHEMATICS"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB15", "NATURAL SCIENCES", - "Research Subject Categories::NATURAL SCIENCES"), + "NATURAL SCIENCES"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB16", "TECHNOLOGY", - "Research Subject Categories::TECHNOLOGY"), + "TECHNOLOGY"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB17", "FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING", - "Research Subject Categories::FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING"), + "FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB18", "MEDICINE", - "Research Subject Categories::MEDICINE"), + "MEDICINE"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB19", "ODONTOLOGY", - "Research Subject Categories::ODONTOLOGY"), + "ODONTOLOGY"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB21", "PHARMACY", - "Research Subject Categories::PHARMACY"), + "PHARMACY"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB22", "VETERINARY MEDICINE", - "Research Subject Categories::VETERINARY MEDICINE"), + "VETERINARY MEDICINE"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB23", "INTERDISCIPLINARY RESEARCH AREAS", - "Research Subject Categories::INTERDISCIPLINARY RESEARCH AREAS") + "INTERDISCIPLINARY RESEARCH AREAS") ))) .andExpect(jsonPath("$.page.totalElements", Matchers.is(12))); @@ -134,30 +134,30 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.vocabularyEntryDetails", Matchers.containsInAnyOrder( VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB11", "HUMANITIES and RELIGION", - "Research Subject Categories::HUMANITIES and RELIGION"), + "HUMANITIES and RELIGION"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB12", "LAW/JURISPRUDENCE", - "Research Subject Categories::LAW/JURISPRUDENCE"), + "LAW/JURISPRUDENCE"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB13", "SOCIAL SCIENCES", - "Research Subject Categories::SOCIAL SCIENCES"), + "SOCIAL SCIENCES"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB14", "MATHEMATICS", - "Research Subject Categories::MATHEMATICS"), + "MATHEMATICS"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB15", "NATURAL SCIENCES", - "Research Subject Categories::NATURAL SCIENCES"), + "NATURAL SCIENCES"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB16", "TECHNOLOGY", - "Research Subject Categories::TECHNOLOGY"), + "TECHNOLOGY"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB17", "FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING", - "Research Subject Categories::FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING"), + "FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB18", "MEDICINE", - "Research Subject Categories::MEDICINE"), + "MEDICINE"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB19", "ODONTOLOGY", - "Research Subject Categories::ODONTOLOGY"), + "ODONTOLOGY"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB21", "PHARMACY", - "Research Subject Categories::PHARMACY"), + "PHARMACY"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB22", "VETERINARY MEDICINE", - "Research Subject Categories::VETERINARY MEDICINE"), + "VETERINARY MEDICINE"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB23", "INTERDISCIPLINARY RESEARCH AREAS", - "Research Subject Categories::INTERDISCIPLINARY RESEARCH AREAS") + "INTERDISCIPLINARY RESEARCH AREAS") ))) .andExpect(jsonPath("$.page.totalElements", Matchers.is(12))); } @@ -170,14 +170,14 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(jsonPath("$._embedded.children", Matchers.containsInAnyOrder( VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB1401", "Algebra, geometry and mathematical analysis", - "Research Subject Categories::MATHEMATICS::Algebra, geometry and mathematical analysis"), + "MATHEMATICS :: Algebra, geometry and mathematical analysis"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB1402", "Applied mathematics", - "Research Subject Categories::MATHEMATICS::Applied mathematics"), + "MATHEMATICS :: Applied mathematics"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB1409", "Other mathematics", - "Research Subject Categories::MATHEMATICS::Other mathematics") + "MATHEMATICS :: Other mathematics") ))) .andExpect(jsonPath("$._embedded.children[*].otherInformation.parent", - Matchers.everyItem(is("Research Subject Categories::MATHEMATICS")))) + Matchers.everyItem(is("MATHEMATICS")))) .andExpect(jsonPath("$.page.totalElements", Matchers.is(3))); } @@ -191,15 +191,15 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.vocabularyEntryDetails", Matchers.containsInAnyOrder( VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB11", "HUMANITIES and RELIGION", - "Research Subject Categories::HUMANITIES and RELIGION"), + "HUMANITIES and RELIGION"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB12", "LAW/JURISPRUDENCE", - "Research Subject Categories::LAW/JURISPRUDENCE"), + "LAW/JURISPRUDENCE"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB13", "SOCIAL SCIENCES", - "Research Subject Categories::SOCIAL SCIENCES"), + "SOCIAL SCIENCES"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB14", "MATHEMATICS", - "Research Subject Categories::MATHEMATICS"), + "MATHEMATICS"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB15", "NATURAL SCIENCES", - "Research Subject Categories::NATURAL SCIENCES") + "NATURAL SCIENCES") ))) .andExpect(jsonPath("$.page.totalElements", is(12))) .andExpect(jsonPath("$.page.totalPages", is(3))) @@ -213,16 +213,16 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.vocabularyEntryDetails", Matchers.containsInAnyOrder( VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB16", "TECHNOLOGY", - "Research Subject Categories::TECHNOLOGY"), + "TECHNOLOGY"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB17", "FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING", - "Research Subject Categories::FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING"), + "FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB18", "MEDICINE", - "Research Subject Categories::MEDICINE"), + "MEDICINE"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB19", "ODONTOLOGY", - "Research Subject Categories::ODONTOLOGY"), + "ODONTOLOGY"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB21", "PHARMACY", - "Research Subject Categories::PHARMACY") + "PHARMACY") ))) .andExpect(jsonPath("$.page.totalElements", is(12))) .andExpect(jsonPath("$.page.totalPages", is(3))) @@ -236,9 +236,9 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.vocabularyEntryDetails", Matchers.containsInAnyOrder( VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB22", "VETERINARY MEDICINE", - "Research Subject Categories::VETERINARY MEDICINE"), + "VETERINARY MEDICINE"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB23", "INTERDISCIPLINARY RESEARCH AREAS", - "Research Subject Categories::INTERDISCIPLINARY RESEARCH AREAS") + "INTERDISCIPLINARY RESEARCH AREAS") ))) .andExpect(jsonPath("$.page.totalElements", is(12))) .andExpect(jsonPath("$.page.totalPages", is(3))) @@ -271,9 +271,9 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(jsonPath("$._embedded.children", Matchers.containsInAnyOrder( VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB1401", "Algebra, geometry and mathematical analysis", - "Research Subject Categories::MATHEMATICS::Algebra, geometry and mathematical analysis"), + "MATHEMATICS :: Algebra, geometry and mathematical analysis"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB1402", "Applied mathematics", - "Research Subject Categories::MATHEMATICS::Applied mathematics") + "MATHEMATICS :: Applied mathematics") ))) .andExpect(jsonPath("$.page.totalElements", is(3))) .andExpect(jsonPath("$.page.totalPages", is(2))) @@ -286,7 +286,7 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.children", Matchers.contains( VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:SCB1409", "Other mathematics", - "Research Subject Categories::MATHEMATICS::Other mathematics") + "MATHEMATICS :: Other mathematics") ))) .andExpect(jsonPath("$.page.totalElements", is(3))) .andExpect(jsonPath("$.page.totalPages", is(2))) @@ -300,13 +300,13 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.children", Matchers.containsInAnyOrder( VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR140202", "Numerical analysis", - "Research Subject Categories::MATHEMATICS::Applied mathematics::Numerical analysis"), + "MATHEMATICS :: Applied mathematics :: Numerical analysis"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR140203", "Mathematical statistics", - "Research Subject Categories::MATHEMATICS::Applied mathematics::Mathematical statistics"), + "MATHEMATICS :: Applied mathematics :: Mathematical statistics"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR140204", "Optimization, systems theory", - "Research Subject Categories::MATHEMATICS::Applied mathematics::Optimization, systems theory"), + "MATHEMATICS :: Applied mathematics :: Optimization, systems theory"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR140205", "Theoretical computer science", - "Research Subject Categories::MATHEMATICS::Applied mathematics::Theoretical computer science") + "MATHEMATICS :: Applied mathematics :: Theoretical computer science") ))) .andExpect(jsonPath("$.page.totalElements", Matchers.is(4))); } @@ -341,7 +341,7 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(status().isOk()) .andExpect(jsonPath("$", is( VocabularyEntryDetailsMatcher.matchAuthorityEntry( - "srsc:SCB18", "MEDICINE","Research Subject Categories::MEDICINE") + "srsc:SCB18", "MEDICINE","MEDICINE") ))); } @@ -355,7 +355,7 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest @Test public void findParentByChildUnauthorizedTest() throws Exception { getClient().perform(get("/api/submission/vocabularyEntryDetails/srsc:SCB180/parent")) - .andExpect(status().isUnauthorized()); + .andExpect(status().isOk()); } @Test @@ -375,11 +375,11 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(jsonPath("$._embedded.parent", VocabularyEntryDetailsMatcher.matchAuthorityEntry( "srsc:SCB11", "HUMANITIES and RELIGION", - "Research Subject Categories::HUMANITIES and RELIGION"))) + "HUMANITIES and RELIGION"))) .andExpect(jsonPath("$._embedded.children._embedded.children", matchAllSrscSC110Children())) .andExpect(jsonPath("$._embedded.children._embedded.children[*].otherInformation.parent", Matchers.everyItem( - is("Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology")))); + is("HUMANITIES and RELIGION :: Religion/Theology")))); getClient(tokenAdmin).perform( get("/api/submission/vocabularyEntryDetails/srsc:SCB110").param("embed", "children")) @@ -387,7 +387,7 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(jsonPath("$._embedded.children._embedded.children", matchAllSrscSC110Children())) .andExpect(jsonPath("$._embedded.children._embedded.children[*].otherInformation.parent", Matchers.everyItem( - is("Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology")))); + is("HUMANITIES and RELIGION :: Religion/Theology")))); getClient(tokenAdmin).perform( get("/api/submission/vocabularyEntryDetails/srsc:SCB110").param("embed", "parent")) @@ -395,47 +395,47 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest .andExpect(jsonPath("$._embedded.parent", VocabularyEntryDetailsMatcher.matchAuthorityEntry( "srsc:SCB11", "HUMANITIES and RELIGION", - "Research Subject Categories::HUMANITIES and RELIGION"))); + "HUMANITIES and RELIGION"))); } private Matcher> matchAllSrscSC110Children() { return Matchers.containsInAnyOrder( VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR110102", "History of religion", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology::History of religion"), + "HUMANITIES and RELIGION :: Religion/Theology :: History of religion"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR110103", "Church studies", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology::Church studies"), + "HUMANITIES and RELIGION :: Religion/Theology :: Church studies"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR110104", "Missionary studies", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology::Missionary studies"), + "HUMANITIES and RELIGION :: Religion/Theology :: Missionary studies"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR110105", "Systematic theology", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology::Systematic theology"), + "HUMANITIES and RELIGION :: Religion/Theology :: Systematic theology"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR110106", "Islamology", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology::Islamology"), + "HUMANITIES and RELIGION :: Religion/Theology :: Islamology"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR110107", "Faith and reason", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology::Faith and reason"), + "HUMANITIES and RELIGION :: Religion/Theology :: Faith and reason"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR110108", "Sociology of religion", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology::Sociology of religion"), + "HUMANITIES and RELIGION :: Religion/Theology :: Sociology of religion"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR110109", "Psychology of religion", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology::Psychology of religion"), + "HUMANITIES and RELIGION :: Religion/Theology :: Psychology of religion"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR110110", "Philosophy of religion", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology::Philosophy of religion"), + "HUMANITIES and RELIGION :: Religion/Theology :: Philosophy of religion"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR110111", "New Testament exegesis", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology::New Testament exegesis"), + "HUMANITIES and RELIGION :: Religion/Theology :: New Testament exegesis"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR110112", "Old Testament exegesis", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology::Old Testament exegesis"), + "HUMANITIES and RELIGION :: Religion/Theology :: Old Testament exegesis"), VocabularyEntryDetailsMatcher.matchAuthorityEntry("srsc:VR110113", "Dogmatics with symbolics", - "Research Subject Categories::HUMANITIES and RELIGION::Religion/Theology::Dogmatics with symbolics") + "HUMANITIES and RELIGION :: Religion/Theology :: Dogmatics with symbolics") ); } diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyRestRepositoryIT.java index 5ea8cdb231..a84e2242a3 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyRestRepositoryIT.java @@ -179,9 +179,9 @@ public class VocabularyRestRepositoryIT extends AbstractControllerIntegrationTes .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.entries", Matchers.containsInAnyOrder( VocabularyMatcher.matchVocabularyEntry("Research Subject Categories", - "Research Subject Categories", "vocabularyEntry"), + "", "vocabularyEntry"), VocabularyMatcher.matchVocabularyEntry("Family research", - "Research Subject Categories::SOCIAL SCIENCES::Social sciences::Social work::Family research", + "SOCIAL SCIENCES :: Social sciences :: Social work :: Family research", "vocabularyEntry")))) .andExpect(jsonPath("$.page.totalElements", Matchers.is(26))) .andExpect(jsonPath("$.page.totalPages", Matchers.is(13))) diff --git a/dspace/config/dspace.cfg b/dspace/config/dspace.cfg index 02c618abf4..5c1fd9763c 100644 --- a/dspace/config/dspace.cfg +++ b/dspace/config/dspace.cfg @@ -1386,7 +1386,7 @@ orcid.oauth.url = https://orcid.org/oauth/token plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \ org.dspace.content.authority.DCInputAuthority, \ - org.dspace.content.authority.DSpaceControlledVocabulary + com.atmire.dspace.content.authority.WbDSpaceControlledVocabulary ## ## This sets the default lowest confidence level at which a metadata value is included From 188d02c82215f86e746309faac95c3dd2e5d02fd Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 8 Dec 2021 10:09:41 +0100 Subject: [PATCH 2/6] taskid 85555 Custom DSpaceControlledVocabulary for WB syntax - permissions --- .../repository/VocabularyEntryDetailsRestRepository.java | 4 ++-- .../java/org/dspace/app/rest/VocabularyEntryDetailsIT.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsRestRepository.java index 911a4ae49b..fdfa28dd05 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsRestRepository.java @@ -60,7 +60,7 @@ public class VocabularyEntryDetailsRestRepository extends DSpaceRestRepository findAll(Context context, Pageable pageable) { throw new RepositoryMethodNotImplementedException(ResourcePolicyRest.NAME, "findAll"); @@ -82,7 +82,7 @@ public class VocabularyEntryDetailsRestRepository extends DSpaceRestRepository findAllTop(@Parameter(value = "vocabulary", required = true) String vocabularyId, Pageable pageable) { Context context = obtainContext(); diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyEntryDetailsIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyEntryDetailsIT.java index a580c28c92..fa277bf8a9 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyEntryDetailsIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyEntryDetailsIT.java @@ -256,8 +256,8 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest @Test public void searchTopUnauthorizedTest() throws Exception { getClient().perform(get("/api/submission/vocabularyEntryDetails/search/top") - .param("vocabulary", "srsc:SCB16")) - .andExpect(status().isUnauthorized()); + .param("vocabulary", "srsc")) + .andExpect(status().isOk()); } @Test @@ -331,7 +331,7 @@ public class VocabularyEntryDetailsIT extends AbstractControllerIntegrationTest public void srscSearchTopUnauthorizedTest() throws Exception { getClient().perform(get("/api/submission/vocabularyEntryDetails/search/top") .param("vocabulary", "srsc")) - .andExpect(status().isUnauthorized()); + .andExpect(status().isOk()); } @Test From f065f12fa75f2392db49888f269a45daa872f2e5 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 8 Dec 2021 17:27:20 +0100 Subject: [PATCH 3/6] taskid 85816 Rename vocabularies to match the discovery config --- .../atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dspace-server-webapp/src/test/java/com/atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java b/dspace-server-webapp/src/test/java/com/atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java index cd7baae915..d22525223a 100644 --- a/dspace-server-webapp/src/test/java/com/atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java +++ b/dspace-server-webapp/src/test/java/com/atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java @@ -27,14 +27,14 @@ public class WbVocabularyEntryDetailsIT extends AbstractControllerIntegrationTes String token = getAuthToken(eperson.getEmail(), password); getClient(token) - .perform(get("/api/submission/vocabularyEntryDetails/topics:Information_Technology")) + .perform(get("/api/submission/vocabularyEntryDetails/topic:Information_Technology")) .andExpect(status().isOk()) .andExpect(jsonPath("$.value", is( "Information and Communication Technologies :: Information Technology" ))); getClient(token) - .perform(get("/api/submission/vocabularies/topics/entries") + .perform(get("/api/submission/vocabularies/topic/entries") .param("filter", "Information and Communication Technologies :: Information Technology") .param("exact", "true")) .andExpect(status().isOk()) @@ -43,7 +43,7 @@ public class WbVocabularyEntryDetailsIT extends AbstractControllerIntegrationTes ))); getClient(token) - .perform(get("/api/submission/vocabularyEntryDetails/search/top?vocabulary=topics")) + .perform(get("/api/submission/vocabularyEntryDetails/search/top?vocabulary=topic")) .andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.vocabularyEntryDetails", everyItem( hasJsonPath("$.value", not(startsWith("Topics:"))) From cfbd7785e5a4378d8db71ced59b76394a264723c Mon Sep 17 00:00:00 2001 From: Joost Date: Tue, 18 Jan 2022 09:46:35 +0100 Subject: [PATCH 4/6] [task 86387] made findone for vocabularies publicly available --- .../app/rest/repository/VocabularyRestRepository.java | 2 +- .../org/dspace/app/rest/VocabularyRestRepositoryIT.java | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyRestRepository.java index dcdf71186b..fcc37d1316 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyRestRepository.java @@ -53,7 +53,7 @@ public class VocabularyRestRepository extends DSpaceRestRepository Date: Thu, 1 Dec 2022 15:36:16 +0100 Subject: [PATCH 5/6] 97049: Remove client structure --- .../WbDSpaceControlledVocabulary.java | 30 ------------------- .../authority/DSpaceControlledVocabulary.java | 6 +++- .../test/data/dspaceFolder/config/local.cfg | 2 +- dspace/config/dspace.cfg | 2 +- 4 files changed, 7 insertions(+), 33 deletions(-) delete mode 100644 dspace-api/src/main/java/com/atmire/dspace/content/authority/WbDSpaceControlledVocabulary.java diff --git a/dspace-api/src/main/java/com/atmire/dspace/content/authority/WbDSpaceControlledVocabulary.java b/dspace-api/src/main/java/com/atmire/dspace/content/authority/WbDSpaceControlledVocabulary.java deleted file mode 100644 index ed05325ace..0000000000 --- a/dspace-api/src/main/java/com/atmire/dspace/content/authority/WbDSpaceControlledVocabulary.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE and NOTICE files at the root of the source - * tree and available online at - * - * http://www.dspace.org/license/ - */ -package com.atmire.dspace.content.authority; - -import org.dspace.content.authority.DSpaceControlledVocabulary; -import org.w3c.dom.Node; - -public class WbDSpaceControlledVocabulary extends DSpaceControlledVocabulary { - - @Override - protected void init() { - super.init(); - hierarchyDelimiter = " " + hierarchyDelimiter + " "; - } - - protected String buildString(Node node) { - if (node.getNodeType() == Node.DOCUMENT_NODE || ( - node.getParentNode() != null && - node.getParentNode().getNodeType() == Node.DOCUMENT_NODE)) { - return (""); - } else { - return super.buildString(node); - } - } -} diff --git a/dspace-api/src/main/java/org/dspace/content/authority/DSpaceControlledVocabulary.java b/dspace-api/src/main/java/org/dspace/content/authority/DSpaceControlledVocabulary.java index dfaf4a107f..d5e350faf0 100644 --- a/dspace-api/src/main/java/org/dspace/content/authority/DSpaceControlledVocabulary.java +++ b/dspace-api/src/main/java/org/dspace/content/authority/DSpaceControlledVocabulary.java @@ -132,11 +132,15 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Hiera String filename = vocabulariesPath + vocabularyName + ".xml"; log.info("Loading " + filename); vocabulary = new InputSource(filename); + + hierarchyDelimiter = " " + hierarchyDelimiter + " "; } } protected String buildString(Node node) { - if (node.getNodeType() == Node.DOCUMENT_NODE) { + if (node.getNodeType() == Node.DOCUMENT_NODE || ( + node.getParentNode() != null && + node.getParentNode().getNodeType() == Node.DOCUMENT_NODE)) { return (""); } else { String parentValue = buildString(node.getParentNode()); diff --git a/dspace-api/src/test/data/dspaceFolder/config/local.cfg b/dspace-api/src/test/data/dspaceFolder/config/local.cfg index 74e3e14d6a..3c19a68e9f 100644 --- a/dspace-api/src/test/data/dspaceFolder/config/local.cfg +++ b/dspace-api/src/test/data/dspaceFolder/config/local.cfg @@ -97,7 +97,7 @@ event.dispatcher.exclude-discovery.consumers = versioning, eperson # (This overrides default, commented out settings in dspace.cfg) plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \ org.dspace.content.authority.DCInputAuthority, \ - com.atmire.dspace.content.authority.WbDSpaceControlledVocabulary + org.dspace.content.authority.DSpaceControlledVocabulary # Configure some more Plugins for PluginTest class # NOTE: Plugins are just *interfaces*. So, here we are defining some plugins diff --git a/dspace/config/dspace.cfg b/dspace/config/dspace.cfg index 5c1fd9763c..02c618abf4 100644 --- a/dspace/config/dspace.cfg +++ b/dspace/config/dspace.cfg @@ -1386,7 +1386,7 @@ orcid.oauth.url = https://orcid.org/oauth/token plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \ org.dspace.content.authority.DCInputAuthority, \ - com.atmire.dspace.content.authority.WbDSpaceControlledVocabulary + org.dspace.content.authority.DSpaceControlledVocabulary ## ## This sets the default lowest confidence level at which a metadata value is included From f7e7f69f2d71523d4a760fad2e51d96888dfecc1 Mon Sep 17 00:00:00 2001 From: Jens Vannerum Date: Thu, 1 Dec 2022 17:49:15 +0100 Subject: [PATCH 6/6] 97049: Remove client specific test --- .../app/rest/WbVocabularyEntryDetailsIT.java | 52 ------------------- 1 file changed, 52 deletions(-) delete mode 100644 dspace-server-webapp/src/test/java/com/atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java diff --git a/dspace-server-webapp/src/test/java/com/atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java b/dspace-server-webapp/src/test/java/com/atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java deleted file mode 100644 index d22525223a..0000000000 --- a/dspace-server-webapp/src/test/java/com/atmire/dspace/app/rest/WbVocabularyEntryDetailsIT.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * The contents of this file are subject to the license and copyright - * detailed in the LICENSE and NOTICE files at the root of the source - * tree and available online at - * - * http://www.dspace.org/license/ - */ -package com.atmire.dspace.app.rest; - -import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath; -import static org.hamcrest.Matchers.everyItem; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.startsWith; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import org.dspace.app.rest.test.AbstractControllerIntegrationTest; -import org.junit.Test; - -public class WbVocabularyEntryDetailsIT extends AbstractControllerIntegrationTest { - - @Test - public void testCustomWbSyntax() throws Exception { - - String token = getAuthToken(eperson.getEmail(), password); - - getClient(token) - .perform(get("/api/submission/vocabularyEntryDetails/topic:Information_Technology")) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.value", is( - "Information and Communication Technologies :: Information Technology" - ))); - - getClient(token) - .perform(get("/api/submission/vocabularies/topic/entries") - .param("filter", "Information and Communication Technologies :: Information Technology") - .param("exact", "true")) - .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.entries[0].value", is( - "Information and Communication Technologies :: Information Technology" - ))); - - getClient(token) - .perform(get("/api/submission/vocabularyEntryDetails/search/top?vocabulary=topic")) - .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.vocabularyEntryDetails", everyItem( - hasJsonPath("$.value", not(startsWith("Topics:"))) - ))); - } -}