From eb2e4f1155864d190a3458210419c02978519ec0 Mon Sep 17 00:00:00 2001 From: Toni Prieto Date: Fri, 27 Oct 2023 14:10:49 +0200 Subject: [PATCH 1/2] Correct response of byMetadataAndCollection operation of Controlled Vocabularies Endpoint when no controlled vocabulary is available for the specified metadata and collection --- .../dspace/app/rest/repository/VocabularyRestRepository.java | 3 +++ 1 file changed, 3 insertions(+) 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 fcc37d13160d..783ed418233d 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 @@ -100,6 +100,9 @@ public VocabularyRest findByMetadataAndCollection( } String authorityName = cas.getChoiceAuthorityName(tokens[0], tokens[1], tokens[2], collection); + if (authorityName == null) { + return null; + } ChoiceAuthority source = cas.getChoiceAuthorityByAuthorityName(authorityName); return authorityUtils.convertAuthority(source, authorityName, utils.obtainProjection()); } From a294f996cf8c6169d6414609363997e118bc41d0 Mon Sep 17 00:00:00 2001 From: Toni Prieto Date: Fri, 27 Oct 2023 14:26:37 +0200 Subject: [PATCH 2/2] Add missing test for byMetadataAndCollection operation of Controlled Vocabularies endpoint --- .../app/rest/VocabularyRestRepositoryIT.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 f9b31fb06de9..81d2dba67911 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 @@ -394,6 +394,20 @@ public void findByMetadataAndCollectionTest() throws Exception { ))); } + @Test + public void findByMetadataAndCollectionWithMetadataWithoutVocabularyTest() throws Exception { + context.turnOffAuthorisationSystem(); + Collection collection = CollectionBuilder.createCollection(context, parentCommunity) + .withName("Test collection") + .build(); + context.restoreAuthSystemState(); + String token = getAuthToken(admin.getEmail(), password); + getClient(token).perform(get("/api/submission/vocabularies/search/byMetadataAndCollection") + .param("metadata", "dc.title") + .param("collection", collection.getID().toString())) + .andExpect(status().isNoContent()); + } + @Test public void findByMetadataAndCollectionUnprocessableEntityTest() throws Exception { context.turnOffAuthorisationSystem();