diff --git a/.github/workflows/create-snapshot.yaml b/.github/workflows/create-snapshot.yaml index 80ef12bd..e6c96d0d 100644 --- a/.github/workflows/create-snapshot.yaml +++ b/.github/workflows/create-snapshot.yaml @@ -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 diff --git a/pom.xml b/pom.xml index b82032a1..9abf620a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.3.0 + 3.3.1 @@ -13,16 +13,16 @@ fr.insee Pogues-BO jar - 4.7.4-SNAPSHOT + 4.7.5-SNAPSHOT Pogues-Back-Office UTF-8 21 pogues-bo - 1.3.7 + 1.3.12 2.9 - 2.5.0 + 2.6.0 0.8.12 12.4 4.28.0 diff --git a/src/main/java/fr/insee/pogues/transforms/visualize/PoguesJSONToPoguesJSONDerefImpl.java b/src/main/java/fr/insee/pogues/transforms/visualize/PoguesJSONToPoguesJSONDerefImpl.java index 40779a4d..6eb25b05 100644 --- a/src/main/java/fr/insee/pogues/transforms/visualize/PoguesJSONToPoguesJSONDerefImpl.java +++ b/src/main/java/fr/insee/pogues/transforms/visualize/PoguesJSONToPoguesJSONDerefImpl.java @@ -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; @@ -26,6 +26,9 @@ public class PoguesJSONToPoguesJSONDerefImpl implements PoguesJSONToPoguesJSONDe @Autowired QuestionnairesService questionnairesService; + @Autowired + SuggesterVisuService suggesterVisuService; + public PoguesJSONToPoguesJSONDerefImpl() {} public PoguesJSONToPoguesJSONDerefImpl(QuestionnairesService questionnairesService) { @@ -45,7 +48,7 @@ public ByteArrayOutputStream transform(InputStream input, Map 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); } diff --git a/src/main/java/fr/insee/pogues/transforms/visualize/uri/LunaticJSONToUriQueenImpl.java b/src/main/java/fr/insee/pogues/transforms/visualize/uri/LunaticJSONToUriQueenImpl.java index c8422b14..e76d7d85 100644 --- a/src/main/java/fr/insee/pogues/transforms/visualize/uri/LunaticJSONToUriQueenImpl.java +++ b/src/main/java/fr/insee/pogues/transforms/visualize/uri/LunaticJSONToUriQueenImpl.java @@ -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; @@ -23,6 +23,9 @@ public class LunaticJSONToUriQueenImpl implements LunaticJSONToUriQueen{ @Autowired private QuestionnairesService questionnaireService; + @Autowired + private SuggesterVisuService suggesterVisuService; + @Value("${application.host}") private String apiHost; @@ -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 params, String surveyName) throws Exception { JsonNode jsonContent = jsonStringtoJsonNode(new String(input.readAllBytes(), StandardCharsets.UTF_8)); @@ -58,7 +58,7 @@ public URI transform(InputStream input, Map params, String surve } List nomenclatureIds = (List) 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( diff --git a/src/main/java/fr/insee/pogues/transforms/visualize/uri/LunaticJSONToUriStromaeV2Impl.java b/src/main/java/fr/insee/pogues/transforms/visualize/uri/LunaticJSONToUriStromaeV2Impl.java index d99bf77a..7e711f05 100644 --- a/src/main/java/fr/insee/pogues/transforms/visualize/uri/LunaticJSONToUriStromaeV2Impl.java +++ b/src/main/java/fr/insee/pogues/transforms/visualize/uri/LunaticJSONToUriStromaeV2Impl.java @@ -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; @@ -23,6 +23,9 @@ public class LunaticJSONToUriStromaeV2Impl implements LunaticJSONToUriStromaeV2{ @Autowired private QuestionnairesService questionnaireService; + @Autowired + private SuggesterVisuService suggesterVisuService; + @Value("${application.host}") private String apiHost; @@ -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 params, String surveyName) throws Exception { JsonNode jsonContent = jsonStringtoJsonNode(new String(input.readAllBytes(), StandardCharsets.UTF_8)); @@ -61,7 +60,7 @@ public URI transform(InputStream input, Map params, String surve } List nomenclatureIds = (List) 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( diff --git a/src/main/java/fr/insee/pogues/transforms/visualize/uri/LunaticJSONToUriStromaeV3Impl.java b/src/main/java/fr/insee/pogues/transforms/visualize/uri/LunaticJSONToUriStromaeV3Impl.java index 74ced245..318a7e08 100644 --- a/src/main/java/fr/insee/pogues/transforms/visualize/uri/LunaticJSONToUriStromaeV3Impl.java +++ b/src/main/java/fr/insee/pogues/transforms/visualize/uri/LunaticJSONToUriStromaeV3Impl.java @@ -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; @@ -23,6 +23,9 @@ public class LunaticJSONToUriStromaeV3Impl implements LunaticJSONToUriStromaeV3{ @Autowired private QuestionnairesService questionnaireService; + @Autowired + private SuggesterVisuService suggesterVisuService; + @Value("${application.host}") private String apiHost; @@ -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 params, String surveyName) throws Exception { JsonNode jsonContent = jsonStringtoJsonNode(new String(input.readAllBytes(), StandardCharsets.UTF_8)); @@ -60,7 +60,7 @@ public URI transform(InputStream input, Map params, String surve } List nomenclatureIds = (List) 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( diff --git a/src/main/java/fr/insee/pogues/utils/suggester/SuggesterVisuTreatment.java b/src/main/java/fr/insee/pogues/utils/suggester/SuggesterVisuService.java similarity index 76% rename from src/main/java/fr/insee/pogues/utils/suggester/SuggesterVisuTreatment.java rename to src/main/java/fr/insee/pogues/utils/suggester/SuggesterVisuService.java index cec38b8b..8bc7b309 100644 --- a/src/main/java/fr/insee/pogues/utils/suggester/SuggesterVisuTreatment.java +++ b/src/main/java/fr/insee/pogues/utils/suggester/SuggesterVisuService.java @@ -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; @@ -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 nomenclaturesIds, String apiUrl){ + public JsonNode createJsonNomenclaturesForVisu(List 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; @@ -43,7 +44,7 @@ public static JsonNode createJsonNomenclaturesForVisu(List nomenclatures * @param jsonQuestionnairePoguesModel * @return List of nomenclatureIds inside questionnaire */ - public static List getNomenclatureIdsFromQuestionnaire(String jsonQuestionnairePoguesModel) throws JAXBException, JsonProcessingException { + public List getNomenclatureIdsFromQuestionnaire(String jsonQuestionnairePoguesModel) throws JAXBException, JsonProcessingException { Questionnaire questionnaire = PoguesDeserializer.questionnaireToJavaObject(jsonStringtoJsonNode(jsonQuestionnairePoguesModel)); return getNomenclatureIdsFromQuestionnaire(questionnaire); } @@ -53,10 +54,11 @@ public static List getNomenclatureIdsFromQuestionnaire(String jsonQuesti * @param questionnaire * @return List of nomenclatureIds inside questionnaire */ - public static List getNomenclatureIdsFromQuestionnaire(Questionnaire questionnaire){ + public List getNomenclatureIdsFromQuestionnaire(Questionnaire questionnaire){ return questionnaire.getCodeLists().getCodeList().stream() .filter(codeList -> codeList.getSuggesterParameters() != null) .map(codeList -> codeList.getId()) .toList(); } + } diff --git a/src/main/java/fr/insee/pogues/webservice/rest/PoguesPersistence.java b/src/main/java/fr/insee/pogues/webservice/rest/PoguesPersistence.java index 492ddc77..605f2b10 100644 --- a/src/main/java/fr/insee/pogues/webservice/rest/PoguesPersistence.java +++ b/src/main/java/fr/insee/pogues/webservice/rest/PoguesPersistence.java @@ -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; @@ -52,6 +53,9 @@ public class PoguesPersistence { @Autowired private VariablesService variablesService; + @Autowired + private SuggesterVisuService suggesterVisuService; + @Autowired private UserProvider userProvider; @@ -350,4 +354,25 @@ public ResponseEntity 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 getNomenclaturesUrls( + @PathVariable(value = "id") String id + ) throws Exception { + JsonNode jsonPoguesQuestionnaire = questionnaireService.getQuestionnaireByIDWithReferences(id); + List nomenclaturesIds = suggesterVisuService.getNomenclatureIdsFromQuestionnaire(String.valueOf(jsonPoguesQuestionnaire)); + JsonNode nomenclaturesUrls = suggesterVisuService.createJsonNomenclaturesForVisu(nomenclaturesIds); + return ResponseEntity.status(HttpStatus.OK).body(nomenclaturesUrls); + } } 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 74d14d19..3c1b74bf 100644 --- a/src/main/java/fr/insee/pogues/webservice/rest/VisualizeWithURI.java +++ b/src/main/java/fr/insee/pogues/webservice/rest/VisualizeWithURI.java @@ -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; @@ -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) @@ -101,7 +104,7 @@ public ResponseEntity visualizeCatiQueenFromBody(@RequestBody String req Map 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()) @@ -122,7 +125,7 @@ public ResponseEntity visualizeQueenFromBody(@RequestBody String request Map 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()) @@ -144,7 +147,7 @@ public ResponseEntity 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)) @@ -168,7 +171,7 @@ public ResponseEntity 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))