Skip to content

Commit

Permalink
Merge branch 'next' into fix/timeout-webclient
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave committed Jul 2, 2024
2 parents cc4ecee + f63e100 commit 7e5de0d
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create-snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
exit 1
fi
if ! [[ "${{ steps.version-step.outputs.version }}" =~ ^[0-9]+.[0-9]+.[0-9]+-SNAPSHOT$ ]]; then
if ! [[ "${{ steps.version-step.outputs.version }}" =~ ^[0-9]+.[0-9]+.[0-9]+-SNAPSHOT.?[0-9]*$ ]]; then
echo "Nothing to tag/release, the tag ${{ steps.version-step.outputs.version }} is not in correct format X.Y.Z-SNAPSHOT"
exit 1
fi
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>

<groupId>fr.insee</groupId>
<artifactId>Pogues-BO</artifactId>
<packaging>jar</packaging>
<version>4.7.4-SNAPSHOT</version>
<version>4.7.5-SNAPSHOT</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.7</pogues-model.version>
<pogues-model.version>1.3.12</pogues-model.version>
<fop.version>2.9</fop.version>
<springdoc-openapi-ui.version>2.5.0</springdoc-openapi-ui.version>
<springdoc-openapi-ui.version>2.6.0</springdoc-openapi-ui.version>
<jacoco.version>0.8.12</jacoco.version>
<saxon.version>12.4</saxon.version>
<liquibase.version>4.28.0</liquibase.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import fr.insee.pogues.persistence.service.QuestionnairesService;
import fr.insee.pogues.utils.PoguesDeserializer;
import fr.insee.pogues.utils.PoguesSerializer;
import fr.insee.pogues.utils.suggester.SuggesterVisuTreatment;
import fr.insee.pogues.utils.suggester.SuggesterVisuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -26,6 +26,9 @@ public class PoguesJSONToPoguesJSONDerefImpl implements PoguesJSONToPoguesJSONDe
@Autowired
QuestionnairesService questionnairesService;

@Autowired
SuggesterVisuService suggesterVisuService;

public PoguesJSONToPoguesJSONDerefImpl() {}

public PoguesJSONToPoguesJSONDerefImpl(QuestionnairesService questionnairesService) {
Expand All @@ -45,7 +48,7 @@ public ByteArrayOutputStream transform(InputStream input, Map<String, Object> pa
}
Questionnaire questionnaire = transformAsQuestionnaire(inputStream2String(input));
// Update nomenclatureIds with ids from references
params.put("nomenclatureIds", SuggesterVisuTreatment.getNomenclatureIdsFromQuestionnaire(questionnaire));
params.put("nomenclatureIds", suggesterVisuService.getNomenclatureIdsFromQuestionnaire(questionnaire));
String questionnaireAsString = PoguesSerializer.questionnaireJavaToString(questionnaire);
return string2BOAS(questionnaireAsString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import fr.insee.pogues.persistence.service.QuestionnairesService;
import fr.insee.pogues.utils.suggester.SuggesterVisuTreatment;
import fr.insee.pogues.utils.suggester.SuggesterVisuService;
import fr.insee.pogues.webservice.rest.PoguesException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -23,6 +23,9 @@ public class LunaticJSONToUriQueenImpl implements LunaticJSONToUriQueen{
@Autowired
private QuestionnairesService questionnaireService;

@Autowired
private SuggesterVisuService suggesterVisuService;

@Value("${application.host}")
private String apiHost;

Expand All @@ -42,9 +45,6 @@ public class LunaticJSONToUriQueenImpl implements LunaticJSONToUriQueen{
@Value("${application.queen.vis.queryparams.nomenclatures}")
private String queryParamsNomenclatures;

@Value("${application.api.nomenclatures}")
private String apiNomenclatures;

@Override
public URI transform(InputStream input, Map<String, Object> params, String surveyName) throws Exception {
JsonNode jsonContent = jsonStringtoJsonNode(new String(input.readAllBytes(), StandardCharsets.UTF_8));
Expand All @@ -58,7 +58,7 @@ public URI transform(InputStream input, Map<String, Object> params, String surve
}

List<String> nomenclatureIds = (List<String>) params.get("nomenclatureIds");
String jsonStringNomenclaturesForVisu = SuggesterVisuTreatment.createJsonNomenclaturesForVisu(nomenclatureIds, apiNomenclatures).toString();
String jsonStringNomenclaturesForVisu = suggesterVisuService.createJsonNomenclaturesForVisu(nomenclatureIds).toString();
String urlGetJsonLunatic = String.format("%s://%s%s/api/persistence/questionnaire/json-lunatic/%s", apiScheme, apiHost, apiName, id);

return URI.create(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import fr.insee.pogues.persistence.service.QuestionnairesService;
import fr.insee.pogues.utils.suggester.SuggesterVisuTreatment;
import fr.insee.pogues.utils.suggester.SuggesterVisuService;
import fr.insee.pogues.webservice.rest.PoguesException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -23,6 +23,9 @@ public class LunaticJSONToUriStromaeV2Impl implements LunaticJSONToUriStromaeV2{
@Autowired
private QuestionnairesService questionnaireService;

@Autowired
private SuggesterVisuService suggesterVisuService;

@Value("${application.host}")
private String apiHost;

Expand All @@ -44,10 +47,6 @@ public class LunaticJSONToUriStromaeV2Impl implements LunaticJSONToUriStromaeV2{
@Value("${application.stromaev2.vis.queryparams.nomenclatures}")
private String queryParamsNomenclatures;

@Value("${application.api.nomenclatures}")
private String apiNomenclatures;


@Override
public URI transform(InputStream input, Map<String, Object> params, String surveyName) throws Exception {
JsonNode jsonContent = jsonStringtoJsonNode(new String(input.readAllBytes(), StandardCharsets.UTF_8));
Expand All @@ -61,7 +60,7 @@ public URI transform(InputStream input, Map<String, Object> params, String surve
}

List<String> nomenclatureIds = (List<String>) params.get("nomenclatureIds");
String jsonStringNomenclaturesForVisu = SuggesterVisuTreatment.createJsonNomenclaturesForVisu(nomenclatureIds, apiNomenclatures).toString();
String jsonStringNomenclaturesForVisu = suggesterVisuService.createJsonNomenclaturesForVisu(nomenclatureIds).toString();
String urlGetJsonLunatic = String.format("%s://%s%s/api/persistence/questionnaire/json-lunatic/%s", apiScheme, apiHost, apiName, id);

return URI.create(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import fr.insee.pogues.persistence.service.QuestionnairesService;
import fr.insee.pogues.utils.suggester.SuggesterVisuTreatment;
import fr.insee.pogues.utils.suggester.SuggesterVisuService;
import fr.insee.pogues.webservice.rest.PoguesException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -23,6 +23,9 @@ public class LunaticJSONToUriStromaeV3Impl implements LunaticJSONToUriStromaeV3{
@Autowired
private QuestionnairesService questionnaireService;

@Autowired
private SuggesterVisuService suggesterVisuService;

@Value("${application.host}")
private String apiHost;

Expand All @@ -44,9 +47,6 @@ public class LunaticJSONToUriStromaeV3Impl implements LunaticJSONToUriStromaeV3{
@Value("${application.stromaev3.vis.queryparams.nomenclatures}")
private String queryParamsNomenclatures;

@Value("${application.api.nomenclatures}")
private String apiNomenclatures;

@Override
public URI transform(InputStream input, Map<String, Object> params, String surveyName) throws Exception {
JsonNode jsonContent = jsonStringtoJsonNode(new String(input.readAllBytes(), StandardCharsets.UTF_8));
Expand All @@ -60,7 +60,7 @@ public URI transform(InputStream input, Map<String, Object> params, String surve
}

List<String> nomenclatureIds = (List<String>) params.get("nomenclatureIds");
String jsonStringNomenclaturesForVisu = SuggesterVisuTreatment.createJsonNomenclaturesForVisu(nomenclatureIds, apiNomenclatures).toString();
String jsonStringNomenclaturesForVisu = suggesterVisuService.createJsonNomenclaturesForVisu(nomenclatureIds).toString();
String urlGetJsonLunatic = String.format("%s://%s%s/api/persistence/questionnaire/json-lunatic/%s", apiScheme, apiHost, apiName, id);

return URI.create(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import fr.insee.pogues.model.Questionnaire;
import fr.insee.pogues.utils.PoguesDeserializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.xml.bind.JAXBException;
import java.util.List;
Expand All @@ -16,23 +18,22 @@
* Class with static method.
* These method are usefull for visualization with nomenclatures
*/
public class SuggesterVisuTreatment {
private SuggesterVisuTreatment() {

}
@Service
public class SuggesterVisuService {

@Value("${application.api.nomenclatures}")
private String apiNomenclatures;
/**
* Create a JSONObject for queryParam for Visualisation
* @param nomenclaturesIds
* @param apiUrl
* @return The expected jsonObject
* @example_return :{ "id_1": "${apiUrl}/api/nomenclature/${id_1}", "id_2": "${apiUrl}/api/nomenclature/${id_2}"}
*/
public static JsonNode createJsonNomenclaturesForVisu(List<String> nomenclaturesIds, String apiUrl){
public JsonNode createJsonNomenclaturesForVisu(List<String> nomenclaturesIds){
ObjectNode finalNomenclatures = JsonNodeFactory.instance.objectNode();
nomenclaturesIds.forEach(
id -> {
finalNomenclatures.put(id,String.format("%s/api/nomenclature/%s", apiUrl, id));
finalNomenclatures.put(id,String.format("%s/api/nomenclature/%s", apiNomenclatures, id));
}
);
return finalNomenclatures;
Expand All @@ -43,7 +44,7 @@ public static JsonNode createJsonNomenclaturesForVisu(List<String> nomenclatures
* @param jsonQuestionnairePoguesModel
* @return List of nomenclatureIds inside questionnaire
*/
public static List<String> getNomenclatureIdsFromQuestionnaire(String jsonQuestionnairePoguesModel) throws JAXBException, JsonProcessingException {
public List<String> getNomenclatureIdsFromQuestionnaire(String jsonQuestionnairePoguesModel) throws JAXBException, JsonProcessingException {
Questionnaire questionnaire = PoguesDeserializer.questionnaireToJavaObject(jsonStringtoJsonNode(jsonQuestionnairePoguesModel));
return getNomenclatureIdsFromQuestionnaire(questionnaire);
}
Expand All @@ -53,10 +54,11 @@ public static List<String> getNomenclatureIdsFromQuestionnaire(String jsonQuesti
* @param questionnaire
* @return List of nomenclatureIds inside questionnaire
*/
public static List<String> getNomenclatureIdsFromQuestionnaire(Questionnaire questionnaire){
public List<String> getNomenclatureIdsFromQuestionnaire(Questionnaire questionnaire){
return questionnaire.getCodeLists().getCodeList().stream()
.filter(codeList -> codeList.getSuggesterParameters() != null)
.map(codeList -> codeList.getId())
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import fr.insee.pogues.configuration.properties.ApplicationProperties;
import fr.insee.pogues.persistence.service.QuestionnairesService;
import fr.insee.pogues.persistence.service.VariablesService;
import fr.insee.pogues.utils.suggester.SuggesterVisuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down Expand Up @@ -52,6 +53,9 @@ public class PoguesPersistence {
@Autowired
private VariablesService variablesService;

@Autowired
private SuggesterVisuService suggesterVisuService;

@Autowired
private UserProvider userProvider;

Expand Down Expand Up @@ -350,4 +354,25 @@ public ResponseEntity<Object> createJsonLunatic(
throw new PoguesException(400,BAD_REQUEST,String.format(MESSAGE_INVALID_IDENTIFIER,id));
}
}

@GetMapping("questionnaire/{id}/nomenclatures")
@Operation(
operationId = "getNomenclaturesUrls",
summary = "Get object representation of id:url for suggester of a questionnaire",
description = "Gets the suggesters with questionnaire id {id}",
responses = {
@ApiResponse(content = @Content(mediaType = "application/json"))}
)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Success"),
@ApiResponse(responseCode = "404", description = "Not found")
})
public ResponseEntity<JsonNode> getNomenclaturesUrls(
@PathVariable(value = "id") String id
) throws Exception {
JsonNode jsonPoguesQuestionnaire = questionnaireService.getQuestionnaireByIDWithReferences(id);
List<String> nomenclaturesIds = suggesterVisuService.getNomenclatureIdsFromQuestionnaire(String.valueOf(jsonPoguesQuestionnaire));
JsonNode nomenclaturesUrls = suggesterVisuService.createJsonNomenclaturesForVisu(nomenclaturesIds);
return ResponseEntity.status(HttpStatus.OK).body(nomenclaturesUrls);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import fr.insee.pogues.transforms.visualize.uri.LunaticJSONToUriStromaeV2;
import fr.insee.pogues.transforms.visualize.uri.LunaticJSONToUriStromaeV3;
import fr.insee.pogues.transforms.visualize.uri.XFormsToURIStromaeV1;
import fr.insee.pogues.utils.suggester.SuggesterVisuTreatment;
import fr.insee.pogues.utils.suggester.SuggesterVisuService;
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 @@ -66,6 +66,9 @@ public class VisualizeWithURI {
@Autowired
PoguesJSONToPoguesJSONDeref jsonToJsonDeref;

@Autowired
SuggesterVisuService suggesterVisuService;

private static final String CONTENT_DISPOSITION = HttpHeaders.CONTENT_DISPOSITION;

@PostMapping(path = "visualize/{dataCollection}/{questionnaire}", consumes = MediaType.APPLICATION_JSON_VALUE)
Expand Down Expand Up @@ -101,7 +104,7 @@ public ResponseEntity<String> visualizeCatiQueenFromBody(@RequestBody String req
Map<String, Object> params = new HashMap<>();
params.put("mode", "CATI");
params.put("needDeref", ref);
params.put("nomenclatureIds", SuggesterVisuTreatment.getNomenclatureIdsFromQuestionnaire(request));
params.put("nomenclatureIds", suggesterVisuService.getNomenclatureIdsFromQuestionnaire(request));
URI uri;
ByteArrayOutputStream outputStream = pipeline.from(string2InputStream(request))
.map(jsonToJsonDeref::transform, params, questionnaireName.toLowerCase())
Expand All @@ -122,7 +125,7 @@ public ResponseEntity<String> visualizeQueenFromBody(@RequestBody String request
Map<String, Object> params = new HashMap<>();
params.put("mode", "CAPI");
params.put("needDeref", ref);
params.put("nomenclatureIds", SuggesterVisuTreatment.getNomenclatureIdsFromQuestionnaire(request));
params.put("nomenclatureIds", suggesterVisuService.getNomenclatureIdsFromQuestionnaire(request));
URI uri;
ByteArrayOutputStream outputStream = pipeline.from(new ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8)))
.map(jsonToJsonDeref::transform, params, questionnaireName.toLowerCase())
Expand All @@ -144,7 +147,7 @@ public ResponseEntity<String> visualizeStromaeV2FromBody(@RequestBody String req
params.put("questionnaire", questionnaireName.toLowerCase());
params.put("needDeref", ref);
params.put("mode", "CAWI");
params.put("nomenclatureIds", SuggesterVisuTreatment.getNomenclatureIdsFromQuestionnaire(request));
params.put("nomenclatureIds", suggesterVisuService.getNomenclatureIdsFromQuestionnaire(request));

URI uri;
ByteArrayOutputStream outputStream = pipeline.from(string2InputStream(request))
Expand All @@ -168,7 +171,7 @@ public ResponseEntity<String> visualizeStromaeV3FromBody(@RequestBody String req
params.put("questionnaire", questionnaireName.toLowerCase());
params.put("needDeref", ref);
params.put("mode", "CAWI");
params.put("nomenclatureIds", SuggesterVisuTreatment.getNomenclatureIdsFromQuestionnaire(request));
params.put("nomenclatureIds", suggesterVisuService.getNomenclatureIdsFromQuestionnaire(request));
params.put("dsfr", true);
URI uri;
ByteArrayOutputStream outputStream = pipeline.from(string2InputStream(request))
Expand Down

0 comments on commit 7e5de0d

Please sign in to comment.