From df2a94107805fcb74e6955f12db4a97299d76a18 Mon Sep 17 00:00:00 2001 From: Laurent Caouissin <38245508+laurentC35@users.noreply.github.com> Date: Wed, 22 May 2024 12:00:40 +0200 Subject: [PATCH] Fix: visu web dsfr (#284) * fix: visu for dsfr use string2InputStream method to avoid issue * bump to 4.6.5-SNAPSHOT --- pom.xml | 2 +- .../pogues/webservice/rest/ModelTransform.java | 16 +++++++++------- .../pogues/webservice/rest/VisualizeWithURI.java | 8 ++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 344fa8f5..fe958c72 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ fr.insee Pogues-BO jar - 4.6.4-SNAPSHOT + 4.6.5-SNAPSHOT Pogues-Back-Office diff --git a/src/main/java/fr/insee/pogues/webservice/rest/ModelTransform.java b/src/main/java/fr/insee/pogues/webservice/rest/ModelTransform.java index 1dd0fd7f..61fc8a44 100644 --- a/src/main/java/fr/insee/pogues/webservice/rest/ModelTransform.java +++ b/src/main/java/fr/insee/pogues/webservice/rest/ModelTransform.java @@ -77,7 +77,7 @@ public ResponseEntity visualizeSpecFromBody(@RequestBody StreamingResponseBody stream = output -> { try { output.write( - pipeline.from(new ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8))) + pipeline.from(string2InputStream(request)) .map(jsonToJsonDeref::transform, params, questionnaireName) .map(jsonToXML::transform, params, questionnaireName) .map(poguesXMLToDDI::transform, params, questionnaireName) @@ -108,7 +108,7 @@ public ResponseEntity visualizeDDIFromBody(@RequestBody S StreamingResponseBody stream = output -> { try { output.write( - pipeline.from(new ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8))) + pipeline.from(string2InputStream(request)) .map(jsonToJsonDeref::transform, params, questionnaireName) .map(jsonToXML::transform, params, questionnaireName) .map(poguesXMLToDDI::transform, params, questionnaireName).transform().toByteArray()); @@ -136,7 +136,7 @@ public ResponseEntity visualizePDFFromBody(@RequestBody S StreamingResponseBody stream = output -> { try { - output.write(pipeline.from(new ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8))) + output.write(pipeline.from(string2InputStream(request)) .map(jsonToJsonDeref::transform, params, questionnaireName) .map(jsonToXML::transform, params, questionnaireName) .map(poguesXMLToDDI::transform, params, questionnaireName) @@ -181,7 +181,7 @@ public ResponseEntity ddi2pdfWithParamTest(@RequestBody S StreamingResponseBody stream = output -> { try { - output.write(pipeline.from(new ByteArrayInputStream(questDDI.getBytes(StandardCharsets.UTF_8))) + output.write(pipeline.from(string2InputStream(questDDI)) .map(ddiToFo::transform, params, questionnaireName) .map(foToPdf::transform, params, questionnaireName) .transform().toByteArray()); @@ -205,7 +205,7 @@ public ResponseEntity fo2Pdf(@RequestBody String questFO) StreamingResponseBody stream = output -> { try { - output.write(pipeline.from(new ByteArrayInputStream(questFO.getBytes(StandardCharsets.UTF_8))) + output.write(pipeline.from(string2InputStream(questFO)) .map(foToPdf::transform, params, questionnaireName) .transform().toByteArray()); } catch (Exception e) { @@ -225,7 +225,7 @@ public ResponseEntity fo2Pdf(@RequestBody String questFO) }) public ResponseEntity json2XML(@RequestBody String questJson) throws Exception { String questionnaire = "xforms"; - return transform(new ByteArrayInputStream(questJson.getBytes(StandardCharsets.UTF_8)), jsonToXML, + return transform(string2InputStream(questJson), jsonToXML, questionnaire, MediaType.APPLICATION_XML); } @@ -248,7 +248,9 @@ public ResponseEntity xml2Json(@RequestBody String questX @ApiResponse(responseCode = "500", description = "Error") }) @ResponseBody public ResponseEntity jsonRef2JsonDeref(@RequestBody String questJson) throws Exception { - ByteArrayOutputStream result = jsonToJsonDeref.transform(string2InputStream(questJson), Map.of("needDeref", true), null); + Map params = new HashMap<>(); + params.put("needDeref", true); + ByteArrayOutputStream result = jsonToJsonDeref.transform(string2InputStream(questJson), params, null); return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(result.toString(StandardCharsets.UTF_8)); } diff --git a/src/main/java/fr/insee/pogues/webservice/rest/VisualizeWithURI.java b/src/main/java/fr/insee/pogues/webservice/rest/VisualizeWithURI.java index 3a2feae4..74d14d19 100644 --- a/src/main/java/fr/insee/pogues/webservice/rest/VisualizeWithURI.java +++ b/src/main/java/fr/insee/pogues/webservice/rest/VisualizeWithURI.java @@ -103,7 +103,7 @@ public ResponseEntity visualizeCatiQueenFromBody(@RequestBody String req params.put("needDeref", ref); params.put("nomenclatureIds", SuggesterVisuTreatment.getNomenclatureIdsFromQuestionnaire(request)); URI uri; - ByteArrayOutputStream outputStream = pipeline.from(new ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8))) + ByteArrayOutputStream outputStream = pipeline.from(string2InputStream(request)) .map(jsonToJsonDeref::transform, params, questionnaireName.toLowerCase()) .map(jsonToXML::transform, params, questionnaireName.toLowerCase()) .map(poguesXMLToDDI::transform, params, questionnaireName.toLowerCase()) @@ -147,7 +147,7 @@ public ResponseEntity visualizeStromaeV2FromBody(@RequestBody String req params.put("nomenclatureIds", SuggesterVisuTreatment.getNomenclatureIdsFromQuestionnaire(request)); URI uri; - ByteArrayOutputStream outputStream = pipeline.from(new ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8))) + ByteArrayOutputStream outputStream = pipeline.from(string2InputStream(request)) .map(jsonToJsonDeref::transform, params, questionnaireName.toLowerCase()) .map(jsonToXML::transform, params, questionnaireName.toLowerCase()) .map(poguesXMLToDDI::transform, params, questionnaireName.toLowerCase()) @@ -171,7 +171,7 @@ public ResponseEntity visualizeStromaeV3FromBody(@RequestBody String req params.put("nomenclatureIds", SuggesterVisuTreatment.getNomenclatureIdsFromQuestionnaire(request)); params.put("dsfr", true); URI uri; - ByteArrayOutputStream outputStream = pipeline.from(new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8))) + ByteArrayOutputStream outputStream = pipeline.from(string2InputStream(request)) .map(jsonToJsonDeref::transform, params, questionnaireName.toLowerCase()) .map(jsonToXML::transform, params, questionnaireName.toLowerCase()) .map(poguesXMLToDDI::transform, params, questionnaireName.toLowerCase()) @@ -192,7 +192,7 @@ public ResponseEntity visualizeFromDDIBody(@RequestBody String request, params.put("dataCollection", dataCollection.toLowerCase()); params.put("questionnaire", questionnaire.toLowerCase()); URI uri; - ByteArrayOutputStream outputStream = pipeline.from(new ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8))) + ByteArrayOutputStream outputStream = pipeline.from(string2InputStream(request)) .map(ddiToXForm::transform, params, questionnaire.toLowerCase()) .transform(); uri = xformToUri.transform(output2Input(outputStream), params, questionnaire.toLowerCase());