From eb43dc3c06dd355e7e6441a3509525a5e49e594c Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Fri, 8 Nov 2024 14:35:18 +0000 Subject: [PATCH] fix: remove duplicated theme --- .../datasets/DatasetServiceImpl.java | 12 ++++-------- .../datasets/DatasetServiceImplTest.java | 10 ++++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetServiceImpl.java b/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetServiceImpl.java index e23e2f32c..c4cfa4a5a 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetServiceImpl.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/datasets/DatasetServiceImpl.java @@ -30,10 +30,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.regex.Pattern; import static fr.insee.rmes.exceptions.ErrorCodes.DATASET_PATCH_INCORRECT_BODY; @@ -146,10 +143,10 @@ public Dataset getDatasetByID(String id) throws RmesException { } JSONObject dataset = datasetWithThemes.getJSONObject(0); - List themes = new ArrayList<>(); - for(int i = 0; i < datasetWithThemes.length(); i++){ + Set themes = new HashSet<>(); + for (int i = 0; i < datasetWithThemes.length(); i++) { JSONObject tempDataset = datasetWithThemes.getJSONObject(i); - if(tempDataset.has(THEME)){ + if (tempDataset.has(THEME)) { themes.add(tempDataset.getString(THEME)); } } @@ -434,7 +431,6 @@ private void persistNotes(IRI datasetIri, Dataset dataset, Model model, Resource RdfUtils.addTripleString(datasetIri, DCTERMS.ABSTRACT, dataset.getAbstractLg2(), config.getLg2(), model, graph); RdfUtils.addTripleString(datasetIri, SKOS.SCOPE_NOTE, dataset.getCautionLg1(), config.getLg1(), model, graph); RdfUtils.addTripleString(datasetIri, SKOS.SCOPE_NOTE, dataset.getCautionLg2(), config.getLg2(), model, graph); - } private void persistStatisticsInformations(IRI datasetIri, Dataset dataset, Model model, Resource graph){ diff --git a/src/test/java/fr/insee/rmes/bauhaus_services/datasets/DatasetServiceImplTest.java b/src/test/java/fr/insee/rmes/bauhaus_services/datasets/DatasetServiceImplTest.java index c2990985f..e2c46a179 100644 --- a/src/test/java/fr/insee/rmes/bauhaus_services/datasets/DatasetServiceImplTest.java +++ b/src/test/java/fr/insee/rmes/bauhaus_services/datasets/DatasetServiceImplTest.java @@ -120,9 +120,11 @@ void getDatasetsForDistributionCreationWithStamp() throws RmesException { @Test void shouldReturnDataset() throws RmesException, JSONException, JsonProcessingException { - JSONObject object = new JSONObject(); - object.put("id", "1"); - JSONArray array = new JSONArray().put(object); + JSONObject object = new JSONObject().put("id", "1").put("theme", "theme1"); + JSONObject object1 = new JSONObject().put("id", "1").put("theme", "theme1"); + JSONObject object2 = new JSONObject().put("id", "1").put("theme", "theme2"); + JSONArray array = new JSONArray().put(object).put(object1).put(object2); + when(repositoryGestion.getResponseAsArray("query")).thenReturn(array); when(repositoryGestion.getResponseAsArray("query-creators")).thenReturn(new JSONArray().put(new JSONObject().put("creator", "creator-1"))); when(repositoryGestion.getResponseAsArray("query-spacialResolutions")).thenReturn(new JSONArray().put(new JSONObject().put("spacialResolution", "spacialResolutions-1"))); @@ -134,7 +136,7 @@ void shouldReturnDataset() throws RmesException, JSONException, JsonProcessingEx mockedFactory.when(() -> DatasetQueries.getDatasetStatisticalUnits(eq("1"), any())).thenReturn("query-statisticalUnits"); Dataset response = datasetService.getDatasetByID("1"); String responseJson = objectMapper.writeValueAsString(response); - Assertions.assertEquals("{\"creators\":[\"creator-1\"],\"keywords\":{\"lg1\":[],\"lg2\":[]},\"statisticalUnit\":[\"statisticalUnit-1\"],\"spacialResolutions\":[\"spacialResolutions-1\"],\"id\":\"1\",\"themes\":[],\"catalogRecord\":{\"creator\":null,\"contributor\":null,\"created\":null,\"updated\":null}}", responseJson); + Assertions.assertEquals("{\"creators\":[\"creator-1\"],\"keywords\":{\"lg1\":[],\"lg2\":[]},\"statisticalUnit\":[\"statisticalUnit-1\"],\"spacialResolutions\":[\"spacialResolutions-1\"],\"id\":\"1\",\"themes\":[\"theme2\",\"theme1\"],\"catalogRecord\":{\"creator\":null,\"contributor\":null,\"created\":null,\"updated\":null}}", responseJson); } }