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

feat: add new ENO transformation PoguesJSONToLunaticJSON #314

Merged
merged 3 commits into from
Oct 30, 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<groupId>fr.insee</groupId>
<artifactId>Pogues-BO</artifactId>
<packaging>jar</packaging>
<version>4.8.1</version>
<version>4.8.2-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be 4.9.0 since its a feature

<name>Pogues-Back-Office</name>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface EnoClient {
String getDDITOLunaticJSON(String inputAsString, Map<String, Object> params) throws URISyntaxException, IOException, EnoException;

String getDDITOXForms(String inputAsString) throws URISyntaxException, IOException, EnoException;

String getJSONPoguesToLunaticJson(String inputAsString, Map<String, Object> params) throws URISyntaxException, IOException, EnoException;

void getParameters () throws Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import org.springframework.web.reactive.function.client.WebClientResponseException;
import org.springframework.web.util.UriComponentsBuilder;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Map;

Expand All @@ -29,7 +31,11 @@ public class EnoClientImpl implements EnoClient{
@Autowired
private WebClient webClient;

private static final String BASE_PATH = "/questionnaire/DEFAULT";
private static String DEFAULT_CONTEXT = "DEFAULT";

private static final String DSFR_QUERY_PARAM = "dsfr";

private static final String BASE_PATH = "/questionnaire/" + DEFAULT_CONTEXT;
private static final String MODE = "CAWI";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

à renommer en CAWI_MODE ou qqch de plus explicite ?


public EnoClientImpl(WebClient webClient) {
Expand Down Expand Up @@ -63,7 +69,7 @@ public String getDDITOLunaticJSON(String inputAsString, Map<String, Object> para
MultiValueMap<String,String> queryParams = new LinkedMultiValueMap<>();
String modePathParam = params.get("mode") != null ? params.get("mode").toString() : MODE;
String WSPath = BASE_PATH + "/lunatic-json/" + modePathParam;
queryParams.add("dsfr", Boolean.TRUE.equals(params.get("dsfr")) ? "true" : "false");
queryParams.add(DSFR_QUERY_PARAM, Boolean.TRUE.equals(params.get("dsfr")) ? "true" : "false");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dsfr" est encore en dur dans params.get("dsfr")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peut-être une façon plus simple de cast le booléen en string qu'avec un ternaire

+ vérifier qu'on a bien ce qu'on veut si c'est null

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

à encadrer dans une méthode pour contrôler le truc

return callEnoApiWithParams(inputAsString, WSPath, queryParams);
}

Expand All @@ -72,6 +78,19 @@ public String getDDITOXForms(String inputAsString) throws EnoException, PoguesEx
return callEnoApi(inputAsString, BASE_PATH+"/xforms");
}

@Override
public String getJSONPoguesToLunaticJson(String inputAsString, Map<String, Object> params) throws URISyntaxException, IOException, EnoException {
log.info("getJSONPoguesToLunaticJson - started");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peut-être que le log.info devrait être à un niveau plus élevé, log.debug ici ?

MultiValueMap<String,String> queryParams = new LinkedMultiValueMap<>();
String modePathParam = params.get("mode") != null ? params.get("mode").toString() : MODE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getOrDefault au lieu du ternaire ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peut-être extraire ce bout de logique dans une méthode pour bien gérer le cas null

String WSPath = String.format("/questionnaire/pogues-2-lunatic/%s/%s",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nom de variable locale qui commence par une majuscule -> wsPath

DEFAULT_CONTEXT,
modePathParam);
log.info("WSPath : {} ",WSPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.debug ?

queryParams.add(DSFR_QUERY_PARAM, Boolean.TRUE.equals(params.get("dsfr")) ? "true" : "false");
return callEnoApiWithParams(inputAsString, WSPath, queryParams);
}

@Override
public String getDDIToODT (String inputAsString) throws EnoException, PoguesException {
return callEnoApi(inputAsString, BASE_PATH+"/fodt");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package fr.insee.pogues.transforms.visualize.eno;

import fr.insee.pogues.transforms.visualize.ModelTransformer;

public interface PoguesJSONToLunaticJSON extends ModelTransformer {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fr.insee.pogues.transforms.visualize.eno;

import fr.insee.pogues.api.remote.eno.transforms.EnoClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Map;

import static fr.insee.pogues.utils.IOStreamsUtils.inputStream2String;
import static fr.insee.pogues.utils.IOStreamsUtils.string2BOAS;

@Service
public class PoguesJSONToLunaticJSONImpl implements PoguesJSONToLunaticJSON {

@Autowired
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remplacer les autorwired par un constructeur

NB : peut être fait avec un record

private EnoClient enoClient;

@Override
public ByteArrayOutputStream transform(InputStream inputStream, Map<String, Object> params, String surveyName) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥲

String inputAsString = inputStream2String(inputStream);
String outputAsString = transform(inputAsString, params);
return string2BOAS(outputAsString);
}

private String transform(String inputAsString, Map<String, Object> params) throws Exception {
return enoClient.getJSONPoguesToLunaticJson(inputAsString, params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fr.insee.pogues.transforms.visualize.PoguesJSONToPoguesXML;
import fr.insee.pogues.transforms.visualize.eno.DDIToLunaticJSON;
import fr.insee.pogues.transforms.visualize.eno.DDIToXForms;
import fr.insee.pogues.transforms.visualize.eno.PoguesJSONToLunaticJSON;
import fr.insee.pogues.transforms.visualize.eno.PoguesXMLToDDI;
import fr.insee.pogues.transforms.visualize.uri.LunaticJSONToUriQueen;
import fr.insee.pogues.transforms.visualize.uri.LunaticJSONToUriStromaeV2;
Expand Down Expand Up @@ -52,7 +53,7 @@ public class VisualizeWithURI {
XFormsToURIStromaeV1 xformToUri;

@Autowired
DDIToLunaticJSON ddiToLunaticJSON;
PoguesJSONToLunaticJSON poguesJSONToLunaticJSON;

@Autowired
LunaticJSONToUriQueen lunaticJSONToUriQueen;
Expand All @@ -69,8 +70,6 @@ public class VisualizeWithURI {
@Autowired
SuggesterVisuService suggesterVisuService;

private static final String CONTENT_DISPOSITION = HttpHeaders.CONTENT_DISPOSITION;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice


@PostMapping(path = "visualize/{dataCollection}/{questionnaire}", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get visualization URI from JSON serialized Pogues entity", description = "dataCollection MUST refer to the name attribute owned by the nested DataCollectionObject")
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "JSON representation of the Pogues Model")
Expand Down Expand Up @@ -108,9 +107,7 @@ public ResponseEntity<String> visualizeCatiQueenFromBody(@RequestBody String req
URI uri;
ByteArrayOutputStream outputStream = pipeline.from(string2InputStream(request))
.map(jsonToJsonDeref::transform, params, questionnaireName.toLowerCase())
.map(jsonToXML::transform, params, questionnaireName.toLowerCase())
.map(poguesXMLToDDI::transform, params, questionnaireName.toLowerCase())
.map(ddiToLunaticJSON::transform, params, questionnaireName.toLowerCase())
.map(poguesJSONToLunaticJSON::transform, params, questionnaireName.toLowerCase())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on pourrait passer null plutôt que le questionnaireName s'il ne sert pas dans la sous méthode

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ou créer une nouvelle méthode map(Runable trunable, Map<String, Object> params) et utiliser celle là pour se préparer à virer celle avec le String questionnaireName

.transform();
uri = lunaticJSONToUriQueen.transform(output2Input(outputStream), params, questionnaireName.toLowerCase());
return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.TEXT_PLAIN).body(uri.toString());
Expand All @@ -129,9 +126,7 @@ public ResponseEntity<String> visualizeQueenFromBody(@RequestBody String request
URI uri;
ByteArrayOutputStream outputStream = pipeline.from(new ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8)))
.map(jsonToJsonDeref::transform, params, questionnaireName.toLowerCase())
.map(jsonToXML::transform, params, questionnaireName.toLowerCase())
.map(poguesXMLToDDI::transform, params, questionnaireName.toLowerCase())
.map(ddiToLunaticJSON::transform, params, questionnaireName.toLowerCase())
.map(poguesJSONToLunaticJSON::transform, params, questionnaireName.toLowerCase())
.transform();
uri = lunaticJSONToUriQueen.transform(output2Input(outputStream), params, questionnaireName.toLowerCase());
return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.TEXT_PLAIN).body(uri.toString());
Expand All @@ -152,9 +147,7 @@ public ResponseEntity<String> visualizeStromaeV2FromBody(@RequestBody String req
URI uri;
ByteArrayOutputStream outputStream = pipeline.from(string2InputStream(request))
.map(jsonToJsonDeref::transform, params, questionnaireName.toLowerCase())
.map(jsonToXML::transform, params, questionnaireName.toLowerCase())
.map(poguesXMLToDDI::transform, params, questionnaireName.toLowerCase())
.map(ddiToLunaticJSON::transform, params, questionnaireName.toLowerCase())
.map(poguesJSONToLunaticJSON::transform, params, questionnaireName.toLowerCase())
.transform();

uri = lunaticJSONToUriStromaeV2.transform(output2Input(outputStream), params, questionnaireName.toLowerCase());
Expand All @@ -176,9 +169,7 @@ public ResponseEntity<String> visualizeStromaeV3FromBody(@RequestBody String req
URI uri;
ByteArrayOutputStream outputStream = pipeline.from(string2InputStream(request))
.map(jsonToJsonDeref::transform, params, questionnaireName.toLowerCase())
.map(jsonToXML::transform, params, questionnaireName.toLowerCase())
.map(poguesXMLToDDI::transform, params, questionnaireName.toLowerCase())
.map(ddiToLunaticJSON::transform, params, questionnaireName.toLowerCase())
.map(poguesJSONToLunaticJSON::transform, params, questionnaireName.toLowerCase())
.transform();
uri = lunaticJSONToUriStromaeV3.transform(output2Input(outputStream), params, questionnaireName.toLowerCase());
return ResponseEntity.status(HttpStatus.OK).contentType(MediaType.TEXT_PLAIN).body(uri.toString());
Expand Down
Loading