From 7f301a0915d03a0a95ab52247aeb18bb338c3903 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Tue, 17 Dec 2024 09:28:36 +0000 Subject: [PATCH] fix: remove sonar issues --- .../collections/CollectionExportBuilder.java | 48 +++++++++---------- .../rdf_utils/RdfUtilsTest.java | 14 +++++- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/main/java/fr/insee/rmes/bauhaus_services/concepts/collections/CollectionExportBuilder.java b/src/main/java/fr/insee/rmes/bauhaus_services/concepts/collections/CollectionExportBuilder.java index b0eadb761..5d7284cfc 100644 --- a/src/main/java/fr/insee/rmes/bauhaus_services/concepts/collections/CollectionExportBuilder.java +++ b/src/main/java/fr/insee/rmes/bauhaus_services/concepts/collections/CollectionExportBuilder.java @@ -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(); @@ -64,17 +64,17 @@ public CollectionForExport getCollectionData(String id) throws RmesException { instance.setStrength(Collator.NO_DECOMPOSITION); - Collections.sort( orderMembers, new Comparator() { - 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); @@ -105,34 +105,34 @@ public int compare(JSONObject a, JSONObject b) { public ResponseEntity exportAsResponse(String fileName, Map 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 exportAsResponseODT(String fileName, Map 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 exportAsResponseODS(String fileName, Map 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> collections, boolean lg1, boolean lg2, boolean includeEmptyFields, HttpServletResponse response, ConceptsCollectionsResources.Language lg, Map> 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> collections, boolean lg1, boolean lg2, boolean includeEmptyFields, HttpServletResponse response, Map> 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> resources, String xslFile, String xmlPattern, String zip, HttpServletResponse response, String extension, Map> concepts, boolean withConcepts) throws RmesException { diff --git a/src/test/java/fr/insee/rmes/bauhaus_services/rdf_utils/RdfUtilsTest.java b/src/test/java/fr/insee/rmes/bauhaus_services/rdf_utils/RdfUtilsTest.java index 672a77862..1cefb3d3b 100644 --- a/src/test/java/fr/insee/rmes/bauhaus_services/rdf_utils/RdfUtilsTest.java +++ b/src/test/java/fr/insee/rmes/bauhaus_services/rdf_utils/RdfUtilsTest.java @@ -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; @@ -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"); @@ -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, \"

value

\"^^) [null], (http://iri/prefix/fr, http://www.w3.org/2001/XMLSchema#language, \"fr\"^^) [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, \"

value

\"^^) [null], (http://iri/prefix/fr, http://www.w3.org/2001/XMLSchema#language, \"fr\"^^) [null]]", model.toString()); } } \ No newline at end of file