Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: review for 4.1.6 #828

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/insee/rmes/utils/FilesUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(":", "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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://www.w3.org/2001/XMLSchema#int>, 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://www.w3.org/2001/XMLSchema#gYear>, http://operations-graph/) [http://operations-graph/]]", model.getValue().toString());

}

Expand Down
1 change: 1 addition & 0 deletions src/test/java/fr/insee/rmes/utils/FilesUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
Loading