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

Next: 4.9.1 #322

Merged
merged 5 commits into from
Nov 13, 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 Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:21.0.4_7-jre
FROM eclipse-temurin:21.0.5_11-jre

ENV PATH_TO_JAR=/opt/pogues/pogues-bo.jar
WORKDIR /opt/pogues
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version>
<version>3.3.5</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>

<groupId>fr.insee</groupId>
<artifactId>Pogues-BO</artifactId>
<packaging>jar</packaging>
<version>4.8.1</version>
<version>4.9.1</version>
<name>Pogues-Back-Office</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>21</java.version>
<final.asset.name>pogues-bo</final.asset.name>
<pogues-model.version>1.3.14</pogues-model.version>
<fop.version>2.9</fop.version>
<pogues-model.version>1.4.0</pogues-model.version>
<fop.version>2.10</fop.version>
<springdoc-openapi-ui.version>2.6.0</springdoc-openapi-ui.version>
<jacoco.version>0.8.12</jacoco.version>
<saxon.version>12.5</saxon.version>
<liquibase.version>4.29.1</liquibase.version>
<liquibase.version>4.29.2</liquibase.version>

<caffeine.version>3.1.8</caffeine.version>

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
@@ -1,7 +1,9 @@
package fr.insee.pogues.api.remote.eno.transforms;

import fr.insee.pogues.exception.EnoException;
import fr.insee.pogues.webservice.model.StudyUnitEnum;
import fr.insee.pogues.webservice.rest.PoguesException;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -15,6 +17,7 @@
import org.springframework.web.reactive.function.client.WebClientResponseException;
import org.springframework.web.util.UriComponentsBuilder;

import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Map;
Expand All @@ -27,9 +30,11 @@ public class EnoClientImpl implements EnoClient{
String enoHost;

@Autowired
private WebClient webClient;
private final WebClient webClient;

private static final String BASE_PATH = "/questionnaire/DEFAULT";
private static final String DEFAULT_CONTEXT = "DEFAULT";
private static final String BASE_PATH = "/questionnaire/" + DEFAULT_CONTEXT;
private static final String DSFR_QUERY_PARAM = "dsfr";
private static final String MODE = "CAWI";

public EnoClientImpl(WebClient webClient) {
Expand All @@ -39,14 +44,12 @@ public EnoClientImpl(WebClient webClient) {
@Override
public String getDDI32ToDDI33 (String inputAsString) throws EnoException, PoguesException {
return callEnoApi(inputAsString, "/questionnaire/ddi32-2-ddi33");
};

}

@Override
public String getXMLPoguesToDDI (String inputAsString) throws EnoException, PoguesException {
return callEnoApi(inputAsString, "/questionnaire/poguesxml-2-ddi");
};

}

@Override
public String getDDIToFO(String inputAsString) throws EnoException, PoguesException {
Expand All @@ -60,26 +63,68 @@ public String getDDITOLunaticXML(String inputAsString) throws EnoException, Pogu

@Override
public String getDDITOLunaticJSON(String inputAsString, Map<String, Object> params) throws EnoException, PoguesException {
MultiValueMap<String,String> queryParams = new LinkedMultiValueMap<>();
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");
return callEnoApiWithParams(inputAsString, WSPath, queryParams);

StudyUnitEnum contextRequestParam = getContextParam(params);
String wsPath = buildWSPath(contextRequestParam, modePathParam);

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

/**
* Retrieves the context parameter from the provided map of parameters.
* This method attempts to fetch the "context" parameter from the specified map
* and casts it to a {@code StudyUnitEnum}. If the parameter is not present or is {@code null},
* it returns a default value {@code StudyUnitEnum.DEFAULT}.
* @param params a map of parameters where the "context" key may be present,
* associated with a {@code StudyUnitEnum} value.
* @return the {@code StudyUnitEnum} value associated with the "context" key,
* or {@code StudyUnitEnum.DEFAULT} if not found or {@code null}.
*/
static StudyUnitEnum getContextParam(Map<String, Object> params) {
StudyUnitEnum context = (StudyUnitEnum) params.get("context");
return (context != null) ? context : StudyUnitEnum.DEFAULT;
}

/**
* Constructs the WSPath for the questionnaire based on the context and mode.
*
* @param context The context of type {@link StudyUnitEnum} used in the path. Cannot be null.
* @param mode The specified mode for the path. Cannot be null.
* @return The WSPath as a string, structured as "questionnaire/{context}/lunatic-json/{mode}".
* @throws NullPointerException if {@code context} or {@code mode} is null.
*/
static String buildWSPath(@NonNull StudyUnitEnum context, @NonNull String mode) {
return "questionnaire/" + context + "/lunatic-json/" + mode;
}

@Override
public String getDDITOXForms(String inputAsString) throws EnoException, PoguesException {
return callEnoApi(inputAsString, BASE_PATH+"/xforms");
}

@Override
public String getJSONPoguesToLunaticJson(String inputAsString, Map<String, Object> params) throws IOException, EnoException {
log.info("getJSONPoguesToLunaticJson - started");
MultiValueMap<String,String> queryParams = new LinkedMultiValueMap<>();
String modePathParam = params.get("mode") != null ? params.get("mode").toString() : MODE;
String wsPath = String.format("/questionnaire/pogues-2-lunatic/%s/%s",
DEFAULT_CONTEXT,
modePathParam);
log.info("WSPath : {} ",wsPath);
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");
};

}

@Override
public void getParameters () throws Exception{
public void getParameters () {
URI uri = UriComponentsBuilder
.fromHttpUrl(enoHost)
.path("/parameters/xml/all")
Expand All @@ -91,17 +136,17 @@ public void getParameters () throws Exception{
.retrieve().bodyToMono(String.class).block();

log.debug(xmlParams);
};
}

private String callEnoApi(String inputAsString, String WSPath) throws EnoException, PoguesException {
private String callEnoApi(String inputAsString, String wsPath) throws EnoException, PoguesException {
MultiValueMap<String,String> queryParams = new LinkedMultiValueMap<>();
return callEnoApiWithParams(inputAsString, WSPath, queryParams);
return callEnoApiWithParams(inputAsString, wsPath, queryParams);
}

private String callEnoApiWithParams(String inputAsString, String WSPath, MultiValueMap<String,String> params) throws EnoException, PoguesException {
private String callEnoApiWithParams(String inputAsString, String wsPath, MultiValueMap<String,String> params) throws EnoException, PoguesException {
URI uri = UriComponentsBuilder
.fromHttpUrl(enoHost)
.path(WSPath)
.path(wsPath)
.queryParams(params)
.build().toUri();

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
private EnoClient enoClient;

@Override
public ByteArrayOutputStream transform(InputStream inputStream, Map<String, Object> params, String surveyName) throws Exception {
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);
}
}
Loading