Skip to content

Commit

Permalink
fix: remove duplicated theme (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey authored Nov 18, 2024
1 parent 8d26559 commit cb05174
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,10 +143,10 @@ public Dataset getDatasetByID(String id) throws RmesException {
}

JSONObject dataset = datasetWithThemes.getJSONObject(0);
List<String> themes = new ArrayList<>();
for(int i = 0; i < datasetWithThemes.length(); i++){
Set<String> 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));
}
}
Expand Down Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand All @@ -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);
}
}

Expand Down

0 comments on commit cb05174

Please sign in to comment.