diff --git a/pom.xml b/pom.xml index 027def78..5f7b79ee 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ Modules for queen back-office - 4.2.12 + 4.2.13 21 21 diff --git a/queen-application/src/main/java/fr/insee/queen/application/surveyunit/controller/PerfDataController.java b/queen-application/src/main/java/fr/insee/queen/application/surveyunit/controller/PerfDataController.java deleted file mode 100644 index fc53d1b5..00000000 --- a/queen-application/src/main/java/fr/insee/queen/application/surveyunit/controller/PerfDataController.java +++ /dev/null @@ -1,66 +0,0 @@ -package fr.insee.queen.application.surveyunit.controller; - -import com.fasterxml.jackson.databind.node.ObjectNode; -import fr.insee.queen.application.configuration.auth.AuthorityPrivileges; -import fr.insee.queen.application.pilotage.controller.PilotageComponent; -import fr.insee.queen.application.surveyunit.dto.input.StateDataInput; -import fr.insee.queen.application.surveyunit.dto.input.SurveyUnitDataStateDataUpdateInput; -import fr.insee.queen.application.web.validation.IdValid; -import fr.insee.queen.domain.pilotage.service.PilotageRole; -import fr.insee.queen.domain.surveyunit.model.StateData; -import fr.insee.queen.domain.surveyunit.service.DataService; -import fr.insee.queen.domain.surveyunit.service.SurveyUnitService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -@RestController -@Tag(name = "06. Survey units", description = "Endpoints for survey units") -@RequestMapping(path = "/api") -@Slf4j -@RequiredArgsConstructor -@Validated -@ConditionalOnExpression(value = "${feature.perfdata.enabled} == true") -public class PerfDataController { - private final SurveyUnitService surveyUnitService; - private final PilotageComponent pilotageComponent; - private final DataService dataService; - - /** - * Update a survey unit data/state-data - * - * @param surveyUnitId survey unit id - * @param surveyUnitUpdateInput survey unit form data/state data - */ - @Operation(summary = "Update survey-unit data/state-data") - @PatchMapping(path = {"/survey-unit/{id}"}) - @PreAuthorize(AuthorityPrivileges.HAS_USER_PRIVILEGES) - public void updateSurveyUnitDataStateDataById(@IdValid @PathVariable(value = "id") String surveyUnitId, - @Valid @RequestBody SurveyUnitDataStateDataUpdateInput surveyUnitUpdateInput) { - pilotageComponent.checkHabilitations(surveyUnitId, PilotageRole.INTERVIEWER, PilotageRole.REVIEWER); - StateData stateData = StateDataInput.toModel(surveyUnitUpdateInput.stateData()); - surveyUnitService.updateSurveyUnit(surveyUnitId, surveyUnitUpdateInput.data(), stateData); - } - - /** - * Update the collected data of a survey unit - * - * @param collectedDataValue the collected form data to update - * @param surveyUnitId the id of the survey unit - */ - @Operation(summary = "Update collected data for a survey unit") - @PatchMapping(path = "/survey-unit/{id}/data") - @PreAuthorize(AuthorityPrivileges.HAS_USER_PRIVILEGES) - public void updateCollectedData(@NotNull @RequestBody ObjectNode collectedDataValue, - @IdValid @PathVariable(value = "id") String surveyUnitId) { - pilotageComponent.checkHabilitations(surveyUnitId, PilotageRole.INTERVIEWER); - dataService.updateCollectedData(surveyUnitId, collectedDataValue); - } -} diff --git a/queen-application/src/main/java/fr/insee/queen/application/surveyunit/controller/SurveyUnitController.java b/queen-application/src/main/java/fr/insee/queen/application/surveyunit/controller/SurveyUnitController.java index f1daea66..9bfea2b8 100644 --- a/queen-application/src/main/java/fr/insee/queen/application/surveyunit/controller/SurveyUnitController.java +++ b/queen-application/src/main/java/fr/insee/queen/application/surveyunit/controller/SurveyUnitController.java @@ -2,11 +2,14 @@ import fr.insee.queen.application.configuration.auth.AuthorityPrivileges; import fr.insee.queen.application.pilotage.controller.PilotageComponent; +import fr.insee.queen.application.surveyunit.dto.input.StateDataInput; import fr.insee.queen.application.surveyunit.dto.input.SurveyUnitCreationInput; +import fr.insee.queen.application.surveyunit.dto.input.SurveyUnitDataStateDataUpdateInput; import fr.insee.queen.application.surveyunit.dto.input.SurveyUnitUpdateInput; import fr.insee.queen.application.surveyunit.dto.output.SurveyUnitDto; import fr.insee.queen.application.web.validation.IdValid; import fr.insee.queen.domain.pilotage.service.PilotageRole; +import fr.insee.queen.domain.surveyunit.model.StateData; import fr.insee.queen.domain.surveyunit.model.SurveyUnit; import fr.insee.queen.domain.surveyunit.service.SurveyUnitService; import fr.insee.queen.domain.surveyunit.service.exception.StateDataInvalidDateException; @@ -100,6 +103,16 @@ public ResponseEntity createUpdateSurveyUnit(@IdValid @PathVariable(value return new ResponseEntity<>(HttpStatus.CREATED); } + @Operation(summary = "Update survey-unit updated data/state-data") + @PatchMapping(path = {"/survey-unit/{id}"}) + @PreAuthorize(AuthorityPrivileges.HAS_USER_PRIVILEGES) + public void updateSurveyUnitDataStateDataById(@IdValid @PathVariable(value = "id") String surveyUnitId, + @Valid @RequestBody SurveyUnitDataStateDataUpdateInput surveyUnitUpdateInput) { + pilotageComponent.checkHabilitations(surveyUnitId, PilotageRole.INTERVIEWER, PilotageRole.REVIEWER); + StateData stateData = StateDataInput.toModel(surveyUnitUpdateInput.stateData()); + surveyUnitService.updateSurveyUnit(surveyUnitId, surveyUnitUpdateInput.data(), stateData); + } + /** * Delete a survey unit diff --git a/queen-application/src/main/resources/application.yml b/queen-application/src/main/resources/application.yml index 1251c2f8..eb15a5ac 100644 --- a/queen-application/src/main/resources/application.yml +++ b/queen-application/src/main/resources/application.yml @@ -45,8 +45,6 @@ feature: enabled: false interviewer-mode: enabled: false - perfdata: - enabled: false spring: main: diff --git a/queen-application/src/test/java/fr/insee/queen/application/surveyunit/controller/PerfDataControllerTest.java b/queen-application/src/test/java/fr/insee/queen/application/surveyunit/controller/PerfDataControllerTest.java deleted file mode 100644 index 61e2151f..00000000 --- a/queen-application/src/test/java/fr/insee/queen/application/surveyunit/controller/PerfDataControllerTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package fr.insee.queen.application.surveyunit.controller; - -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; -import fr.insee.queen.application.pilotage.controller.dummy.PilotageFakeComponent; -import fr.insee.queen.application.surveyunit.dto.input.StateDataInput; -import fr.insee.queen.application.surveyunit.dto.input.StateDataTypeInput; -import fr.insee.queen.application.surveyunit.dto.input.SurveyUnitDataStateDataUpdateInput; -import fr.insee.queen.application.surveyunit.service.dummy.DataFakeService; -import fr.insee.queen.application.surveyunit.service.dummy.SurveyUnitFakeService; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class PerfDataControllerTest { - private PilotageFakeComponent pilotageFakeComponent; - private PerfDataController perfDataController; - private SurveyUnitFakeService surveyUnitFakeService; - private DataFakeService dataFakeService; - - @BeforeEach - void init() { - surveyUnitFakeService = new SurveyUnitFakeService(); - pilotageFakeComponent = new PilotageFakeComponent(); - dataFakeService = new DataFakeService(); - perfDataController = new PerfDataController(surveyUnitFakeService, pilotageFakeComponent, dataFakeService); - } - - @Test - @DisplayName("When updating data/state data, then verify habilitation") - void testSurveyUnitUpdateDataStateData01() { - String surveyUnitId = "11"; - ObjectNode data = JsonNodeFactory.instance.objectNode(); - StateDataInput stateData = new StateDataInput(StateDataTypeInput.INIT, 0L, "2.3"); - SurveyUnitDataStateDataUpdateInput su = new SurveyUnitDataStateDataUpdateInput(data, stateData); - perfDataController.updateSurveyUnitDataStateDataById(surveyUnitId, su); - assertThat(pilotageFakeComponent.isChecked()).isTrue(); - assertThat(surveyUnitFakeService.isCheckSurveyUnitUpdate()).isTrue(); - } - - @Test - @DisplayName("When updating collected data, then verify habilitation") - void testSurveyUnitUpdateColllectedData01() { - String surveyUnitId = "11"; - ObjectNode collectedData = JsonNodeFactory.instance.objectNode(); - perfDataController.updateCollectedData(collectedData, surveyUnitId); - assertThat(pilotageFakeComponent.isChecked()).isTrue(); - assertThat(dataFakeService.isCheckUpdateCollectedData()).isTrue(); - } -} diff --git a/queen-application/src/test/java/fr/insee/queen/application/surveyunit/integration/DataTests.java b/queen-application/src/test/java/fr/insee/queen/application/surveyunit/integration/DataTests.java index 60d8b974..a07f9f24 100644 --- a/queen-application/src/test/java/fr/insee/queen/application/surveyunit/integration/DataTests.java +++ b/queen-application/src/test/java/fr/insee/queen/application/surveyunit/integration/DataTests.java @@ -18,7 +18,6 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; -import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; @@ -157,99 +156,159 @@ void on_update_data_when_anonymous_user_return_401() throws Exception { @Test @DisplayName("Given survey unit data with collected data, when inserting partial collected data, then merge collected datas") @Sql(value = ScriptConstants.REINIT_SQL_SCRIPT, executionPhase = AFTER_TEST_METHOD) - void updateCollectedData01() throws Exception { - String surveyUnitId = "11"; - String collectedDataJson = """ - { - "hey": "ho", - "obj": {"plip": "plop"}, - "numb": 2, + void updateCollectedData02() throws Exception { + String surveyUnitId = "su-test-diff-data"; + String externalData = """ + "EXTERNAL": {"LAST_BROADCAST": "12/07/1998"}"""; + String stateData = """ + { + "state": "EXTRACTED", + "date": 1111111111, + "currentPage": "2.3#5" + }"""; + + String newCollectedVar = """ + "DTA": { + "EDITED": null, + "FORCED": null, + "INPUTED": null, + "PREVIOUS": null, + "COLLECTED": "updated" + } + """; + + String collectedVarToUpdate = """ "READY": { - "EDITED": true, - "COLLECTED":false + "EDITED": null, + "FORCED": null, + "INPUTED": null, + "PREVIOUS": null, + "COLLECTED": "plop" + } + """; + String collectedVarNotTouched = """ + "PRODUCER": { + "EDITED": null, + "FORCED": null, + "INPUTED": null, + "PREVIOUS": null, + "COLLECTED": "Matt Groening" + } + """; + String surveyUnitDataStateData = String.format(""" + { + "data": { + %s, + %s }, - "COMMENT": null - }"""; + "stateData": %s + }""", collectedVarToUpdate, newCollectedVar, stateData); - mockMvc.perform(patch("/api/survey-unit/" + surveyUnitId + "/data") - .content(collectedDataJson) - .contentType(MediaType.APPLICATION_JSON) + // check it works when already collected data + mockMvc.perform(patch("/api/survey-unit/" + surveyUnitId) .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(surveyUnitDataStateData) .with(authentication(authenticatedUserTestHelper.getSurveyUnitUser())) ) .andExpect(status().isOk()); MvcResult result = mockMvc.perform(get("/api/survey-unit/" + surveyUnitId + "/data") .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) .with(authentication(authenticatedUserTestHelper.getSurveyUnitUser())) ) .andExpect(status().isOk()) .andReturn(); String content = result.getResponse().getContentAsString(); - String expectedResult = """ - { - "EXTERNAL":{ - "LAST_BROADCAST":"12/07/1998" - }, - "COLLECTED":{ - "hey":"ho", - "obj":{ - "plip":"plop" - }, - "numb":2, - "READY":{ - "EDITED":true, - "COLLECTED":false - }, - "COMMENT": null, - "PRODUCER":{ - "EDITED":null, - "FORCED":null, - "INPUTED":null, - "PREVIOUS":null, - "COLLECTED":"Matt Groening" - } - } - } - """; + String expectedResult = String.format(""" + { + %s, + "COLLECTED": { + %s, + %s, + %s, + } + }""", externalData, collectedVarNotTouched, collectedVarToUpdate, newCollectedVar); JSONAssert.assertEquals(expectedResult, content, JSONCompareMode.STRICT); } @Test @DisplayName("Given survey unit with no collected json data, when updating data then insert partial data as collected data") @Sql(value = ScriptConstants.REINIT_SQL_SCRIPT, executionPhase = AFTER_TEST_METHOD) - void updateCollectedData02() throws Exception { - String surveyUnitId = "21"; - String collectedDataJson = """ + void updateCollectedData01() throws Exception { + String surveyUnitId = "su-test-diff-without-collected-data"; + String externalData = """ + "EXTERNAL": {"LAST_BROADCAST": "12/07/1998"}"""; + String stateData = """ + { + "state": "EXTRACTED", + "date": 1111111111, + "currentPage": "2.3#5" + }"""; + + String collectedVar1 = """ + "DAG": { + "EDITED": null, + "FORCED": null, + "INPUTED": null, + "PREVIOUS": null, + "COLLECTED": "3" + } + """; + + String collectedVar2 = """ + "DTA": { + "EDITED": null, + "FORCED": null, + "INPUTED": null, + "PREVIOUS": null, + "COLLECTED": "4" + } + """; + + String surveyUnitDataStateData = String.format(""" { - "COMMENT": null - }"""; + "data": { + %s, + %s + }, + "stateData": %s + }""", collectedVar1, collectedVar2, stateData); - mockMvc.perform(patch("/api/survey-unit/" + surveyUnitId + "/data") - .content(collectedDataJson) - .contentType(MediaType.APPLICATION_JSON) + mockMvc.perform(patch("/api/survey-unit/" + surveyUnitId) .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(surveyUnitDataStateData) .with(authentication(authenticatedUserTestHelper.getSurveyUnitUser())) ) .andExpect(status().isOk()); MvcResult result = mockMvc.perform(get("/api/survey-unit/" + surveyUnitId + "/data") .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) .with(authentication(authenticatedUserTestHelper.getSurveyUnitUser())) ) .andExpect(status().isOk()) .andReturn(); String content = result.getResponse().getContentAsString(); - String expectedResult = "{\"COLLECTED\":" + collectedDataJson + "}"; + String expectedResult = String.format(""" + { + %s, + "COLLECTED": { + %s, + %s + } + }""", externalData, collectedVar1, collectedVar2); JSONAssert.assertEquals(expectedResult, content, JSONCompareMode.STRICT); } @Test @DisplayName("Given invalid survey unit id, when updating collected data then throw bad request") void updateCollectedDataError02() throws Exception { - mockMvc.perform(patch("/api/survey-unit/invalid$identifier/data") + mockMvc.perform(patch("/api/survey-unit/invalid$identifier") .content("{}") .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) @@ -261,7 +320,7 @@ void updateCollectedDataError02() throws Exception { @Test @DisplayName("Given invalid json collected input data, when updating collected data then throw bad request") void updateCollectedDataError03() throws Exception { - mockMvc.perform(patch("/api/survey-unit/12/data") + mockMvc.perform(patch("/api/survey-unit/12") .content("[]") .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) @@ -273,7 +332,7 @@ void updateCollectedDataError03() throws Exception { @Test @DisplayName("Given an anoymous user, when updating collected data then return unauthenticated error") void updateCollectedDataError04() throws Exception { - mockMvc.perform(patch("/api/survey-unit/12/data") + mockMvc.perform(patch("/api/survey-unit/12") .content("{}") .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) diff --git a/queen-application/src/test/java/fr/insee/queen/application/surveyunit/integration/StateDataTests.java b/queen-application/src/test/java/fr/insee/queen/application/surveyunit/integration/StateDataTests.java index b4f68115..baa8941e 100644 --- a/queen-application/src/test/java/fr/insee/queen/application/surveyunit/integration/StateDataTests.java +++ b/queen-application/src/test/java/fr/insee/queen/application/surveyunit/integration/StateDataTests.java @@ -173,6 +173,65 @@ void on_retrieve_state_datas_by_survey_units_return_correct_values() throws Exce JSONAssert.assertNotEquals(expectedJson, content, JSONCompareMode.NON_EXTENSIBLE); } + @Test + @Sql(value = ScriptConstants.REINIT_SQL_SCRIPT, executionPhase = AFTER_TEST_METHOD) + void when_user_update_surveyunit_data_state_data_return_updated_state_data() throws Exception { + String stateData = """ + { + "state": "EXTRACTED", + "date": 1111111111, + "currentPage": "2.3#5" + }"""; + + String surveyUnitDataStateData = String.format(""" + { + "data": { + "COLLECTED": { + } + }, + "stateData": %s + }""", stateData); + mockMvc.perform(patch("/api/survey-unit/su-test-diff-data") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(surveyUnitDataStateData) + .with(authentication(authenticatedUserTestHelper.getSurveyUnitUser())) + ) + .andExpect(status().isOk()); + + MvcResult result = mockMvc.perform(get("/api/survey-unit/11/state-data") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(surveyUnitDataStateData) + .with(authentication(authenticatedUserTestHelper.getSurveyUnitUser())) + ) + .andExpect(status().isOk()) + .andReturn(); + + String content = result.getResponse().getContentAsString(); + JSONAssert.assertEquals(stateData, content, JSONCompareMode.STRICT); + } + + @Test + void when_user_update_surveyunit_with_incorrect_state_data_return_400() throws Exception { + String surveyUnitDataStateData = """ + { + "data":{}, + "stateData": { + "state": "EACTED", + "date": 1111111111, + "currentPage": "2.3#5" + } + }"""; + mockMvc.perform(patch("/api/survey-unit/11") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(surveyUnitDataStateData) + .with(authentication(authenticatedUserTestHelper.getSurveyUnitUser())) + ) + .andExpect(status().isBadRequest()); + } + @Test void on_update_state_data_when_su_not_exist_return_404() throws Exception { String stateDataJson = JsonTestHelper.getResourceFileAsString("surveyunit/state_data.json"); diff --git a/queen-application/src/test/java/fr/insee/queen/application/surveyunit/integration/SurveyUnitTests.java b/queen-application/src/test/java/fr/insee/queen/application/surveyunit/integration/SurveyUnitTests.java index c8ef8d27..42d62c9b 100644 --- a/queen-application/src/test/java/fr/insee/queen/application/surveyunit/integration/SurveyUnitTests.java +++ b/queen-application/src/test/java/fr/insee/queen/application/surveyunit/integration/SurveyUnitTests.java @@ -74,7 +74,7 @@ void on_get_survey_unit_ids_return_ids() throws Exception { .with(authentication(authenticatedUserTestHelper.getAdminUser())) ) .andExpect(status().isOk()) - .andExpect(jsonPath("$.size()", is(14))); + .andExpect(jsonPath("$.size()", is(16))); } @Test @@ -324,48 +324,6 @@ void when_authenticated_non_admin_user_access_admin_endpoints_return_403() throw .andExpect(status().isForbidden()); } - @Test - void when_user_update_surveyunit_data_state_data_return_200() throws Exception { - String surveyUnitDataStateData = """ - { - "data":""" + surveyUnitData + ", " + - """ - "stateData": { - "state": "EXTRACTED", - "date": 1111111111, - "currentPage": "2.3#5" - } - }"""; - mockMvc.perform(patch("/api/survey-unit/11") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(surveyUnitDataStateData) - .with(authentication(authenticatedUserTestHelper.getSurveyUnitUser())) - ) - .andExpect(status().isOk()); - } - - @Test - void when_user_update_surveyunit_with_incorrect_state_data_return_400() throws Exception { - String surveyUnitDataStateData = """ - { - "data":""" + surveyUnitData + ", " + - """ - "stateData": { - "state": "EACTED", - "date": 1111111111, - "currentPage": "2.3#5" - } - }"""; - mockMvc.perform(patch("/api/survey-unit/11") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(surveyUnitDataStateData) - .with(authentication(authenticatedUserTestHelper.getSurveyUnitUser())) - ) - .andExpect(status().isBadRequest()); - } - @Test void when_user_update_surveyunit_with_incorrect_identifier_return_400() throws Exception { String surveyUnitDataStateData = """ @@ -405,7 +363,7 @@ void when_get_survey_units_for_interviewers_return_survey_units() throws Excepti .with(authentication(authenticatedUserTestHelper.getAuthenticatedUser(AuthorityRoleEnum.INTERVIEWER))) ) .andExpect(status().isOk()) - .andExpect(jsonPath("$.size()", is(14))) + .andExpect(jsonPath("$.size()", is(16))) .andExpect(jsonPath("$[0].id").value("11")) .andExpect(jsonPath("$[0].questionnaireId").value("simpsons")) .andExpect(jsonPath("$[0].personalization.size()", is(2))) diff --git a/queen-application/src/test/resources/application-test.yml b/queen-application/src/test/resources/application-test.yml index 9059510c..d65dd84d 100644 --- a/queen-application/src/test/resources/application-test.yml +++ b/queen-application/src/test/resources/application-test.yml @@ -31,8 +31,6 @@ feature: enabled: true interviewer-mode: enabled: true - perfdata: - enabled: true spring: liquibase: diff --git a/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/SurveyUnitApiService.java b/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/SurveyUnitApiService.java index fc8e1a21..1ddbf4a5 100644 --- a/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/SurveyUnitApiService.java +++ b/queen-domain/src/main/java/fr/insee/queen/domain/surveyunit/service/SurveyUnitApiService.java @@ -108,12 +108,12 @@ public void updateSurveyUnit(SurveyUnit surveyUnit) { @Transactional @Override - public void updateSurveyUnit(String surveyUnitId, ObjectNode data, StateData stateData) { - dataService.saveData(surveyUnitId, data); + public void updateSurveyUnit(String surveyUnitId, ObjectNode collectedDataToUpdate, StateData stateData) { + dataService.updateCollectedData(surveyUnitId, collectedDataToUpdate); try { stateDataService.saveStateData(surveyUnitId, stateData); } catch (StateDataInvalidDateException ex) { - // in the case of survey unit update, a problem with state data does not require to + // in the case of survey unit update, a problem with state collectedDataToUpdate does not require to // rollback the other updates on survey unit log.warn(String.format("%s - %s", surveyUnitId, ex.getMessage())); } diff --git a/queen-domain/src/test/java/fr/insee/queen/domain/surveyunit/service/dummy/DataFakeService.java b/queen-domain/src/test/java/fr/insee/queen/domain/surveyunit/service/dummy/DataFakeService.java index 01c49b52..809ed393 100644 --- a/queen-domain/src/test/java/fr/insee/queen/domain/surveyunit/service/dummy/DataFakeService.java +++ b/queen-domain/src/test/java/fr/insee/queen/domain/surveyunit/service/dummy/DataFakeService.java @@ -21,6 +21,6 @@ public void saveData(String surveyUnitId, ObjectNode dataValue) { @Override public void updateCollectedData(String surveyUnitId, ObjectNode collectedData) { - // not used at this moment + dataSaved = collectedData; } } diff --git a/queen-infra-db/src/main/resources/db/scripts/init-data.sql b/queen-infra-db/src/main/resources/db/scripts/init-data.sql index c0796ee9..d6abd300 100644 --- a/queen-infra-db/src/main/resources/db/scripts/init-data.sql +++ b/queen-infra-db/src/main/resources/db/scripts/init-data.sql @@ -105,6 +105,8 @@ INSERT INTO public.survey_unit VALUES ('LOG2021X11Web-03', 'LOG2021X11Web', 'LOG INSERT INTO public.survey_unit VALUES ('LOG2021X11Tel_01', 'LOG2021X11Tel', 'LOG2021X11Tel'); INSERT INTO public.survey_unit VALUES ('LOG2021X11Tel_02', 'LOG2021X11Tel', 'LOG2021X11Tel'); INSERT INTO public.survey_unit VALUES ('LOG2021X11Tel_03', 'LOG2021X11Tel', 'LOG2021X11Tel'); +INSERT INTO public.survey_unit VALUES ('su-test-diff-data', 'LOG2021X11Tel', 'LOG2021X11Tel'); +INSERT INTO public.survey_unit VALUES ('su-test-diff-without-collected-data', 'LOG2021X11Tel', 'LOG2021X11Tel'); -- -- TOC entry 3399 (class 0 OID 16396) @@ -126,6 +128,8 @@ INSERT INTO public.comment VALUES ('d8b683e0-850e-487f-bc8d-6f3c9440e32b', '{}', INSERT INTO public.comment VALUES ('d6f92b88-0b80-41dc-a1b3-e69b2fb71846', '{}', 'LOG2021X11Tel_01'); INSERT INTO public.comment VALUES ('70ee3af3-fd2c-4745-b0bb-73124fa016b8', '{}', 'LOG2021X11Tel_02'); INSERT INTO public.comment VALUES ('833b5a5d-845e-4b3e-a725-d444907ee476', '{}', 'LOG2021X11Tel_03'); +INSERT INTO public.comment VALUES ('692a1749-e293-4bcf-8456-4fb8edc9a5a8', '{}', 'su-test-diff-data'); +INSERT INTO public.comment VALUES ('692a1749-e293-4bcf-8456-4fb8edc9a5a9', '{}', 'su-test-diff-without-collected-data'); -- @@ -142,6 +146,8 @@ INSERT INTO public.data VALUES ('e9e97450-ef9c-4f49-9375-adf11b6a158b', '{}', '2 INSERT INTO public.data VALUES ('42dc1400-0a36-4c20-8742-115e22c42369', '{}', '21'); INSERT INTO public.data VALUES ('4540afba-ee51-42e4-bf74-d2346d813e89', '{}', '22'); INSERT INTO public.data VALUES ('757170c2-b2d5-4c71-85c1-61988b36e416', '{}', '23'); +INSERT INTO public.data VALUES ('757170c2-b2d5-4c71-85c1-61988b36e417', '{"EXTERNAL": {"LAST_BROADCAST": "12/07/1998"}, "COLLECTED": {"PRODUCER": {"EDITED": null, "FORCED": null, "INPUTED": null, "PREVIOUS": null, "COLLECTED": "Matt Groening"}, "READY": {"EDITED": null, "FORCED": null, "INPUTED": null, "PREVIOUS": null, "COLLECTED": true}}}', 'su-test-diff-data'); +INSERT INTO public.data VALUES ('757170c2-b2d5-4c71-85c1-61988b36e418', '{"EXTERNAL": {"LAST_BROADCAST": "12/07/1998"}}', 'su-test-diff-without-collected-data'); INSERT INTO public.data VALUES ('27abfaed-187a-44ab-8287-af08f3bd7158', '{}', 'LOG2021X11Web-01'); INSERT INTO public.data VALUES ('c118114a-c0be-462d-9fe9-604436bea20a', '{}', 'LOG2021X11Web-02'); INSERT INTO public.data VALUES ('df044ba3-9abb-451e-9e4d-75ba98ace5e6', '{}', 'LOG2021X11Web-03'); @@ -191,6 +197,8 @@ INSERT INTO public.personalization VALUES ('65ec0765-4a5e-4518-be79-bc2be6b882b8 INSERT INTO public.personalization VALUES ('fc73766c-ffb7-4443-9135-1e39939320a0', '[]', '21'); INSERT INTO public.personalization VALUES ('d14499b0-93f2-4722-a624-47d7cafc26a6', '[]', '22'); INSERT INTO public.personalization VALUES ('a7e878fa-d12a-4a25-bc17-08a583b0127d', '[]', '23'); +INSERT INTO public.personalization VALUES ('a7e878fa-d12a-4a25-bc17-08a583b0127e', '[]', 'su-test-diff-data'); +INSERT INTO public.personalization VALUES ('a7e878fa-d12a-4a25-bc17-08a583b0127f', '[]', 'su-test-diff-without-collected-data'); INSERT INTO public.personalization VALUES ('eec3ae3f-ad9e-45d6-b2f8-191e19f2a571', '[]', 'LOG2021X11Web-01'); INSERT INTO public.personalization VALUES ('3cf06171-2f86-4724-8c86-fb9b2f40286a', '[]', 'LOG2021X11Web-02'); INSERT INTO public.personalization VALUES ('1683a6ff-3c40-47c8-8862-9c685c6f5e88', '[]', 'LOG2021X11Web-03');