Skip to content

Commit

Permalink
fix: remove sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey committed Dec 17, 2024
1 parent 66d34ce commit 7f301a0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public class CollectionExportBuilder extends RdfService {
@Autowired
ExportUtils exportUtils;

private static final String xslFile = "/xslTransformerFiles/rmes2odt.xsl";
private static final String xmlPattern = "/xslTransformerFiles/collection/collectionPatternContent.xml";
private static final String zip = "/xslTransformerFiles/collection/toZipForCollection.zip";
private static final String zipold = "/xslTransformerFiles/collection/toZipForCollectionOld.zip";
private static final String xmlPatternFR = "/xslTransformerFiles/collection/collectionFrPatternContent.xml";
private static final String xmlPatternEN = "/xslTransformerFiles/collection/collectionEnPatternContent.xml";
private static final String xmlPatternODS = "/xslTransformerFiles/collection/collectionOdsPatternContent.xml";
private static final String zipODS = "/xslTransformerFiles/collection/toZipForCollectionOds.zip";
private static final String XSL_FILE = "/xslTransformerFiles/rmes2odt.xsl";
private static final String XML_PATERN = "/xslTransformerFiles/collection/collectionPatternContent.xml";
private static final String ZIP = "/xslTransformerFiles/collection/toZipForCollection.zip";
private static final String ZIP_OLD = "/xslTransformerFiles/collection/toZipForCollectionOld.zip";
private static final String XML_PATTERN_FR = "/xslTransformerFiles/collection/collectionFrPatternContent.xml";
private static final String XML_PATTERN_EN = "/xslTransformerFiles/collection/collectionEnPatternContent.xml";
private static final String XML_PATTERN_ODS = "/xslTransformerFiles/collection/collectionOdsPatternContent.xml";
private static final String ZIP_ODS = "/xslTransformerFiles/collection/toZipForCollectionOds.zip";

final Collator instance = Collator.getInstance();

Expand All @@ -64,17 +64,17 @@ public CollectionForExport getCollectionData(String id) throws RmesException {

instance.setStrength(Collator.NO_DECOMPOSITION);

Collections.sort( orderMembers, new Comparator<JSONObject>() {
private static final String KEY_NAME = "prefLabelLg1";
Collections.sort( orderMembers, new Comparator<>() {
private static final String KEY_NAME = "prefLabelLg1";

@Override
public int compare(JSONObject a, JSONObject b) {
String valA = (String) a.get(KEY_NAME);
String valB = (String) b.get(KEY_NAME);
@Override
public int compare(JSONObject a, JSONObject b) {
String valA = (String) a.get(KEY_NAME);
String valB = (String) b.get(KEY_NAME);

return instance.compare(valA.toLowerCase(), valB.toLowerCase());
}
});
return instance.compare(valA.toLowerCase(), valB.toLowerCase());
}
});


JSONArray orderMembersJSONArray = new JSONArray(orderMembers);
Expand Down Expand Up @@ -105,34 +105,34 @@ public int compare(JSONObject a, JSONObject b) {
public ResponseEntity<Resource> exportAsResponse(String fileName, Map<String, String> xmlContent, boolean lg1, boolean lg2, boolean includeEmptyFields) throws RmesException {
String parametersXML = XsltUtils.buildParams(lg1, lg2, includeEmptyFields, Constants.COLLECTION);
xmlContent.put(Constants.PARAMETERS_FILE, parametersXML);
return exportUtils.exportAsODT(fileName, xmlContent,xslFile,xmlPattern,zipold, Constants.COLLECTION);
return exportUtils.exportAsODT(fileName, xmlContent,XSL_FILE,XML_PATERN,ZIP_OLD, Constants.COLLECTION);
}


public ResponseEntity<Resource> exportAsResponseODT(String fileName, Map<String, String> xmlContent, boolean lg1, boolean lg2, boolean includeEmptyFields, ConceptsCollectionsResources.Language lg) throws RmesException {
String parametersXML = XsltUtils.buildParams(true, true, includeEmptyFields, Constants.COLLECTION);
xmlContent.put(Constants.PARAMETERS_FILE, parametersXML);
String xmlPattern = lg == ConceptsCollectionsResources.Language.lg1 ? xmlPatternFR : xmlPatternEN;
return exportUtils.exportAsODT(fileName, xmlContent, xslFile, xmlPattern, zip, Constants.COLLECTION);
String xmlPattern = lg == ConceptsCollectionsResources.Language.lg1 ? XML_PATTERN_FR : XML_PATTERN_EN;
return exportUtils.exportAsODT(fileName, xmlContent, XSL_FILE, xmlPattern, ZIP, Constants.COLLECTION);
}

public ResponseEntity<Resource> exportAsResponseODS(String fileName, Map<String, String> xmlContent, boolean lg1, boolean lg2, boolean includeEmptyFields) throws RmesException {
String parametersXML = XsltUtils.buildParams(lg1, lg2, includeEmptyFields, Constants.COLLECTION);
xmlContent.put(Constants.PARAMETERS_FILE, parametersXML);
return exportUtils.exportAsODS(fileName, xmlContent,xslFile,xmlPatternODS,zipODS, Constants.COLLECTION);
return exportUtils.exportAsODS(fileName, xmlContent,XSL_FILE,XML_PATTERN_ODS,ZIP_ODS, Constants.COLLECTION);
}

public void exportMultipleCollectionsAsZipOdt(Map<String, Map<String, String>> collections, boolean lg1, boolean lg2, boolean includeEmptyFields, HttpServletResponse response, ConceptsCollectionsResources.Language lg, Map<String, Map<String, InputStream>> concepts, boolean withConcepts) throws RmesException {
String parametersXML = XsltUtils.buildParams(lg1, lg2, includeEmptyFields, Constants.COLLECTION);
collections.values().stream().forEach(collection -> collection.put(Constants.PARAMETERS_FILE, parametersXML));
String xmlPattern = lg == ConceptsCollectionsResources.Language.lg1 ? xmlPatternFR : xmlPatternEN;
exportMultipleResourceAsZip(collections,xslFile,xmlPattern,zip, response, FilesUtils.ODT_EXTENSION, concepts, withConcepts);
String xmlPattern = lg == ConceptsCollectionsResources.Language.lg1 ? XML_PATTERN_FR : XML_PATTERN_EN;
exportMultipleResourceAsZip(collections,XSL_FILE,xmlPattern,ZIP, response, FilesUtils.ODT_EXTENSION, concepts, withConcepts);
}

public void exportMultipleCollectionsAsZipOds(Map<String, Map<String, String>> collections, boolean lg1, boolean lg2, boolean includeEmptyFields, HttpServletResponse response, Map<String, Map<String, InputStream>> concepts, boolean withConcepts) throws RmesException {
String parametersXML = XsltUtils.buildParams(lg1, lg2, includeEmptyFields, Constants.COLLECTION);
collections.values().stream().forEach(collection -> collection.put(Constants.PARAMETERS_FILE, parametersXML));
exportMultipleResourceAsZip(collections,xslFile,xmlPatternODS, zipODS, response, FilesUtils.ODS_EXTENSION, concepts, withConcepts);
exportMultipleResourceAsZip(collections,XSL_FILE,XML_PATTERN_ODS, ZIP_ODS, response, FilesUtils.ODS_EXTENSION, concepts, withConcepts);
}

private void exportMultipleResourceAsZip(Map<String, Map<String, String>> resources, String xslFile, String xmlPattern, String zip, HttpServletResponse response, String extension, Map<String, Map<String, InputStream>> concepts, boolean withConcepts) throws RmesException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insee.rmes.bauhaus_services.rdf_utils;

import org.eclipse.rdf4j.model.BNode;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
Expand All @@ -8,7 +9,18 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class RdfUtilsTest {

@Test
void testCreateBlankNode_ShouldReturnNonNullBNode() {
BNode result = RdfUtils.createBlankNode();
assertTrue(result.isBNode(), "The created blank node should be a blank node");
}

@Test
void shouldReturnNullWhenCallingAddTripeStringMdToXhtml2WithNullValue(){
IRI iri = SimpleValueFactory.getInstance().createIRI("http://iri");
Expand Down Expand Up @@ -44,6 +56,6 @@ void shouldUpdateModelWhenCallingAddTripeStringMdToXhtml2WithValidValue(){
Resource graph = null;

RdfUtils.addTripleStringMdToXhtml2(iri, predicate, value, lang, prefix, model, graph);
Assertions.assertEquals("[(http://iri, http://predicate, http://iri/prefix/fr) [null], (http://iri/prefix/fr, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://rdf-vocabulary.ddialliance.org/xkos#ExplanatoryNote) [null], (http://iri/prefix/fr, http://eurovoc.europa.eu/schema#noteLiteral, \"<p>value</p>\"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>) [null], (http://iri/prefix/fr, http://www.w3.org/2001/XMLSchema#language, \"fr\"^^<http://www.w3.org/2001/XMLSchema#language>) [null]]", model.toString());
assertEquals("[(http://iri, http://predicate, http://iri/prefix/fr) [null], (http://iri/prefix/fr, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://rdf-vocabulary.ddialliance.org/xkos#ExplanatoryNote) [null], (http://iri/prefix/fr, http://eurovoc.europa.eu/schema#noteLiteral, \"<p>value</p>\"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>) [null], (http://iri/prefix/fr, http://www.w3.org/2001/XMLSchema#language, \"fr\"^^<http://www.w3.org/2001/XMLSchema#language>) [null]]", model.toString());
}
}

0 comments on commit 7f301a0

Please sign in to comment.