Skip to content

Commit

Permalink
Issue #317 visualize links : separate web business/household
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiVerriez committed Oct 17, 2024
1 parent f7f91a1 commit fe57170
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -62,11 +63,23 @@ public String getDDITOLunaticXML(String inputAsString) throws EnoException, Pogu
public String getDDITOLunaticJSON(String inputAsString, Map<String, Object> params) throws EnoException, PoguesException {
MultiValueMap<String,String> queryParams = new LinkedMultiValueMap<>();
String modePathParam = params.get("mode") != null ? params.get("mode").toString() : MODE;
String WSPath = BASE_PATH + "/lunatic-json/" + modePathParam;
StudyUnitEnum contextRequestParam = getContextParam(params); // Extraction de cette logique dans une méthode séparée
String WSPath = buildWSPath(contextRequestParam, modePathParam); // Extraction de la construction du chemin

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

// Méthode pour récupérer le contexte
public StudyUnitEnum getContextParam(Map<String, Object> params) {
return (StudyUnitEnum) params.getOrDefault("context", StudyUnitEnum.DEFAULT);
}

// Méthode pour construire le WSPath
public String buildWSPath(StudyUnitEnum context, String mode) {
return "questionnaire/" + context + "/lunatic-json/" + mode;
}

@Override
public String getDDITOXForms(String inputAsString) throws EnoException, PoguesException {
return callEnoApi(inputAsString, BASE_PATH+"/xforms");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import fr.insee.pogues.transforms.visualize.uri.LunaticJSONToUriStromaeV3;
import fr.insee.pogues.transforms.visualize.uri.XFormsToURIStromaeV1;
import fr.insee.pogues.utils.suggester.SuggesterVisuService;
import fr.insee.pogues.webservice.model.StudyUnitEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
Expand Down Expand Up @@ -165,14 +166,16 @@ public ResponseEntity<String> visualizeStromaeV2FromBody(@RequestBody String req
@Operation(summary = "Get visualization URI Stromae V3 from JSON serialized Pogues entity", description = "Get visualization URI Stromae V3 from JSON serialized Pogues entity")
public ResponseEntity<String> visualizeStromaeV3FromBody(@RequestBody String request,
@PathVariable(value = "questionnaire") String questionnaireName,
@RequestParam(name = "references", defaultValue = "false") Boolean ref) throws Exception {
@RequestParam(name = "references", defaultValue = "false") Boolean ref, @RequestParam(defaultValue = "DEFAULT") StudyUnitEnum context) throws Exception {

PipeLine pipeline = new PipeLine();
Map<String, Object> params = new HashMap<>();
params.put("questionnaire", questionnaireName.toLowerCase());
params.put("needDeref", ref);
params.put("mode", "CAWI");
params.put("nomenclatureIds", suggesterVisuService.getNomenclatureIdsFromQuestionnaire(request));
params.put("dsfr", true);
params.put("context", context);
URI uri;
ByteArrayOutputStream outputStream = pipeline.from(string2InputStream(request))
.map(jsonToJsonDeref::transform, params, questionnaireName.toLowerCase())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package fr.insee.pogues.api.remote.eno.transforms;

import fr.insee.pogues.webservice.model.StudyUnitEnum;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.mockito.Mockito;
import org.springframework.web.reactive.function.client.WebClient;

import java.util.HashMap;
import java.util.Map;

public class EnoClientImplTest {
@Test
void testWSPathWhenContextIsMissing() {
// Mock de WebClient
WebClient webClient = Mockito.mock(WebClient.class);

// Création de l'instance d'EnoClientImpl avec WebClient mocké
EnoClientImpl client = new EnoClientImpl(webClient);

// Paramètres d'entrée
Map<String, Object> params = new HashMap<>();
params.put("mode", "CAWI"); // Mode explicite

// Appel de la méthode
String wsPath = client.buildWSPath(client.getContextParam(params), "CAWI");

// Vérification que le contexte par défaut est utilisé
assertEquals("questionnaire/DEFAULT/lunatic-json/CAWI", wsPath);
}

@ParameterizedTest
@EnumSource(StudyUnitEnum.class) // Test avec toutes les valeurs de StudyUnitEnum
void testWSPathWithDifferentContexts(StudyUnitEnum context) {
// Mock de WebClient
WebClient webClient = Mockito.mock(WebClient.class);

// Création de l'instance d'EnoClientImpl avec WebClient mocké
EnoClientImpl client = new EnoClientImpl(webClient);

// Paramètres d'entrée
Map<String, Object> params = new HashMap<>();
params.put("mode", "CAWI"); // Mode explicite
params.put("context", context); // Contexte à tester

// Appel de la méthode
String wsPath = client.buildWSPath(client.getContextParam(params), "CAWI");

// Vérification que le contexte correct est utilisé
assertEquals("questionnaire/" + context + "/lunatic-json/CAWI", wsPath);
}

}

0 comments on commit fe57170

Please sign in to comment.