From 3a09bf7c32608b4cc44b738d9e28625f3beb78fe Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Thu, 5 Dec 2024 16:55:02 +0000 Subject: [PATCH] fix: reviw for 4.1.6 --- .../operations/operations/OperationsUtils.java | 3 ++- .../insee/rmes/bauhaus_services/rdf_utils/RdfUtils.java | 8 ++++++-- src/main/java/fr/insee/rmes/utils/FilesUtils.java | 2 +- .../operations/operations/OperationsUtilsTest.java | 4 +++- src/test/java/fr/insee/rmes/utils/FilesUtilsTest.java | 1 + 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationsUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationsUtils.java index b87ed8ef4..4a1f62b2e 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationsUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationsUtils.java @@ -24,6 +24,7 @@ import org.eclipse.rdf4j.model.vocabulary.DCTERMS; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.model.vocabulary.SKOS; +import org.eclipse.rdf4j.model.vocabulary.XSD; import org.json.JSONArray; import org.json.JSONObject; import org.slf4j.Logger; @@ -179,7 +180,7 @@ private void createRdfOperation(Operation operation, IRI serieUri, ValidationSta RdfUtils.addTripleDateTime(operationURI, DCTERMS.MODIFIED, operation.getModified(), model, RdfUtils.operationsGraph()); if(operation.getYear() != null){ - RdfUtils.addTripleInt(operationURI, DCTERMS.TEMPORAL, operation.getYear().toString(), model, RdfUtils.operationsGraph()); + model.add(operationURI, DCTERMS.TEMPORAL, RdfUtils.createLiteral(operation.getYear().toString(), XSD.GYEAR), RdfUtils.operationsGraph()); } if (serieUri != null) { diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RdfUtils.java b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RdfUtils.java index 7e72db4d4..7d6ba2209 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RdfUtils.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/rdf_utils/RdfUtils.java @@ -187,11 +187,15 @@ public static Literal setLiteralString(String string, String language) { public static Literal setLiteralBoolean(Boolean bool) { return factory.createLiteral(bool); } - + + public static Literal createLiteral(String value, IRI datatype){ + return factory.createLiteral(value, datatype); + } + public static Literal setLiteralInt(String number) { return factory.createLiteral(number, XSD.INT); } - + public static Literal setLiteralDateTime(String date) { String parsedDate = DateTimeFormatter.ISO_DATE_TIME.format(DateUtils.parseDateTime(date)); return factory.createLiteral(parsedDate, XSD.DATETIME); diff --git a/src/main/java/fr/insee/rmes/utils/FilesUtils.java b/src/main/java/fr/insee/rmes/utils/FilesUtils.java index f40b31ef5..8841ad4c8 100644 --- a/src/main/java/fr/insee/rmes/utils/FilesUtils.java +++ b/src/main/java/fr/insee/rmes/utils/FilesUtils.java @@ -73,10 +73,10 @@ private static String reduceFileNameSize(String fileName, int maxLength) { private static String removeAsciiCharacters(String fileName) { return Normalizer.normalize(fileName, Normalizer.Form.NFD) + .replaceAll("\\p{M}+", "") .replace("œ", "oe") .replace("Œ", "OE") .replaceAll("[-_]", " ") - .replaceAll("\\p{M}+", " ") .replaceAll("\\p{Punct}", "") .replace(":", ""); } diff --git a/src/test/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationsUtilsTest.java b/src/test/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationsUtilsTest.java index 176f1d4f1..08df7c36d 100644 --- a/src/test/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationsUtilsTest.java +++ b/src/test/java/fr/insee/rmes/bauhaus_services/operations/operations/OperationsUtilsTest.java @@ -12,6 +12,7 @@ import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.XSD; import org.json.JSONObject; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -65,6 +66,7 @@ void shouldStoreYearProperty() throws RmesException { mockedFactory.when(() -> RdfUtils.setLiteralString(anyString(), anyString())).thenCallRealMethod(); mockedFactory.when(() -> RdfUtils.setLiteralString(anyString(), anyString())).thenCallRealMethod(); mockedFactory.when(() -> RdfUtils.setLiteralString(anyString())).thenCallRealMethod(); + mockedFactory.when(() -> RdfUtils.createLiteral(anyString(), eq(XSD.GYEAR))).thenCallRealMethod(); mockedFactory.when(() -> RdfUtils.operationsGraph()).thenReturn(valueFactory.createIRI("http://operations-graph/")); mockedFactory.when(() -> RdfUtils.objectIRI(eq(ObjectType.SERIES), eq("2"))).thenReturn(valueFactory.createIRI("http://series/2")); mockedFactory.when(() -> RdfUtils.objectIRI(eq(ObjectType.OPERATION), eq("1"))).thenReturn(operationIRI); @@ -88,7 +90,7 @@ void shouldStoreYearProperty() throws RmesException { verify(repositoryGestion, times(1)).loadSimpleObject(eq(operationIRI), model.capture()); - Assertions.assertEquals("[(http://operation/2, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://rdf.insee.fr/def/base#StatisticalOperation, http://operations-graph/) [http://operations-graph/], (http://operation/2, http://www.w3.org/2004/02/skos/core#prefLabel, \"prefLabelLg1\"@fr, http://operations-graph/) [http://operations-graph/], (http://operation/2, http://rdf.insee.fr/def/base#validationState, \"Unpublished\", http://operations-graph/) [http://operations-graph/], (http://operation/2, http://www.w3.org/2004/02/skos/core#prefLabel, \"prefLabelLg2\"@en, http://operations-graph/) [http://operations-graph/], (http://operation/2, http://www.w3.org/2004/02/skos/core#altLabel, \"altLabelLg1\"@fr, http://operations-graph/) [http://operations-graph/], (http://operation/2, http://www.w3.org/2004/02/skos/core#altLabel, \"altLabelLg2\"@en, http://operations-graph/) [http://operations-graph/], (http://operation/2, http://purl.org/dc/terms/temporal, \"2024\"^^, http://operations-graph/) [http://operations-graph/]]", model.getValue().toString()); + Assertions.assertEquals("[(http://operation/2, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://rdf.insee.fr/def/base#StatisticalOperation, http://operations-graph/) [http://operations-graph/], (http://operation/2, http://www.w3.org/2004/02/skos/core#prefLabel, \"prefLabelLg1\"@fr, http://operations-graph/) [http://operations-graph/], (http://operation/2, http://rdf.insee.fr/def/base#validationState, \"Unpublished\", http://operations-graph/) [http://operations-graph/], (http://operation/2, http://www.w3.org/2004/02/skos/core#prefLabel, \"prefLabelLg2\"@en, http://operations-graph/) [http://operations-graph/], (http://operation/2, http://www.w3.org/2004/02/skos/core#altLabel, \"altLabelLg1\"@fr, http://operations-graph/) [http://operations-graph/], (http://operation/2, http://www.w3.org/2004/02/skos/core#altLabel, \"altLabelLg2\"@en, http://operations-graph/) [http://operations-graph/], (http://operation/2, http://purl.org/dc/terms/temporal, \"2024\"^^, http://operations-graph/) [http://operations-graph/]]", model.getValue().toString()); } diff --git a/src/test/java/fr/insee/rmes/utils/FilesUtilsTest.java b/src/test/java/fr/insee/rmes/utils/FilesUtilsTest.java index 67beb3ca7..6509968a1 100644 --- a/src/test/java/fr/insee/rmes/utils/FilesUtilsTest.java +++ b/src/test/java/fr/insee/rmes/utils/FilesUtilsTest.java @@ -45,6 +45,7 @@ void testGenerateFinalFileNameWithoutExtension_LongFileName() { String result = FilesUtils.generateFinalFileNameWithoutExtension(fileName, maxLength); + assertEquals("rapportQualiteEnquet", FilesUtils.generateFinalFileNameWithoutExtension("Rapport qualité : Enquête annuelle de recensement 2022", maxLength), "Le nom de fichier généré sans extension pour un long nom est incorrect"); assertEquals("averylongfilenameexa", result, "Le nom de fichier généré sans extension pour un long nom est incorrect"); }