From 96e09c70c5d1c441114951fc9525c4a5ba812547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Henninger?= Date: Wed, 8 Jan 2025 14:40:12 +0100 Subject: [PATCH 1/7] Rename idUE, idQuest and IdCampaign --- .../adapter/LunaticJsonAdapter.java | 6 +- .../controller/adapter/LunaticXmlAdapter.java | 6 +- .../rest/responses/ResponseController.java | 12 ++-- .../model/surveyunit/SurveyUnitModel.java | 14 ++--- .../service/surveyunit/SurveyUnitService.java | 2 +- .../genesis/domain/utils/DataVerifier.java | 12 ++-- .../adapter/SurveyUnitMongoAdapter.java | 2 +- .../surveyunit/SurveyUnitDocument.java | 6 +- .../mappers/SurveyUnitDocumentMapper.java | 2 - .../functional_tests/MainDefinitions.java | 16 +++--- .../adapter/LunaticXmlAdapterTest.java | 4 +- .../rest/HealthCheckControllerTest.java | 6 +- .../controller/rest/UtilsControllerTest.java | 12 ++-- .../responses/ResponseControllerTest.java | 8 +-- .../controller/rest/responses/Utils.java | 12 ++-- .../controller/utils/DataVerifierTest.java | 28 +++++----- .../model/surveyunit/SurveyUnitModelTest.java | 8 +-- .../domain/service/SurveyUnitServiceTest.java | 56 +++++++++---------- .../domain/utils/DataVerifierTest.java | 12 ++-- .../SurveyUnitModelMongoAdapterTest.java | 26 ++++----- .../SurveyUnitDocumentMapperImplTest.java | 36 ++++++------ .../stubs/SurveyUnitPersistencePortStub.java | 30 +++++----- 22 files changed, 157 insertions(+), 159 deletions(-) diff --git a/src/main/java/fr/insee/genesis/controller/adapter/LunaticJsonAdapter.java b/src/main/java/fr/insee/genesis/controller/adapter/LunaticJsonAdapter.java index a818967e..8892594c 100644 --- a/src/main/java/fr/insee/genesis/controller/adapter/LunaticJsonAdapter.java +++ b/src/main/java/fr/insee/genesis/controller/adapter/LunaticJsonAdapter.java @@ -13,9 +13,9 @@ public class LunaticJsonAdapter { public SurveyUnitModel convert(LunaticJsonSurveyUnit su){ return SurveyUnitModel.builder() - .idQuest(su.getIdQuest()) - .idCampaign("") - .idUE(su.getIdUE()) + .questionnaireId(su.getIdQuest()) + .campaignId("") + .interrogationId(su.getIdUE()) .state(DataState.COLLECTED) .mode(Mode.WEB) .recordDate(LocalDateTime.now()) diff --git a/src/main/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapter.java b/src/main/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapter.java index fbe8d0b6..6835a687 100644 --- a/src/main/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapter.java +++ b/src/main/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapter.java @@ -70,9 +70,9 @@ public static List convert(LunaticXmlSurveyUnit su, VariablesMa */ private static SurveyUnitModel getStateDataFromSurveyUnit(LunaticXmlSurveyUnit su, VariablesMap variablesMap, String idCampaign, DataState dataState, Mode mode) { SurveyUnitModel surveyUnitModel = SurveyUnitModel.builder() - .idQuest(su.getQuestionnaireModelId()) - .idCampaign(idCampaign) - .idUE(su.getId()) + .questionnaireId(su.getQuestionnaireModelId()) + .campaignId(idCampaign) + .interrogationId(su.getId()) .state(dataState) .mode(mode) .recordDate(LocalDateTime.now()) diff --git a/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java b/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java index cc6fdcaa..9c5c7091 100644 --- a/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java +++ b/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java @@ -319,9 +319,9 @@ public ResponseEntity getLatestByUEOneObject(@RequestParam outputExternalVariables.addAll(response.getExternalVariables()); }); return ResponseEntity.ok(SurveyUnitSimplified.builder() - .idQuest(responses.getFirst().getIdQuest()) - .idCampaign(responses.getFirst().getIdCampaign()) - .idUE(responses.getFirst().getIdUE()) + .idQuest(responses.getFirst().getQuestionnaireId()) + .idCampaign(responses.getFirst().getCampaignId()) + .idUE(responses.getFirst().getInterrogationId()) .variablesUpdate(outputVariables) .externalVariables(outputExternalVariables) .build()); @@ -347,9 +347,9 @@ public ResponseEntity> getLatestForUEList(@RequestPar }); if (!outputVariables.isEmpty() || !outputExternalVariables.isEmpty()) { results.add(SurveyUnitSimplified.builder() - .idQuest(responses.getFirst().getIdQuest()) - .idCampaign(responses.getFirst().getIdCampaign()) - .idUE(responses.getFirst().getIdUE()) + .idQuest(responses.getFirst().getQuestionnaireId()) + .idCampaign(responses.getFirst().getCampaignId()) + .idUE(responses.getFirst().getInterrogationId()) .mode(mode) .variablesUpdate(outputVariables) .externalVariables(outputExternalVariables) diff --git a/src/main/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModel.java b/src/main/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModel.java index ee04645b..8ef52f08 100644 --- a/src/main/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModel.java +++ b/src/main/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModel.java @@ -16,9 +16,9 @@ @AllArgsConstructor public class SurveyUnitModel { - private String idQuest; - private String idCampaign; - private String idUE; + private String questionnaireId; + private String campaignId; + private String interrogationId; private DataState state; private Mode mode; @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'hh:mm") @@ -29,8 +29,8 @@ public class SurveyUnitModel { private List collectedVariables; private List externalVariables; - public SurveyUnitModel(String idUE, Mode mode) { - this.idUE = idUE; + public SurveyUnitModel(String interrogationId, Mode mode) { + this.interrogationId = interrogationId; this.mode = mode; } @@ -43,11 +43,11 @@ public boolean equals(Object o) { return false; } SurveyUnitModel that = (SurveyUnitModel) o; - return Objects.equals(idUE, that.idUE) && Objects.equals(mode, that.mode); + return Objects.equals(interrogationId, that.interrogationId) && Objects.equals(mode, that.mode); } @Override public int hashCode() { - return Objects.hash(idUE) + Objects.hash(mode); + return Objects.hash(interrogationId) + Objects.hash(mode); } } diff --git a/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java b/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java index e44ae9e7..2c2af33e 100644 --- a/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java +++ b/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java @@ -136,7 +136,7 @@ public SurveyUnitDto findLatestValuesByStateByIdAndByIdQuestionnaire(String idUE public List findDistinctIdUEsByIdQuestionnaire(String idQuestionnaire) { List surveyUnitModels = surveyUnitPersistencePort.findIdUEsByIdQuestionnaire(idQuestionnaire); List suIds = new ArrayList<>(); - surveyUnitModels.forEach(surveyUnitDto -> suIds.add(new SurveyUnitId(surveyUnitDto.getIdUE()))); + surveyUnitModels.forEach(surveyUnitDto -> suIds.add(new SurveyUnitId(surveyUnitDto.getInterrogationId()))); return suIds.stream().distinct().toList(); } diff --git a/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java b/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java index ab9a5b6d..e3940e3c 100644 --- a/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java +++ b/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java @@ -48,7 +48,7 @@ public static void verifySurveyUnits(List suDtosList, Variables List suDtosListForced = new ArrayList<>(); // Created FORCED SU DTOs for(String idUE : getIdUEs(suDtosList)) { // For each id of the list - List srcSuDtosOfIdUE = suDtosList.stream().filter(element -> element.getIdUE().equals(idUE)).toList(); + List srcSuDtosOfIdUE = suDtosList.stream().filter(element -> element.getInterrogationId().equals(idUE)).toList(); List correctedCollectedVariables = new ArrayList<>(); List correctedExternalVariables = new ArrayList<>(); @@ -71,11 +71,11 @@ private static SurveyUnitModel createForcedDto( List correctedCollectedVariables, List correctedExternalVariables ) { - SurveyUnitModel sampleSuDto = suDtosList.stream().filter(element -> element.getIdUE().equals(idUE)).toList().getFirst(); + SurveyUnitModel sampleSuDto = suDtosList.stream().filter(element -> element.getInterrogationId().equals(idUE)).toList().getFirst(); SurveyUnitModel newForcedSuDto = SurveyUnitModel.builder() - .idQuest(sampleSuDto.getIdQuest()) - .idCampaign(sampleSuDto.getIdCampaign()) - .idUE(idUE) + .questionnaireId(sampleSuDto.getQuestionnaireId()) + .campaignId(sampleSuDto.getCampaignId()) + .interrogationId(idUE) .state(DataState.FORCED) .mode(sampleSuDto.getMode()) .recordDate(LocalDateTime.now()) @@ -114,7 +114,7 @@ private static SurveyUnitModel createForcedDto( private static Set getIdUEs(List suDtosList) { Set idUEs = new HashSet<>(); for(SurveyUnitModel surveyUnitModel : suDtosList){ - idUEs.add(surveyUnitModel.getIdUE()); + idUEs.add(surveyUnitModel.getInterrogationId()); } return idUEs; diff --git a/src/main/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitMongoAdapter.java b/src/main/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitMongoAdapter.java index d8a64d10..be5daced 100644 --- a/src/main/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitMongoAdapter.java +++ b/src/main/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitMongoAdapter.java @@ -59,7 +59,7 @@ public List findByIdUEsAndIdQuestionnaire(List List surveyUnits= new ArrayList<>(); // TODO: 18-10-2023 : find a way to do this in one query idUEs.forEach(su -> { - List docs = mongoRepository.findByIdUEAndIdQuestionnaire(su.getIdUE(), idQuestionnaire); + List docs = mongoRepository.findByIdUEAndIdQuestionnaire(su.getInterrogationId(), idQuestionnaire); surveyUnits.addAll(docs); }); return surveyUnits.isEmpty() ? Collections.emptyList() : SurveyUnitDocumentMapper.INSTANCE.listDocumentToListModel(surveyUnits); diff --git a/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/SurveyUnitDocument.java b/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/SurveyUnitDocument.java index f4b0f562..16417b02 100644 --- a/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/SurveyUnitDocument.java +++ b/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/SurveyUnitDocument.java @@ -14,9 +14,9 @@ @CompoundIndex(name = "idQuestionnaire_1_idCampaign_1", def = "{'idQuestionnaire': 1, 'idCampaign': 1}") @CompoundIndex(name = "idQuestionnaire_1_idUE_1", def = "{'idQuestionnaire': 1, 'idUE': 1}") public class SurveyUnitDocument { - private String idCampaign; - private String idUE; - private String idQuestionnaire; + private String campaignId; + private String interrogationId; + private String questionnaireId; private String state; private String mode; private LocalDateTime recordDate; diff --git a/src/main/java/fr/insee/genesis/infrastructure/mappers/SurveyUnitDocumentMapper.java b/src/main/java/fr/insee/genesis/infrastructure/mappers/SurveyUnitDocumentMapper.java index db0ada3b..f89ba3e1 100644 --- a/src/main/java/fr/insee/genesis/infrastructure/mappers/SurveyUnitDocumentMapper.java +++ b/src/main/java/fr/insee/genesis/infrastructure/mappers/SurveyUnitDocumentMapper.java @@ -12,10 +12,8 @@ public interface SurveyUnitDocumentMapper { SurveyUnitDocumentMapper INSTANCE = Mappers.getMapper(SurveyUnitDocumentMapper.class); - @Mapping(source = "idQuestionnaire", target = "idQuest") SurveyUnitModel documentToModel(SurveyUnitDocument surveyUnit); - @Mapping(source = "idQuest", target = "idQuestionnaire") SurveyUnitDocument modelToDocument(SurveyUnitModel surveyUnitModel); List listDocumentToListModel(List surveyUnits); diff --git a/src/test/java/cucumber/functional_tests/MainDefinitions.java b/src/test/java/cucumber/functional_tests/MainDefinitions.java index 95deef9c..cedc5206 100644 --- a/src/test/java/cucumber/functional_tests/MainDefinitions.java +++ b/src/test/java/cucumber/functional_tests/MainDefinitions.java @@ -130,7 +130,7 @@ public void check_surveyunits_by_state(int expectedCount, String expectedStatus) public void check_expected_datastate_dto(String surveyUnitId, String expectedDataState) { Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitDto -> surveyUnitDto.getState().toString().equals(expectedDataState) - && surveyUnitDto.getIdUE().equals(surveyUnitId) + && surveyUnitDto.getInterrogationId().equals(surveyUnitId) ).isNotEmpty(); } @@ -138,7 +138,7 @@ public void check_expected_datastate_dto(String surveyUnitId, String expectedDat public void check_unexpected_datastate_dto(String surveyUnitId, String unexpectedDataState) { Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitDto -> surveyUnitDto.getState().toString().equals(unexpectedDataState) - && surveyUnitDto.getIdUE().equals(surveyUnitId) + && surveyUnitDto.getInterrogationId().equals(surveyUnitId) ).isEmpty(); } @@ -147,12 +147,12 @@ public void check_survey_unit_dto_content(String dataState, String surveyUnitId, //Get DTO Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitDto -> surveyUnitDto.getState().toString().equals(dataState) - && surveyUnitDto.getIdUE().equals(surveyUnitId) + && surveyUnitDto.getInterrogationId().equals(surveyUnitId) ).isNotEmpty(); Optional concernedDtoOptional = this.surveyUnitModels.stream().filter(dto -> dto.getState().toString().equals(dataState) - && dto.getIdUE().equals(surveyUnitId) + && dto.getInterrogationId().equals(surveyUnitId) ).findFirst(); Assertions.assertThat(concernedDtoOptional).isPresent(); @@ -182,12 +182,12 @@ public void external_variable_volumetric_check(int expectedNumberOfValues, Strin //Get DTO Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitDto -> surveyUnitDto.getState().equals(DataState.COLLECTED) - && surveyUnitDto.getIdUE().equals(surveyUnitId) + && surveyUnitDto.getInterrogationId().equals(surveyUnitId) ).isNotEmpty(); Optional concernedDtoOptional = this.surveyUnitModels.stream().filter(dto -> dto.getState().equals(DataState.COLLECTED) - && dto.getIdUE().equals(surveyUnitId) + && dto.getInterrogationId().equals(surveyUnitId) ).findFirst(); Assertions.assertThat(concernedDtoOptional).isPresent(); @@ -216,12 +216,12 @@ public void external_variable_content_check(String externalVariableName, String //Get DTO Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitDto -> surveyUnitDto.getState().equals(DataState.COLLECTED) - && surveyUnitDto.getIdUE().equals(surveyUnitId) + && surveyUnitDto.getInterrogationId().equals(surveyUnitId) ).isNotEmpty(); Optional concernedDtoOptional = this.surveyUnitModels.stream().filter(dto -> dto.getState().equals(DataState.COLLECTED) - && dto.getIdUE().equals(surveyUnitId) + && dto.getInterrogationId().equals(surveyUnitId) ).findFirst(); Assertions.assertThat(concernedDtoOptional).isPresent(); diff --git a/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java b/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java index 29ddd262..f2e5b233 100644 --- a/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java +++ b/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java @@ -214,7 +214,7 @@ void test02() { // When List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit1, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos.getFirst().getIdQuest()).isEqualTo("idQuest1"); + Assertions.assertThat(suDtos.getFirst().getQuestionnaireId()).isEqualTo("idQuest1"); } @Test @@ -223,7 +223,7 @@ void test03() { // When List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit1, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos.getFirst().getIdUE()).isEqualTo("idUE1"); + Assertions.assertThat(suDtos.getFirst().getInterrogationId()).isEqualTo("idUE1"); } @Test diff --git a/src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.java index 8b85eac3..4081ebec 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.java @@ -38,10 +38,10 @@ static void init() { CollectedVariable collectedVariable = new CollectedVariable("TESTIDVAR", List.of(new String[]{"V1", "V2"}), "TESTIDLOOP", "TESTIDPARENT"); collectedVariableList.add(collectedVariable); surveyUnitPersistencePortStub.getMongoStub().add(SurveyUnitModel.builder() - .idCampaign("TESTIDCAMPAIGN") + .campaignId("TESTIDCAMPAIGN") .mode(Mode.WEB) - .idUE("TESTIDUE") - .idQuest("TESTIDQUESTIONNAIRE") + .interrogationId("TESTIDUE") + .questionnaireId("TESTIDQUESTIONNAIRE") .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023, 1, 1, 0, 0, 0)) .recordDate(LocalDateTime.of(2024, 1, 1, 0, 0, 0)) diff --git a/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java index 9867067a..cfd59a9c 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java @@ -68,10 +68,10 @@ void reset() throws IOException { CollectedVariable collectedVariable = new CollectedVariable("TESTIDVAR", List.of(new String[]{"V1", "V2"}), "TESTIDLOOP", "TESTIDPARENT"); collectedVariableList.add(collectedVariable); surveyUnitPersistencePortStub.getMongoStub().add(SurveyUnitModel.builder() - .idCampaign("TESTIDCAMPAIGN") + .campaignId("TESTIDCAMPAIGN") .mode(Mode.WEB) - .idUE(defaultIdUE) - .idQuest(defaultIdQuest) + .interrogationId(defaultIdUE) + .questionnaireId(defaultIdQuest) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023, 1, 1, 0, 0, 0)) .recordDate(LocalDateTime.of(2024, 1, 1, 0, 0, 0)) @@ -356,10 +356,10 @@ private void addAdditionalDtoToMongoStub(String idCampaign, String idQuestionnai collectedVariableList.add(collectedVariable); SurveyUnitModel recentDTO = SurveyUnitModel.builder() - .idCampaign(idCampaign) + .campaignId(idCampaign) .mode(Mode.WEB) - .idUE(defaultIdUE) - .idQuest(idQuestionnaire) + .interrogationId(defaultIdUE) + .questionnaireId(idQuestionnaire) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023, 2, 2, 0, 0, 0)) .recordDate(LocalDateTime.of(2024, 2, 2, 0, 0, 0)) diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java index 77dbdeac..918e06a1 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java @@ -202,8 +202,8 @@ void findResponsesByUEAndQuestionnaireTest() { Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty(); - Assertions.assertThat(response.getBody().getFirst().getIdUE()).isEqualTo(DEFAULT_ID_UE); - Assertions.assertThat(response.getBody().getFirst().getIdQuest()).isEqualTo(DEFAULT_ID_QUEST); + Assertions.assertThat(response.getBody().getFirst().getInterrogationId()).isEqualTo(DEFAULT_ID_UE); + Assertions.assertThat(response.getBody().getFirst().getQuestionnaireId()).isEqualTo(DEFAULT_ID_QUEST); } @Test @@ -258,8 +258,8 @@ void getLatestByUETest() { Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty(); - Assertions.assertThat(response.getBody().getFirst().getIdUE()).isEqualTo(DEFAULT_ID_UE); - Assertions.assertThat(response.getBody().getFirst().getIdQuest()).isEqualTo(DEFAULT_ID_QUEST); + Assertions.assertThat(response.getBody().getFirst().getInterrogationId()).isEqualTo(DEFAULT_ID_UE); + Assertions.assertThat(response.getBody().getFirst().getQuestionnaireId()).isEqualTo(DEFAULT_ID_QUEST); Assertions.assertThat(response.getBody().getFirst().getFileDate()).hasMonth(Month.FEBRUARY); } diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/Utils.java b/src/test/java/fr/insee/genesis/controller/rest/responses/Utils.java index 424bb4b0..5a98dfe3 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/Utils.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/Utils.java @@ -193,10 +193,10 @@ static void addAdditionalDtoToMongoStub(String idCampaign, String idQuestionnair collectedVariableList.add(collectedVariable); SurveyUnitModel recentDTO = SurveyUnitModel.builder() - .idCampaign(idCampaign) + .campaignId(idCampaign) .mode(Mode.WEB) - .idUE(defaultIdUE) - .idQuest(idQuestionnaire) + .interrogationId(defaultIdUE) + .questionnaireId(idQuestionnaire) .state(DataState.COLLECTED) .fileDate(fileDate) .recordDate(recordDate) @@ -223,10 +223,10 @@ static void addAdditionalDtoToMongoStub(DataState state, collectedVariableList.add(collectedVariable); SurveyUnitModel recentDTO = SurveyUnitModel.builder() - .idCampaign("TESTIDCAMPAIGN") + .campaignId("TESTIDCAMPAIGN") .mode(Mode.WEB) - .idUE(defaultIdUE) - .idQuest(defaultIdQuest) + .interrogationId(defaultIdUE) + .questionnaireId(defaultIdQuest) .state(state) .fileDate(fileDate) .recordDate(recordDate) diff --git a/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java b/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java index fef9c86c..14965fcd 100644 --- a/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java +++ b/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java @@ -89,13 +89,13 @@ static void setUp() { //Manual modifications //Valid 2nd variable on 5th and 13th case SurveyUnitModel suDto = testSurveyUnitModels.stream().filter(surveyUnitDto -> - surveyUnitDto.getIdUE().equals("TestUE5") + surveyUnitDto.getInterrogationId().equals("TestUE5") ).toList().getFirst(); suDto.getCollectedVariables().get(1).getValues().set(0,"1"); suDto = testSurveyUnitModels.stream().filter(surveyUnitDto -> - surveyUnitDto.getIdUE().equals("TestUE13") + surveyUnitDto.getInterrogationId().equals("TestUE13") ).toList().getFirst(); suDto.getCollectedVariables().get(1).getValues().set(0,"1"); @@ -104,14 +104,14 @@ static void setUp() { //Valid EDITED variables on 3rd and 7th case for priority test SurveyUnitModel suDtoEdited = testSurveyUnitModels.stream().filter(surveyUnitDto -> - surveyUnitDto.getIdUE().equals("TestUE3") + surveyUnitDto.getInterrogationId().equals("TestUE3") && surveyUnitDto.getState().equals(DataState.EDITED) ).toList().getFirst(); suDtoEdited.getCollectedVariables().getFirst().getValues().set(0,"1"); suDtoEdited = testSurveyUnitModels.stream().filter(surveyUnitDto -> - surveyUnitDto.getIdUE().equals("TestUE7") + surveyUnitDto.getInterrogationId().equals("TestUE7") && surveyUnitDto.getState().equals(DataState.EDITED) ).toList().getFirst(); @@ -120,7 +120,7 @@ static void setUp() { //Remove EDITED variable on 8th case suDtoEdited = testSurveyUnitModels.stream().filter(surveyUnitDto -> - surveyUnitDto.getIdUE().equals("TestUE8") + surveyUnitDto.getInterrogationId().equals("TestUE8") && surveyUnitDto.getState().equals(DataState.EDITED) ).toList().getFirst(); @@ -165,9 +165,9 @@ private static void createCase(int variableNumber, int stateNumber, int valueNum } SurveyUnitModel surveyUnitModel = SurveyUnitModel.builder() - .idQuest("IdQuest1") - .idCampaign("IdCampaign1") - .idUE(idUE) + .questionnaireId("IdQuest1") + .campaignId("IdCampaign1") + .interrogationId(idUE) .state(stateIndex % 2 == 0 ? DataState.COLLECTED : DataState.EDITED) .mode(Mode.WEB) .recordDate(LocalDateTime.now()) @@ -187,12 +187,12 @@ private static void createCase(int variableNumber, int stateNumber, int valueNum private void assertForcedExistence(List testSurveyUnitModels, String idUE, boolean hasToExist) { if(hasToExist) assertThat(testSurveyUnitModels).filteredOn(surveyUnit -> - surveyUnit.getIdUE().equals(idUE) + surveyUnit.getInterrogationId().equals(idUE) && surveyUnit.getState() == DataState.FORCED) .hasSize(1); else assertThat(testSurveyUnitModels).filteredOn(surveyUnit -> - surveyUnit.getIdUE().equals(idUE) + surveyUnit.getInterrogationId().equals(idUE) && surveyUnit.getState() == DataState.FORCED) .isEmpty(); } @@ -201,7 +201,7 @@ private void assertCollectedVariableContent(List testSurveyUnit assertForcedExistence(testSurveyUnitModels,idUE,true); Optional suDtoOpt = testSurveyUnitModels.stream().filter(surveyUnit -> - surveyUnit.getIdUE().equals(idUE) + surveyUnit.getInterrogationId().equals(idUE) && surveyUnit.getState() == DataState.FORCED).findFirst(); assertThat(suDtoOpt).isPresent(); @@ -225,7 +225,7 @@ private void assertCollectedVariableContent(List testSurveyUnit private void assertForcedCollectedVariableExistence(List testSurveyUnitModels, String idUE, String variableName, boolean hasToExist) { assertForcedExistence(testSurveyUnitModels,idUE, true); Optional suDtoOpt = testSurveyUnitModels.stream().filter(surveyUnit -> - surveyUnit.getIdUE().equals(idUE) + surveyUnit.getInterrogationId().equals(idUE) && surveyUnit.getState() == DataState.FORCED).findFirst(); assertThat(suDtoOpt).isPresent(); @@ -240,7 +240,7 @@ private void assertForcedCollectedVariableExistence(List testSu private void assertForcedExternalVariableExistence(List testSurveyUnitModels, String idUE, String variableName, boolean hasToExist) { assertForcedExistence(testSurveyUnitModels,idUE, true); Optional suDtoOpt = testSurveyUnitModels.stream().filter(surveyUnit -> - surveyUnit.getIdUE().equals(idUE) + surveyUnit.getInterrogationId().equals(idUE) && surveyUnit.getState() == DataState.FORCED).findFirst(); assertThat(suDtoOpt).isPresent(); @@ -256,7 +256,7 @@ private void assertExternalVariableContent(List testSurveyUnitM assertForcedExistence(testSurveyUnitModels,idUE,true); Optional suDtoOpt = testSurveyUnitModels.stream().filter(surveyUnit -> - surveyUnit.getIdUE().equals(idUE) + surveyUnit.getInterrogationId().equals(idUE) && surveyUnit.getState() == DataState.FORCED).findFirst(); assertThat(suDtoOpt).isPresent(); diff --git a/src/test/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModelTest.java b/src/test/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModelTest.java index 2ef657d0..1c2f5a3f 100644 --- a/src/test/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModelTest.java +++ b/src/test/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModelTest.java @@ -21,9 +21,9 @@ public void toJSONTest() throws JsonProcessingException { collectedVariableList.add(collectedVariable); SurveyUnitModel surveyUnitModel = SurveyUnitModel.builder() - .idCampaign("TESTIDCAMPAIGN") - .idQuest("TESTIDQUEST") - .idUE("TESTIDUE") + .campaignId("TESTIDCAMPAIGN") + .questionnaireId("TESTIDQUEST") + .interrogationId("TESTIDUE") .mode(Mode.WEB) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2000,1,1,0,0,0)) @@ -37,7 +37,7 @@ public void toJSONTest() throws JsonProcessingException { objectMapper.findAndRegisterModules(); Assertions.assertEquals( - objectMapper.readTree("{\"idQuest\":\"TESTIDQUEST\",\"idCampaign\":\"TESTIDCAMPAIGN\",\"idUE\":\"TESTIDUE\",\"state\":\"COLLECTED\",\"mode\":\"WEB\",\"recordDate\":\"2000-01-01T12:00\",\"fileDate\":\"2000-01-01T12:00\",\"collectedVariables\":[{\"idVar\":\"TESTIDVAR\",\"values\":[\"V1\",\"V2\"],\"idLoop\":\"TESTIDLOOP\",\"idParent\":\"TESTIDPARENT\"}],\"externalVariables\":[{\"idVar\":\"TESTIDVAR\",\"values\":[\"V1\",\"V2\"]}]}"), + objectMapper.readTree("{\"questionnaireId\":\"TESTIDQUEST\",\"campaignId\":\"TESTIDCAMPAIGN\",\"interrogationId\":\"TESTIDUE\",\"state\":\"COLLECTED\",\"mode\":\"WEB\",\"recordDate\":\"2000-01-01T12:00\",\"fileDate\":\"2000-01-01T12:00\",\"collectedVariables\":[{\"idVar\":\"TESTIDVAR\",\"values\":[\"V1\",\"V2\"],\"idLoop\":\"TESTIDLOOP\",\"idParent\":\"TESTIDPARENT\"}],\"externalVariables\":[{\"varId\":\"TESTIDVAR\",\"values\":[\"V1\",\"V2\"]}]}"), objectMapper.readTree(objectMapper.writeValueAsString(surveyUnitModel)) ); } diff --git a/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java b/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java index 5ccd0ce1..779271d7 100644 --- a/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java +++ b/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java @@ -51,10 +51,10 @@ void reset(){ CollectedVariable collectedVariable = new CollectedVariable("TESTIDVAR", List.of(new String[]{"V1", "V2"}),"TESTIDLOOP","TESTIDPARENT"); collectedVariableList.add(collectedVariable); surveyUnitPersistencePortStub.getMongoStub().add(SurveyUnitModel.builder() - .idCampaign("TESTIDCAMPAIGN") + .campaignId("TESTIDCAMPAIGN") .mode(Mode.WEB) - .idUE(defaultIdUE) - .idQuest(defaultIdQuest) + .interrogationId(defaultIdUE) + .questionnaireId(defaultIdQuest) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023,1,1,0,0,0)) .recordDate(LocalDateTime.of(2024,1,1,0,0,0)) @@ -79,10 +79,10 @@ void saveAllTest(){ newSurveyUnitModelList.add( SurveyUnitModel.builder() - .idCampaign("TESTIDCAMPAIGN") + .campaignId("TESTIDCAMPAIGN") .mode(Mode.WEB) - .idUE("TESTIDUE2") - .idQuest(defaultIdQuest) + .interrogationId("TESTIDUE2") + .questionnaireId(defaultIdQuest) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023,1,1,0,0,0)) .recordDate(LocalDateTime.of(2024,1,1,0,0,0)) @@ -94,10 +94,10 @@ void saveAllTest(){ surveyUnitServiceStatic.saveSurveyUnits(newSurveyUnitModelList); Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub()).filteredOn(surveyUnitDto -> - surveyUnitDto.getIdCampaign().equals("TESTIDCAMPAIGN") + surveyUnitDto.getCampaignId().equals("TESTIDCAMPAIGN") && surveyUnitDto.getMode().equals(Mode.WEB) - && surveyUnitDto.getIdUE().equals("TESTIDUE2") - && surveyUnitDto.getIdQuest().equals(defaultIdQuest) + && surveyUnitDto.getInterrogationId().equals("TESTIDUE2") + && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) && surveyUnitDto.getState().equals(DataState.COLLECTED) && surveyUnitDto.getFileDate().equals(LocalDateTime.of(2023,1,1,0,0,0)) && surveyUnitDto.getRecordDate().equals(LocalDateTime.of(2024,1,1,0,0,0)) @@ -116,8 +116,8 @@ void saveAllTest(){ void findByIdsUEAndQuestionnaireTest(){ Assertions.assertThat(surveyUnitServiceStatic.findByIdsUEAndQuestionnaire(defaultIdUE, defaultIdQuest)).filteredOn( surveyUnitDto -> - surveyUnitDto.getIdUE().equals(defaultIdUE) - && surveyUnitDto.getIdQuest().equals(defaultIdQuest) + surveyUnitDto.getInterrogationId().equals(defaultIdUE) + && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) ).isNotEmpty(); } @@ -125,14 +125,14 @@ void findByIdsUEAndQuestionnaireTest(){ void findByIdUETest(){ Assertions.assertThat(surveyUnitServiceStatic.findByIdUE(defaultIdUE)).filteredOn( surveyUnitDto -> - surveyUnitDto.getIdUE().equals(defaultIdUE) + surveyUnitDto.getInterrogationId().equals(defaultIdUE) ).isNotEmpty(); } @Test void findByIdQuestionnaireTest(){ Assertions.assertThat(surveyUnitServiceStatic.findByIdQuestionnaire(defaultIdQuest)).filteredOn( - surveyUnitDto -> surveyUnitDto.getIdQuest().equals(defaultIdQuest) + surveyUnitDto -> surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) ).isNotEmpty(); } @@ -141,8 +141,8 @@ void findLatestByIdAndByModeTest(){ addAdditionnalDtoToMongoStub(); Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByIdQuestionnaire(defaultIdUE, defaultIdQuest)).filteredOn( - surveyUnitDto -> surveyUnitDto.getIdUE().equals(defaultIdUE) - && surveyUnitDto.getIdQuest().equals(defaultIdQuest) + surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultIdUE) + && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) && surveyUnitDto.getFileDate().getMonth().equals(Month.FEBRUARY) ).isNotEmpty(); } @@ -158,8 +158,8 @@ void findResponsesByUEAndQuestionnaireTest_null_collectedVariables() { surveyUnitPersistencePortStub.getMongoStub().getLast().setCollectedVariables(null); Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByIdQuestionnaire(defaultIdUE, defaultIdQuest)).filteredOn( - surveyUnitDto -> surveyUnitDto.getIdUE().equals(defaultIdUE) - && surveyUnitDto.getIdQuest().equals(defaultIdQuest) + surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultIdUE) + && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) && surveyUnitDto.getFileDate().getMonth().equals(Month.FEBRUARY) ).isNotEmpty(); } @@ -174,8 +174,8 @@ void findResponsesByUEAndQuestionnaireTest_null_externalVariables() { surveyUnitPersistencePortStub.getMongoStub().getLast().setExternalVariables(null); Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByIdQuestionnaire(defaultIdUE, defaultIdQuest)).filteredOn( - surveyUnitDto -> surveyUnitDto.getIdUE().equals(defaultIdUE) - && surveyUnitDto.getIdQuest().equals(defaultIdQuest) + surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultIdUE) + && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) && surveyUnitDto.getFileDate().getMonth().equals(Month.FEBRUARY) ).isNotEmpty(); } @@ -423,10 +423,10 @@ private void addAdditionnalDtoToMongoStub(){ collectedVariableList.add(collectedVariable); SurveyUnitModel recentDTO = SurveyUnitModel.builder() - .idCampaign("TESTIDCAMPAIGN") + .campaignId("TESTIDCAMPAIGN") .mode(Mode.WEB) - .idUE(defaultIdUE) - .idQuest(defaultIdQuest) + .interrogationId(defaultIdUE) + .questionnaireId(defaultIdQuest) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023,2,2,0,0,0)) .recordDate(LocalDateTime.of(2024,2,2,0,0,0)) @@ -446,10 +446,10 @@ private void addAdditionnalDtoToMongoStub(String idQuestionnaire) { collectedVariableList.add(collectedVariable); SurveyUnitModel recentDTO = SurveyUnitModel.builder() - .idCampaign("TESTIDCAMPAIGN") + .campaignId("TESTIDCAMPAIGN") .mode(Mode.WEB) - .idUE(defaultIdUE) - .idQuest(idQuestionnaire) + .interrogationId(defaultIdUE) + .questionnaireId(idQuestionnaire) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023, 2, 2, 0, 0, 0)) .recordDate(LocalDateTime.of(2024, 2, 2, 0, 0, 0)) @@ -473,10 +473,10 @@ private void addAdditionnalDtoToMongoStub(DataState state, collectedVariableList.add(collectedVariable); SurveyUnitModel recentDTO = SurveyUnitModel.builder() - .idCampaign("TESTIDCAMPAIGN") + .campaignId("TESTIDCAMPAIGN") .mode(Mode.WEB) - .idUE(defaultIdUE) - .idQuest(defaultIdQuest) + .interrogationId(defaultIdUE) + .questionnaireId(defaultIdQuest) .state(state) .fileDate(fileDate) .recordDate(recordDate) diff --git a/src/test/java/fr/insee/genesis/domain/utils/DataVerifierTest.java b/src/test/java/fr/insee/genesis/domain/utils/DataVerifierTest.java index 8404fe47..cbbbd565 100644 --- a/src/test/java/fr/insee/genesis/domain/utils/DataVerifierTest.java +++ b/src/test/java/fr/insee/genesis/domain/utils/DataVerifierTest.java @@ -39,9 +39,9 @@ void setUp() { CollectedVariable cv2 = new CollectedVariable("var2", List.of("true"), "loop2", "parent2"); SurveyUnitModel surveyUnit = SurveyUnitModel.builder() - .idUE("UE1100000001") - .idQuest("Quest1") - .idCampaign("Camp1") + .interrogationId("UE1100000001") + .questionnaireId("Quest1") + .campaignId("Camp1") .state(DataState.COLLECTED) .collectedVariables(List.of(cv1, cv2)) .externalVariables(List.of()) @@ -92,9 +92,9 @@ void shouldAddForcedSurveyUnit_WhenInvalidExternalVariable() { listVarExt.add(extVar); SurveyUnitModel surveyUnitWithInvalidExt = SurveyUnitModel.builder() - .idUE("UE1100000002") - .idQuest("Quest1") - .idCampaign("Camp1") + .interrogationId("UE1100000002") + .questionnaireId("Quest1") + .campaignId("Camp1") .state(DataState.COLLECTED) .collectedVariables(List.of()) .externalVariables(listVarExt) diff --git a/src/test/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitModelMongoAdapterTest.java b/src/test/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitModelMongoAdapterTest.java index 5e5a76c2..9cee571f 100644 --- a/src/test/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitModelMongoAdapterTest.java +++ b/src/test/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitModelMongoAdapterTest.java @@ -39,9 +39,9 @@ class SurveyUnitModelMongoAdapterTest { static void setUp() { surveyUnitMongoAdapter = new SurveyUnitMongoAdapter(mongoRepository, null); suDoc= new SurveyUnitDocument(); - suDoc.setIdCampaign("idCampaign"); - suDoc.setIdUE("UE1100000001"); - suDoc.setIdQuestionnaire("TEST2023X01"); + suDoc.setCampaignId("idCampaign"); + suDoc.setInterrogationId("UE1100000001"); + suDoc.setQuestionnaireId("TEST2023X01"); suDoc.setState("COLLECTED"); suDoc.setMode("WEB"); suDoc.setRecordDate(LocalDateTime.now()); @@ -49,9 +49,9 @@ static void setUp() { suDoc.setExternalVariables(List.of(new ExternalVariable())); suDoc2= new SurveyUnitDocument(); - suDoc2.setIdCampaign("idCampaign"); - suDoc2.setIdUE("UE1100000001"); - suDoc2.setIdQuestionnaire("TEST2023X01"); + suDoc2.setCampaignId("idCampaign"); + suDoc2.setInterrogationId("UE1100000001"); + suDoc2.setQuestionnaireId("TEST2023X01"); suDoc2.setState("COLLECTED"); suDoc2.setMode("TEL"); suDoc2.setRecordDate(LocalDateTime.now()); @@ -59,9 +59,9 @@ static void setUp() { suDoc2.setExternalVariables(List.of(new ExternalVariable())); suDoc3= new SurveyUnitDocument(); - suDoc3.setIdCampaign("idCampaign"); - suDoc3.setIdUE("UE1100000002"); - suDoc3.setIdQuestionnaire("TEST2023X01"); + suDoc3.setCampaignId("idCampaign"); + suDoc3.setInterrogationId("UE1100000002"); + suDoc3.setQuestionnaireId("TEST2023X01"); suDoc3.setState("COLLECTED"); suDoc3.setMode("WEB"); suDoc3.setRecordDate(LocalDateTime.now()); @@ -152,8 +152,8 @@ void shouldReturnListOfSurveyUnitDto_WhenGivenAListOfIdUEs() { responses2.add(suDoc3); when(mongoRepository.findByIdUEAndIdQuestionnaire("UE1100000001", "TEST2023X01")).thenReturn(responses1); when(mongoRepository.findByIdUEAndIdQuestionnaire("UE1100000002", "TEST2023X01")).thenReturn(responses2); - SurveyUnitModel id1 = SurveyUnitModel.builder().idUE("UE1100000001").build(); - SurveyUnitModel id2 = SurveyUnitModel.builder().idUE("UE1100000002").build(); + SurveyUnitModel id1 = SurveyUnitModel.builder().interrogationId("UE1100000001").build(); + SurveyUnitModel id2 = SurveyUnitModel.builder().interrogationId("UE1100000002").build(); List ids = List.of(id1, id2); // When List updates = surveyUnitMongoAdapter.findByIdUEsAndIdQuestionnaire(ids, "TEST2023X01"); @@ -166,8 +166,8 @@ void shouldReturnListOfSurveyUnitDto_WhenGivenAListOfIdUEs() { void shouldReturnEmptyList_IfIdUEsNotFoundInDataBase() { //Given when(mongoRepository.findByIdUEAndIdQuestionnaire(any(String.class),any(String.class))).thenReturn(List.of()); - SurveyUnitModel id1 = SurveyUnitModel.builder().idUE("UE1100000001").build(); - SurveyUnitModel id2 = SurveyUnitModel.builder().idUE("UE1100000002").build(); + SurveyUnitModel id1 = SurveyUnitModel.builder().interrogationId("UE1100000001").build(); + SurveyUnitModel id2 = SurveyUnitModel.builder().interrogationId("UE1100000002").build(); List ids = List.of(id1, id2); // When List updates = surveyUnitMongoAdapter.findByIdUEsAndIdQuestionnaire(ids, "TEST2023X01"); diff --git a/src/test/java/fr/insee/genesis/infrastructure/mapper/SurveyUnitDocumentMapperImplTest.java b/src/test/java/fr/insee/genesis/infrastructure/mapper/SurveyUnitDocumentMapperImplTest.java index f3ca02ba..1e576cd9 100644 --- a/src/test/java/fr/insee/genesis/infrastructure/mapper/SurveyUnitDocumentMapperImplTest.java +++ b/src/test/java/fr/insee/genesis/infrastructure/mapper/SurveyUnitDocumentMapperImplTest.java @@ -32,10 +32,10 @@ static void init(){ surveyUnitDocumentMapperImplStatic = new SurveyUnitDocumentMapperImpl(); surveyUnitDocumentStatic = new SurveyUnitDocument(); - surveyUnitDocumentStatic.setIdCampaign("TESTIDCAMPAIGN"); + surveyUnitDocumentStatic.setCampaignId("TESTIDCAMPAIGN"); surveyUnitDocumentStatic.setMode("WEB"); - surveyUnitDocumentStatic.setIdUE("TESTIDUE"); - surveyUnitDocumentStatic.setIdQuestionnaire("TESTIDQUESTIONNAIRE"); + surveyUnitDocumentStatic.setInterrogationId("TESTIDUE"); + surveyUnitDocumentStatic.setQuestionnaireId("TESTIDQUESTIONNAIRE"); surveyUnitDocumentStatic.setState("COLLECTED"); surveyUnitDocumentStatic.setFileDate(LocalDateTime.of(2023,1,1,0,0,0)); @@ -63,10 +63,10 @@ static void init(){ surveyUnitStatic = SurveyUnitModel.builder() - .idCampaign("TESTIDCAMPAIGN") + .campaignId("TESTIDCAMPAIGN") .mode(Mode.WEB) - .idUE("TESTIDUE") - .idQuest("TESTIDQUESTIONNAIRE") + .interrogationId("TESTIDUE") + .questionnaireId("TESTIDQUESTIONNAIRE") .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023,1,1,0,0,0)) .recordDate(LocalDateTime.of(2024,1,1,0,0,0)) @@ -91,10 +91,10 @@ void shouldReturnNull(){ void shouldReturnDocumentDtoFromDocument(){ SurveyUnitModel surveyUnit = surveyUnitDocumentMapperImplStatic.documentToModel(surveyUnitDocumentStatic); - Assertions.assertThat(surveyUnit.getIdCampaign()).isEqualTo("TESTIDCAMPAIGN"); + Assertions.assertThat(surveyUnit.getCampaignId()).isEqualTo("TESTIDCAMPAIGN"); Assertions.assertThat(surveyUnit.getMode()).isEqualTo(Mode.WEB); - Assertions.assertThat(surveyUnit.getIdUE()).isEqualTo("TESTIDUE"); - Assertions.assertThat(surveyUnit.getIdQuest()).isEqualTo("TESTIDQUESTIONNAIRE"); + Assertions.assertThat(surveyUnit.getInterrogationId()).isEqualTo("TESTIDUE"); + Assertions.assertThat(surveyUnit.getQuestionnaireId()).isEqualTo("TESTIDQUESTIONNAIRE"); Assertions.assertThat(surveyUnit.getState()).isEqualTo(DataState.COLLECTED); Assertions.assertThat(surveyUnit.getFileDate()).isEqualTo(LocalDateTime.of(2023,1,1,0,0,0)); @@ -115,10 +115,10 @@ void shouldReturnDocumentDtoFromDocument(){ void shouldReturnDocumentFromDocumentDto(){ SurveyUnitDocument surveyUnitDocument = surveyUnitDocumentMapperImplStatic.modelToDocument(surveyUnitStatic); - Assertions.assertThat(surveyUnitDocument.getIdCampaign()).isEqualTo("TESTIDCAMPAIGN"); + Assertions.assertThat(surveyUnitDocument.getCampaignId()).isEqualTo("TESTIDCAMPAIGN"); Assertions.assertThat(surveyUnitDocument.getMode()).isEqualTo("WEB"); - Assertions.assertThat(surveyUnitDocument.getIdUE()).isEqualTo("TESTIDUE"); - Assertions.assertThat(surveyUnitDocument.getIdQuestionnaire()).isEqualTo("TESTIDQUESTIONNAIRE"); + Assertions.assertThat(surveyUnitDocument.getInterrogationId()).isEqualTo("TESTIDUE"); + Assertions.assertThat(surveyUnitDocument.getQuestionnaireId()).isEqualTo("TESTIDQUESTIONNAIRE"); Assertions.assertThat(surveyUnitDocument.getState()).isEqualTo("COLLECTED"); Assertions.assertThat(surveyUnitDocument.getFileDate()).isEqualTo(LocalDateTime.of(2023,1,1,0,0,0)); @@ -143,10 +143,10 @@ void shouldReturnDocumentLDtoListFromDocumentList(){ List surveyUnitList = surveyUnitDocumentMapperImplStatic.listDocumentToListModel(surveyUnitDocumentList); - Assertions.assertThat(surveyUnitList.getFirst().getIdCampaign()).isEqualTo("TESTIDCAMPAIGN"); + Assertions.assertThat(surveyUnitList.getFirst().getCampaignId()).isEqualTo("TESTIDCAMPAIGN"); Assertions.assertThat(surveyUnitList.getFirst().getMode()).isEqualTo(Mode.WEB); - Assertions.assertThat(surveyUnitList.getFirst().getIdUE()).isEqualTo("TESTIDUE"); - Assertions.assertThat(surveyUnitList.getFirst().getIdQuest()).isEqualTo("TESTIDQUESTIONNAIRE"); + Assertions.assertThat(surveyUnitList.getFirst().getInterrogationId()).isEqualTo("TESTIDUE"); + Assertions.assertThat(surveyUnitList.getFirst().getQuestionnaireId()).isEqualTo("TESTIDQUESTIONNAIRE"); Assertions.assertThat(surveyUnitList.getFirst().getState()).isEqualTo(DataState.COLLECTED); Assertions.assertThat(surveyUnitList.getFirst().getFileDate()).isEqualTo(LocalDateTime.of(2023,1,1,0,0,0)); @@ -169,10 +169,10 @@ void shouldReturnDocumentListFromDocumentDtoList(){ List surveyUnitDocumentList = surveyUnitDocumentMapperImplStatic.listModelToListDocument(surveyUnitList); - Assertions.assertThat(surveyUnitDocumentList.getFirst().getIdCampaign()).isEqualTo("TESTIDCAMPAIGN"); + Assertions.assertThat(surveyUnitDocumentList.getFirst().getCampaignId()).isEqualTo("TESTIDCAMPAIGN"); Assertions.assertThat(surveyUnitDocumentList.getFirst().getMode()).isEqualTo("WEB"); - Assertions.assertThat(surveyUnitDocumentList.getFirst().getIdUE()).isEqualTo("TESTIDUE"); - Assertions.assertThat(surveyUnitDocumentList.getFirst().getIdQuestionnaire()).isEqualTo("TESTIDQUESTIONNAIRE"); + Assertions.assertThat(surveyUnitDocumentList.getFirst().getInterrogationId()).isEqualTo("TESTIDUE"); + Assertions.assertThat(surveyUnitDocumentList.getFirst().getQuestionnaireId()).isEqualTo("TESTIDQUESTIONNAIRE"); Assertions.assertThat(surveyUnitDocumentList.getFirst().getState()).isEqualTo("COLLECTED"); Assertions.assertThat(surveyUnitDocumentList.getFirst().getFileDate()).isEqualTo(LocalDateTime.of(2023,1,1,0,0,0)); diff --git a/src/test/java/fr/insee/genesis/stubs/SurveyUnitPersistencePortStub.java b/src/test/java/fr/insee/genesis/stubs/SurveyUnitPersistencePortStub.java index b5852aa9..667847eb 100644 --- a/src/test/java/fr/insee/genesis/stubs/SurveyUnitPersistencePortStub.java +++ b/src/test/java/fr/insee/genesis/stubs/SurveyUnitPersistencePortStub.java @@ -23,7 +23,7 @@ public void saveAll(List suList) { public List findByIds(String idUE, String idQuest) { List surveyUnitModelList = new ArrayList<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getIdUE().equals(idUE) && SurveyUnitModel.getIdQuest().equals(idQuest)) + if(SurveyUnitModel.getInterrogationId().equals(idUE) && SurveyUnitModel.getQuestionnaireId().equals(idQuest)) surveyUnitModelList.add(SurveyUnitModel); } @@ -34,7 +34,7 @@ public List findByIds(String idUE, String idQuest) { public List findByIdUE(String idUE) { List surveyUnitModelList = new ArrayList<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getIdUE().equals(idUE)) + if(SurveyUnitModel.getInterrogationId().equals(idUE)) surveyUnitModelList.add(SurveyUnitModel); } @@ -46,7 +46,7 @@ public List findByIdUEsAndIdQuestionnaire(List List surveyUnitModelList = new ArrayList<>(); for(SurveyUnitModel surveyUnitModel : idUEs) { for (SurveyUnitModel document : mongoStub) { - if (surveyUnitModel.getIdUE().equals(document.getIdUE()) && document.getIdQuest().equals(idQuestionnaire)) + if (surveyUnitModel.getInterrogationId().equals(document.getInterrogationId()) && document.getQuestionnaireId().equals(idQuestionnaire)) surveyUnitModelList.add(document); } } @@ -58,7 +58,7 @@ public List findByIdUEsAndIdQuestionnaire(List public Stream findByIdQuestionnaire(String idQuestionnaire) { List surveyUnitModelList = new ArrayList<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getIdQuest().equals(idQuestionnaire)) + if(SurveyUnitModel.getQuestionnaireId().equals(idQuestionnaire)) surveyUnitModelList.add(SurveyUnitModel); } @@ -69,9 +69,9 @@ public Stream findByIdQuestionnaire(String idQuestionnaire) { public List findIdUEsByIdQuestionnaire(String idQuestionnaire) { List surveyUnitModelList = new ArrayList<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getIdQuest().equals(idQuestionnaire)) + if(SurveyUnitModel.getQuestionnaireId().equals(idQuestionnaire)) surveyUnitModelList.add( - new SurveyUnitModel(SurveyUnitModel.getIdUE(), SurveyUnitModel.getMode()) + new SurveyUnitModel(SurveyUnitModel.getInterrogationId(), SurveyUnitModel.getMode()) ); } @@ -82,9 +82,9 @@ public List findIdUEsByIdQuestionnaire(String idQuestionnaire) public List findIdUEsByIdCampaign(String idCampaign) { List surveyUnitModelList = new ArrayList<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getIdCampaign().equals(idCampaign)) + if(SurveyUnitModel.getCampaignId().equals(idCampaign)) surveyUnitModelList.add( - new SurveyUnitModel(SurveyUnitModel.getIdUE(), SurveyUnitModel.getMode()) + new SurveyUnitModel(SurveyUnitModel.getInterrogationId(), SurveyUnitModel.getMode()) ); } @@ -105,8 +105,8 @@ public long count() { public Set findIdQuestionnairesByIdCampaign(String idCampaign) { Set idQuestionnaireSet = new HashSet<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getIdCampaign().equals(idCampaign)) - idQuestionnaireSet.add(SurveyUnitModel.getIdQuest()); + if(SurveyUnitModel.getCampaignId().equals(idCampaign)) + idQuestionnaireSet.add(SurveyUnitModel.getQuestionnaireId()); } return idQuestionnaireSet; @@ -116,7 +116,7 @@ public Set findIdQuestionnairesByIdCampaign(String idCampaign) { public Set findDistinctIdCampaigns() { Set campaignIds = new HashSet<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - campaignIds.add(SurveyUnitModel.getIdCampaign()); + campaignIds.add(SurveyUnitModel.getCampaignId()); } return campaignIds; @@ -125,14 +125,14 @@ public Set findDistinctIdCampaigns() { @Override public long countByIdCampaign(String idCampaign) { return mongoStub.stream().filter( - SurveyUnitDto -> SurveyUnitDto.getIdCampaign().equals(idCampaign)).toList().size(); + SurveyUnitDto -> SurveyUnitDto.getCampaignId().equals(idCampaign)).toList().size(); } @Override public Set findDistinctIdQuestionnaires() { Set questionnaireIds = new HashSet<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - questionnaireIds.add(SurveyUnitModel.getIdQuest()); + questionnaireIds.add(SurveyUnitModel.getQuestionnaireId()); } return questionnaireIds; } @@ -141,8 +141,8 @@ public Set findDistinctIdQuestionnaires() { public Set findIdCampaignsByIdQuestionnaire(String idQuestionnaire) { Set idCampaignSet = new HashSet<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getIdQuest().equals(idQuestionnaire)) - idCampaignSet.add(SurveyUnitModel.getIdCampaign()); + if(SurveyUnitModel.getQuestionnaireId().equals(idQuestionnaire)) + idCampaignSet.add(SurveyUnitModel.getCampaignId()); } return idCampaignSet; From ce1441953531e2fce92db64fae5004203150bb74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Henninger?= Date: Wed, 8 Jan 2025 14:56:35 +0100 Subject: [PATCH 2/7] Standardisation of ids name with the rule Id --- .../controller/adapter/LunaticXmlAdapter.java | 8 +++--- .../model/surveyunit/CollectedVariable.java | 12 ++++---- .../domain/model/surveyunit/IdLoopTuple.java | 2 +- .../domain/model/surveyunit/Variable.java | 2 +- .../service/surveyunit/SurveyUnitService.java | 24 ++++++++-------- .../genesis/domain/utils/DataVerifier.java | 28 +++++++++---------- .../document/surveyunit/ExternalVariable.java | 2 +- .../document/surveyunit/VariableState.java | 6 ++-- .../functional_tests/MainDefinitions.java | 12 ++++---- .../adapter/LunaticXmlAdapterTest.java | 20 ++++++------- .../rest/HealthCheckControllerTest.java | 2 +- .../controller/rest/UtilsControllerTest.java | 4 +-- .../controller/rest/responses/Utils.java | 4 +-- .../controller/utils/DataVerifierTest.java | 24 ++++++++-------- .../surveyunit/CollectedVariableTest.java | 8 +++--- .../model/surveyunit/SurveyUnitModelTest.java | 4 +-- .../domain/model/surveyunit/VariableTest.java | 2 +- .../domain/service/SurveyUnitServiceTest.java | 15 +++++----- .../domain/utils/DataVerifierTest.java | 2 +- .../SurveyUnitDocumentMapperImplTest.java | 22 +++++++-------- 20 files changed, 101 insertions(+), 102 deletions(-) diff --git a/src/main/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapter.java b/src/main/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapter.java index 6835a687..203685e8 100644 --- a/src/main/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapter.java +++ b/src/main/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapter.java @@ -122,10 +122,10 @@ private static SurveyUnitModel getCollectedDataFromSurveyUnit(LunaticXmlSurveyUn if (valueTypeList.get(i-1).getValue()!=null) { variableValues.add(valueTypeList.get(i-1).getValue()); variablesUpdate.add(CollectedVariable.collectedVariableBuilder() - .idVar(lunaticXmlCollectedData.getVariableName()) + .varId(lunaticXmlCollectedData.getVariableName()) .values(variableValues) - .idLoop(LoopIdentifier.getLoopIdentifier(lunaticXmlCollectedData.getVariableName(), variablesMap, i)) - .idParent(LoopIdentifier.getRelatedVariableName(lunaticXmlCollectedData.getVariableName(), variablesMap)) + .loopId(LoopIdentifier.getLoopIdentifier(lunaticXmlCollectedData.getVariableName(), variablesMap, i)) + .parentId(LoopIdentifier.getRelatedVariableName(lunaticXmlCollectedData.getVariableName(), variablesMap)) .build()); dataCount++; } @@ -152,7 +152,7 @@ private static void getExternalDataFromSurveyUnit(LunaticXmlSurveyUnit su, Surve List externalVariables = new ArrayList<>(); su.getData().getExternal().forEach(lunaticXmlExternalData -> externalVariables.add(Variable.builder() - .idVar(lunaticXmlExternalData.getVariableName()) + .varId(lunaticXmlExternalData.getVariableName()) .values(getValuesFromValueTypeList(lunaticXmlExternalData.getValues())) .build()) ); diff --git a/src/main/java/fr/insee/genesis/domain/model/surveyunit/CollectedVariable.java b/src/main/java/fr/insee/genesis/domain/model/surveyunit/CollectedVariable.java index 2d88a2d1..62c5f18f 100644 --- a/src/main/java/fr/insee/genesis/domain/model/surveyunit/CollectedVariable.java +++ b/src/main/java/fr/insee/genesis/domain/model/surveyunit/CollectedVariable.java @@ -11,14 +11,14 @@ @Setter public class CollectedVariable extends Variable { - private String idLoop; - private String idParent; + private String loopId; + private String parentId; @Builder(builderMethodName = "collectedVariableBuilder") - public CollectedVariable(String idVar, List values, String idLoop, String idParent) { - super(idVar, values); - this.idLoop = idLoop; - this.idParent = idParent; + public CollectedVariable(String varId, List values, String loopId, String parentId) { + super(varId, values); + this.loopId = loopId; + this.parentId = parentId; } } diff --git a/src/main/java/fr/insee/genesis/domain/model/surveyunit/IdLoopTuple.java b/src/main/java/fr/insee/genesis/domain/model/surveyunit/IdLoopTuple.java index 6d1ac551..615a25d2 100644 --- a/src/main/java/fr/insee/genesis/domain/model/surveyunit/IdLoopTuple.java +++ b/src/main/java/fr/insee/genesis/domain/model/surveyunit/IdLoopTuple.java @@ -1,4 +1,4 @@ package fr.insee.genesis.domain.model.surveyunit; -public record IdLoopTuple(String idVar, String idLoop) { +public record IdLoopTuple(String varId, String idLoop) { } diff --git a/src/main/java/fr/insee/genesis/domain/model/surveyunit/Variable.java b/src/main/java/fr/insee/genesis/domain/model/surveyunit/Variable.java index c5066b23..6f7a0dc2 100644 --- a/src/main/java/fr/insee/genesis/domain/model/surveyunit/Variable.java +++ b/src/main/java/fr/insee/genesis/domain/model/surveyunit/Variable.java @@ -11,7 +11,7 @@ @Setter public class Variable { - private String idVar; + private String varId; private List values; } diff --git a/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java b/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java index 2c2af33e..937b8a89 100644 --- a/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java +++ b/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java @@ -74,25 +74,25 @@ public List findLatestByIdAndByIdQuestionnaire(String idUE, Str if(latestUpdate.getExternalVariables() == null){ latestUpdate.setExternalVariables(new ArrayList<>()); } - latestUpdate.getCollectedVariables().forEach(colVar -> addedVariables.add(new IdLoopTuple(colVar.getIdVar(), colVar.getIdLoop()))); - latestUpdate.getExternalVariables().forEach(extVar -> addedVariables.add(new IdLoopTuple(extVar.getIdVar(), ""))); + latestUpdate.getCollectedVariables().forEach(colVar -> addedVariables.add(new IdLoopTuple(colVar.getVarId(), colVar.getLoopId()))); + latestUpdate.getExternalVariables().forEach(extVar -> addedVariables.add(new IdLoopTuple(extVar.getVarId(), ""))); suByMode.forEach(surveyUnitModel -> { List variablesToKeep = new ArrayList<>(); List externalToKeep = new ArrayList<>(); // We iterate over the variables of the update and add them to the list if they are not already added surveyUnitModel.getCollectedVariables().stream() - .filter(colVar -> !addedVariables.contains(new IdLoopTuple(colVar.getIdVar(), colVar.getIdLoop()))) + .filter(colVar -> !addedVariables.contains(new IdLoopTuple(colVar.getVarId(), colVar.getLoopId()))) .forEach(colVar -> { variablesToKeep.add(colVar); - addedVariables.add(new IdLoopTuple(colVar.getIdVar(), colVar.getIdLoop())); + addedVariables.add(new IdLoopTuple(colVar.getVarId(), colVar.getLoopId())); }); if (surveyUnitModel.getExternalVariables() != null){ surveyUnitModel.getExternalVariables().stream() - .filter(extVar -> !addedVariables.contains(new IdLoopTuple(extVar.getIdVar(), ""))) + .filter(extVar -> !addedVariables.contains(new IdLoopTuple(extVar.getVarId(), ""))) .forEach(extVar -> { externalToKeep.add(extVar); - addedVariables.add(new IdLoopTuple(extVar.getIdVar(), "")); + addedVariables.add(new IdLoopTuple(extVar.getVarId(), "")); }); } @@ -236,14 +236,14 @@ private void extractVariables(SurveyUnitModel surveyUnitModel, surveyUnitModel.setCollectedVariables(new ArrayList<>()); } for (CollectedVariable collectedVariable : surveyUnitModel.getCollectedVariables()) { - IdLoopTuple idLoopTuple = new IdLoopTuple(collectedVariable.getIdVar(), collectedVariable.getIdLoop()); + IdLoopTuple idLoopTuple = new IdLoopTuple(collectedVariable.getVarId(), collectedVariable.getLoopId()); VariableDto variableDto = collectedVariableMap.get(idLoopTuple); //Create variable into map if not exists if (variableDto == null) { variableDto = VariableDto.builder() - .variableName(collectedVariable.getIdVar()) - .idLoop(collectedVariable.getIdLoop()) + .variableName(collectedVariable.getVarId()) + .idLoop(collectedVariable.getLoopId()) .variableStateDtoList(new ArrayList<>()) .build(); collectedVariableMap.put(idLoopTuple, variableDto); @@ -265,15 +265,15 @@ private void extractVariables(SurveyUnitModel surveyUnitModel, surveyUnitModel.setExternalVariables(new ArrayList<>()); } for(Variable externalVariable : surveyUnitModel.getExternalVariables()){ - VariableDto variableDto = externalVariableMap.get(externalVariable.getIdVar()); + VariableDto variableDto = externalVariableMap.get(externalVariable.getVarId()); //Create variable into map if not exists if(variableDto == null){ variableDto = VariableDto.builder() - .variableName(externalVariable.getIdVar()) + .variableName(externalVariable.getVarId()) .variableStateDtoList(new ArrayList<>()) .build(); - externalVariableMap.put(externalVariable.getIdVar(), variableDto); + externalVariableMap.put(externalVariable.getVarId(), variableDto); } //Extract variable state if(!externalVariable.getValues().isEmpty() && isMostRecentForSameState(surveyUnitModel, variableDto)){ diff --git a/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java b/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java index e3940e3c..39781d92 100644 --- a/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java +++ b/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java @@ -86,10 +86,10 @@ private static SurveyUnitModel createForcedDto( for(CollectedVariable correctedCollectedVariable : correctedCollectedVariables){ newForcedSuDto.getCollectedVariables().add( - new CollectedVariable(correctedCollectedVariable.getIdVar(), + new CollectedVariable(correctedCollectedVariable.getVarId(), correctedCollectedVariable.getValues() - ,correctedCollectedVariable.getIdLoop() - ,correctedCollectedVariable.getIdParent() + ,correctedCollectedVariable.getLoopId() + ,correctedCollectedVariable.getParentId() ) ); } @@ -97,7 +97,7 @@ private static SurveyUnitModel createForcedDto( for(Variable correctedExternalVariable : correctedExternalVariables){ newForcedSuDto.getExternalVariables().add( Variable.builder() - .idVar(correctedExternalVariable.getIdVar()) + .varId(correctedExternalVariable.getVarId()) .values(correctedExternalVariable.getValues()) .build() ); @@ -136,8 +136,8 @@ private static void collectedVariablesManagement(List srcSuDtos //Get more priority variables to verify for(SurveyUnitModel srcSuDto : sortedSuDtos){ for(CollectedVariable collectedVariable : srcSuDto.getCollectedVariables()){ - if(!variableNames.contains(collectedVariable.getIdVar())){ - variableNames.add(collectedVariable.getIdVar()); + if(!variableNames.contains(collectedVariable.getVarId())){ + variableNames.add(collectedVariable.getVarId()); variablesToVerify.add(collectedVariable); } } @@ -145,11 +145,11 @@ private static void collectedVariablesManagement(List srcSuDtos //Verify variables for(CollectedVariable collectedVariableToVerify : variablesToVerify){ - if(variablesMap.hasVariable(collectedVariableToVerify.getIdVar())) + if(variablesMap.hasVariable(collectedVariableToVerify.getVarId())) { CollectedVariable correctedCollectedVariable = verifyCollectedVariable( collectedVariableToVerify, - variablesMap.getVariable(collectedVariableToVerify.getIdVar()) + variablesMap.getVariable(collectedVariableToVerify.getVarId()) ); if(correctedCollectedVariable != null){ @@ -173,10 +173,10 @@ private static CollectedVariable verifyCollectedVariable(CollectedVariable colle } return isInvalid ? new CollectedVariable( - collectedVariable.getIdVar(), + collectedVariable.getVarId(), newValues, - collectedVariable.getIdLoop(), - collectedVariable.getIdParent() + collectedVariable.getLoopId(), + collectedVariable.getParentId() ) : null; } @@ -189,10 +189,10 @@ private static void externalVariablesManagement(List srcSuDtosO //Verify variables if(collectedSuDtoOpt.isPresent()){ for(Variable variable: collectedSuDtoOpt.get().getExternalVariables()){ - if(variablesMap.hasVariable(variable.getIdVar())) { + if(variablesMap.hasVariable(variable.getVarId())) { Variable correctedExternalVariable = verifyExternalVariable( variable, - variablesMap.getVariable(variable.getIdVar()) + variablesMap.getVariable(variable.getVarId()) ); if (correctedExternalVariable != null) { correctedExternalVariables.add(correctedExternalVariable); @@ -222,7 +222,7 @@ private static Variable verifyExternalVariable(Variable externalVariable, fr.ins } return isInvalid ? Variable.builder() - .idVar(externalVariable.getIdVar()) + .varId(externalVariable.getVarId()) .values(newValues) .build() : null; } diff --git a/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/ExternalVariable.java b/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/ExternalVariable.java index 197c7a98..ee14fc89 100644 --- a/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/ExternalVariable.java +++ b/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/ExternalVariable.java @@ -11,6 +11,6 @@ public class ExternalVariable implements Serializable { @Serial private static final long serialVersionUID = 6267528628435012000L; - private String idVar; + private String varId; private List values; } \ No newline at end of file diff --git a/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/VariableState.java b/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/VariableState.java index cf177107..799512ec 100644 --- a/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/VariableState.java +++ b/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/VariableState.java @@ -11,8 +11,8 @@ public class VariableState implements Serializable { @Serial private static final long serialVersionUID = -1576556180669134053L; - private String idVar; - private String idLoop; - private String idParent; + private String varId; + private String loopId; + private String parentId; private List values; } \ No newline at end of file diff --git a/src/test/java/cucumber/functional_tests/MainDefinitions.java b/src/test/java/cucumber/functional_tests/MainDefinitions.java index cedc5206..82557cda 100644 --- a/src/test/java/cucumber/functional_tests/MainDefinitions.java +++ b/src/test/java/cucumber/functional_tests/MainDefinitions.java @@ -161,10 +161,10 @@ public void check_survey_unit_dto_content(String dataState, String surveyUnitId, //Get Variable Assertions.assertThat(concernedDto.getCollectedVariables()).filteredOn(collectedVariableDto -> - collectedVariableDto.getIdVar().equals(variableName)).isNotEmpty(); + collectedVariableDto.getVarId().equals(variableName)).isNotEmpty(); Optional concernedVariableOptional = concernedDto.getCollectedVariables().stream().filter(variable -> - variable.getIdVar().equals(variableName) + variable.getVarId().equals(variableName) ).findFirst(); Assertions.assertThat(concernedVariableOptional).isPresent(); @@ -196,10 +196,10 @@ public void external_variable_volumetric_check(int expectedNumberOfValues, Strin //Get Variable Assertions.assertThat(concernedDto.getExternalVariables()).filteredOn(variableDto -> - variableDto.getIdVar().equals(externalVariableName)).isNotEmpty(); + variableDto.getVarId().equals(externalVariableName)).isNotEmpty(); Optional concernedVariableOptional = concernedDto.getExternalVariables().stream().filter(variable -> - variable.getIdVar().equals(externalVariableName) + variable.getVarId().equals(externalVariableName) ).findFirst(); Assertions.assertThat(concernedVariableOptional).isPresent(); @@ -230,10 +230,10 @@ public void external_variable_content_check(String externalVariableName, String //Get Variable Assertions.assertThat(concernedDto.getExternalVariables()).filteredOn(variableDto -> - variableDto.getIdVar().equals(externalVariableName)).isNotEmpty(); + variableDto.getVarId().equals(externalVariableName)).isNotEmpty(); Optional concernedVariableOptional = concernedDto.getExternalVariables().stream().filter(variable -> - variable.getIdVar().equals(externalVariableName) + variable.getVarId().equals(externalVariableName) ).findFirst(); Assertions.assertThat(concernedVariableOptional).isPresent(); diff --git a/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java b/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java index f2e5b233..eb71fd69 100644 --- a/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java +++ b/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java @@ -315,11 +315,11 @@ void test09() { Assertions.assertThat(suDtos).hasSize(1); Assertions.assertThat(suDtos.getFirst().getCollectedVariables()).filteredOn(collectedVariableDto -> - collectedVariableDto.getIdVar().equals("var3")).isNotEmpty(); + collectedVariableDto.getVarId().equals("var3")).isNotEmpty(); Assertions.assertThat(suDtos.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> - collectedVariableDto.getIdVar().equals("var3")).toList().getFirst().getIdParent()).isNull(); + collectedVariableDto.getVarId().equals("var3")).toList().getFirst().getParentId()).isNull(); Assertions.assertThat(suDtos.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> - collectedVariableDto.getIdVar().equals("var3")).toList().getFirst().getIdLoop()).isEqualTo(Constants.ROOT_GROUP_NAME); + collectedVariableDto.getVarId().equals("var3")).toList().getFirst().getLoopId()).isEqualTo(Constants.ROOT_GROUP_NAME); } @Test @@ -332,11 +332,11 @@ void test10() { Assertions.assertThat(suDtos).hasSize(1); Assertions.assertThat(suDtos.getFirst().getCollectedVariables()).filteredOn(collectedVariableDto -> - collectedVariableDto.getIdVar().equals("var1_MISSING")).isNotEmpty(); + collectedVariableDto.getVarId().equals("var1_MISSING")).isNotEmpty(); Assertions.assertThat(suDtos.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> - collectedVariableDto.getIdVar().equals("var1_MISSING")).toList().getFirst().getIdParent()).isNotNull().isEqualTo("var1"); + collectedVariableDto.getVarId().equals("var1_MISSING")).toList().getFirst().getParentId()).isNotNull().isEqualTo("var1"); Assertions.assertThat(suDtos.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> - collectedVariableDto.getIdVar().equals("var1_MISSING")).toList().getFirst().getIdLoop()).isNotEqualTo(Constants.ROOT_GROUP_NAME).isEqualTo(LOOP_NAME); + collectedVariableDto.getVarId().equals("var1_MISSING")).toList().getFirst().getLoopId()).isNotEqualTo(Constants.ROOT_GROUP_NAME).isEqualTo(LOOP_NAME); } @Test @@ -348,13 +348,13 @@ void test11(){ Assertions.assertThat(suDtos).hasSize(1); Assertions.assertThat(suDtos.getFirst().getCollectedVariables()).hasSize(3); Assertions.assertThat(suDtos.getFirst().getCollectedVariables()).filteredOn(collectedVariableDto -> - collectedVariableDto.getIdVar().equals("var1")).isNotEmpty(); + collectedVariableDto.getVarId().equals("var1")).isNotEmpty(); Assertions.assertThat(suDtos.getFirst().getCollectedVariables()).filteredOn(collectedVariableDto -> - collectedVariableDto.getIdLoop().equals("BOUCLE1_1")).isEmpty(); + collectedVariableDto.getLoopId().equals("BOUCLE1_1")).isEmpty(); Assertions.assertThat(suDtos.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> - collectedVariableDto.getIdLoop().equals("BOUCLE1_2")).toList().getFirst().getValues().getFirst()).isEqualTo("1"); + collectedVariableDto.getLoopId().equals("BOUCLE1_2")).toList().getFirst().getValues().getFirst()).isEqualTo("1"); Assertions.assertThat(suDtos.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> - collectedVariableDto.getIdLoop().equals("BOUCLE1_3")).toList().getFirst().getValues().getFirst()).isEqualTo("2"); + collectedVariableDto.getLoopId().equals("BOUCLE1_3")).toList().getFirst().getValues().getFirst()).isEqualTo("2"); } } diff --git a/src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.java index 4081ebec..b52f615a 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.java @@ -31,7 +31,7 @@ static void init() { surveyUnitPersistencePortStub = new SurveyUnitPersistencePortStub(); SurveyUnitApiPort surveyUnitApiPort = new SurveyUnitService(surveyUnitPersistencePortStub); List externalVariableList = new ArrayList<>(); - Variable variable = Variable.builder().idVar("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); + Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); externalVariableList.add(variable); List collectedVariableList = new ArrayList<>(); diff --git a/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java index cfd59a9c..f6d6b74d 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java @@ -61,7 +61,7 @@ void reset() throws IOException { surveyUnitPersistencePortStub.getMongoStub().clear(); List externalVariableList = new ArrayList<>(); - Variable variable = Variable.builder().idVar("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); + Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); externalVariableList.add(variable); List collectedVariableList = new ArrayList<>(); @@ -348,7 +348,7 @@ private void addAdditionalDtoToMongoStub(String idQuestionnaire) { private void addAdditionalDtoToMongoStub(String idCampaign, String idQuestionnaire) { List externalVariableList = new ArrayList<>(); - Variable variable = Variable.builder().idVar("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); + Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); externalVariableList.add(variable); List collectedVariableList = new ArrayList<>(); diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/Utils.java b/src/test/java/fr/insee/genesis/controller/rest/responses/Utils.java index 5a98dfe3..a3c76fed 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/Utils.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/Utils.java @@ -185,7 +185,7 @@ static void addAdditionalDtoToMongoStub(String idCampaign, String idQuestionnair LocalDateTime fileDate, LocalDateTime recordDate, SurveyUnitPersistencePortStub surveyUnitPersistencePortStub) { List externalVariableList = new ArrayList<>(); - Variable variable = Variable.builder().idVar("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); + Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); externalVariableList.add(variable); List collectedVariableList = new ArrayList<>(); @@ -215,7 +215,7 @@ static void addAdditionalDtoToMongoStub(DataState state, LocalDateTime recordDate, SurveyUnitPersistencePortStub surveyUnitPersistencePortStub) { List externalVariableList = new ArrayList<>(); - Variable variable = Variable.builder().idVar("TESTIDVAR").values(List.of(new String[]{externalVariableValue})).build(); + Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{externalVariableValue})).build(); externalVariableList.add(variable); List collectedVariableList = new ArrayList<>(); diff --git a/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java b/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java index 14965fcd..b38b4da7 100644 --- a/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java +++ b/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java @@ -150,14 +150,14 @@ private static void createCase(int variableNumber, int stateNumber, int valueNum } variableUpdates.add(CollectedVariable.collectedVariableBuilder() - .idVar("testInteger" + variableIndex) + .varId("testInteger" + variableIndex) .values(new ArrayList<>(values)) .build() ); if(hasExternalVariables){ externalVariables.add(Variable.builder() - .idVar("testInteger" + variableIndex) + .varId("testInteger" + variableIndex) .values(new ArrayList<>(values)) .build() ); @@ -210,15 +210,15 @@ private void assertCollectedVariableContent(List testSurveyUnit SurveyUnitModel suDto = suDtoOpt.get(); assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> - collectedVariableDto.getIdVar().equals(variableName) + collectedVariableDto.getVarId().equals(variableName) )).isNotEmpty(); assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> - collectedVariableDto.getIdVar().equals(variableName) + collectedVariableDto.getVarId().equals(variableName) ).findFirst()).isPresent(); assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> - collectedVariableDto.getIdVar().equals(variableName) + collectedVariableDto.getVarId().equals(variableName) ).findFirst().get().getValues().get(valueIndex)).isEqualTo(expectedContent); } @@ -232,9 +232,9 @@ private void assertForcedCollectedVariableExistence(List testSu SurveyUnitModel suDto = suDtoOpt.get(); if(hasToExist) - assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getIdVar().equals(variableName)).toList()).isNotEmpty(); + assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals(variableName)).toList()).isNotEmpty(); else - assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getIdVar().equals(variableName)).toList()).isEmpty(); + assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals(variableName)).toList()).isEmpty(); } private void assertForcedExternalVariableExistence(List testSurveyUnitModels, String idUE, String variableName, boolean hasToExist) { @@ -247,9 +247,9 @@ private void assertForcedExternalVariableExistence(List testSur SurveyUnitModel suDto = suDtoOpt.get(); if(hasToExist) - assertThat(suDto.getExternalVariables().stream().filter(variableDto -> variableDto.getIdVar().equals(variableName)).toList()).isNotEmpty(); + assertThat(suDto.getExternalVariables().stream().filter(variableDto -> variableDto.getVarId().equals(variableName)).toList()).isNotEmpty(); else - assertThat(suDto.getExternalVariables().stream().filter(variableDto -> variableDto.getIdVar().equals(variableName)).toList()).isEmpty(); + assertThat(suDto.getExternalVariables().stream().filter(variableDto -> variableDto.getVarId().equals(variableName)).toList()).isEmpty(); } private void assertExternalVariableContent(List testSurveyUnitModels, String idUE, String variableName, int valueIndex, String expectedContent) { @@ -265,15 +265,15 @@ private void assertExternalVariableContent(List testSurveyUnitM SurveyUnitModel suDto = suDtoOpt.get(); assertThat(suDto.getExternalVariables().stream().filter(variableDto -> - variableDto.getIdVar().equals(variableName) + variableDto.getVarId().equals(variableName) )).isNotEmpty(); assertThat(suDto.getExternalVariables().stream().filter(variableDto -> - variableDto.getIdVar().equals(variableName) + variableDto.getVarId().equals(variableName) ).findFirst()).isPresent(); assertThat(suDto.getExternalVariables().stream().filter(variableDto -> - variableDto.getIdVar().equals(variableName) + variableDto.getVarId().equals(variableName) ).findFirst().get().getValues().get(valueIndex)).isEqualTo(expectedContent); } diff --git a/src/test/java/fr/insee/genesis/domain/model/surveyunit/CollectedVariableTest.java b/src/test/java/fr/insee/genesis/domain/model/surveyunit/CollectedVariableTest.java index 0a560c3e..b79fa76f 100644 --- a/src/test/java/fr/insee/genesis/domain/model/surveyunit/CollectedVariableTest.java +++ b/src/test/java/fr/insee/genesis/domain/model/surveyunit/CollectedVariableTest.java @@ -12,9 +12,9 @@ class CollectedVariableTest { @Test void toJSONTest() throws JsonProcessingException { CollectedVariable collectedVariable = CollectedVariable.collectedVariableBuilder() - .idVar("TESTIDVAR") - .idParent("TESTIDPARENT") - .idLoop("TESTIDLOOP") + .varId("TESTIDVAR") + .parentId("TESTIDPARENT") + .loopId("TESTIDLOOP") .values(new ArrayList<>(List.of(new String[]{"V1", "V2"}))) .build(); @@ -22,7 +22,7 @@ void toJSONTest() throws JsonProcessingException { objectMapper.findAndRegisterModules(); Assertions.assertEquals(objectMapper.readTree(objectMapper.writeValueAsString(collectedVariable)), - objectMapper.readTree("{\"values\":[\"V1\",\"V2\"],\"idVar\":\"TESTIDVAR\",\"idLoop\":\"TESTIDLOOP\",\"idParent\":\"TESTIDPARENT\"}")); + objectMapper.readTree("{\"values\":[\"V1\",\"V2\"],\"varId\":\"TESTIDVAR\",\"loopId\":\"TESTIDLOOP\",\"parentId\":\"TESTIDPARENT\"}")); } } diff --git a/src/test/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModelTest.java b/src/test/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModelTest.java index 1c2f5a3f..00bda95c 100644 --- a/src/test/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModelTest.java +++ b/src/test/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModelTest.java @@ -13,7 +13,7 @@ public class SurveyUnitModelTest { @Test public void toJSONTest() throws JsonProcessingException { List externalVariableList = new ArrayList<>(); - Variable variable = Variable.builder().idVar("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); + Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); externalVariableList.add(variable); List collectedVariableList = new ArrayList<>(); @@ -37,7 +37,7 @@ public void toJSONTest() throws JsonProcessingException { objectMapper.findAndRegisterModules(); Assertions.assertEquals( - objectMapper.readTree("{\"questionnaireId\":\"TESTIDQUEST\",\"campaignId\":\"TESTIDCAMPAIGN\",\"interrogationId\":\"TESTIDUE\",\"state\":\"COLLECTED\",\"mode\":\"WEB\",\"recordDate\":\"2000-01-01T12:00\",\"fileDate\":\"2000-01-01T12:00\",\"collectedVariables\":[{\"idVar\":\"TESTIDVAR\",\"values\":[\"V1\",\"V2\"],\"idLoop\":\"TESTIDLOOP\",\"idParent\":\"TESTIDPARENT\"}],\"externalVariables\":[{\"varId\":\"TESTIDVAR\",\"values\":[\"V1\",\"V2\"]}]}"), + objectMapper.readTree("{\"questionnaireId\":\"TESTIDQUEST\",\"campaignId\":\"TESTIDCAMPAIGN\",\"interrogationId\":\"TESTIDUE\",\"state\":\"COLLECTED\",\"mode\":\"WEB\",\"recordDate\":\"2000-01-01T12:00\",\"fileDate\":\"2000-01-01T12:00\",\"collectedVariables\":[{\"varId\":\"TESTIDVAR\",\"values\":[\"V1\",\"V2\"],\"loopId\":\"TESTIDLOOP\",\"parentId\":\"TESTIDPARENT\"}],\"externalVariables\":[{\"varId\":\"TESTIDVAR\",\"values\":[\"V1\",\"V2\"]}]}"), objectMapper.readTree(objectMapper.writeValueAsString(surveyUnitModel)) ); } diff --git a/src/test/java/fr/insee/genesis/domain/model/surveyunit/VariableTest.java b/src/test/java/fr/insee/genesis/domain/model/surveyunit/VariableTest.java index 640ff5d4..2325b736 100644 --- a/src/test/java/fr/insee/genesis/domain/model/surveyunit/VariableTest.java +++ b/src/test/java/fr/insee/genesis/domain/model/surveyunit/VariableTest.java @@ -15,7 +15,7 @@ void toJSONTest() throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.findAndRegisterModules(); Assertions.assertEquals(objectMapper.readTree(objectMapper.writeValueAsString(variable)), - objectMapper.readTree("{\"values\":[\"V1\",\"V2\"],\"idVar\":\"TESTIDVAR\"}")); + objectMapper.readTree("{\"values\":[\"V1\",\"V2\"],\"varId\":\"TESTIDVAR\"}")); } } diff --git a/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java b/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java index 779271d7..a4639315 100644 --- a/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java +++ b/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java @@ -13,7 +13,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.http.ResponseEntity; import java.time.LocalDateTime; import java.time.Month; @@ -44,7 +43,7 @@ static void init(){ void reset(){ surveyUnitPersistencePortStub.getMongoStub().clear(); List externalVariableList = new ArrayList<>(); - Variable variable = Variable.builder().idVar("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); + Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); externalVariableList.add(variable); List collectedVariableList = new ArrayList<>(); @@ -70,7 +69,7 @@ void saveAllTest(){ List newSurveyUnitModelList = new ArrayList<>(); List externalVariableList = new ArrayList<>(); - Variable variable = Variable.builder().idVar("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); + Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); externalVariableList.add(variable); List collectedVariableList = new ArrayList<>(); @@ -102,11 +101,11 @@ void saveAllTest(){ && surveyUnitDto.getFileDate().equals(LocalDateTime.of(2023,1,1,0,0,0)) && surveyUnitDto.getRecordDate().equals(LocalDateTime.of(2024,1,1,0,0,0)) && !surveyUnitDto.getExternalVariables().stream().filter( - externalVariable -> externalVariable.getIdVar().equals("TESTIDVAR") + externalVariable -> externalVariable.getVarId().equals("TESTIDVAR") && externalVariable.getValues().containsAll(List.of(new String[]{"V1", "V2"})) ).toList().isEmpty() && !surveyUnitDto.getCollectedVariables().stream().filter( - collectedVariable -> collectedVariable.getIdVar().equals("TESTIDVAR") + collectedVariable -> collectedVariable.getVarId().equals("TESTIDVAR") && collectedVariable.getValues().containsAll(List.of(new String[]{"V1", "V2"})) ).toList().isEmpty() ).isNotEmpty(); @@ -415,7 +414,7 @@ void findLatestByIdAndByIdQuestionnairePerretTest_null_externalVariables(){ private void addAdditionnalDtoToMongoStub(){ List externalVariableList = new ArrayList<>(); - Variable variable = Variable.builder().idVar("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); + Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); externalVariableList.add(variable); List collectedVariableList = new ArrayList<>(); @@ -438,7 +437,7 @@ private void addAdditionnalDtoToMongoStub(){ private void addAdditionnalDtoToMongoStub(String idQuestionnaire) { List externalVariableList = new ArrayList<>(); - Variable variable = Variable.builder().idVar("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); + Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); externalVariableList.add(variable); List collectedVariableList = new ArrayList<>(); @@ -465,7 +464,7 @@ private void addAdditionnalDtoToMongoStub(DataState state, LocalDateTime fileDate, LocalDateTime recordDate) { List externalVariableList = new ArrayList<>(); - Variable variable = Variable.builder().idVar("TESTIDVAR").values(List.of(new String[]{externalVariableValue})).build(); + Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{externalVariableValue})).build(); externalVariableList.add(variable); List collectedVariableList = new ArrayList<>(); diff --git a/src/test/java/fr/insee/genesis/domain/utils/DataVerifierTest.java b/src/test/java/fr/insee/genesis/domain/utils/DataVerifierTest.java index cbbbd565..c558f0c5 100644 --- a/src/test/java/fr/insee/genesis/domain/utils/DataVerifierTest.java +++ b/src/test/java/fr/insee/genesis/domain/utils/DataVerifierTest.java @@ -87,7 +87,7 @@ void shouldNotAddForcedSurveyUnit_WhenAllVariablesAreValid() { void shouldAddForcedSurveyUnit_WhenInvalidExternalVariable() { //Add surveyUnit with invalid external Variable - fr.insee.genesis.domain.model.surveyunit.Variable extVar = fr.insee.genesis.domain.model.surveyunit.Variable.builder().idVar("var2").values(List.of("notBoolean")).build(); + fr.insee.genesis.domain.model.surveyunit.Variable extVar = fr.insee.genesis.domain.model.surveyunit.Variable.builder().varId("var2").values(List.of("notBoolean")).build(); List listVarExt = new ArrayList<>(); listVarExt.add(extVar); diff --git a/src/test/java/fr/insee/genesis/infrastructure/mapper/SurveyUnitDocumentMapperImplTest.java b/src/test/java/fr/insee/genesis/infrastructure/mapper/SurveyUnitDocumentMapperImplTest.java index 1e576cd9..f88d5334 100644 --- a/src/test/java/fr/insee/genesis/infrastructure/mapper/SurveyUnitDocumentMapperImplTest.java +++ b/src/test/java/fr/insee/genesis/infrastructure/mapper/SurveyUnitDocumentMapperImplTest.java @@ -41,20 +41,20 @@ static void init(){ List externalVariableList = new ArrayList<>(); ExternalVariable externalVariable = new ExternalVariable(); - externalVariable.setIdVar("TESTIDVAR"); + externalVariable.setVarId("TESTIDVAR"); externalVariable.setValues(List.of(new String[]{"V1", "V2"})); externalVariableList.add(externalVariable); surveyUnitDocumentStatic.setExternalVariables(externalVariableList); List variableStateList = new ArrayList<>(); VariableState variableState = new VariableState(); - variableState.setIdVar("TESTIDVAR"); + variableState.setVarId("TESTIDVAR"); variableState.setValues(List.of(new String[]{"V1", "V2"})); variableStateList.add(variableState); surveyUnitDocumentStatic.setCollectedVariables(variableStateList); List externalVariableDtoList = new ArrayList<>(); - Variable variable = Variable.builder().idVar("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); + Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); externalVariableDtoList.add(variable); List collectedVariableList = new ArrayList<>(); @@ -99,12 +99,12 @@ void shouldReturnDocumentDtoFromDocument(){ Assertions.assertThat(surveyUnit.getFileDate()).isEqualTo(LocalDateTime.of(2023,1,1,0,0,0)); Assertions.assertThat(surveyUnit.getExternalVariables()).filteredOn(externalVariableDto -> - externalVariableDto.getIdVar().equals("TESTIDVAR") + externalVariableDto.getVarId().equals("TESTIDVAR") && externalVariableDto.getValues().containsAll(List.of(new String[]{"V1", "V2"})) ).isNotEmpty(); Assertions.assertThat(surveyUnit.getCollectedVariables()).filteredOn(variableStateDto -> - variableStateDto.getIdVar().equals("TESTIDVAR") + variableStateDto.getVarId().equals("TESTIDVAR") && variableStateDto.getValues().containsAll(List.of(new String[]{"V1", "V2"})) ).isNotEmpty(); @@ -123,12 +123,12 @@ void shouldReturnDocumentFromDocumentDto(){ Assertions.assertThat(surveyUnitDocument.getFileDate()).isEqualTo(LocalDateTime.of(2023,1,1,0,0,0)); Assertions.assertThat(surveyUnitDocument.getExternalVariables()).filteredOn(externalVariableDto -> - externalVariableDto.getIdVar().equals("TESTIDVAR") + externalVariableDto.getVarId().equals("TESTIDVAR") && externalVariableDto.getValues().containsAll(List.of(new String[]{"V1", "V2"})) ).isNotEmpty(); Assertions.assertThat(surveyUnitDocument.getCollectedVariables()).filteredOn(variableStateDto -> - variableStateDto.getIdVar().equals("TESTIDVAR") + variableStateDto.getVarId().equals("TESTIDVAR") && variableStateDto.getValues().containsAll(List.of(new String[]{"V1", "V2"})) ).isNotEmpty(); @@ -151,12 +151,12 @@ void shouldReturnDocumentLDtoListFromDocumentList(){ Assertions.assertThat(surveyUnitList.getFirst().getFileDate()).isEqualTo(LocalDateTime.of(2023,1,1,0,0,0)); Assertions.assertThat(surveyUnitList.getFirst().getExternalVariables()).filteredOn(externalVariableDto -> - externalVariableDto.getIdVar().equals("TESTIDVAR") + externalVariableDto.getVarId().equals("TESTIDVAR") && externalVariableDto.getValues().containsAll(List.of(new String[]{"V1", "V2"})) ).isNotEmpty(); Assertions.assertThat(surveyUnitList.getFirst().getCollectedVariables()).filteredOn(variableStateDto -> - variableStateDto.getIdVar().equals("TESTIDVAR") + variableStateDto.getVarId().equals("TESTIDVAR") && variableStateDto.getValues().containsAll(List.of(new String[]{"V1", "V2"})) ).isNotEmpty(); } @@ -177,12 +177,12 @@ void shouldReturnDocumentListFromDocumentDtoList(){ Assertions.assertThat(surveyUnitDocumentList.getFirst().getFileDate()).isEqualTo(LocalDateTime.of(2023,1,1,0,0,0)); Assertions.assertThat(surveyUnitDocumentList.getFirst().getExternalVariables()).filteredOn(externalVariableDto -> - externalVariableDto.getIdVar().equals("TESTIDVAR") + externalVariableDto.getVarId().equals("TESTIDVAR") && externalVariableDto.getValues().containsAll(List.of(new String[]{"V1", "V2"})) ).isNotEmpty(); Assertions.assertThat(surveyUnitDocumentList.getFirst().getCollectedVariables()).filteredOn(variableStateDto -> - variableStateDto.getIdVar().equals("TESTIDVAR") + variableStateDto.getVarId().equals("TESTIDVAR") && variableStateDto.getValues().containsAll(List.of(new String[]{"V1", "V2"})) ).isNotEmpty(); } From cff5812a083ad6423f9b408200e1f1d7f00ab9f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Henninger?= Date: Fri, 10 Jan 2025 16:51:05 +0100 Subject: [PATCH 3/7] End of refactor on ids name --- .../controller/dto/SurveyUnitSimplified.java | 6 +- .../rest/responses/CampaignController.java | 2 +- ...ller.java => InterrogationController.java} | 12 +-- .../rest/responses/ModeController.java | 8 +- .../responses/QuestionnaireController.java | 6 +- .../rest/responses/ResponseController.java | 81 ++++++++++--------- .../sources/json/LunaticJsonDataFile.java | 2 +- .../domain/ports/api/SurveyUnitApiPort.java | 28 +++---- .../ports/spi/SurveyUnitPersistencePort.java | 24 +++--- .../service/surveyunit/SurveyUnitService.java | 74 ++++++++--------- .../volumetry/VolumetryLogService.java | 4 +- .../adapter/SurveyUnitMongoAdapter.java | 78 +++++++++--------- .../SurveyUnitMongoDBRepository.java | 26 +++--- .../java/fr/insee/genesis/TestConstants.java | 3 + ....java => InterrogationControllerTest.java} | 16 ++-- .../rest/responses/ModeControllerTest.java | 8 +- .../QuestionnaireControllerTest.java | 14 ++-- .../responses/ResponseControllerTest.java | 46 +++++------ .../domain/service/SurveyUnitServiceTest.java | 38 ++++----- .../SurveyUnitModelMongoAdapterTest.java | 42 +++++----- .../stubs/SurveyUnitPersistencePortStub.java | 56 ++++++------- 21 files changed, 287 insertions(+), 287 deletions(-) rename src/main/java/fr/insee/genesis/controller/rest/responses/{IdUEController.java => InterrogationController.java} (66%) rename src/test/java/fr/insee/genesis/controller/rest/responses/{IdUEControllerTest.java => InterrogationControllerTest.java} (70%) diff --git a/src/main/java/fr/insee/genesis/controller/dto/SurveyUnitSimplified.java b/src/main/java/fr/insee/genesis/controller/dto/SurveyUnitSimplified.java index cdec5d58..06262775 100644 --- a/src/main/java/fr/insee/genesis/controller/dto/SurveyUnitSimplified.java +++ b/src/main/java/fr/insee/genesis/controller/dto/SurveyUnitSimplified.java @@ -12,9 +12,9 @@ @Data public class SurveyUnitSimplified { - private String idQuest; - private String idCampaign; - private String idUE; + private String questionnaireId; + private String campaignId; + private String interrogationId; private Mode mode; private List variablesUpdate; private List externalVariables; diff --git a/src/main/java/fr/insee/genesis/controller/rest/responses/CampaignController.java b/src/main/java/fr/insee/genesis/controller/rest/responses/CampaignController.java index 1e3135c4..549e02f7 100644 --- a/src/main/java/fr/insee/genesis/controller/rest/responses/CampaignController.java +++ b/src/main/java/fr/insee/genesis/controller/rest/responses/CampaignController.java @@ -27,7 +27,7 @@ public CampaignController(SurveyUnitApiPort surveyUnitService) { @Operation(summary = "List campaigns in database") @GetMapping(path = "/") public ResponseEntity> getCampaigns() { - Set campaigns = surveyUnitService.findDistinctIdCampaigns(); + Set campaigns = surveyUnitService.findDistinctCampaignIds(); return ResponseEntity.ok(campaigns); } diff --git a/src/main/java/fr/insee/genesis/controller/rest/responses/IdUEController.java b/src/main/java/fr/insee/genesis/controller/rest/responses/InterrogationController.java similarity index 66% rename from src/main/java/fr/insee/genesis/controller/rest/responses/IdUEController.java rename to src/main/java/fr/insee/genesis/controller/rest/responses/InterrogationController.java index b47df612..4bfc4960 100644 --- a/src/main/java/fr/insee/genesis/controller/rest/responses/IdUEController.java +++ b/src/main/java/fr/insee/genesis/controller/rest/responses/InterrogationController.java @@ -12,23 +12,23 @@ import java.util.List; -@RequestMapping(path = "/idUEs" ) +@RequestMapping(path = "/interrogations" ) @Controller @Slf4j -public class IdUEController { +public class InterrogationController { private final SurveyUnitApiPort surveyUnitService; - public IdUEController(SurveyUnitApiPort surveyUnitService) { + public InterrogationController(SurveyUnitApiPort surveyUnitService) { this.surveyUnitService = surveyUnitService; } - @Operation(summary = "Retrieve all IdUEs for a given questionnaire") + @Operation(summary = "Retrieve all interrogations for a given questionnaire") @GetMapping(path = "/by-questionnaire") - public ResponseEntity> getAllIdUEsByQuestionnaire(@RequestParam("idQuestionnaire") String idQuestionnaire) { - List responses = surveyUnitService.findDistinctIdUEsByIdQuestionnaire(idQuestionnaire); + public ResponseEntity> getAllInterrogationIdsByQuestionnaire(@RequestParam("questionnaireId") String questionnaireId) { + List responses = surveyUnitService.findDistinctInterrogationIdsByQuestionnaireId(questionnaireId); return ResponseEntity.ok(responses); } diff --git a/src/main/java/fr/insee/genesis/controller/rest/responses/ModeController.java b/src/main/java/fr/insee/genesis/controller/rest/responses/ModeController.java index 320af308..3fb31e7e 100644 --- a/src/main/java/fr/insee/genesis/controller/rest/responses/ModeController.java +++ b/src/main/java/fr/insee/genesis/controller/rest/responses/ModeController.java @@ -28,15 +28,15 @@ public ModeController(SurveyUnitApiPort surveyUnitService) { @Operation(summary = "List sources/modes used for a given questionnaire") @GetMapping(path = "/by-questionnaire") - public ResponseEntity> getModesByQuestionnaire(@RequestParam("idQuestionnaire") String idQuestionnaire) { - List modes = surveyUnitService.findModesByIdQuestionnaire(idQuestionnaire); + public ResponseEntity> getModesByQuestionnaire(@RequestParam("questionnaireId") String questionnaireId) { + List modes = surveyUnitService.findModesByQuestionnaireId(questionnaireId); return ResponseEntity.ok(modes); } @Operation(summary = "List sources/modes used for a given campaign") @GetMapping(path = "/by-campaign") - public ResponseEntity> getModesByCampaign(@RequestParam("idCampaign") String idCampaign) { - List modes = surveyUnitService.findModesByIdCampaign(idCampaign); + public ResponseEntity> getModesByCampaign(@RequestParam("campaignId") String campaignId) { + List modes = surveyUnitService.findModesByCampaignId(campaignId); return ResponseEntity.ok(modes); } diff --git a/src/main/java/fr/insee/genesis/controller/rest/responses/QuestionnaireController.java b/src/main/java/fr/insee/genesis/controller/rest/responses/QuestionnaireController.java index ad8303c4..82064575 100644 --- a/src/main/java/fr/insee/genesis/controller/rest/responses/QuestionnaireController.java +++ b/src/main/java/fr/insee/genesis/controller/rest/responses/QuestionnaireController.java @@ -30,7 +30,7 @@ public QuestionnaireController(SurveyUnitApiPort surveyUnitService) { @Operation(summary = "List questionnaires in database") @GetMapping(path = "/") public ResponseEntity> getQuestionnaires() { - Set questionnaires = surveyUnitService.findDistinctIdQuestionnaires(); + Set questionnaires = surveyUnitService.findDistinctQuestionnaireIds(); return ResponseEntity.ok(questionnaires); } @@ -45,8 +45,8 @@ public ResponseEntity> getQuestionnairesWithCamp @Operation(summary = "List questionnaires used for a given campaign") @GetMapping(path = "/by-campaign") - public ResponseEntity> getQuestionnairesByCampaign(@RequestParam("idCampaign") String idCampaign) { - Set questionnaires = surveyUnitService.findIdQuestionnairesByIdCampaign(idCampaign); + public ResponseEntity> getQuestionnairesByCampaign(@RequestParam("campaignId") String campaignId) { + Set questionnaires = surveyUnitService.findQuestionnaireIdsByCampaignId(campaignId); return ResponseEntity.ok(questionnaires); } diff --git a/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java b/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java index 9c5c7091..7a95bef7 100644 --- a/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java +++ b/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java @@ -58,7 +58,7 @@ @RequestMapping(path = "/responses" ) @Controller -@Tag(name = "Response services for interrogations", description = "A **response** is considered the entire set of data associated with an interrogation (idUE x idQuestionnaire). \n\n These data may have different state (collected, edited, external, ...) ") +@Tag(name = "Response services", description = "A **response** is considered the entire set of data associated with an interrogation (survey unit x questionnaireId). \n\n These data may have different state (collected, edited, external, ...) ") @Slf4j public class ResponseController { @@ -251,67 +251,67 @@ public ResponseEntity saveResponsesFromAllCampaignFolders(){ //DELETE @Operation(summary = "Delete all responses associated with a questionnaire") @DeleteMapping(path = "/delete/by-questionnaire") - public ResponseEntity deleteAllResponsesByQuestionnaire(@RequestParam("idQuestionnaire") String idQuestionnaire) { - log.info("Try to delete all responses of questionnaire : {}", idQuestionnaire); - Long ndDocuments = surveyUnitService.deleteByIdQuestionnaire(idQuestionnaire); + public ResponseEntity deleteAllResponsesByQuestionnaire(@RequestParam("questionnaireId") String questionnaireId) { + log.info("Try to delete all responses of questionnaire : {}", questionnaireId); + Long ndDocuments = surveyUnitService.deleteByQuestionnaireId(questionnaireId); log.info("{} responses deleted", ndDocuments); return ResponseEntity.ok(String.format("%d responses deleted", ndDocuments)); } //GET - @Operation(summary = "Retrieve responses for an interrogation, using IdUE and IdQuestionnaire from Genesis Database") + @Operation(summary = "Retrieve responses for an interrogation, using interrogationId and questionnaireId from Genesis Database") @GetMapping(path = "/by-ue-and-questionnaire") - public ResponseEntity> findResponsesByUEAndQuestionnaire(@RequestParam("idUE") String idUE, - @RequestParam("idQuestionnaire") String idQuestionnaire) { - List responses = surveyUnitService.findByIdsUEAndQuestionnaire(idUE, idQuestionnaire); + public ResponseEntity> findResponsesByInterrogationAndQuestionnaire(@RequestParam("interrogationId") String interrogationId, + @RequestParam("questionnaireId") String questionnaireId) { + List responses = surveyUnitService.findByIdsInterrogationAndQuestionnaire(interrogationId, questionnaireId); return ResponseEntity.ok(responses); } - @Operation(summary = "Retrieve responses for an interrogation, using IdUE and IdQuestionnaire from Genesis Database with the latest value for each available state of every variable") + @Operation(summary = "Retrieve responses for an interrogation, using interrogationId and questionnaireId from Genesis Database with the latest value for each available state of every variable") @GetMapping(path = "/by-ue-and-questionnaire/latest-states") - public ResponseEntity findResponsesByUEAndQuestionnaireLatestStates( - @RequestParam("idUE") String idUE, - @RequestParam("idQuestionnaire") String idQuestionnaire) { - SurveyUnitDto response = surveyUnitService.findLatestValuesByStateByIdAndByIdQuestionnaire(idUE, idQuestionnaire); + public ResponseEntity findResponsesByInterrogationAndQuestionnaireLatestStates( + @RequestParam("interrogationId") String interrogationId, + @RequestParam("questionnaireId") String questionnaireId) { + SurveyUnitDto response = surveyUnitService.findLatestValuesByStateByIdAndByQuestionnaireId(interrogationId, questionnaireId); return ResponseEntity.ok(response); } @Operation(summary = "Retrieve all responses (for all interrogations) of one questionnaire") @GetMapping(path = "/by-questionnaire") - public ResponseEntity findAllResponsesByQuestionnaire(@RequestParam("idQuestionnaire") String idQuestionnaire) { - log.info("Try to find all responses of questionnaire : {}", idQuestionnaire); + public ResponseEntity findAllResponsesByQuestionnaire(@RequestParam("questionnaireId") String questionnaireId) { + log.info("Try to find all responses of questionnaire : {}", questionnaireId); //Get all IdUEs/modes of the survey - List idUEsResponses = surveyUnitService.findIdUEsAndModesByIdQuestionnaire(idQuestionnaire); - log.info("Responses found : {}", idUEsResponses.size()); + List interrogationIdsResponses = surveyUnitService.findInterrogationIdsAndModesByQuestionnaireId(questionnaireId); + log.info("Responses found : {}", interrogationIdsResponses.size()); - String filepathString = String.format("OUT/%s/OUT_ALL_%s.json", idQuestionnaire, LocalDateTime.now().toString().replace(":", "")); + String filepathString = String.format("OUT/%s/OUT_ALL_%s.json", questionnaireId, LocalDateTime.now().toString().replace(":", "")); Path filepath = Path.of(fileUtils.getDataFolderSource(), filepathString); - try (Stream responsesStream = surveyUnitService.findByIdQuestionnaire(idQuestionnaire)) { + try (Stream responsesStream = surveyUnitService.findByQuestionnaireId(questionnaireId)) { fileUtils.writeSuUpdatesInFile(filepath, responsesStream); } catch (IOException e) { log.error("Error while writing file", e); return ResponseEntity.internalServerError().body(filepath); } - log.info("End of extraction, responses extracted: {}", idUEsResponses.size()); + log.info("End of extraction, responses extracted: {}", interrogationIdsResponses.size()); return ResponseEntity.ok(filepath); } - @Operation(summary = "Retrieve responses for an interrogation, using IdUE and IdQuestionnaire from Genesis Database. It returns only the latest value of each variable regardless of the state.") + @Operation(summary = "Retrieve responses for an interrogation, using interrogationId and questionnaireId from Genesis Database. It returns only the latest value of each variable regardless of the state.") @GetMapping(path = "/by-ue-and-questionnaire/latest") - public ResponseEntity> getLatestByUE(@RequestParam("idUE") String idUE, - @RequestParam("idQuestionnaire") String idQuestionnaire) { - List responses = surveyUnitService.findLatestByIdAndByIdQuestionnaire(idUE, idQuestionnaire); + public ResponseEntity> getLatestByInterrogation(@RequestParam("interrogationId") String interrogationId, + @RequestParam("questionnaireId") String questionnaireId) { + List responses = surveyUnitService.findLatestByIdAndByQuestionnaireId(interrogationId, questionnaireId); return ResponseEntity.ok(responses); } - @Operation(summary = "Retrieve responses for an interrogation, using IdUE and IdQuestionnaire from Genesis Database. For a given mode, it returns only the latest value of each variable regardless of the state. The result is one object by mode in the output") + @Operation(summary = "Retrieve responses for an interrogation, using interrogationId and questionnaireId from Genesis Database. For a given mode, it returns only the latest value of each variable regardless of the state. The result is one object by mode in the output") @GetMapping(path = "/simplified/by-ue-questionnaire-and-mode/latest") - public ResponseEntity getLatestByUEOneObject(@RequestParam("idUE") String idUE, - @RequestParam("idQuestionnaire") String idQuestionnaire, + public ResponseEntity getLatestByInterrogationOneObject(@RequestParam("interrogationId") String interrogationId, + @RequestParam("questionnaireId") String questionnaireId, @RequestParam("mode") Mode mode) { - List responses = surveyUnitService.findLatestByIdAndByIdQuestionnaire(idUE, idQuestionnaire); + List responses = surveyUnitService.findLatestByIdAndByQuestionnaireId(interrogationId, questionnaireId); List outputVariables = new ArrayList<>(); List outputExternalVariables = new ArrayList<>(); responses.stream().filter(rep -> rep.getMode().equals(mode)).forEach(response -> { @@ -319,9 +319,9 @@ public ResponseEntity getLatestByUEOneObject(@RequestParam outputExternalVariables.addAll(response.getExternalVariables()); }); return ResponseEntity.ok(SurveyUnitSimplified.builder() - .idQuest(responses.getFirst().getQuestionnaireId()) - .idCampaign(responses.getFirst().getCampaignId()) - .idUE(responses.getFirst().getInterrogationId()) + .questionnaireId(responses.getFirst().getQuestionnaireId()) + .campaignId(responses.getFirst().getCampaignId()) + .interrogationId(responses.getFirst().getInterrogationId()) .variablesUpdate(outputVariables) .externalVariables(outputExternalVariables) .build()); @@ -331,13 +331,13 @@ public ResponseEntity getLatestByUEOneObject(@RequestParam @Operation(summary = "Retrieve all responses for a questionnaire and a list of UE", description = "Return the latest state for each variable for the given ids and a given questionnaire.
" + "For a given id, the endpoint returns a document by collection mode (if there is more than one).") - @PostMapping(path = "/simplified/by-list-ue-and-questionnaire/latest") - public ResponseEntity> getLatestForUEList(@RequestParam("idQuestionnaire") String idQuestionnaire, - @RequestBody List idUEs) { + @PostMapping(path = "/simplified/by-list-interrogation-and-questionnaire/latest") + public ResponseEntity> getLatestForInterrogationList(@RequestParam("questionnaireId") String questionnaireId, + @RequestBody List interrogationIds) { List results = new ArrayList<>(); - List modes = surveyUnitService.findModesByIdQuestionnaire(idQuestionnaire); - idUEs.forEach(idUE -> { - List responses = surveyUnitService.findLatestByIdAndByIdQuestionnaire(idUE.getIdUE(), idQuestionnaire); + List modes = surveyUnitService.findModesByQuestionnaireId(questionnaireId); + interrogationIds.forEach(interrogationId -> { + List responses = surveyUnitService.findLatestByIdAndByQuestionnaireId(interrogationId.getIdUE(), questionnaireId); modes.forEach(mode -> { List outputVariables = new ArrayList<>(); List outputExternalVariables = new ArrayList<>(); @@ -347,9 +347,9 @@ public ResponseEntity> getLatestForUEList(@RequestPar }); if (!outputVariables.isEmpty() || !outputExternalVariables.isEmpty()) { results.add(SurveyUnitSimplified.builder() - .idQuest(responses.getFirst().getQuestionnaireId()) - .idCampaign(responses.getFirst().getCampaignId()) - .idUE(responses.getFirst().getInterrogationId()) + .questionnaireId(responses.getFirst().getQuestionnaireId()) + .campaignId(responses.getFirst().getCampaignId()) + .interrogationId(responses.getFirst().getInterrogationId()) .mode(mode) .variablesUpdate(outputVariables) .externalVariables(outputExternalVariables) @@ -554,6 +554,7 @@ private ResponseEntity processRawXmlFile(Path filepath, Mode modeSpecifi lunaticXmlRawDataApiPort.saveData(campaign, modeSpecified); log.debug(SUCCESS_MESSAGE); + log.info("File {} processed" , filepath.getFileName()); return ResponseEntity.ok().build(); } diff --git a/src/main/java/fr/insee/genesis/controller/sources/json/LunaticJsonDataFile.java b/src/main/java/fr/insee/genesis/controller/sources/json/LunaticJsonDataFile.java index 9ffc07c8..7ca26137 100644 --- a/src/main/java/fr/insee/genesis/controller/sources/json/LunaticJsonDataFile.java +++ b/src/main/java/fr/insee/genesis/controller/sources/json/LunaticJsonDataFile.java @@ -9,7 +9,7 @@ public class LunaticJsonDataFile { @JsonProperty("Id") - String idQuest; + String questionnaireId; @JsonProperty("Label") String labelQuest; diff --git a/src/main/java/fr/insee/genesis/domain/ports/api/SurveyUnitApiPort.java b/src/main/java/fr/insee/genesis/domain/ports/api/SurveyUnitApiPort.java index 29a5def5..e2f1d701 100644 --- a/src/main/java/fr/insee/genesis/domain/ports/api/SurveyUnitApiPort.java +++ b/src/main/java/fr/insee/genesis/domain/ports/api/SurveyUnitApiPort.java @@ -16,34 +16,34 @@ public interface SurveyUnitApiPort { void saveSurveyUnits(List suList); - List findByIdsUEAndQuestionnaire(String idUE, String idQuest); + List findByIdsInterrogationAndQuestionnaire(String interrogationId, String questionnaireId); - List findByIdUE(String idUE); + List findByInterrogationId(String interrogationId); - Stream findByIdQuestionnaire(String idQuestionnaire); + Stream findByQuestionnaireId(String questionnaireId); - List findLatestByIdAndByIdQuestionnaire(String idUE, String idQuest); - SurveyUnitDto findLatestValuesByStateByIdAndByIdQuestionnaire(String idUE, String idQuest); + List findLatestByIdAndByQuestionnaireId(String interrogationId, String questionnaireId); + SurveyUnitDto findLatestValuesByStateByIdAndByQuestionnaireId(String interrogationId, String questionnaireId); - List findIdUEsAndModesByIdQuestionnaire(String idQuestionnaire); + List findInterrogationIdsAndModesByQuestionnaireId(String questionnaireId); - List findDistinctIdUEsByIdQuestionnaire(String idQuestionnaire); + List findDistinctInterrogationIdsByQuestionnaireId(String questionnaireId); - List findModesByIdQuestionnaire(String idQuestionnaire); + List findModesByQuestionnaireId(String questionnaireId); - List findModesByIdCampaign(String idCampaign); + List findModesByCampaignId(String campaignId); - Long deleteByIdQuestionnaire(String idQuestionnaire); + Long deleteByQuestionnaireId(String questionnaireId); long countResponses(); - Set findIdQuestionnairesByIdCampaign(String idCampaign); + Set findQuestionnaireIdsByCampaignId(String campaignId); - Set findDistinctIdCampaigns(); + Set findDistinctCampaignIds(); - long countResponsesByIdCampaign(String idCampaign); + long countResponsesByCampaignId(String campaignId); - Set findDistinctIdQuestionnaires(); + Set findDistinctQuestionnaireIds(); List findCampaignsWithQuestionnaires(); diff --git a/src/main/java/fr/insee/genesis/domain/ports/spi/SurveyUnitPersistencePort.java b/src/main/java/fr/insee/genesis/domain/ports/spi/SurveyUnitPersistencePort.java index af4aa319..093a1867 100644 --- a/src/main/java/fr/insee/genesis/domain/ports/spi/SurveyUnitPersistencePort.java +++ b/src/main/java/fr/insee/genesis/domain/ports/spi/SurveyUnitPersistencePort.java @@ -10,29 +10,29 @@ public interface SurveyUnitPersistencePort { void saveAll(List suList); - List findByIds(String idUE, String idQuest); + List findByIds(String interrogationId, String questionnaireId); - List findByIdUE(String idUE); + List findByInterrogationId(String interrogationId); - List findByIdUEsAndIdQuestionnaire(List idUEs, String idQuestionnaire); + List findByInterrogationIdsAndQuestionnaireId(List interrogationIds, String questionnaireId); - Stream findByIdQuestionnaire(String idQuestionnaire); + Stream findByQuestionnaireId(String questionnaireId); - List findIdUEsByIdQuestionnaire(String idQuestionnaire); + List findInterrogationIdsByQuestionnaireId(String questionnaireId); - List findIdUEsByIdCampaign(String idCampaign); + List findInterrogationIdsByCampaignId(String campaignId); - Long deleteByIdQuestionnaire(String idQuestionnaire); + Long deleteByQuestionnaireId(String questionnaireId); long count(); - Set findIdQuestionnairesByIdCampaign(String idCampaign); + Set findQuestionnaireIdsByCampaignId(String campaignId); - Set findDistinctIdCampaigns(); + Set findDistinctCampaignIds(); - long countByIdCampaign(String idCampaign); + long countByCampaignId(String campaignId); - Set findDistinctIdQuestionnaires(); + Set findDistinctQuestionnaireIds(); - Set findIdCampaignsByIdQuestionnaire(String idQuestionnaire); + Set findCampaignIdsByQuestionnaireId(String questionnaireId); } diff --git a/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java b/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java index 937b8a89..ff6d8dc3 100644 --- a/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java +++ b/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java @@ -29,32 +29,32 @@ public void saveSurveyUnits(List suDtos) { } @Override - public List findByIdsUEAndQuestionnaire(String idUE, String idQuest) { - return surveyUnitPersistencePort.findByIds(idUE, idQuest); + public List findByIdsInterrogationAndQuestionnaire(String interrogationId, String questionnaireId) { + return surveyUnitPersistencePort.findByIds(interrogationId, questionnaireId); } @Override - public List findByIdUE(String idUE) { - return surveyUnitPersistencePort.findByIdUE(idUE); + public List findByInterrogationId(String interrogationId) { + return surveyUnitPersistencePort.findByInterrogationId(interrogationId); } @Override - public Stream findByIdQuestionnaire(String idQuestionnaire) { - return surveyUnitPersistencePort.findByIdQuestionnaire(idQuestionnaire); + public Stream findByQuestionnaireId(String questionnaireId) { + return surveyUnitPersistencePort.findByQuestionnaireId(questionnaireId); } /** * In this method we want to get the latest update for each variable of a survey unit * But we need to separate the updates by mode * So we will calculate the latest state for a given collection mode - * @param idUE : Survey unit id - * @param idQuest : Questionnaire id + * @param interrogationId : Survey unit id + * @param questionnaireId : Questionnaire id * @return the latest update for each variable of a survey unit */ @Override - public List findLatestByIdAndByIdQuestionnaire(String idUE, String idQuest) { + public List findLatestByIdAndByQuestionnaireId(String interrogationId, String questionnaireId) { List latestUpdatesbyVariables = new ArrayList<>(); - List surveyUnitModels = surveyUnitPersistencePort.findByIds(idUE, idQuest); + List surveyUnitModels = surveyUnitPersistencePort.findByIds(interrogationId, questionnaireId); List modes = getDistinctsModes(surveyUnitModels); modes.forEach(mode ->{ List suByMode = surveyUnitModels.stream() @@ -108,9 +108,9 @@ public List findLatestByIdAndByIdQuestionnaire(String idUE, Str } @Override - public SurveyUnitDto findLatestValuesByStateByIdAndByIdQuestionnaire(String idUE, String idQuest) { + public SurveyUnitDto findLatestValuesByStateByIdAndByQuestionnaireId(String interrogationId, String questionnaireId) { SurveyUnitDto surveyUnitDto = SurveyUnitDto.builder() - .surveyUnitId(idUE) + .surveyUnitId(interrogationId) .collectedVariables(new ArrayList<>()) .externalVariables(new ArrayList<>()) .build(); @@ -118,7 +118,7 @@ public SurveyUnitDto findLatestValuesByStateByIdAndByIdQuestionnaire(String idUE //Extract variables Map collectedVariableMap = new HashMap<>(); Map externalVariableMap = new HashMap<>(); - List surveyUnitModels = surveyUnitPersistencePort.findByIds(idUE, idQuest); + List surveyUnitModels = surveyUnitPersistencePort.findByIds(interrogationId, questionnaireId); List modes = getDistinctsModes(surveyUnitModels); modes.forEach(mode -> { List suByMode = surveyUnitModels.stream() @@ -133,38 +133,38 @@ public SurveyUnitDto findLatestValuesByStateByIdAndByIdQuestionnaire(String idUE } @Override - public List findDistinctIdUEsByIdQuestionnaire(String idQuestionnaire) { - List surveyUnitModels = surveyUnitPersistencePort.findIdUEsByIdQuestionnaire(idQuestionnaire); + public List findDistinctInterrogationIdsByQuestionnaireId(String questionnaireId) { + List surveyUnitModels = surveyUnitPersistencePort.findInterrogationIdsByQuestionnaireId(questionnaireId); List suIds = new ArrayList<>(); surveyUnitModels.forEach(surveyUnitDto -> suIds.add(new SurveyUnitId(surveyUnitDto.getInterrogationId()))); return suIds.stream().distinct().toList(); } @Override - public List findIdUEsAndModesByIdQuestionnaire(String idQuestionnaire) { - List surveyUnitModels = surveyUnitPersistencePort.findIdUEsByIdQuestionnaire(idQuestionnaire); + public List findInterrogationIdsAndModesByQuestionnaireId(String questionnaireId) { + List surveyUnitModels = surveyUnitPersistencePort.findInterrogationIdsByQuestionnaireId(questionnaireId); return surveyUnitModels.stream().distinct().toList(); } @Override - public List findModesByIdQuestionnaire(String idQuestionnaire) { - List surveyUnitModels = surveyUnitPersistencePort.findIdUEsByIdQuestionnaire(idQuestionnaire); + public List findModesByQuestionnaireId(String questionnaireId) { + List surveyUnitModels = surveyUnitPersistencePort.findInterrogationIdsByQuestionnaireId(questionnaireId); List sources = new ArrayList<>(); surveyUnitModels.forEach(surveyUnitDto -> sources.add(surveyUnitDto.getMode())); return sources.stream().distinct().toList(); } @Override - public List findModesByIdCampaign(String idCampaign) { - List surveyUnitModels = surveyUnitPersistencePort.findIdUEsByIdCampaign(idCampaign); + public List findModesByCampaignId(String campaignId) { + List surveyUnitModels = surveyUnitPersistencePort.findInterrogationIdsByCampaignId(campaignId); List sources = new ArrayList<>(); surveyUnitModels.forEach(surveyUnitDto -> sources.add(surveyUnitDto.getMode())); return sources.stream().distinct().toList(); } @Override - public Long deleteByIdQuestionnaire(String idQuestionnaire) { - return surveyUnitPersistencePort.deleteByIdQuestionnaire(idQuestionnaire); + public Long deleteByQuestionnaireId(String questionnaireId) { + return surveyUnitPersistencePort.deleteByQuestionnaireId(questionnaireId); } @Override @@ -173,42 +173,42 @@ public long countResponses() { } @Override - public Set findIdQuestionnairesByIdCampaign(String idCampaign) { - return surveyUnitPersistencePort.findIdQuestionnairesByIdCampaign(idCampaign); + public Set findQuestionnaireIdsByCampaignId(String campaignId) { + return surveyUnitPersistencePort.findQuestionnaireIdsByCampaignId(campaignId); } @Override - public Set findDistinctIdCampaigns() { - return surveyUnitPersistencePort.findDistinctIdCampaigns(); + public Set findDistinctCampaignIds() { + return surveyUnitPersistencePort.findDistinctCampaignIds(); } @Override public List findCampaignsWithQuestionnaires() { List campaignsWithQuestionnaireList = new ArrayList<>(); - for(String idCampaign : findDistinctIdCampaigns()){ - Set questionnaires = findIdQuestionnairesByIdCampaign(idCampaign); - campaignsWithQuestionnaireList.add(new CampaignWithQuestionnaire(idCampaign,questionnaires)); + for(String campaignId : findDistinctCampaignIds()){ + Set questionnaires = findQuestionnaireIdsByCampaignId(campaignId); + campaignsWithQuestionnaireList.add(new CampaignWithQuestionnaire(campaignId,questionnaires)); } return campaignsWithQuestionnaireList; } @Override - public long countResponsesByIdCampaign(String idCampaign){ - return surveyUnitPersistencePort.countByIdCampaign(idCampaign); + public long countResponsesByCampaignId(String campaignId){ + return surveyUnitPersistencePort.countByCampaignId(campaignId); } @Override - public Set findDistinctIdQuestionnaires() { - return surveyUnitPersistencePort.findDistinctIdQuestionnaires(); + public Set findDistinctQuestionnaireIds() { + return surveyUnitPersistencePort.findDistinctQuestionnaireIds(); } @Override public List findQuestionnairesWithCampaigns() { List questionnaireWithCampaignList = new ArrayList<>(); - for(String idQuestionnaire : findDistinctIdQuestionnaires()){ - Set campaigns = surveyUnitPersistencePort.findIdCampaignsByIdQuestionnaire(idQuestionnaire); + for(String questionnaireId : findDistinctQuestionnaireIds()){ + Set campaigns = surveyUnitPersistencePort.findCampaignIdsByQuestionnaireId(questionnaireId); questionnaireWithCampaignList.add(new QuestionnaireWithCampaign( - idQuestionnaire, + questionnaireId, campaigns) ); diff --git a/src/main/java/fr/insee/genesis/domain/service/volumetry/VolumetryLogService.java b/src/main/java/fr/insee/genesis/domain/service/volumetry/VolumetryLogService.java index a4600ca0..e324e61b 100644 --- a/src/main/java/fr/insee/genesis/domain/service/volumetry/VolumetryLogService.java +++ b/src/main/java/fr/insee/genesis/domain/service/volumetry/VolumetryLogService.java @@ -39,9 +39,9 @@ public void writeVolumetries(SurveyUnitApiPort surveyUnitApiPort) throws IOExcep Files.writeString(logFilePath, "campaign;volumetry\n"); //Write lines - Set campaigns = surveyUnitApiPort.findDistinctIdCampaigns(); + Set campaigns = surveyUnitApiPort.findDistinctCampaignIds(); for (String campaignId : campaigns) { - long countResult = surveyUnitApiPort.countResponsesByIdCampaign(campaignId); + long countResult = surveyUnitApiPort.countResponsesByCampaignId(campaignId); String line = campaignId + ";" + countResult + "\n"; diff --git a/src/main/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitMongoAdapter.java b/src/main/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitMongoAdapter.java index be5daced..57c5ab1a 100644 --- a/src/main/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitMongoAdapter.java +++ b/src/main/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitMongoAdapter.java @@ -43,23 +43,23 @@ public void saveAll(List suListDto) { } @Override - public List findByIds(String idUE, String idQuest) { - List surveyUnits = mongoRepository.findByIdUEAndIdQuestionnaire(idUE, idQuest); + public List findByIds(String interrogationId, String questionnaireId) { + List surveyUnits = mongoRepository.findByInterrogationIdAndQuestionnaireId(interrogationId, questionnaireId); return surveyUnits.isEmpty() ? Collections.emptyList() : SurveyUnitDocumentMapper.INSTANCE.listDocumentToListModel(surveyUnits); } @Override - public List findByIdUE(String idUE) { - List surveyUnits = mongoRepository.findByIdUE(idUE); + public List findByInterrogationId(String questionnaireId) { + List surveyUnits = mongoRepository.findByInterrogationId(questionnaireId); return surveyUnits.isEmpty() ? Collections.emptyList() : SurveyUnitDocumentMapper.INSTANCE.listDocumentToListModel(surveyUnits); } @Override - public List findByIdUEsAndIdQuestionnaire(List idUEs, String idQuestionnaire) { + public List findByInterrogationIdsAndQuestionnaireId(List questionnaireIds, String questionnaireId) { List surveyUnits= new ArrayList<>(); // TODO: 18-10-2023 : find a way to do this in one query - idUEs.forEach(su -> { - List docs = mongoRepository.findByIdUEAndIdQuestionnaire(su.getInterrogationId(), idQuestionnaire); + questionnaireIds.forEach(su -> { + List docs = mongoRepository.findByInterrogationIdAndQuestionnaireId(su.getInterrogationId(), questionnaireId); surveyUnits.addAll(docs); }); return surveyUnits.isEmpty() ? Collections.emptyList() : SurveyUnitDocumentMapper.INSTANCE.listDocumentToListModel(surveyUnits); @@ -67,14 +67,14 @@ public List findByIdUEsAndIdQuestionnaire(List @Override - public Stream findByIdQuestionnaire(String idQuestionnaire) { - Stream surveyUnits = mongoRepository.findByIdQuestionnaire(idQuestionnaire); + public Stream findByQuestionnaireId(String questionnaireId) { + Stream surveyUnits = mongoRepository.findByQuestionnaireId(questionnaireId); return surveyUnits.map(SurveyUnitDocumentMapper.INSTANCE::documentToModel); } @Override - public Long deleteByIdQuestionnaire(String idQuestionnaire) { - return mongoRepository.deleteByIdQuestionnaire(idQuestionnaire); + public Long deleteByQuestionnaireId(String questionnaireId) { + return mongoRepository.deleteByQuestionnaireId(questionnaireId); } @Override @@ -83,80 +83,80 @@ public long count() { } @Override - public Set findIdQuestionnairesByIdCampaign(String idCampaign){ + public Set findQuestionnaireIdsByCampaignId(String campaignId){ Set mongoResponse = - mongoRepository.findIdQuestionnairesByIdCampaign(idCampaign); + mongoRepository.findQuestionnaireIdsByCampaignId(campaignId); - //Extract idQuestionnaires from JSON response - Set idQuestionnaires = new HashSet<>(); + //Extract questionnaireIds from JSON response + Set questionnaireIds = new HashSet<>(); for(String line : mongoResponse){ ObjectMapper objectMapper = new ObjectMapper(); try{ JsonNode jsonNode = objectMapper.readTree(line); - idQuestionnaires.add(jsonNode.get("idQuestionnaire").asText()); + questionnaireIds.add(jsonNode.get("questionnaireId").asText()); }catch (JsonProcessingException e){ log.error(e.getMessage()); } } - return idQuestionnaires; + return questionnaireIds; } @Override - public Set findDistinctIdCampaigns() { - Set idCampaigns = new HashSet<>(); - for(String idCampaign : mongoTemplate.getCollection(Constants.MONGODB_RESPONSE_COLLECTION_NAME).distinct("idCampaign", + public Set findDistinctCampaignIds() { + Set campaignIds = new HashSet<>(); + for(String campaignId : mongoTemplate.getCollection(Constants.MONGODB_RESPONSE_COLLECTION_NAME).distinct("campaignId", String.class)){ - idCampaigns.add(idCampaign); + campaignIds.add(campaignId); } - return idCampaigns; + return campaignIds; } @Override - public List findIdUEsByIdQuestionnaire(String idQuestionnaire) { - List surveyUnits = mongoRepository.findIdUEsByIdQuestionnaire(idQuestionnaire); + public List findInterrogationIdsByQuestionnaireId(String questionnaireId) { + List surveyUnits = mongoRepository.findInterrogationIdsByQuestionnaireId(questionnaireId); return surveyUnits.isEmpty() ? Collections.emptyList() : SurveyUnitDocumentMapper.INSTANCE.listDocumentToListModel(surveyUnits); } @Override - public List findIdUEsByIdCampaign(String idCampaign) { - List surveyUnits = mongoRepository.findIdUEsByIdCampaign(idCampaign); + public List findInterrogationIdsByCampaignId(String campaignId) { + List surveyUnits = mongoRepository.findInterrogationIdsByCampaignId(campaignId); return surveyUnits.isEmpty() ? Collections.emptyList() : SurveyUnitDocumentMapper.INSTANCE.listDocumentToListModel(surveyUnits); } - public long countByIdCampaign(String idCampaign){ - return mongoRepository.countByIdCampaign(idCampaign); + public long countByCampaignId(String campaignId){ + return mongoRepository.countByCampaignId(campaignId); } @Override - public Set findDistinctIdQuestionnaires() { - Set idQuestionnaires = new HashSet<>(); - for(String idQuestionnaire : mongoTemplate.getCollection(Constants.MONGODB_RESPONSE_COLLECTION_NAME).distinct( - "idQuestionnaire", + public Set findDistinctQuestionnaireIds() { + Set questionnaireIds = new HashSet<>(); + for(String questionnaireId : mongoTemplate.getCollection(Constants.MONGODB_RESPONSE_COLLECTION_NAME).distinct( + "questionnaireId", String.class)){ - idQuestionnaires.add(idQuestionnaire); + questionnaireIds.add(questionnaireId); } - return idQuestionnaires; + return questionnaireIds; } @Override - public Set findIdCampaignsByIdQuestionnaire(String idQuestionnaire) { + public Set findCampaignIdsByQuestionnaireId(String questionnaireId) { List mongoResponse = - mongoRepository.findIdCampaignsByIdQuestionnaire(idQuestionnaire).stream().distinct().toList(); + mongoRepository.findCampaignIdsByQuestionnaireId(questionnaireId).stream().distinct().toList(); //Extract idCampagigns from JSON response - Set idCampaigns = new HashSet<>(); + Set campaignIds = new HashSet<>(); for(String line : mongoResponse){ ObjectMapper objectMapper = new ObjectMapper(); try{ JsonNode jsonNode = objectMapper.readTree(line); - idCampaigns.add(jsonNode.get("idCampaign").asText()); + campaignIds.add(jsonNode.get("campaignId").asText()); }catch (JsonProcessingException e){ log.error(e.getMessage()); } } - return idCampaigns; + return campaignIds; } } diff --git a/src/main/java/fr/insee/genesis/infrastructure/repository/SurveyUnitMongoDBRepository.java b/src/main/java/fr/insee/genesis/infrastructure/repository/SurveyUnitMongoDBRepository.java index 18c2152b..88624365 100644 --- a/src/main/java/fr/insee/genesis/infrastructure/repository/SurveyUnitMongoDBRepository.java +++ b/src/main/java/fr/insee/genesis/infrastructure/repository/SurveyUnitMongoDBRepository.java @@ -13,28 +13,28 @@ @Repository public interface SurveyUnitMongoDBRepository extends MongoRepository { - List findByIdUE(String idUE); + List findByInterrogationId(String interrogationId); - List findByIdUEAndIdQuestionnaire(String idUE, String idQuestionnaire); + List findByInterrogationIdAndQuestionnaireId(String interrogationId, String questionnaireId); - @Query(value = "{ 'idQuestionnaire' : ?0 }", fields = "{ 'idUE' : 1, 'mode' : 1 }") - List findIdUEsByIdQuestionnaire(String idQuestionnaire); + @Query(value = "{ 'questionnaireId' : ?0 }", fields = "{ 'interrogationId' : 1, 'mode' : 1 }") + List findInterrogationIdsByQuestionnaireId(String questionnaireId); - @Query(value = "{ 'idCampaign' : ?0 }", fields = "{ 'idUE' : 1, 'mode' : 1 }") - List findIdUEsByIdCampaign(String idCampaign); + @Query(value = "{ 'campaignId' : ?0 }", fields = "{ 'interrogationId' : 1, 'mode' : 1 }") + List findInterrogationIdsByCampaignId(String campaignId); - Long deleteByIdQuestionnaire(String idQuestionnaire); + Long deleteByQuestionnaireId(String questionnaireId); @Meta(cursorBatchSize = 20) - Stream findByIdQuestionnaire(String idQuestionnaire); + Stream findByQuestionnaireId(String questionnaireId); long count(); - @Query(value = "{ 'idCampaign' : ?0 }", fields = "{ _id : 0, 'idQuestionnaire' : 1 }") - Set findIdQuestionnairesByIdCampaign(String idCampaign); + @Query(value = "{ 'campaignId' : ?0 }", fields = "{ _id : 0, 'questionnaireId' : 1 }") + Set findQuestionnaireIdsByCampaignId(String campaignId); - long countByIdCampaign(String idCampaign); + long countByCampaignId(String campaignId); - @Query(value = "{ 'idQuestionnaire' : ?0 }", fields = "{ _id : 0, 'idCampaign' : 1 }") - Set findIdCampaignsByIdQuestionnaire(String idQuestionnaire); + @Query(value = "{ 'questionnaireId' : ?0 }", fields = "{ _id : 0, 'campaignId' : 1 }") + Set findCampaignIdsByQuestionnaireId(String questionnaireId); } \ No newline at end of file diff --git a/src/test/java/fr/insee/genesis/TestConstants.java b/src/test/java/fr/insee/genesis/TestConstants.java index f0d78aee..88892875 100644 --- a/src/test/java/fr/insee/genesis/TestConstants.java +++ b/src/test/java/fr/insee/genesis/TestConstants.java @@ -7,4 +7,7 @@ public class TestConstants { public static final String TEST_RESOURCES_DIRECTORY = "src/test/resources"; public static final String UNIT_TESTS_DDI_DIRECTORY = TEST_RESOURCES_DIRECTORY + "/specs"; + + public static final String DEFAULT_INTERROGATION_ID = "TESTIDUE"; + public static final String DEFAULT_QUESTIONNAIRE_ID = "TESTIDQUESTIONNAIRE"; } diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/IdUEControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/InterrogationControllerTest.java similarity index 70% rename from src/test/java/fr/insee/genesis/controller/rest/responses/IdUEControllerTest.java rename to src/test/java/fr/insee/genesis/controller/rest/responses/InterrogationControllerTest.java index c750f9d1..315c21d0 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/IdUEControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/InterrogationControllerTest.java @@ -13,20 +13,20 @@ import java.io.IOException; import java.util.List; -class IdUEControllerTest { +import static fr.insee.genesis.TestConstants.DEFAULT_INTERROGATION_ID; +import static fr.insee.genesis.TestConstants.DEFAULT_QUESTIONNAIRE_ID; + +class InterrogationControllerTest { //Given - static IdUEController idUeControllerStatic; + static InterrogationController interrogationControllerStatic; static SurveyUnitPersistencePortStub surveyUnitPersistencePortStub; - //Constants - static final String defaultIdUE = "TESTIDUE"; - static final String defaultIdQuest = "TESTIDQUESTIONNAIRE"; @BeforeAll static void init() { surveyUnitPersistencePortStub = new SurveyUnitPersistencePortStub(); SurveyUnitApiPort surveyUnitApiPort = new SurveyUnitService(surveyUnitPersistencePortStub); - idUeControllerStatic = new IdUEController( surveyUnitApiPort ); + interrogationControllerStatic = new InterrogationController( surveyUnitApiPort ); } @@ -39,11 +39,11 @@ void reset() throws IOException { //When + Then @Test void getAllIdUEsByQuestionnaireTest() { - ResponseEntity> response = idUeControllerStatic.getAllIdUEsByQuestionnaire(defaultIdQuest); + ResponseEntity> response = interrogationControllerStatic.getAllInterrogationIdsByQuestionnaire(DEFAULT_QUESTIONNAIRE_ID); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty(); - Assertions.assertThat(response.getBody().getFirst().getIdUE()).isEqualTo(defaultIdUE); + Assertions.assertThat(response.getBody().getFirst().getIdUE()).isEqualTo(DEFAULT_INTERROGATION_ID); } diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/ModeControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/ModeControllerTest.java index 06376ccd..914e91c7 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/ModeControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/ModeControllerTest.java @@ -13,15 +13,13 @@ import java.io.IOException; import java.util.List; +import static fr.insee.genesis.TestConstants.DEFAULT_QUESTIONNAIRE_ID; + class ModeControllerTest { //Given static ModeController modeControllerStatic; static SurveyUnitPersistencePortStub surveyUnitPersistencePortStub; - //Constants - static final String defaultIdUE = "TESTIDUE"; - static final String defaultIdQuest = "TESTIDQUESTIONNAIRE"; - @BeforeAll static void init() { surveyUnitPersistencePortStub = new SurveyUnitPersistencePortStub(); @@ -40,7 +38,7 @@ void reset() throws IOException { //When + Then @Test void getModesByQuestionnaireTest() { - ResponseEntity> response = modeControllerStatic.getModesByQuestionnaire(defaultIdQuest); + ResponseEntity> response = modeControllerStatic.getModesByQuestionnaire(DEFAULT_QUESTIONNAIRE_ID); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty().hasSize(1); diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/QuestionnaireControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/QuestionnaireControllerTest.java index 17caeb3b..fb89a31f 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/QuestionnaireControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/QuestionnaireControllerTest.java @@ -14,15 +14,13 @@ import java.util.List; import java.util.Set; +import static fr.insee.genesis.TestConstants.DEFAULT_QUESTIONNAIRE_ID; + class QuestionnaireControllerTest { //Given static QuestionnaireController questionnaireControllerStatic; static SurveyUnitPersistencePortStub surveyUnitPersistencePortStub; - //Constants - static final String defaultIdUE = "TESTIDUE"; - static final String defaultIdQuest = "TESTIDQUESTIONNAIRE"; - @BeforeAll static void init() { surveyUnitPersistencePortStub = new SurveyUnitPersistencePortStub(); @@ -48,7 +46,7 @@ void getQuestionnairesTest() { Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty().containsExactly( - defaultIdQuest,"TESTQUESTIONNAIRE2"); + DEFAULT_QUESTIONNAIRE_ID,"TESTQUESTIONNAIRE2"); } @Test @@ -59,7 +57,7 @@ void getQuestionnairesByCampaignTest() { Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty().containsExactly( - defaultIdQuest,"TESTQUESTIONNAIRE2"); + DEFAULT_QUESTIONNAIRE_ID,"TESTQUESTIONNAIRE2"); } @@ -75,12 +73,12 @@ void getQuestionnairesWithCampaignsTest() { Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty(); Assertions.assertThat(response.getBody().stream().filter(questionnaireWithCampaign -> - questionnaireWithCampaign.getIdQuestionnaire().equals(defaultIdQuest) + questionnaireWithCampaign.getIdQuestionnaire().equals(DEFAULT_QUESTIONNAIRE_ID) || questionnaireWithCampaign.getIdQuestionnaire().equals("TESTQUESTIONNAIRE2") )).isNotNull().isNotEmpty().hasSize(2); Assertions.assertThat(response.getBody().stream().filter( - questionnaireWithCampaign -> questionnaireWithCampaign.getIdQuestionnaire().equals(defaultIdQuest) + questionnaireWithCampaign -> questionnaireWithCampaign.getIdQuestionnaire().equals(DEFAULT_QUESTIONNAIRE_ID) ).findFirst().get().getCampaigns()).containsExactly("TESTIDCAMPAIGN"); Assertions.assertThat(response.getBody().stream().filter( diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java index 918e06a1..ff0c05ec 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java @@ -37,6 +37,9 @@ import java.util.ArrayList; import java.util.List; +import static fr.insee.genesis.TestConstants.DEFAULT_INTERROGATION_ID; +import static fr.insee.genesis.TestConstants.DEFAULT_QUESTIONNAIRE_ID; + class ResponseControllerTest { //Given static ResponseController responseControllerStatic; @@ -45,9 +48,6 @@ class ResponseControllerTest { static LunaticJsonPersistanceStub lunaticJsonPersistanceStub; static List surveyUnitIdList; - //Constants - static final String DEFAULT_ID_UE = "TESTIDUE"; - static final String DEFAULT_ID_QUEST = "TESTIDQUESTIONNAIRE"; @BeforeAll static void init() { @@ -71,7 +71,7 @@ static void init() { ); surveyUnitIdList = new ArrayList<>(); - surveyUnitIdList.add(new SurveyUnitId(DEFAULT_ID_UE)); + surveyUnitIdList.add(new SurveyUnitId(DEFAULT_INTERROGATION_ID)); } @BeforeEach @@ -198,21 +198,21 @@ void saveResponsesFromAllCampaignFoldersTests(){ //Gets @Test void findResponsesByUEAndQuestionnaireTest() { - ResponseEntity> response = responseControllerStatic.findResponsesByUEAndQuestionnaire(DEFAULT_ID_UE, DEFAULT_ID_QUEST); + ResponseEntity> response = responseControllerStatic.findResponsesByInterrogationAndQuestionnaire(DEFAULT_INTERROGATION_ID, DEFAULT_QUESTIONNAIRE_ID); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty(); - Assertions.assertThat(response.getBody().getFirst().getInterrogationId()).isEqualTo(DEFAULT_ID_UE); - Assertions.assertThat(response.getBody().getFirst().getQuestionnaireId()).isEqualTo(DEFAULT_ID_QUEST); + Assertions.assertThat(response.getBody().getFirst().getInterrogationId()).isEqualTo(DEFAULT_INTERROGATION_ID); + Assertions.assertThat(response.getBody().getFirst().getQuestionnaireId()).isEqualTo(DEFAULT_QUESTIONNAIRE_ID); } @Test void findAllResponsesByQuestionnaireTest() { - Path path = Path.of(TestConstants.TEST_RESOURCES_DIRECTORY, "OUT", DEFAULT_ID_QUEST); + Path path = Path.of(TestConstants.TEST_RESOURCES_DIRECTORY, "OUT", DEFAULT_QUESTIONNAIRE_ID); File dir = new File(String.valueOf(path)); FileSystemUtils.deleteRecursively(dir); - ResponseEntity response = responseControllerStatic.findAllResponsesByQuestionnaire(DEFAULT_ID_QUEST); + ResponseEntity response = responseControllerStatic.findAllResponsesByQuestionnaire(DEFAULT_QUESTIONNAIRE_ID); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull(); @@ -230,14 +230,14 @@ void getAllResponsesByQuestionnaireTestSequential() throws IOException { surveyUnitPersistencePortStub.getMongoStub().clear(); for (int i = 0; i < Constants.BATCH_SIZE + 2; i++) { - Utils.addAdditionalDtoToMongoStub("TESTIDCAMPAIGN", DEFAULT_ID_UE + i, + Utils.addAdditionalDtoToMongoStub("TESTIDCAMPAIGN", DEFAULT_INTERROGATION_ID + i, LocalDateTime.of(2023, 1, 1, 0, 0, 0), LocalDateTime.of(2024, 1, 1, 0, 0, 0), surveyUnitPersistencePortStub); } //When - ResponseEntity response = responseControllerStatic.findAllResponsesByQuestionnaire(DEFAULT_ID_QUEST); + ResponseEntity response = responseControllerStatic.findAllResponsesByQuestionnaire(DEFAULT_QUESTIONNAIRE_ID); //Then Assertions.assertThat(response).isNotNull(); @@ -254,32 +254,32 @@ void getAllResponsesByQuestionnaireTestSequential() throws IOException { void getLatestByUETest() { Utils.addAdditionalDtoToMongoStub(surveyUnitPersistencePortStub); - ResponseEntity> response = responseControllerStatic.getLatestByUE(DEFAULT_ID_UE, DEFAULT_ID_QUEST); + ResponseEntity> response = responseControllerStatic.getLatestByInterrogation(DEFAULT_INTERROGATION_ID, DEFAULT_QUESTIONNAIRE_ID); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty(); - Assertions.assertThat(response.getBody().getFirst().getInterrogationId()).isEqualTo(DEFAULT_ID_UE); - Assertions.assertThat(response.getBody().getFirst().getQuestionnaireId()).isEqualTo(DEFAULT_ID_QUEST); + Assertions.assertThat(response.getBody().getFirst().getInterrogationId()).isEqualTo(DEFAULT_INTERROGATION_ID); + Assertions.assertThat(response.getBody().getFirst().getQuestionnaireId()).isEqualTo(DEFAULT_QUESTIONNAIRE_ID); Assertions.assertThat(response.getBody().getFirst().getFileDate()).hasMonth(Month.FEBRUARY); } @Test void getLatestByUEOneObjectTest() { - ResponseEntity response = responseControllerStatic.getLatestByUEOneObject(DEFAULT_ID_UE, DEFAULT_ID_QUEST, Mode.WEB); + ResponseEntity response = responseControllerStatic.getLatestByInterrogationOneObject(DEFAULT_INTERROGATION_ID, DEFAULT_QUESTIONNAIRE_ID, Mode.WEB); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull(); - Assertions.assertThat(response.getBody().getIdUE()).isEqualTo(DEFAULT_ID_UE); - Assertions.assertThat(response.getBody().getIdQuest()).isEqualTo(DEFAULT_ID_QUEST); + Assertions.assertThat(response.getBody().getInterrogationId()).isEqualTo(DEFAULT_INTERROGATION_ID); + Assertions.assertThat(response.getBody().getQuestionnaireId()).isEqualTo(DEFAULT_QUESTIONNAIRE_ID); } @Test void getLatestForUEListTest() { - ResponseEntity> response = responseControllerStatic.getLatestForUEList(DEFAULT_ID_QUEST, surveyUnitIdList); + ResponseEntity> response = responseControllerStatic.getLatestForInterrogationList(DEFAULT_QUESTIONNAIRE_ID, surveyUnitIdList); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty(); - Assertions.assertThat(response.getBody().getFirst().getIdUE()).isEqualTo(DEFAULT_ID_UE); + Assertions.assertThat(response.getBody().getFirst().getInterrogationId()).isEqualTo(DEFAULT_INTERROGATION_ID); } // Perret tests @@ -316,9 +316,9 @@ void getLatestByStatesSurveyDataTest(){ //WHEN - ResponseEntity response = responseControllerStatic.findResponsesByUEAndQuestionnaireLatestStates( - DEFAULT_ID_UE, - DEFAULT_ID_QUEST + ResponseEntity response = responseControllerStatic.findResponsesByInterrogationAndQuestionnaireLatestStates( + DEFAULT_INTERROGATION_ID, + DEFAULT_QUESTIONNAIRE_ID ); @@ -326,7 +326,7 @@ void getLatestByStatesSurveyDataTest(){ SurveyUnitDto surveyUnitDto = response.getBody(); Assertions.assertThat(surveyUnitDto).isNotNull(); - Assertions.assertThat(surveyUnitDto.getSurveyUnitId()).isEqualTo(DEFAULT_ID_UE); + Assertions.assertThat(surveyUnitDto.getSurveyUnitId()).isEqualTo(DEFAULT_INTERROGATION_ID); Assertions.assertThat(surveyUnitDto.getCollectedVariables().getFirst().getVariableName()) .isEqualTo("TESTIDVAR"); diff --git a/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java b/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java index a4639315..f9005f53 100644 --- a/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java +++ b/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java @@ -113,7 +113,7 @@ void saveAllTest(){ @Test void findByIdsUEAndQuestionnaireTest(){ - Assertions.assertThat(surveyUnitServiceStatic.findByIdsUEAndQuestionnaire(defaultIdUE, defaultIdQuest)).filteredOn( + Assertions.assertThat(surveyUnitServiceStatic.findByIdsInterrogationAndQuestionnaire(defaultIdUE, defaultIdQuest)).filteredOn( surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultIdUE) && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) @@ -122,15 +122,15 @@ void findByIdsUEAndQuestionnaireTest(){ @Test void findByIdUETest(){ - Assertions.assertThat(surveyUnitServiceStatic.findByIdUE(defaultIdUE)).filteredOn( + Assertions.assertThat(surveyUnitServiceStatic.findByInterrogationId(defaultIdUE)).filteredOn( surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultIdUE) ).isNotEmpty(); } @Test - void findByIdQuestionnaireTest(){ - Assertions.assertThat(surveyUnitServiceStatic.findByIdQuestionnaire(defaultIdQuest)).filteredOn( + void findByQuestionnaireIdTest(){ + Assertions.assertThat(surveyUnitServiceStatic.findByQuestionnaireId(defaultIdQuest)).filteredOn( surveyUnitDto -> surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) ).isNotEmpty(); } @@ -139,7 +139,7 @@ void findByIdQuestionnaireTest(){ void findLatestByIdAndByModeTest(){ addAdditionnalDtoToMongoStub(); - Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByIdQuestionnaire(defaultIdUE, defaultIdQuest)).filteredOn( + Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(defaultIdUE, defaultIdQuest)).filteredOn( surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultIdUE) && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) && surveyUnitDto.getFileDate().getMonth().equals(Month.FEBRUARY) @@ -156,7 +156,7 @@ void findResponsesByUEAndQuestionnaireTest_null_collectedVariables() { ); surveyUnitPersistencePortStub.getMongoStub().getLast().setCollectedVariables(null); - Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByIdQuestionnaire(defaultIdUE, defaultIdQuest)).filteredOn( + Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(defaultIdUE, defaultIdQuest)).filteredOn( surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultIdUE) && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) && surveyUnitDto.getFileDate().getMonth().equals(Month.FEBRUARY) @@ -172,7 +172,7 @@ void findResponsesByUEAndQuestionnaireTest_null_externalVariables() { ); surveyUnitPersistencePortStub.getMongoStub().getLast().setExternalVariables(null); - Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByIdQuestionnaire(defaultIdUE, defaultIdQuest)).filteredOn( + Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(defaultIdUE, defaultIdQuest)).filteredOn( surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultIdUE) && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) && surveyUnitDto.getFileDate().getMonth().equals(Month.FEBRUARY) @@ -180,17 +180,17 @@ void findResponsesByUEAndQuestionnaireTest_null_externalVariables() { } @Test - void findDistinctIdUEsByIdQuestionnaireTest(){ + void findDistinctIdUEsByQuestionnaireIdTest(){ addAdditionnalDtoToMongoStub(); - Assertions.assertThat(surveyUnitServiceStatic.findDistinctIdUEsByIdQuestionnaire(defaultIdQuest)).filteredOn( + Assertions.assertThat(surveyUnitServiceStatic.findDistinctInterrogationIdsByQuestionnaireId(defaultIdQuest)).filteredOn( surveyUnitId -> surveyUnitId.getIdUE().equals(defaultIdUE) ).isNotEmpty().hasSize(1); } @Test - void findIdUEsByIdQuestionnaireTest(){ - Assertions.assertThat(surveyUnitServiceStatic.findModesByIdQuestionnaire(defaultIdQuest)).filteredOn( + void findIdUEsByQuestionnaireIdTest(){ + Assertions.assertThat(surveyUnitServiceStatic.findModesByQuestionnaireId(defaultIdQuest)).filteredOn( mode -> mode.equals(Mode.WEB) ).isNotEmpty(); } @@ -199,17 +199,17 @@ void findIdUEsByIdQuestionnaireTest(){ void getQuestionnairesByCampaignTest() { addAdditionnalDtoToMongoStub("TESTQUESTIONNAIRE2"); - Assertions.assertThat(surveyUnitServiceStatic.findIdQuestionnairesByIdCampaign("TESTIDCAMPAIGN")).isNotEmpty().hasSize(2); + Assertions.assertThat(surveyUnitServiceStatic.findQuestionnaireIdsByCampaignId("TESTIDCAMPAIGN")).isNotEmpty().hasSize(2); } @Test void getAllCampaignsTest() { - Assertions.assertThat(surveyUnitServiceStatic.findDistinctIdCampaigns()).contains("TESTIDCAMPAIGN"); + Assertions.assertThat(surveyUnitServiceStatic.findDistinctCampaignIds()).contains("TESTIDCAMPAIGN"); } @Test - void findLatestByIdAndByIdQuestionnairePerretTest(){ + void findLatestByIdAndByQuestionnaireIdPerretTest(){ //Given //Recent Collected already in stub //Old Collected @@ -238,7 +238,7 @@ void findLatestByIdAndByIdQuestionnairePerretTest(){ //When - SurveyUnitDto surveyUnitDto = surveyUnitServiceStatic.findLatestValuesByStateByIdAndByIdQuestionnaire( + SurveyUnitDto surveyUnitDto = surveyUnitServiceStatic.findLatestValuesByStateByIdAndByQuestionnaireId( defaultIdUE, defaultIdQuest ); @@ -295,7 +295,7 @@ void findLatestByIdAndByIdQuestionnairePerretTest(){ } @Test - void findLatestByIdAndByIdQuestionnairePerretTest_null_collectedVariables(){ + void findLatestByIdAndByQuestionnaireIdPerretTest_null_collectedVariables(){ //Given addAdditionnalDtoToMongoStub(DataState.EDITED, "C NEW E", @@ -307,7 +307,7 @@ void findLatestByIdAndByIdQuestionnairePerretTest_null_collectedVariables(){ //When - SurveyUnitDto surveyUnitDto = surveyUnitServiceStatic.findLatestValuesByStateByIdAndByIdQuestionnaire( + SurveyUnitDto surveyUnitDto = surveyUnitServiceStatic.findLatestValuesByStateByIdAndByQuestionnaireId( defaultIdUE, defaultIdQuest ); @@ -354,7 +354,7 @@ void findLatestByIdAndByIdQuestionnairePerretTest_null_collectedVariables(){ } @Test - void findLatestByIdAndByIdQuestionnairePerretTest_null_externalVariables(){ + void findLatestByIdAndByQuestionnaireIdPerretTest_null_externalVariables(){ //Given addAdditionnalDtoToMongoStub(DataState.EDITED, "C NEW E", @@ -366,7 +366,7 @@ void findLatestByIdAndByIdQuestionnairePerretTest_null_externalVariables(){ //When - SurveyUnitDto surveyUnitDto = surveyUnitServiceStatic.findLatestValuesByStateByIdAndByIdQuestionnaire( + SurveyUnitDto surveyUnitDto = surveyUnitServiceStatic.findLatestValuesByStateByIdAndByQuestionnaireId( defaultIdUE, defaultIdQuest ); diff --git a/src/test/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitModelMongoAdapterTest.java b/src/test/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitModelMongoAdapterTest.java index 9cee571f..d151d803 100644 --- a/src/test/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitModelMongoAdapterTest.java +++ b/src/test/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitModelMongoAdapterTest.java @@ -75,7 +75,7 @@ void shouldReturnListOfSurveyUnitDto_IfIdsFoundInDataBase() { List responses = new ArrayList<>(); responses.add(suDoc); responses.add(suDoc2); - when(mongoRepository.findByIdUEAndIdQuestionnaire(any(String.class), any(String.class))).thenReturn(responses); + when(mongoRepository.findByInterrogationIdAndQuestionnaireId(any(String.class), any(String.class))).thenReturn(responses); // When List updates = surveyUnitMongoAdapter.findByIds("UE1100000001", "TEST2023X01"); // Then @@ -86,7 +86,7 @@ void shouldReturnListOfSurveyUnitDto_IfIdsFoundInDataBase() { @Test void shouldReturnEmptyList_IfIdsNotFoundInDataBase() { //Given - when(mongoRepository.findByIdUEAndIdQuestionnaire(any(String.class), any(String.class))).thenReturn(List.of()); + when(mongoRepository.findByInterrogationIdAndQuestionnaireId(any(String.class), any(String.class))).thenReturn(List.of()); // When List updates = surveyUnitMongoAdapter.findByIds("UE1100000001", "TEST2023X01"); // Then @@ -94,83 +94,83 @@ void shouldReturnEmptyList_IfIdsNotFoundInDataBase() { } @Test - void shouldReturnListOfSurveyUnitDto_IfIdUEFoundInDataBase() { + void shouldReturnListOfSurveyUnitDto_IfInterrogationIdFoundInDataBase() { //Given List responses = new ArrayList<>(); responses.add(suDoc); responses.add(suDoc2); - when(mongoRepository.findByIdUE(any(String.class))).thenReturn(responses); + when(mongoRepository.findByInterrogationId(any(String.class))).thenReturn(responses); // When - List updates = surveyUnitMongoAdapter.findByIdUE("UE1100000001"); + List updates = surveyUnitMongoAdapter.findByInterrogationId("UE1100000001"); // Then Assertions.assertThat(updates).isNotNull().hasSize(2); Assertions.assertThat(updates.getFirst().getMode()).isEqualTo(Mode.WEB); } @Test - void shouldReturnEmptyList_IfIdUENotFoundInDataBase() { + void shouldReturnEmptyList_IfInterrogationIdNotFoundInDataBase() { //Given - when(mongoRepository.findByIdUE(any(String.class))).thenReturn(List.of()); + when(mongoRepository.findByInterrogationId(any(String.class))).thenReturn(List.of()); // When - List updates = surveyUnitMongoAdapter.findByIdUE("UE1100000001"); + List updates = surveyUnitMongoAdapter.findByInterrogationId("UE1100000001"); // Then Assertions.assertThat(updates).isEmpty(); } @Test - void shouldReturnListOfSurveyUnitDto_IfIdQuestionnaireFoundInDataBase() { + void shouldReturnListOfSurveyUnitDto_IfQuestionnaireIdFoundInDataBase() { //Given List responses = new ArrayList<>(); responses.add(suDoc); responses.add(suDoc2); responses.add(suDoc3); - when(mongoRepository.findByIdQuestionnaire(any(String.class))).thenReturn(responses.stream()); + when(mongoRepository.findByQuestionnaireId(any(String.class))).thenReturn(responses.stream()); // When - Stream updates = surveyUnitMongoAdapter.findByIdQuestionnaire("TEST2023X01"); + Stream updates = surveyUnitMongoAdapter.findByQuestionnaireId("TEST2023X01"); // Then Assertions.assertThat(updates).isNotNull().hasSize(3); //Assertions.assertThat(updates.get(2).getMode()).isEqualTo(Mode.WEB); } @Test - void shouldReturnEmptyList_IfIdQuestionnaireNotFoundInDataBase() { + void shouldReturnEmptyList_IfQuestionnaireIdNotFoundInDataBase() { //Given - when(mongoRepository.findByIdQuestionnaire(any(String.class))).thenReturn(Stream.empty()); + when(mongoRepository.findByQuestionnaireId(any(String.class))).thenReturn(Stream.empty()); // When - List updates = surveyUnitMongoAdapter.findByIdQuestionnaire("TEST2023X01").toList(); + List updates = surveyUnitMongoAdapter.findByQuestionnaireId("TEST2023X01").toList(); // Then Assertions.assertThat(updates).isEmpty(); } @Test - void shouldReturnListOfSurveyUnitDto_WhenGivenAListOfIdUEs() { + void shouldReturnListOfSurveyUnitDto_WhenGivenAListOfInterrogationIds() { //Given List responses1 = new ArrayList<>(); responses1.add(suDoc); responses1.add(suDoc2); List responses2 = new ArrayList<>(); responses2.add(suDoc3); - when(mongoRepository.findByIdUEAndIdQuestionnaire("UE1100000001", "TEST2023X01")).thenReturn(responses1); - when(mongoRepository.findByIdUEAndIdQuestionnaire("UE1100000002", "TEST2023X01")).thenReturn(responses2); + when(mongoRepository.findByInterrogationIdAndQuestionnaireId("UE1100000001", "TEST2023X01")).thenReturn(responses1); + when(mongoRepository.findByInterrogationIdAndQuestionnaireId("UE1100000002", "TEST2023X01")).thenReturn(responses2); SurveyUnitModel id1 = SurveyUnitModel.builder().interrogationId("UE1100000001").build(); SurveyUnitModel id2 = SurveyUnitModel.builder().interrogationId("UE1100000002").build(); List ids = List.of(id1, id2); // When - List updates = surveyUnitMongoAdapter.findByIdUEsAndIdQuestionnaire(ids, "TEST2023X01"); + List updates = surveyUnitMongoAdapter.findByInterrogationIdsAndQuestionnaireId(ids, "TEST2023X01"); // Then Assertions.assertThat(updates).isNotNull().hasSize(3); Assertions.assertThat(updates.getFirst().getMode()).isEqualTo(Mode.WEB); } @Test - void shouldReturnEmptyList_IfIdUEsNotFoundInDataBase() { + void shouldReturnEmptyList_IfInterrogationIdsNotFoundInDataBase() { //Given - when(mongoRepository.findByIdUEAndIdQuestionnaire(any(String.class),any(String.class))).thenReturn(List.of()); + when(mongoRepository.findByInterrogationIdAndQuestionnaireId(any(String.class),any(String.class))).thenReturn(List.of()); SurveyUnitModel id1 = SurveyUnitModel.builder().interrogationId("UE1100000001").build(); SurveyUnitModel id2 = SurveyUnitModel.builder().interrogationId("UE1100000002").build(); List ids = List.of(id1, id2); // When - List updates = surveyUnitMongoAdapter.findByIdUEsAndIdQuestionnaire(ids, "TEST2023X01"); + List updates = surveyUnitMongoAdapter.findByInterrogationIdsAndQuestionnaireId(ids, "TEST2023X01"); // Then Assertions.assertThat(updates).isEmpty(); } diff --git a/src/test/java/fr/insee/genesis/stubs/SurveyUnitPersistencePortStub.java b/src/test/java/fr/insee/genesis/stubs/SurveyUnitPersistencePortStub.java index 667847eb..67a9e042 100644 --- a/src/test/java/fr/insee/genesis/stubs/SurveyUnitPersistencePortStub.java +++ b/src/test/java/fr/insee/genesis/stubs/SurveyUnitPersistencePortStub.java @@ -20,10 +20,10 @@ public void saveAll(List suList) { } @Override - public List findByIds(String idUE, String idQuest) { + public List findByIds(String interrogationId, String questionnaireId) { List surveyUnitModelList = new ArrayList<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getInterrogationId().equals(idUE) && SurveyUnitModel.getQuestionnaireId().equals(idQuest)) + if(SurveyUnitModel.getInterrogationId().equals(interrogationId) && SurveyUnitModel.getQuestionnaireId().equals(questionnaireId)) surveyUnitModelList.add(SurveyUnitModel); } @@ -31,10 +31,10 @@ public List findByIds(String idUE, String idQuest) { } @Override - public List findByIdUE(String idUE) { + public List findByInterrogationId(String interrogationId) { List surveyUnitModelList = new ArrayList<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getInterrogationId().equals(idUE)) + if(SurveyUnitModel.getInterrogationId().equals(interrogationId)) surveyUnitModelList.add(SurveyUnitModel); } @@ -42,11 +42,11 @@ public List findByIdUE(String idUE) { } @Override - public List findByIdUEsAndIdQuestionnaire(List idUEs, String idQuestionnaire) { + public List findByInterrogationIdsAndQuestionnaireId(List interrogationIds, String questionnaireId) { List surveyUnitModelList = new ArrayList<>(); - for(SurveyUnitModel surveyUnitModel : idUEs) { + for(SurveyUnitModel surveyUnitModel : interrogationIds) { for (SurveyUnitModel document : mongoStub) { - if (surveyUnitModel.getInterrogationId().equals(document.getInterrogationId()) && document.getQuestionnaireId().equals(idQuestionnaire)) + if (surveyUnitModel.getInterrogationId().equals(document.getInterrogationId()) && document.getQuestionnaireId().equals(questionnaireId)) surveyUnitModelList.add(document); } } @@ -55,10 +55,10 @@ public List findByIdUEsAndIdQuestionnaire(List } @Override - public Stream findByIdQuestionnaire(String idQuestionnaire) { + public Stream findByQuestionnaireId(String questionnaireId) { List surveyUnitModelList = new ArrayList<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getQuestionnaireId().equals(idQuestionnaire)) + if(SurveyUnitModel.getQuestionnaireId().equals(questionnaireId)) surveyUnitModelList.add(SurveyUnitModel); } @@ -66,10 +66,10 @@ public Stream findByIdQuestionnaire(String idQuestionnaire) { } @Override - public List findIdUEsByIdQuestionnaire(String idQuestionnaire) { + public List findInterrogationIdsByQuestionnaireId(String questionnaireId) { List surveyUnitModelList = new ArrayList<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getQuestionnaireId().equals(idQuestionnaire)) + if(SurveyUnitModel.getQuestionnaireId().equals(questionnaireId)) surveyUnitModelList.add( new SurveyUnitModel(SurveyUnitModel.getInterrogationId(), SurveyUnitModel.getMode()) ); @@ -79,10 +79,10 @@ public List findIdUEsByIdQuestionnaire(String idQuestionnaire) } @Override - public List findIdUEsByIdCampaign(String idCampaign) { + public List findInterrogationIdsByCampaignId(String campaignId) { List surveyUnitModelList = new ArrayList<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getCampaignId().equals(idCampaign)) + if(SurveyUnitModel.getCampaignId().equals(campaignId)) surveyUnitModelList.add( new SurveyUnitModel(SurveyUnitModel.getInterrogationId(), SurveyUnitModel.getMode()) ); @@ -92,7 +92,7 @@ public List findIdUEsByIdCampaign(String idCampaign) { } @Override - public Long deleteByIdQuestionnaire(String idQuestionnaire) { + public Long deleteByQuestionnaireId(String questionnaireId) { return null; } @@ -102,18 +102,18 @@ public long count() { } @Override - public Set findIdQuestionnairesByIdCampaign(String idCampaign) { - Set idQuestionnaireSet = new HashSet<>(); + public Set findQuestionnaireIdsByCampaignId(String campaignId) { + Set questionnaireIdSet = new HashSet<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getCampaignId().equals(idCampaign)) - idQuestionnaireSet.add(SurveyUnitModel.getQuestionnaireId()); + if(SurveyUnitModel.getCampaignId().equals(campaignId)) + questionnaireIdSet.add(SurveyUnitModel.getQuestionnaireId()); } - return idQuestionnaireSet; + return questionnaireIdSet; } @Override - public Set findDistinctIdCampaigns() { + public Set findDistinctCampaignIds() { Set campaignIds = new HashSet<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ campaignIds.add(SurveyUnitModel.getCampaignId()); @@ -123,13 +123,13 @@ public Set findDistinctIdCampaigns() { } @Override - public long countByIdCampaign(String idCampaign) { + public long countByCampaignId(String campaignId) { return mongoStub.stream().filter( - SurveyUnitDto -> SurveyUnitDto.getCampaignId().equals(idCampaign)).toList().size(); + SurveyUnitDto -> SurveyUnitDto.getCampaignId().equals(campaignId)).toList().size(); } @Override - public Set findDistinctIdQuestionnaires() { + public Set findDistinctQuestionnaireIds() { Set questionnaireIds = new HashSet<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ questionnaireIds.add(SurveyUnitModel.getQuestionnaireId()); @@ -138,13 +138,13 @@ public Set findDistinctIdQuestionnaires() { } @Override - public Set findIdCampaignsByIdQuestionnaire(String idQuestionnaire) { - Set idCampaignSet = new HashSet<>(); + public Set findCampaignIdsByQuestionnaireId(String questionnaireId) { + Set campaignIdSet = new HashSet<>(); for(SurveyUnitModel SurveyUnitModel : mongoStub){ - if(SurveyUnitModel.getQuestionnaireId().equals(idQuestionnaire)) - idCampaignSet.add(SurveyUnitModel.getCampaignId()); + if(SurveyUnitModel.getQuestionnaireId().equals(questionnaireId)) + campaignIdSet.add(SurveyUnitModel.getCampaignId()); } - return idCampaignSet; + return campaignIdSet; } } From d1a5284714e93df6917fcf391c2b7232cadc4d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Henninger?= Date: Wed, 15 Jan 2025 14:53:11 +0100 Subject: [PATCH 4/7] Remaining IdLoop --- .../fr/insee/genesis/domain/model/surveyunit/IdLoopTuple.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/insee/genesis/domain/model/surveyunit/IdLoopTuple.java b/src/main/java/fr/insee/genesis/domain/model/surveyunit/IdLoopTuple.java index 615a25d2..c004dc98 100644 --- a/src/main/java/fr/insee/genesis/domain/model/surveyunit/IdLoopTuple.java +++ b/src/main/java/fr/insee/genesis/domain/model/surveyunit/IdLoopTuple.java @@ -1,4 +1,4 @@ package fr.insee.genesis.domain.model.surveyunit; -public record IdLoopTuple(String varId, String idLoop) { +public record IdLoopTuple(String varId, String loopId) { } From 2ff95aaa567951b9d0af1294bd54edae6913d30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Henninger?= Date: Mon, 20 Jan 2025 18:19:32 +0100 Subject: [PATCH 5/7] Remaining IdUE --- .../dto/{SurveyUnitId.java => InterrogationId.java} | 12 +++++------- .../rest/responses/InterrogationController.java | 6 +++--- .../rest/responses/ResponseController.java | 6 +++--- .../genesis/domain/ports/api/SurveyUnitApiPort.java | 4 ++-- .../domain/service/surveyunit/SurveyUnitService.java | 6 +++--- .../genesis/controller/rest/UtilsControllerTest.java | 8 ++++---- .../rest/responses/InterrogationControllerTest.java | 6 +++--- .../rest/responses/ResponseControllerTest.java | 10 +++++----- .../domain/service/SurveyUnitServiceTest.java | 2 +- 9 files changed, 29 insertions(+), 31 deletions(-) rename src/main/java/fr/insee/genesis/controller/dto/{SurveyUnitId.java => InterrogationId.java} (63%) diff --git a/src/main/java/fr/insee/genesis/controller/dto/SurveyUnitId.java b/src/main/java/fr/insee/genesis/controller/dto/InterrogationId.java similarity index 63% rename from src/main/java/fr/insee/genesis/controller/dto/SurveyUnitId.java rename to src/main/java/fr/insee/genesis/controller/dto/InterrogationId.java index 18b87005..34d80954 100644 --- a/src/main/java/fr/insee/genesis/controller/dto/SurveyUnitId.java +++ b/src/main/java/fr/insee/genesis/controller/dto/InterrogationId.java @@ -1,6 +1,5 @@ package fr.insee.genesis.controller.dto; -import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -12,21 +11,20 @@ @Getter @NoArgsConstructor @AllArgsConstructor -public class SurveyUnitId { +public class InterrogationId { - @JsonProperty("idUE") - private String idUE; + private String interrogationId; @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - SurveyUnitId that = (SurveyUnitId) o; - return Objects.equals(idUE, that.idUE); + InterrogationId that = (InterrogationId) o; + return Objects.equals(interrogationId, that.interrogationId); } @Override public int hashCode() { - return Objects.hash(idUE); + return Objects.hash(interrogationId); } } diff --git a/src/main/java/fr/insee/genesis/controller/rest/responses/InterrogationController.java b/src/main/java/fr/insee/genesis/controller/rest/responses/InterrogationController.java index 4bfc4960..427d966a 100644 --- a/src/main/java/fr/insee/genesis/controller/rest/responses/InterrogationController.java +++ b/src/main/java/fr/insee/genesis/controller/rest/responses/InterrogationController.java @@ -1,6 +1,6 @@ package fr.insee.genesis.controller.rest.responses; -import fr.insee.genesis.controller.dto.SurveyUnitId; +import fr.insee.genesis.controller.dto.InterrogationId; import fr.insee.genesis.domain.ports.api.SurveyUnitApiPort; import io.swagger.v3.oas.annotations.Operation; import lombok.extern.slf4j.Slf4j; @@ -27,8 +27,8 @@ public InterrogationController(SurveyUnitApiPort surveyUnitService) { @Operation(summary = "Retrieve all interrogations for a given questionnaire") @GetMapping(path = "/by-questionnaire") - public ResponseEntity> getAllInterrogationIdsByQuestionnaire(@RequestParam("questionnaireId") String questionnaireId) { - List responses = surveyUnitService.findDistinctInterrogationIdsByQuestionnaireId(questionnaireId); + public ResponseEntity> getAllInterrogationIdsByQuestionnaire(@RequestParam("questionnaireId") String questionnaireId) { + List responses = surveyUnitService.findDistinctInterrogationIdsByQuestionnaireId(questionnaireId); return ResponseEntity.ok(responses); } diff --git a/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java b/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java index 7a95bef7..65b9ca18 100644 --- a/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java +++ b/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java @@ -8,7 +8,7 @@ import fr.insee.genesis.Constants; import fr.insee.genesis.controller.adapter.LunaticXmlAdapter; import fr.insee.genesis.controller.dto.SurveyUnitDto; -import fr.insee.genesis.controller.dto.SurveyUnitId; +import fr.insee.genesis.controller.dto.InterrogationId; import fr.insee.genesis.controller.dto.SurveyUnitSimplified; import fr.insee.genesis.controller.sources.xml.LunaticXmlCampaign; import fr.insee.genesis.controller.sources.xml.LunaticXmlDataParser; @@ -333,11 +333,11 @@ public ResponseEntity getLatestByInterrogationOneObject(@R "For a given id, the endpoint returns a document by collection mode (if there is more than one).") @PostMapping(path = "/simplified/by-list-interrogation-and-questionnaire/latest") public ResponseEntity> getLatestForInterrogationList(@RequestParam("questionnaireId") String questionnaireId, - @RequestBody List interrogationIds) { + @RequestBody List interrogationIds) { List results = new ArrayList<>(); List modes = surveyUnitService.findModesByQuestionnaireId(questionnaireId); interrogationIds.forEach(interrogationId -> { - List responses = surveyUnitService.findLatestByIdAndByQuestionnaireId(interrogationId.getIdUE(), questionnaireId); + List responses = surveyUnitService.findLatestByIdAndByQuestionnaireId(interrogationId.getInterrogationId(), questionnaireId); modes.forEach(mode -> { List outputVariables = new ArrayList<>(); List outputExternalVariables = new ArrayList<>(); diff --git a/src/main/java/fr/insee/genesis/domain/ports/api/SurveyUnitApiPort.java b/src/main/java/fr/insee/genesis/domain/ports/api/SurveyUnitApiPort.java index e2f1d701..e63be7eb 100644 --- a/src/main/java/fr/insee/genesis/domain/ports/api/SurveyUnitApiPort.java +++ b/src/main/java/fr/insee/genesis/domain/ports/api/SurveyUnitApiPort.java @@ -5,7 +5,7 @@ import fr.insee.genesis.domain.model.surveyunit.Mode; import fr.insee.genesis.controller.dto.QuestionnaireWithCampaign; import fr.insee.genesis.domain.model.surveyunit.SurveyUnitModel; -import fr.insee.genesis.controller.dto.SurveyUnitId; +import fr.insee.genesis.controller.dto.InterrogationId; import java.util.List; import java.util.Set; @@ -27,7 +27,7 @@ public interface SurveyUnitApiPort { List findInterrogationIdsAndModesByQuestionnaireId(String questionnaireId); - List findDistinctInterrogationIdsByQuestionnaireId(String questionnaireId); + List findDistinctInterrogationIdsByQuestionnaireId(String questionnaireId); List findModesByQuestionnaireId(String questionnaireId); diff --git a/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java b/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java index ff6d8dc3..e35b6508 100644 --- a/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java +++ b/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java @@ -133,10 +133,10 @@ public SurveyUnitDto findLatestValuesByStateByIdAndByQuestionnaireId(String inte } @Override - public List findDistinctInterrogationIdsByQuestionnaireId(String questionnaireId) { + public List findDistinctInterrogationIdsByQuestionnaireId(String questionnaireId) { List surveyUnitModels = surveyUnitPersistencePort.findInterrogationIdsByQuestionnaireId(questionnaireId); - List suIds = new ArrayList<>(); - surveyUnitModels.forEach(surveyUnitDto -> suIds.add(new SurveyUnitId(surveyUnitDto.getInterrogationId()))); + List suIds = new ArrayList<>(); + surveyUnitModels.forEach(surveyUnitDto -> suIds.add(new InterrogationId(surveyUnitDto.getInterrogationId()))); return suIds.stream().distinct().toList(); } diff --git a/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java index f6d6b74d..c412d319 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java @@ -2,7 +2,7 @@ import cucumber.TestConstants; import fr.insee.genesis.Constants; -import fr.insee.genesis.controller.dto.SurveyUnitId; +import fr.insee.genesis.controller.dto.InterrogationId; import fr.insee.genesis.domain.model.surveyunit.CollectedVariable; import fr.insee.genesis.domain.model.surveyunit.DataState; import fr.insee.genesis.domain.model.surveyunit.Mode; @@ -36,7 +36,7 @@ class UtilsControllerTest { static UtilsController utilsControllerStatic; static SurveyUnitPersistencePortStub surveyUnitPersistencePortStub; - static List surveyUnitIdList; + static List interrogationIdList; //Constants static final String defaultIdUE = "TESTIDUE"; static final String defaultIdQuest = "TESTIDQUESTIONNAIRE"; @@ -51,8 +51,8 @@ static void init() { , new VolumetryLogService(new ConfigStub()) ); - surveyUnitIdList = new ArrayList<>(); - surveyUnitIdList.add(new SurveyUnitId(defaultIdUE)); + interrogationIdList = new ArrayList<>(); + interrogationIdList.add(new InterrogationId(defaultIdUE)); } @BeforeEach diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/InterrogationControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/InterrogationControllerTest.java index 315c21d0..d731e939 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/InterrogationControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/InterrogationControllerTest.java @@ -1,6 +1,6 @@ package fr.insee.genesis.controller.rest.responses; -import fr.insee.genesis.controller.dto.SurveyUnitId; +import fr.insee.genesis.controller.dto.InterrogationId; import fr.insee.genesis.domain.ports.api.SurveyUnitApiPort; import fr.insee.genesis.domain.service.surveyunit.SurveyUnitService; import fr.insee.genesis.stubs.SurveyUnitPersistencePortStub; @@ -39,11 +39,11 @@ void reset() throws IOException { //When + Then @Test void getAllIdUEsByQuestionnaireTest() { - ResponseEntity> response = interrogationControllerStatic.getAllInterrogationIdsByQuestionnaire(DEFAULT_QUESTIONNAIRE_ID); + ResponseEntity> response = interrogationControllerStatic.getAllInterrogationIdsByQuestionnaire(DEFAULT_QUESTIONNAIRE_ID); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty(); - Assertions.assertThat(response.getBody().getFirst().getIdUE()).isEqualTo(DEFAULT_INTERROGATION_ID); + Assertions.assertThat(response.getBody().getFirst().getInterrogationId()).isEqualTo(DEFAULT_INTERROGATION_ID); } diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java index ff0c05ec..e9fb7672 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java @@ -3,7 +3,7 @@ import cucumber.TestConstants; import fr.insee.genesis.Constants; import fr.insee.genesis.controller.dto.SurveyUnitDto; -import fr.insee.genesis.controller.dto.SurveyUnitId; +import fr.insee.genesis.controller.dto.InterrogationId; import fr.insee.genesis.controller.dto.SurveyUnitSimplified; import fr.insee.genesis.controller.utils.ControllerUtils; import fr.insee.genesis.domain.model.surveyunit.DataState; @@ -47,7 +47,7 @@ class ResponseControllerTest { static LunaticXmlPersistanceStub lunaticXmlPersistanceStub; static LunaticJsonPersistanceStub lunaticJsonPersistanceStub; - static List surveyUnitIdList; + static List interrogationIdList; @BeforeAll static void init() { @@ -70,8 +70,8 @@ static void init() { , new ControllerUtils(fileUtils) ); - surveyUnitIdList = new ArrayList<>(); - surveyUnitIdList.add(new SurveyUnitId(DEFAULT_INTERROGATION_ID)); + interrogationIdList = new ArrayList<>(); + interrogationIdList.add(new InterrogationId(DEFAULT_INTERROGATION_ID)); } @BeforeEach @@ -275,7 +275,7 @@ void getLatestByUEOneObjectTest() { @Test void getLatestForUEListTest() { - ResponseEntity> response = responseControllerStatic.getLatestForInterrogationList(DEFAULT_QUESTIONNAIRE_ID, surveyUnitIdList); + ResponseEntity> response = responseControllerStatic.getLatestForInterrogationList(DEFAULT_QUESTIONNAIRE_ID, interrogationIdList); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty(); diff --git a/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java b/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java index f9005f53..dcb6bb8f 100644 --- a/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java +++ b/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java @@ -184,7 +184,7 @@ void findDistinctIdUEsByQuestionnaireIdTest(){ addAdditionnalDtoToMongoStub(); Assertions.assertThat(surveyUnitServiceStatic.findDistinctInterrogationIdsByQuestionnaireId(defaultIdQuest)).filteredOn( - surveyUnitId -> surveyUnitId.getIdUE().equals(defaultIdUE) + surveyUnitId -> surveyUnitId.getInterrogationId().equals(defaultIdUE) ).isNotEmpty().hasSize(1); } From 2604bdc9f9bcae0f92325cb0b18ea8c10a9d73e2 Mon Sep 17 00:00:00 2001 From: QDIBYS Date: Thu, 23 Jan 2025 09:46:25 +0100 Subject: [PATCH 6/7] refactor: Changed more ids IdUE -> interrogationId idCampaign -> campaignId idQuestionnaire -> questionnaireId --- src/main/java/fr/insee/genesis/Constants.java | 2 +- .../adapter/LunaticJsonAdapter.java | 4 +- .../controller/adapter/LunaticXmlAdapter.java | 20 ++-- .../dto/CampaignWithQuestionnaire.java | 2 +- .../dto/QuestionnaireWithCampaign.java | 2 +- .../rest/responses/ResponseController.java | 6 +- .../sources/json/LunaticJsonSurveyUnit.java | 4 +- .../sources/xml/LunaticXmlCampaign.java | 2 +- .../sources/xml/LunaticXmlDataParser.java | 2 +- .../xml/LunaticXmlDataSequentialParser.java | 2 +- .../genesis/domain/utils/DataVerifier.java | 38 +++--- .../surveyunit/SurveyUnitDocument.java | 6 +- .../functional_tests/MainDefinitions.java | 2 +- .../java/fr/insee/genesis/TestConstants.java | 4 +- .../adapter/LunaticXmlAdapterTest.java | 38 +++--- .../rest/HealthCheckControllerTest.java | 6 +- .../controller/rest/UtilsControllerTest.java | 36 +++--- .../responses/CampaignControllerTest.java | 20 ++-- .../InterrogationControllerTest.java | 2 +- .../rest/responses/ModeControllerTest.java | 2 +- .../QuestionnaireControllerTest.java | 20 ++-- .../responses/ResponseControllerTest.java | 2 +- .../controller/rest/responses/Utils.java | 30 ++--- .../sources/xml/LunaticXmlDataParserTest.java | 2 +- .../LunaticXmlDataSequentialParserTest.java | 2 +- .../controller/utils/DataVerifierTest.java | 36 +++--- .../model/surveyunit/SurveyUnitModelTest.java | 8 +- .../domain/service/SurveyUnitServiceTest.java | 108 +++++++++--------- .../SurveyUnitModelMongoAdapterTest.java | 6 +- .../ScheduleDocumentMapperImplTest.java | 12 +- .../SurveyUnitDocumentMapperImplTest.java | 36 +++--- 31 files changed, 231 insertions(+), 231 deletions(-) diff --git a/src/main/java/fr/insee/genesis/Constants.java b/src/main/java/fr/insee/genesis/Constants.java index f1711c2e..e074fe0c 100644 --- a/src/main/java/fr/insee/genesis/Constants.java +++ b/src/main/java/fr/insee/genesis/Constants.java @@ -4,7 +4,7 @@ public class Constants { public static final String XSLT_STRUCTURED_VARIABLES = "xslt/structured-variables.xsl"; public static final String ROOT_GROUP_NAME = "RACINE"; - public static final String ROOT_IDENTIFIER_NAME = "IdUE"; + public static final String ROOT_IDENTIFIER_NAME = "interrogationId"; public static final String METADATA_SEPARATOR = "."; public static final String DATE_REGEX = "(^([0-9]{4})[\\-\\/]([0-9]|1[0-2]|0[1-9])[\\-\\/]([0-9]|[0-2][0-9]|3[0-1])$)|" + "(^([0-9]|[0-2][0-9]|3[0-1])[\\-\\/]([0-9]|1[0-2]|0[1-9])[\\-\\/]([0-9]{4})$)"; diff --git a/src/main/java/fr/insee/genesis/controller/adapter/LunaticJsonAdapter.java b/src/main/java/fr/insee/genesis/controller/adapter/LunaticJsonAdapter.java index 8892594c..edded928 100644 --- a/src/main/java/fr/insee/genesis/controller/adapter/LunaticJsonAdapter.java +++ b/src/main/java/fr/insee/genesis/controller/adapter/LunaticJsonAdapter.java @@ -13,9 +13,9 @@ public class LunaticJsonAdapter { public SurveyUnitModel convert(LunaticJsonSurveyUnit su){ return SurveyUnitModel.builder() - .questionnaireId(su.getIdQuest()) + .questionnaireId(su.getQuestionnaireId()) .campaignId("") - .interrogationId(su.getIdUE()) + .interrogationId(su.getInterrogationId()) .state(DataState.COLLECTED) .mode(Mode.WEB) .recordDate(LocalDateTime.now()) diff --git a/src/main/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapter.java b/src/main/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapter.java index 203685e8..8c398c5a 100644 --- a/src/main/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapter.java +++ b/src/main/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapter.java @@ -24,34 +24,34 @@ public class LunaticXmlAdapter { * Convert a Lunatic XML survey unit into a genesis survey unit DTO * @param su Lunatic XML survey unit to convert * @param variablesMap variable definitions (used for loops) - * @param idCampaign survey id + * @param campaignId survey id * @return a genesis survey unit DTO */ - public static List convert(LunaticXmlSurveyUnit su, VariablesMap variablesMap, String idCampaign, Mode mode){ + public static List convert(LunaticXmlSurveyUnit su, VariablesMap variablesMap, String campaignId, Mode mode){ //Get COLLECTED Data and external variables List surveyUnitModelList = new ArrayList<>(); - SurveyUnitModel surveyUnitModel = getStateDataFromSurveyUnit(su, variablesMap, idCampaign, DataState.COLLECTED, mode); + SurveyUnitModel surveyUnitModel = getStateDataFromSurveyUnit(su, variablesMap, campaignId, DataState.COLLECTED, mode); getExternalDataFromSurveyUnit(su, surveyUnitModel); surveyUnitModelList.add(surveyUnitModel); //Get data from other states - SurveyUnitModel editedSurveyUnitModel = getStateDataFromSurveyUnit(su, variablesMap, idCampaign, DataState.EDITED,mode); + SurveyUnitModel editedSurveyUnitModel = getStateDataFromSurveyUnit(su, variablesMap, campaignId, DataState.EDITED,mode); if(editedSurveyUnitModel != null){ surveyUnitModelList.add(editedSurveyUnitModel); } - SurveyUnitModel inputedSurveyUnitModel = getStateDataFromSurveyUnit(su, variablesMap, idCampaign, DataState.INPUTED,mode); + SurveyUnitModel inputedSurveyUnitModel = getStateDataFromSurveyUnit(su, variablesMap, campaignId, DataState.INPUTED,mode); if(inputedSurveyUnitModel != null){ surveyUnitModelList.add(inputedSurveyUnitModel); } - SurveyUnitModel forcedSurveyUnitModel = getStateDataFromSurveyUnit(su, variablesMap, idCampaign, DataState.FORCED,mode); + SurveyUnitModel forcedSurveyUnitModel = getStateDataFromSurveyUnit(su, variablesMap, campaignId, DataState.FORCED,mode); if(forcedSurveyUnitModel != null){ surveyUnitModelList.add(forcedSurveyUnitModel); } - SurveyUnitModel previousSurveyUnitModel = getStateDataFromSurveyUnit(su, variablesMap, idCampaign, DataState.PREVIOUS,mode); + SurveyUnitModel previousSurveyUnitModel = getStateDataFromSurveyUnit(su, variablesMap, campaignId, DataState.PREVIOUS,mode); if(previousSurveyUnitModel != null){ surveyUnitModelList.add(previousSurveyUnitModel); } @@ -64,14 +64,14 @@ public static List convert(LunaticXmlSurveyUnit su, VariablesMa * Collects data from XML survey unit depending on the data state * @param su source XML Survey Unit * @param variablesMap variable definitions (used for loops) - * @param idCampaign survey id + * @param campaignId survey id * @param dataState state of the DTO to generate * @return Survey Unit DTO with a specific state */ - private static SurveyUnitModel getStateDataFromSurveyUnit(LunaticXmlSurveyUnit su, VariablesMap variablesMap, String idCampaign, DataState dataState, Mode mode) { + private static SurveyUnitModel getStateDataFromSurveyUnit(LunaticXmlSurveyUnit su, VariablesMap variablesMap, String campaignId, DataState dataState, Mode mode) { SurveyUnitModel surveyUnitModel = SurveyUnitModel.builder() .questionnaireId(su.getQuestionnaireModelId()) - .campaignId(idCampaign) + .campaignId(campaignId) .interrogationId(su.getId()) .state(dataState) .mode(mode) diff --git a/src/main/java/fr/insee/genesis/controller/dto/CampaignWithQuestionnaire.java b/src/main/java/fr/insee/genesis/controller/dto/CampaignWithQuestionnaire.java index 17fbeeed..b027afa4 100644 --- a/src/main/java/fr/insee/genesis/controller/dto/CampaignWithQuestionnaire.java +++ b/src/main/java/fr/insee/genesis/controller/dto/CampaignWithQuestionnaire.java @@ -10,6 +10,6 @@ @NoArgsConstructor @Getter public class CampaignWithQuestionnaire { - private String idCampaign; + private String campaignId; private Set questionnaires; } diff --git a/src/main/java/fr/insee/genesis/controller/dto/QuestionnaireWithCampaign.java b/src/main/java/fr/insee/genesis/controller/dto/QuestionnaireWithCampaign.java index f6095337..41815dc8 100644 --- a/src/main/java/fr/insee/genesis/controller/dto/QuestionnaireWithCampaign.java +++ b/src/main/java/fr/insee/genesis/controller/dto/QuestionnaireWithCampaign.java @@ -10,6 +10,6 @@ @NoArgsConstructor @Getter public class QuestionnaireWithCampaign { - private String idQuestionnaire; + private String questionnaireId; private Set campaigns; } diff --git a/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java b/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java index 65b9ca18..73641cc0 100644 --- a/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java +++ b/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java @@ -281,7 +281,7 @@ public ResponseEntity findResponsesByInterrogationAndQuestionnair public ResponseEntity findAllResponsesByQuestionnaire(@RequestParam("questionnaireId") String questionnaireId) { log.info("Try to find all responses of questionnaire : {}", questionnaireId); - //Get all IdUEs/modes of the survey + //Get all interrogationIds/modes of the survey List interrogationIdsResponses = surveyUnitService.findInterrogationIdsAndModesByQuestionnaireId(questionnaireId); log.info("Responses found : {}", interrogationIdsResponses.size()); @@ -526,7 +526,7 @@ private ResponseEntity processXmlFileWithMemory(Path filepath, Mode mode List suDtos = new ArrayList<>(); for (LunaticXmlSurveyUnit su : campaign.getSurveyUnits()) { - suDtos.addAll(LunaticXmlAdapter.convert(su, variablesMap, campaign.getIdCampaign(), modeSpecified)); + suDtos.addAll(LunaticXmlAdapter.convert(su, variablesMap, campaign.getCampaignId(), modeSpecified)); } surveyUnitQualityService.verifySurveyUnits(suDtos, variablesMap); @@ -571,7 +571,7 @@ private ResponseEntity processXmlFileSequentially(Path filepath, Mode mo LunaticXmlSurveyUnit su = parser.readNextSurveyUnit(); while (su != null) { - List suDtos = new ArrayList<>(LunaticXmlAdapter.convert(su, variablesMap, campaign.getIdCampaign(), modeSpecified)); + List suDtos = new ArrayList<>(LunaticXmlAdapter.convert(su, variablesMap, campaign.getCampaignId(), modeSpecified)); surveyUnitQualityService.verifySurveyUnits(suDtos, variablesMap); surveyUnitService.saveSurveyUnits(suDtos); diff --git a/src/main/java/fr/insee/genesis/controller/sources/json/LunaticJsonSurveyUnit.java b/src/main/java/fr/insee/genesis/controller/sources/json/LunaticJsonSurveyUnit.java index d9d7da98..a1d595b7 100644 --- a/src/main/java/fr/insee/genesis/controller/sources/json/LunaticJsonSurveyUnit.java +++ b/src/main/java/fr/insee/genesis/controller/sources/json/LunaticJsonSurveyUnit.java @@ -7,10 +7,10 @@ public class LunaticJsonSurveyUnit { @JsonProperty("Id") - private String idUE; + private String interrogationId; @JsonProperty("QuestionnaireModelId") - private String idQuest; + private String questionnaireId; @JsonProperty("Data") private LunaticJsonDataResponse dataResponse; diff --git a/src/main/java/fr/insee/genesis/controller/sources/xml/LunaticXmlCampaign.java b/src/main/java/fr/insee/genesis/controller/sources/xml/LunaticXmlCampaign.java index a9803eec..e54a0ebd 100644 --- a/src/main/java/fr/insee/genesis/controller/sources/xml/LunaticXmlCampaign.java +++ b/src/main/java/fr/insee/genesis/controller/sources/xml/LunaticXmlCampaign.java @@ -9,7 +9,7 @@ @Setter public class LunaticXmlCampaign { - private String idCampaign; + private String campaignId; private String label; private List surveyUnits; diff --git a/src/main/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataParser.java b/src/main/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataParser.java index a76e9b0d..1f303467 100644 --- a/src/main/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataParser.java +++ b/src/main/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataParser.java @@ -56,7 +56,7 @@ public LunaticXmlCampaign parseDataFile(Path filePath) throws GenesisException, log.debug("Begin to parse {} ", filePath); LunaticXmlCampaign campaign = new LunaticXmlCampaign(); Element root = document.getDocumentElement(); - campaign.setIdCampaign(root.getElementsByTagName("Id").item(0).getFirstChild().getNodeValue()); + campaign.setCampaignId(root.getElementsByTagName("Id").item(0).getFirstChild().getNodeValue()); if(root.getElementsByTagName("Label").item(0).getFirstChild() != null) campaign.setLabel(root.getElementsByTagName("Label").item(0).getFirstChild().getNodeValue()); else campaign.setLabel(""); diff --git a/src/main/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataSequentialParser.java b/src/main/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataSequentialParser.java index ed6c61a9..84409b14 100644 --- a/src/main/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataSequentialParser.java +++ b/src/main/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataSequentialParser.java @@ -57,7 +57,7 @@ public LunaticXmlCampaign getCampaign() throws XMLStreamException { switch (elementName){ case Constants.CAMPAIGN_ID_ELEMENT_NAME: - campaign.setIdCampaign(reader.getElementText()); + campaign.setCampaignId(reader.getElementText()); break; case Constants.CAMPAIGN_LABEL_ELEMENT_NAME: campaign.setLabel(reader.getElementText()); diff --git a/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java b/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java index 39781d92..4e0f8f2b 100644 --- a/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java +++ b/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java @@ -47,18 +47,18 @@ private DataVerifier() { public static void verifySurveyUnits(List suDtosList, VariablesMap variablesMap){ List suDtosListForced = new ArrayList<>(); // Created FORCED SU DTOs - for(String idUE : getIdUEs(suDtosList)) { // For each id of the list - List srcSuDtosOfIdUE = suDtosList.stream().filter(element -> element.getInterrogationId().equals(idUE)).toList(); + for(String interrogationId : getInterrogationIds(suDtosList)) { // For each id of the list + List srcSuDtosOfInterrogationId = suDtosList.stream().filter(element -> element.getInterrogationId().equals(interrogationId)).toList(); List correctedCollectedVariables = new ArrayList<>(); List correctedExternalVariables = new ArrayList<>(); //Get corrected variables - collectedVariablesManagement(srcSuDtosOfIdUE, variablesMap, correctedCollectedVariables); - externalVariablesManagement(srcSuDtosOfIdUE, variablesMap, correctedExternalVariables); + collectedVariablesManagement(srcSuDtosOfInterrogationId, variablesMap, correctedCollectedVariables); + externalVariablesManagement(srcSuDtosOfInterrogationId, variablesMap, correctedExternalVariables); //Create FORCED if any corrected variable if(!correctedCollectedVariables.isEmpty() || !correctedExternalVariables.isEmpty()){ - SurveyUnitModel newForcedSuDto = createForcedDto(suDtosList, idUE, correctedCollectedVariables, correctedExternalVariables); + SurveyUnitModel newForcedSuDto = createForcedDto(suDtosList, interrogationId, correctedCollectedVariables, correctedExternalVariables); suDtosListForced.add(newForcedSuDto); } } @@ -67,15 +67,15 @@ public static void verifySurveyUnits(List suDtosList, Variables private static SurveyUnitModel createForcedDto( List suDtosList, - String idUE, + String interrogationId, List correctedCollectedVariables, List correctedExternalVariables ) { - SurveyUnitModel sampleSuDto = suDtosList.stream().filter(element -> element.getInterrogationId().equals(idUE)).toList().getFirst(); + SurveyUnitModel sampleSuDto = suDtosList.stream().filter(element -> element.getInterrogationId().equals(interrogationId)).toList().getFirst(); SurveyUnitModel newForcedSuDto = SurveyUnitModel.builder() .questionnaireId(sampleSuDto.getQuestionnaireId()) .campaignId(sampleSuDto.getCampaignId()) - .interrogationId(idUE) + .interrogationId(interrogationId) .state(DataState.FORCED) .mode(sampleSuDto.getMode()) .recordDate(LocalDateTime.now()) @@ -106,32 +106,32 @@ private static SurveyUnitModel createForcedDto( } /** - * Fetch individual IdUEs of variable from the list + * Fetch individual interrogationIds of variable from the list * @param suDtosList source list - * @return a set of IdUEs + * @return a set of interrogationIds */ - private static Set getIdUEs(List suDtosList) { - Set idUEs = new HashSet<>(); + private static Set getInterrogationIds(List suDtosList) { + Set interrogationIds = new HashSet<>(); for(SurveyUnitModel surveyUnitModel : suDtosList){ - idUEs.add(surveyUnitModel.getInterrogationId()); + interrogationIds.add(surveyUnitModel.getInterrogationId()); } - return idUEs; + return interrogationIds; } /** * Adds the collected variables for the FORCED document - * @param srcSuDtosOfIdUE source Survey Unit documents associated with IdUE + * @param srcSuDtosOfInterrogationId source Survey Unit documents associated with InterrogationId * @param variablesMap variables definitions * @param correctedCollectedVariables FORCED document variables */ - private static void collectedVariablesManagement(List srcSuDtosOfIdUE, VariablesMap variablesMap, List correctedCollectedVariables){ + private static void collectedVariablesManagement(List srcSuDtosOfInterrogationId, VariablesMap variablesMap, List correctedCollectedVariables){ Set variableNames = new HashSet<>(); List variablesToVerify = new ArrayList<>(); //Sort from more priority to less - List sortedSuDtos = srcSuDtosOfIdUE.stream().sorted(Comparator.comparing(surveyUnitDto -> dataStatesPriority.get(surveyUnitDto.getState()))).toList(); + List sortedSuDtos = srcSuDtosOfInterrogationId.stream().sorted(Comparator.comparing(surveyUnitDto -> dataStatesPriority.get(surveyUnitDto.getState()))).toList(); //Get more priority variables to verify for(SurveyUnitModel srcSuDto : sortedSuDtos){ @@ -180,9 +180,9 @@ private static CollectedVariable verifyCollectedVariable(CollectedVariable colle ) : null; } - private static void externalVariablesManagement(List srcSuDtosOfIdUE, VariablesMap variablesMap, List correctedExternalVariables) { + private static void externalVariablesManagement(List srcSuDtosOfInterrogationId, VariablesMap variablesMap, List correctedExternalVariables) { //COLLECTED only - Optional collectedSuDtoOpt = srcSuDtosOfIdUE.stream().filter( + Optional collectedSuDtoOpt = srcSuDtosOfInterrogationId.stream().filter( suDto -> suDto.getState().equals(DataState.COLLECTED) ).findFirst(); diff --git a/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/SurveyUnitDocument.java b/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/SurveyUnitDocument.java index 16417b02..b569aad1 100644 --- a/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/SurveyUnitDocument.java +++ b/src/main/java/fr/insee/genesis/infrastructure/document/surveyunit/SurveyUnitDocument.java @@ -10,9 +10,9 @@ @Data @Document(collection = Constants.MONGODB_RESPONSE_COLLECTION_NAME) -@CompoundIndex(name = "idCampaign_1_idQuestionnaire_1", def = "{'idCampaign': 1, 'idQuestionnaire': 1}") //1 = ascending, -1 = descending -@CompoundIndex(name = "idQuestionnaire_1_idCampaign_1", def = "{'idQuestionnaire': 1, 'idCampaign': 1}") -@CompoundIndex(name = "idQuestionnaire_1_idUE_1", def = "{'idQuestionnaire': 1, 'idUE': 1}") +@CompoundIndex(name = "campaignId_1_questionnaireId_1", def = "{'campaignId': 1, 'questionnaireId': 1}") //1 = ascending, -1 = descending +@CompoundIndex(name = "questionnaireId_1_campaignId_1", def = "{'questionnaireId': 1, 'campaignId': 1}") +@CompoundIndex(name = "questionnaireId_1_interrogationId_1", def = "{'questionnaireId': 1, 'interrogationId': 1}") public class SurveyUnitDocument { private String campaignId; private String interrogationId; diff --git a/src/test/java/cucumber/functional_tests/MainDefinitions.java b/src/test/java/cucumber/functional_tests/MainDefinitions.java index 82557cda..8e860318 100644 --- a/src/test/java/cucumber/functional_tests/MainDefinitions.java +++ b/src/test/java/cucumber/functional_tests/MainDefinitions.java @@ -93,7 +93,7 @@ public void get_dtos(String fileName, String ddiName) throws IOException, Parser ).getVariables(); List suDtos = new ArrayList<>(); for (LunaticXmlSurveyUnit su : campaign.getSurveyUnits()) { - suDtos.addAll(LunaticXmlAdapter.convert(su, variablesMap, campaign.getIdCampaign(), Mode.WEB)); + suDtos.addAll(LunaticXmlAdapter.convert(su, variablesMap, campaign.getCampaignId(), Mode.WEB)); } surveyUnitQualityService.verifySurveyUnits(suDtos,variablesMap); surveyUnitModels = suDtos; diff --git a/src/test/java/fr/insee/genesis/TestConstants.java b/src/test/java/fr/insee/genesis/TestConstants.java index 88892875..4faa5407 100644 --- a/src/test/java/fr/insee/genesis/TestConstants.java +++ b/src/test/java/fr/insee/genesis/TestConstants.java @@ -8,6 +8,6 @@ public class TestConstants { public static final String TEST_RESOURCES_DIRECTORY = "src/test/resources"; public static final String UNIT_TESTS_DDI_DIRECTORY = TEST_RESOURCES_DIRECTORY + "/specs"; - public static final String DEFAULT_INTERROGATION_ID = "TESTIDUE"; - public static final String DEFAULT_QUESTIONNAIRE_ID = "TESTIDQUESTIONNAIRE"; + public static final String DEFAULT_INTERROGATION_ID = "TESTINTERROGATIONID"; + public static final String DEFAULT_QUESTIONNAIRE_ID = "TESTQUESTIONNAIREID"; } diff --git a/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java b/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java index eb71fd69..86af65a8 100644 --- a/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java +++ b/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java @@ -52,8 +52,8 @@ void setUp() { lunaticXmlData.setCollected(collected); List external = List.of(); lunaticXmlData.setExternal(external); - lunaticXmlSurveyUnit1.setId("idUE1"); - lunaticXmlSurveyUnit1.setQuestionnaireModelId("idQuest1"); + lunaticXmlSurveyUnit1.setId("interrogationId1"); + lunaticXmlSurveyUnit1.setQuestionnaireModelId("questionnaireId1"); lunaticXmlSurveyUnit1.setData(lunaticXmlData); //SurveyUnit 2 : COLLECTED + EDITED @@ -71,8 +71,8 @@ void setUp() { lunaticXmlData.setCollected(collected); lunaticXmlData.setExternal(external); - lunaticXmlSurveyUnit2.setId("idUE1"); - lunaticXmlSurveyUnit2.setQuestionnaireModelId("idQuest1"); + lunaticXmlSurveyUnit2.setId("interrogationId1"); + lunaticXmlSurveyUnit2.setQuestionnaireModelId("questionnaireId1"); lunaticXmlSurveyUnit2.setData(lunaticXmlData); //SurveyUnit 3 : COLLECTED + EDITED + FORCED @@ -91,8 +91,8 @@ void setUp() { lunaticXmlData.setCollected(collected); lunaticXmlData.setExternal(external); - lunaticXmlSurveyUnit3.setId("idUE1"); - lunaticXmlSurveyUnit3.setQuestionnaireModelId("idQuest1"); + lunaticXmlSurveyUnit3.setId("interrogationId1"); + lunaticXmlSurveyUnit3.setQuestionnaireModelId("questionnaireId1"); lunaticXmlSurveyUnit3.setData(lunaticXmlData); //SurveyUnit 4 : COLLECTED + EDITED + PREVIOUS @@ -111,8 +111,8 @@ void setUp() { lunaticXmlData.setCollected(collected); lunaticXmlData.setExternal(external); - lunaticXmlSurveyUnit4.setId("idUE1"); - lunaticXmlSurveyUnit4.setQuestionnaireModelId("idQuest1"); + lunaticXmlSurveyUnit4.setId("interrogationId1"); + lunaticXmlSurveyUnit4.setQuestionnaireModelId("questionnaireId1"); lunaticXmlSurveyUnit4.setData(lunaticXmlData); //SurveyUnit 5 : COLLECTED + EDITED + PREVIOUS + INPUTED @@ -132,8 +132,8 @@ void setUp() { lunaticXmlData.setCollected(collected); lunaticXmlData.setExternal(external); - lunaticXmlSurveyUnit5.setId("idUE1"); - lunaticXmlSurveyUnit5.setQuestionnaireModelId("idQuest1"); + lunaticXmlSurveyUnit5.setId("interrogationId1"); + lunaticXmlSurveyUnit5.setQuestionnaireModelId("questionnaireId1"); lunaticXmlSurveyUnit5.setData(lunaticXmlData); //SurveyUnit 6 : COLLECTED only, has one unknown variable @@ -152,8 +152,8 @@ void setUp() { lunaticXmlData.setCollected(collected); lunaticXmlData.setExternal(external); - lunaticXmlSurveyUnit6.setId("idUE1"); - lunaticXmlSurveyUnit6.setQuestionnaireModelId("idQuest1"); + lunaticXmlSurveyUnit6.setId("interrogationId1"); + lunaticXmlSurveyUnit6.setQuestionnaireModelId("questionnaireId1"); lunaticXmlSurveyUnit6.setData(lunaticXmlData); //SurveyUnit 7 : COLLECTED only, has one unknown variable with known variable prefix @@ -171,8 +171,8 @@ void setUp() { lunaticXmlData.setCollected(collected); lunaticXmlData.setExternal(external); - lunaticXmlSurveyUnit7.setId("idUE1"); - lunaticXmlSurveyUnit7.setQuestionnaireModelId("idQuest1"); + lunaticXmlSurveyUnit7.setId("interrogationId1"); + lunaticXmlSurveyUnit7.setQuestionnaireModelId("questionnaireId1"); lunaticXmlSurveyUnit7.setData(lunaticXmlData); //SurveyUnit 8 : Only collected data @@ -187,8 +187,8 @@ void setUp() { lunaticXmlData.setCollected(collected); external = List.of(); lunaticXmlData.setExternal(external); - lunaticXmlSurveyUnit8.setId("idUE1"); - lunaticXmlSurveyUnit8.setQuestionnaireModelId("idQuest1"); + lunaticXmlSurveyUnit8.setId("interrogationId1"); + lunaticXmlSurveyUnit8.setQuestionnaireModelId("questionnaireId1"); lunaticXmlSurveyUnit8.setData(lunaticXmlData); //VariablesMap @@ -209,12 +209,12 @@ void test01() { } @Test - @DisplayName("SurveyUnitDto should have the right idQuest") + @DisplayName("SurveyUnitDto should have the right questionnaireId") void test02() { // When List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit1, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos.getFirst().getQuestionnaireId()).isEqualTo("idQuest1"); + Assertions.assertThat(suDtos.getFirst().getQuestionnaireId()).isEqualTo("questionnaireId1"); } @Test @@ -223,7 +223,7 @@ void test03() { // When List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit1, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos.getFirst().getInterrogationId()).isEqualTo("idUE1"); + Assertions.assertThat(suDtos.getFirst().getInterrogationId()).isEqualTo("interrogationId1"); } @Test diff --git a/src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.java index b52f615a..1807e149 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/HealthCheckControllerTest.java @@ -38,10 +38,10 @@ static void init() { CollectedVariable collectedVariable = new CollectedVariable("TESTIDVAR", List.of(new String[]{"V1", "V2"}), "TESTIDLOOP", "TESTIDPARENT"); collectedVariableList.add(collectedVariable); surveyUnitPersistencePortStub.getMongoStub().add(SurveyUnitModel.builder() - .campaignId("TESTIDCAMPAIGN") + .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId("TESTIDUE") - .questionnaireId("TESTIDQUESTIONNAIRE") + .interrogationId("TESTINTERROGATIONID") + .questionnaireId("TESTQUESTIONNAIREID") .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023, 1, 1, 0, 0, 0)) .recordDate(LocalDateTime.of(2024, 1, 1, 0, 0, 0)) diff --git a/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java index c412d319..38207290 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/UtilsControllerTest.java @@ -38,8 +38,8 @@ class UtilsControllerTest { static List interrogationIdList; //Constants - static final String defaultIdUE = "TESTIDUE"; - static final String defaultIdQuest = "TESTIDQUESTIONNAIRE"; + static final String defaultInterrogationId = "TESTINTERROGATIONID"; + static final String defaultQuestionnaireId = "TESTQUESTIONNAIREID"; @BeforeAll static void init() { @@ -52,7 +52,7 @@ static void init() { ); interrogationIdList = new ArrayList<>(); - interrogationIdList.add(new InterrogationId(defaultIdUE)); + interrogationIdList.add(new InterrogationId(defaultInterrogationId)); } @BeforeEach @@ -68,10 +68,10 @@ void reset() throws IOException { CollectedVariable collectedVariable = new CollectedVariable("TESTIDVAR", List.of(new String[]{"V1", "V2"}), "TESTIDLOOP", "TESTIDPARENT"); collectedVariableList.add(collectedVariable); surveyUnitPersistencePortStub.getMongoStub().add(SurveyUnitModel.builder() - .campaignId("TESTIDCAMPAIGN") + .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId(defaultIdUE) - .questionnaireId(defaultIdQuest) + .interrogationId(defaultInterrogationId) + .questionnaireId(defaultQuestionnaireId) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023, 1, 1, 0, 0, 0)) .recordDate(LocalDateTime.of(2024, 1, 1, 0, 0, 0)) @@ -243,7 +243,7 @@ void saveVolumetryTest() throws IOException { .resolve(LocalDate.now().format(DateTimeFormatter.ofPattern(Constants.VOLUMETRY_FILE_DATE_FORMAT)) + Constants.VOLUMETRY_FILE_SUFFIX + ".csv"); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); - Assertions.assertThat(logFilePath).exists().content().isNotEmpty().contains("TESTIDCAMPAIGN;1"); + Assertions.assertThat(logFilePath).exists().content().isNotEmpty().contains("TESTCAMPAIGNID;1"); //CLEAN Files.deleteIfExists(logFilePath); @@ -262,7 +262,7 @@ void saveVolumetryTest_overwrite() throws IOException { .resolve(LocalDate.now().format(DateTimeFormatter.ofPattern(Constants.VOLUMETRY_FILE_DATE_FORMAT)) + Constants.VOLUMETRY_FILE_SUFFIX + ".csv"); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); - Assertions.assertThat(logFilePath).exists().content().isNotEmpty().contains("TESTIDCAMPAIGN;1").doesNotContain("TESTIDCAMPAIGN;1\nTESTIDCAMPAIGN;1"); + Assertions.assertThat(logFilePath).exists().content().isNotEmpty().contains("TESTCAMPAIGNID;1").doesNotContain("TESTCAMPAIGNID;1\nTESTCAMPAIGNID;1"); //CLEAN Files.deleteIfExists(logFilePath); @@ -271,7 +271,7 @@ void saveVolumetryTest_overwrite() throws IOException { @Test void saveVolumetryTest_additionnal_campaign() throws IOException { //Given - addAdditionalDtoToMongoStub("TESTIDCAMPAIGN2","TESTQUEST2"); + addAdditionalDtoToMongoStub("TESTCAMPAIGNID2","TESTQUEST2"); //WHEN ResponseEntity response = utilsControllerStatic.saveVolumetry(); @@ -283,7 +283,7 @@ void saveVolumetryTest_additionnal_campaign() throws IOException { .resolve(LocalDate.now().format(DateTimeFormatter.ofPattern(Constants.VOLUMETRY_FILE_DATE_FORMAT)) + Constants.VOLUMETRY_FILE_SUFFIX + ".csv"); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); - Assertions.assertThat(logFilePath).exists().content().isNotEmpty().contains("TESTIDCAMPAIGN;1").contains("TESTIDCAMPAIGN2;1"); + Assertions.assertThat(logFilePath).exists().content().isNotEmpty().contains("TESTCAMPAIGNID;1").contains("TESTCAMPAIGNID2;1"); //CLEAN Files.deleteIfExists(logFilePath); @@ -292,7 +292,7 @@ void saveVolumetryTest_additionnal_campaign() throws IOException { void saveVolumetryTest_additionnal_campaign_and_document() throws IOException { //Given addAdditionalDtoToMongoStub("TESTQUEST"); - addAdditionalDtoToMongoStub("TESTIDCAMPAIGN2","TESTQUEST2"); + addAdditionalDtoToMongoStub("TESTCAMPAIGNID2","TESTQUEST2"); //WHEN ResponseEntity response = utilsControllerStatic.saveVolumetry(); @@ -304,7 +304,7 @@ void saveVolumetryTest_additionnal_campaign_and_document() throws IOException { .resolve(LocalDate.now().format(DateTimeFormatter.ofPattern(Constants.VOLUMETRY_FILE_DATE_FORMAT)) + Constants.VOLUMETRY_FILE_SUFFIX + ".csv"); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); - Assertions.assertThat(logFilePath).exists().content().isNotEmpty().contains("TESTIDCAMPAIGN;2").contains("TESTIDCAMPAIGN2;1"); + Assertions.assertThat(logFilePath).exists().content().isNotEmpty().contains("TESTCAMPAIGNID;2").contains("TESTCAMPAIGNID2;1"); //CLEAN Files.deleteIfExists(logFilePath); @@ -342,11 +342,11 @@ void cleanOldVolumetryLogFiles() throws IOException { // Utilities - private void addAdditionalDtoToMongoStub(String idQuestionnaire) { - addAdditionalDtoToMongoStub("TESTIDCAMPAIGN",idQuestionnaire); + private void addAdditionalDtoToMongoStub(String questionnaireId) { + addAdditionalDtoToMongoStub("TESTCAMPAIGNID",questionnaireId); } - private void addAdditionalDtoToMongoStub(String idCampaign, String idQuestionnaire) { + private void addAdditionalDtoToMongoStub(String campaignId, String questionnaireId) { List externalVariableList = new ArrayList<>(); Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); externalVariableList.add(variable); @@ -356,10 +356,10 @@ private void addAdditionalDtoToMongoStub(String idCampaign, String idQuestionnai collectedVariableList.add(collectedVariable); SurveyUnitModel recentDTO = SurveyUnitModel.builder() - .campaignId(idCampaign) + .campaignId(campaignId) .mode(Mode.WEB) - .interrogationId(defaultIdUE) - .questionnaireId(idQuestionnaire) + .interrogationId(defaultInterrogationId) + .questionnaireId(questionnaireId) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023, 2, 2, 0, 0, 0)) .recordDate(LocalDateTime.of(2024, 2, 2, 0, 0, 0)) diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/CampaignControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/CampaignControllerTest.java index 94180008..c16366a8 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/CampaignControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/CampaignControllerTest.java @@ -20,8 +20,8 @@ class CampaignControllerTest { static SurveyUnitPersistencePortStub surveyUnitPersistencePortStub; //Constants - static final String defaultIdUE = "TESTIDUE"; - static final String defaultIdQuest = "TESTIDQUESTIONNAIRE"; + static final String DEFAULT_INTERROGATION_ID = "TESTINTERROGATIONID"; + static final String DEFAULT_ID_QUEST = "TESTQUESTIONNAIREID"; @BeforeAll static void init() { @@ -47,8 +47,8 @@ void getCampaignsTest() { ResponseEntity> response = campaignControllerStatic.getCampaigns(); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); - Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty().containsExactly( - "TESTIDCAMPAIGN","TESTCAMPAIGN2"); + Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty().containsOnly( + "TESTCAMPAIGNID","TESTCAMPAIGN2"); } @Test @@ -61,17 +61,17 @@ void getCampaignsWithQuestionnairesTest() { Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty(); Assertions.assertThat(response.getBody().stream().filter(campaignWithQuestionnaire -> - campaignWithQuestionnaire.getIdCampaign().equals("TESTIDCAMPAIGN") - || campaignWithQuestionnaire.getIdCampaign().equals("TESTCAMPAIGN2") + campaignWithQuestionnaire.getCampaignId().equals("TESTCAMPAIGNID") + || campaignWithQuestionnaire.getCampaignId().equals("TESTCAMPAIGN2") )).isNotNull().isNotEmpty().hasSize(2); Assertions.assertThat(response.getBody().stream().filter( - campaignWithQuestionnaire -> campaignWithQuestionnaire.getIdCampaign().equals("TESTIDCAMPAIGN") - ).findFirst().get().getQuestionnaires()).containsExactly(defaultIdQuest, "TESTQUESTIONNAIRE2"); + campaignWithQuestionnaire -> campaignWithQuestionnaire.getCampaignId().equals("TESTCAMPAIGNID") + ).findFirst().get().getQuestionnaires()).containsOnly(DEFAULT_ID_QUEST, "TESTQUESTIONNAIRE2"); Assertions.assertThat(response.getBody().stream().filter( - campaignWithQuestionnaire -> campaignWithQuestionnaire.getIdCampaign().equals("TESTCAMPAIGN2") - ).findFirst().get().getQuestionnaires()).containsExactly("TESTQUESTIONNAIRE2"); + campaignWithQuestionnaire -> campaignWithQuestionnaire.getCampaignId().equals("TESTCAMPAIGN2") + ).findFirst().get().getQuestionnaires()).containsOnly("TESTQUESTIONNAIRE2"); } } diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/InterrogationControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/InterrogationControllerTest.java index d731e939..bd75dbab 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/InterrogationControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/InterrogationControllerTest.java @@ -38,7 +38,7 @@ void reset() throws IOException { //When + Then @Test - void getAllIdUEsByQuestionnaireTest() { + void getAllInterrogationIdsByQuestionnaireTest() { ResponseEntity> response = interrogationControllerStatic.getAllInterrogationIdsByQuestionnaire(DEFAULT_QUESTIONNAIRE_ID); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/ModeControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/ModeControllerTest.java index 914e91c7..aca7ca46 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/ModeControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/ModeControllerTest.java @@ -47,7 +47,7 @@ void getModesByQuestionnaireTest() { @Test void getModesByCampaignTest() { - ResponseEntity> response = modeControllerStatic.getModesByCampaign("TESTIDCAMPAIGN"); + ResponseEntity> response = modeControllerStatic.getModesByCampaign("TESTCAMPAIGNID"); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty().hasSize(1); diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/QuestionnaireControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/QuestionnaireControllerTest.java index fb89a31f..88790b58 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/QuestionnaireControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/QuestionnaireControllerTest.java @@ -26,7 +26,7 @@ static void init() { surveyUnitPersistencePortStub = new SurveyUnitPersistencePortStub(); SurveyUnitApiPort surveyUnitApiPort = new SurveyUnitService(surveyUnitPersistencePortStub); - questionnaireControllerStatic = new QuestionnaireController(surveyUnitApiPort ); + questionnaireControllerStatic = new QuestionnaireController(surveyUnitApiPort); } @@ -45,7 +45,7 @@ void getQuestionnairesTest() { ResponseEntity> response = questionnaireControllerStatic.getQuestionnaires(); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); - Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty().containsExactly( + Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty().containsOnly( DEFAULT_QUESTIONNAIRE_ID,"TESTQUESTIONNAIRE2"); } @@ -53,10 +53,10 @@ void getQuestionnairesTest() { void getQuestionnairesByCampaignTest() { Utils.addAdditionalDtoToMongoStub("TESTQUESTIONNAIRE2", surveyUnitPersistencePortStub); - ResponseEntity> response = questionnaireControllerStatic.getQuestionnairesByCampaign("TESTIDCAMPAIGN"); + ResponseEntity> response = questionnaireControllerStatic.getQuestionnairesByCampaign("TESTCAMPAIGNID"); Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); - Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty().containsExactly( + Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty().containsOnly( DEFAULT_QUESTIONNAIRE_ID,"TESTQUESTIONNAIRE2"); } @@ -73,17 +73,17 @@ void getQuestionnairesWithCampaignsTest() { Assertions.assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); Assertions.assertThat(response.getBody()).isNotNull().isNotEmpty(); Assertions.assertThat(response.getBody().stream().filter(questionnaireWithCampaign -> - questionnaireWithCampaign.getIdQuestionnaire().equals(DEFAULT_QUESTIONNAIRE_ID) - || questionnaireWithCampaign.getIdQuestionnaire().equals("TESTQUESTIONNAIRE2") + questionnaireWithCampaign.getQuestionnaireId().equals(DEFAULT_QUESTIONNAIRE_ID) + || questionnaireWithCampaign.getQuestionnaireId().equals("TESTQUESTIONNAIRE2") )).isNotNull().isNotEmpty().hasSize(2); Assertions.assertThat(response.getBody().stream().filter( - questionnaireWithCampaign -> questionnaireWithCampaign.getIdQuestionnaire().equals(DEFAULT_QUESTIONNAIRE_ID) - ).findFirst().get().getCampaigns()).containsExactly("TESTIDCAMPAIGN"); + questionnaireWithCampaign -> questionnaireWithCampaign.getQuestionnaireId().equals(DEFAULT_QUESTIONNAIRE_ID) + ).findFirst().get().getCampaigns()).containsExactly("TESTCAMPAIGNID"); Assertions.assertThat(response.getBody().stream().filter( - questionnaireWithCampaign -> questionnaireWithCampaign.getIdQuestionnaire().equals("TESTQUESTIONNAIRE2") - ).findFirst().get().getCampaigns()).containsExactly("TESTIDCAMPAIGN", "TESTCAMPAIGN2"); + questionnaireWithCampaign -> questionnaireWithCampaign.getQuestionnaireId().equals("TESTQUESTIONNAIRE2") + ).findFirst().get().getCampaigns()).containsExactly("TESTCAMPAIGNID", "TESTCAMPAIGN2"); } } diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java index e9fb7672..c7e7edc9 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java @@ -230,7 +230,7 @@ void getAllResponsesByQuestionnaireTestSequential() throws IOException { surveyUnitPersistencePortStub.getMongoStub().clear(); for (int i = 0; i < Constants.BATCH_SIZE + 2; i++) { - Utils.addAdditionalDtoToMongoStub("TESTIDCAMPAIGN", DEFAULT_INTERROGATION_ID + i, + Utils.addAdditionalDtoToMongoStub("TESTCAMPAIGNID", DEFAULT_INTERROGATION_ID + i, LocalDateTime.of(2023, 1, 1, 0, 0, 0), LocalDateTime.of(2024, 1, 1, 0, 0, 0), surveyUnitPersistencePortStub); diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/Utils.java b/src/test/java/fr/insee/genesis/controller/rest/responses/Utils.java index a3c76fed..d173b5fa 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/Utils.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/Utils.java @@ -21,14 +21,14 @@ class Utils { //Constants - static final String defaultIdUE = "TESTIDUE"; - static final String defaultIdQuest = "TESTIDQUESTIONNAIRE"; + static final String DEFAULT_INTERROGATION_ID = "TESTINTERROGATIONID"; + static final String DEFAULT_ID_QUEST = "TESTQUESTIONNAIREID"; static void reset(SurveyUnitPersistencePortStub surveyUnitPersistencePortStub) throws IOException { //MongoDB stub management surveyUnitPersistencePortStub.getMongoStub().clear(); - addAdditionalDtoToMongoStub("TESTIDCAMPAIGN", defaultIdQuest , + addAdditionalDtoToMongoStub("TESTCAMPAIGNID", DEFAULT_ID_QUEST, LocalDateTime.of(2023, 1, 1, 0, 0, 0), LocalDateTime.of(2024, 1, 1, 0, 0, 0), surveyUnitPersistencePortStub); @@ -167,21 +167,21 @@ static void reset(SurveyUnitPersistencePortStub surveyUnitPersistencePortStub) t } static void addAdditionalDtoToMongoStub(SurveyUnitPersistencePortStub surveyUnitPersistencePortStub) { - addAdditionalDtoToMongoStub(defaultIdQuest, surveyUnitPersistencePortStub); + addAdditionalDtoToMongoStub(DEFAULT_ID_QUEST, surveyUnitPersistencePortStub); } - static void addAdditionalDtoToMongoStub(String idQuestionnaire, SurveyUnitPersistencePortStub surveyUnitPersistencePortStub) { - addAdditionalDtoToMongoStub("TESTIDCAMPAIGN",idQuestionnaire, surveyUnitPersistencePortStub); + static void addAdditionalDtoToMongoStub(String questionnaireId, SurveyUnitPersistencePortStub surveyUnitPersistencePortStub) { + addAdditionalDtoToMongoStub("TESTCAMPAIGNID",questionnaireId, surveyUnitPersistencePortStub); } - static void addAdditionalDtoToMongoStub(String idCampaign, String idQuestionnaire, SurveyUnitPersistencePortStub surveyUnitPersistencePortStub) { - addAdditionalDtoToMongoStub(idCampaign,idQuestionnaire, + static void addAdditionalDtoToMongoStub(String campaignId, String questionnaireId, SurveyUnitPersistencePortStub surveyUnitPersistencePortStub) { + addAdditionalDtoToMongoStub(campaignId,questionnaireId, LocalDateTime.of(2023, 2, 2, 0, 0, 0), LocalDateTime.of(2024, 2, 2, 0, 0, 0), surveyUnitPersistencePortStub); } - static void addAdditionalDtoToMongoStub(String idCampaign, String idQuestionnaire, + static void addAdditionalDtoToMongoStub(String campaignId, String questionnaireId, LocalDateTime fileDate, LocalDateTime recordDate, SurveyUnitPersistencePortStub surveyUnitPersistencePortStub) { List externalVariableList = new ArrayList<>(); @@ -193,10 +193,10 @@ static void addAdditionalDtoToMongoStub(String idCampaign, String idQuestionnair collectedVariableList.add(collectedVariable); SurveyUnitModel recentDTO = SurveyUnitModel.builder() - .campaignId(idCampaign) + .campaignId(campaignId) .mode(Mode.WEB) - .interrogationId(defaultIdUE) - .questionnaireId(idQuestionnaire) + .interrogationId(DEFAULT_INTERROGATION_ID) + .questionnaireId(questionnaireId) .state(DataState.COLLECTED) .fileDate(fileDate) .recordDate(recordDate) @@ -223,10 +223,10 @@ static void addAdditionalDtoToMongoStub(DataState state, collectedVariableList.add(collectedVariable); SurveyUnitModel recentDTO = SurveyUnitModel.builder() - .campaignId("TESTIDCAMPAIGN") + .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId(defaultIdUE) - .questionnaireId(defaultIdQuest) + .interrogationId(DEFAULT_INTERROGATION_ID) + .questionnaireId(DEFAULT_ID_QUEST) .state(state) .fileDate(fileDate) .recordDate(recordDate) diff --git a/src/test/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataParserTest.java b/src/test/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataParserTest.java index 33775160..352f62ae 100644 --- a/src/test/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataParserTest.java +++ b/src/test/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataParserTest.java @@ -20,7 +20,7 @@ static void setUp() throws Exception { @Test void campaignHasGoodLabelAndId() { Assertions.assertThat(campaign.getLabel()).isEqualTo("Enquête Test Unitaire"); - Assertions.assertThat(campaign.getIdCampaign()).isEqualTo("TEST2023X01"); + Assertions.assertThat(campaign.getCampaignId()).isEqualTo("TEST2023X01"); } @Test diff --git a/src/test/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataSequentialParserTest.java b/src/test/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataSequentialParserTest.java index d23518e0..a13cb2fe 100644 --- a/src/test/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataSequentialParserTest.java +++ b/src/test/java/fr/insee/genesis/controller/sources/xml/LunaticXmlDataSequentialParserTest.java @@ -35,7 +35,7 @@ static void setUp() throws Exception { @Test void campaignHasGoodLabelAndId() { Assertions.assertThat(campaign.getLabel()).isEqualTo("Enquête Test Unitaire"); - Assertions.assertThat(campaign.getIdCampaign()).isEqualTo("TEST2023X01"); + Assertions.assertThat(campaign.getCampaignId()).isEqualTo("TEST2023X01"); } @Test diff --git a/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java b/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java index b38b4da7..751ecb64 100644 --- a/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java +++ b/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java @@ -130,7 +130,7 @@ static void setUp() { DataVerifier.verifySurveyUnits(testSurveyUnitModels,metadataModel.getVariables()); } - private static void createCase(int variableNumber, int stateNumber, int valueNumber, boolean hasIncorrectValues, boolean hasExternalVariables, String idUE, List testSurveyUnitModels, VariablesMap variablesMap) { + private static void createCase(int variableNumber, int stateNumber, int valueNumber, boolean hasIncorrectValues, boolean hasExternalVariables, String interrogationId, List testSurveyUnitModels, VariablesMap variablesMap) { for(int stateIndex = 0; stateIndex < stateNumber; stateIndex++){ List variableUpdates = new ArrayList<>(); List externalVariables = new ArrayList<>(); @@ -165,9 +165,9 @@ private static void createCase(int variableNumber, int stateNumber, int valueNum } SurveyUnitModel surveyUnitModel = SurveyUnitModel.builder() - .questionnaireId("IdQuest1") + .questionnaireId("QuestionnaireId1") .campaignId("IdCampaign1") - .interrogationId(idUE) + .interrogationId(interrogationId) .state(stateIndex % 2 == 0 ? DataState.COLLECTED : DataState.EDITED) .mode(Mode.WEB) .recordDate(LocalDateTime.now()) @@ -184,24 +184,24 @@ private static void createCase(int variableNumber, int stateNumber, int valueNum //Then //Assertions - private void assertForcedExistence(List testSurveyUnitModels, String idUE, boolean hasToExist) { + private void assertForcedExistence(List testSurveyUnitModels, String interrogationId, boolean hasToExist) { if(hasToExist) assertThat(testSurveyUnitModels).filteredOn(surveyUnit -> - surveyUnit.getInterrogationId().equals(idUE) + surveyUnit.getInterrogationId().equals(interrogationId) && surveyUnit.getState() == DataState.FORCED) .hasSize(1); else assertThat(testSurveyUnitModels).filteredOn(surveyUnit -> - surveyUnit.getInterrogationId().equals(idUE) + surveyUnit.getInterrogationId().equals(interrogationId) && surveyUnit.getState() == DataState.FORCED) .isEmpty(); } - private void assertCollectedVariableContent(List testSurveyUnitModels, String idUE, String variableName, int valueIndex, String expectedContent) { - assertForcedExistence(testSurveyUnitModels,idUE,true); + private void assertCollectedVariableContent(List testSurveyUnitModels, String interrogationId, String variableName, int valueIndex, String expectedContent) { + assertForcedExistence(testSurveyUnitModels,interrogationId,true); Optional suDtoOpt = testSurveyUnitModels.stream().filter(surveyUnit -> - surveyUnit.getInterrogationId().equals(idUE) + surveyUnit.getInterrogationId().equals(interrogationId) && surveyUnit.getState() == DataState.FORCED).findFirst(); assertThat(suDtoOpt).isPresent(); @@ -222,10 +222,10 @@ private void assertCollectedVariableContent(List testSurveyUnit ).findFirst().get().getValues().get(valueIndex)).isEqualTo(expectedContent); } - private void assertForcedCollectedVariableExistence(List testSurveyUnitModels, String idUE, String variableName, boolean hasToExist) { - assertForcedExistence(testSurveyUnitModels,idUE, true); + private void assertForcedCollectedVariableExistence(List testSurveyUnitModels, String interrogationId, String variableName, boolean hasToExist) { + assertForcedExistence(testSurveyUnitModels,interrogationId, true); Optional suDtoOpt = testSurveyUnitModels.stream().filter(surveyUnit -> - surveyUnit.getInterrogationId().equals(idUE) + surveyUnit.getInterrogationId().equals(interrogationId) && surveyUnit.getState() == DataState.FORCED).findFirst(); assertThat(suDtoOpt).isPresent(); @@ -237,10 +237,10 @@ private void assertForcedCollectedVariableExistence(List testSu assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals(variableName)).toList()).isEmpty(); } - private void assertForcedExternalVariableExistence(List testSurveyUnitModels, String idUE, String variableName, boolean hasToExist) { - assertForcedExistence(testSurveyUnitModels,idUE, true); + private void assertForcedExternalVariableExistence(List testSurveyUnitModels, String interrogationId, String variableName, boolean hasToExist) { + assertForcedExistence(testSurveyUnitModels,interrogationId, true); Optional suDtoOpt = testSurveyUnitModels.stream().filter(surveyUnit -> - surveyUnit.getInterrogationId().equals(idUE) + surveyUnit.getInterrogationId().equals(interrogationId) && surveyUnit.getState() == DataState.FORCED).findFirst(); assertThat(suDtoOpt).isPresent(); @@ -252,11 +252,11 @@ private void assertForcedExternalVariableExistence(List testSur assertThat(suDto.getExternalVariables().stream().filter(variableDto -> variableDto.getVarId().equals(variableName)).toList()).isEmpty(); } - private void assertExternalVariableContent(List testSurveyUnitModels, String idUE, String variableName, int valueIndex, String expectedContent) { - assertForcedExistence(testSurveyUnitModels,idUE,true); + private void assertExternalVariableContent(List testSurveyUnitModels, String interrogationId, String variableName, int valueIndex, String expectedContent) { + assertForcedExistence(testSurveyUnitModels,interrogationId,true); Optional suDtoOpt = testSurveyUnitModels.stream().filter(surveyUnit -> - surveyUnit.getInterrogationId().equals(idUE) + surveyUnit.getInterrogationId().equals(interrogationId) && surveyUnit.getState() == DataState.FORCED).findFirst(); assertThat(suDtoOpt).isPresent(); diff --git a/src/test/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModelTest.java b/src/test/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModelTest.java index 00bda95c..5cff4936 100644 --- a/src/test/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModelTest.java +++ b/src/test/java/fr/insee/genesis/domain/model/surveyunit/SurveyUnitModelTest.java @@ -21,9 +21,9 @@ public void toJSONTest() throws JsonProcessingException { collectedVariableList.add(collectedVariable); SurveyUnitModel surveyUnitModel = SurveyUnitModel.builder() - .campaignId("TESTIDCAMPAIGN") - .questionnaireId("TESTIDQUEST") - .interrogationId("TESTIDUE") + .campaignId("TESTCAMPAIGNID") + .questionnaireId("TESTQUESTIONNAIREID") + .interrogationId("TESTINTERROGATIONID") .mode(Mode.WEB) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2000,1,1,0,0,0)) @@ -37,7 +37,7 @@ public void toJSONTest() throws JsonProcessingException { objectMapper.findAndRegisterModules(); Assertions.assertEquals( - objectMapper.readTree("{\"questionnaireId\":\"TESTIDQUEST\",\"campaignId\":\"TESTIDCAMPAIGN\",\"interrogationId\":\"TESTIDUE\",\"state\":\"COLLECTED\",\"mode\":\"WEB\",\"recordDate\":\"2000-01-01T12:00\",\"fileDate\":\"2000-01-01T12:00\",\"collectedVariables\":[{\"varId\":\"TESTIDVAR\",\"values\":[\"V1\",\"V2\"],\"loopId\":\"TESTIDLOOP\",\"parentId\":\"TESTIDPARENT\"}],\"externalVariables\":[{\"varId\":\"TESTIDVAR\",\"values\":[\"V1\",\"V2\"]}]}"), + objectMapper.readTree("{\"questionnaireId\":\"TESTQUESTIONNAIREID\",\"campaignId\":\"TESTCAMPAIGNID\",\"interrogationId\":\"TESTINTERROGATIONID\",\"state\":\"COLLECTED\",\"mode\":\"WEB\",\"recordDate\":\"2000-01-01T12:00\",\"fileDate\":\"2000-01-01T12:00\",\"collectedVariables\":[{\"varId\":\"TESTIDVAR\",\"values\":[\"V1\",\"V2\"],\"loopId\":\"TESTIDLOOP\",\"parentId\":\"TESTIDPARENT\"}],\"externalVariables\":[{\"varId\":\"TESTIDVAR\",\"values\":[\"V1\",\"V2\"]}]}"), objectMapper.readTree(objectMapper.writeValueAsString(surveyUnitModel)) ); } diff --git a/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java b/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java index dcb6bb8f..bb1f0f9a 100644 --- a/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java +++ b/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java @@ -29,8 +29,8 @@ class SurveyUnitServiceTest { static SurveyUnitPersistencePortStub surveyUnitPersistencePortStub; //Constants - static final String defaultIdUE = "TESTIDUE"; - static final String defaultIdQuest = "TESTIDQUESTIONNAIRE"; + static final String defaultInterrogationId = "TESTINTERROGATIONID"; + static final String defaultQuestionnaireId = "TESTQUESTIONNAIREID"; @BeforeAll static void init(){ @@ -50,10 +50,10 @@ void reset(){ CollectedVariable collectedVariable = new CollectedVariable("TESTIDVAR", List.of(new String[]{"V1", "V2"}),"TESTIDLOOP","TESTIDPARENT"); collectedVariableList.add(collectedVariable); surveyUnitPersistencePortStub.getMongoStub().add(SurveyUnitModel.builder() - .campaignId("TESTIDCAMPAIGN") + .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId(defaultIdUE) - .questionnaireId(defaultIdQuest) + .interrogationId(defaultInterrogationId) + .questionnaireId(defaultQuestionnaireId) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023,1,1,0,0,0)) .recordDate(LocalDateTime.of(2024,1,1,0,0,0)) @@ -78,10 +78,10 @@ void saveAllTest(){ newSurveyUnitModelList.add( SurveyUnitModel.builder() - .campaignId("TESTIDCAMPAIGN") + .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId("TESTIDUE2") - .questionnaireId(defaultIdQuest) + .interrogationId("TESTINTERROGATIONID2") + .questionnaireId(defaultQuestionnaireId) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023,1,1,0,0,0)) .recordDate(LocalDateTime.of(2024,1,1,0,0,0)) @@ -93,10 +93,10 @@ void saveAllTest(){ surveyUnitServiceStatic.saveSurveyUnits(newSurveyUnitModelList); Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub()).filteredOn(surveyUnitDto -> - surveyUnitDto.getCampaignId().equals("TESTIDCAMPAIGN") + surveyUnitDto.getCampaignId().equals("TESTCAMPAIGNID") && surveyUnitDto.getMode().equals(Mode.WEB) - && surveyUnitDto.getInterrogationId().equals("TESTIDUE2") - && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) + && surveyUnitDto.getInterrogationId().equals("TESTINTERROGATIONID2") + && surveyUnitDto.getQuestionnaireId().equals(defaultQuestionnaireId) && surveyUnitDto.getState().equals(DataState.COLLECTED) && surveyUnitDto.getFileDate().equals(LocalDateTime.of(2023,1,1,0,0,0)) && surveyUnitDto.getRecordDate().equals(LocalDateTime.of(2024,1,1,0,0,0)) @@ -113,25 +113,25 @@ void saveAllTest(){ @Test void findByIdsUEAndQuestionnaireTest(){ - Assertions.assertThat(surveyUnitServiceStatic.findByIdsInterrogationAndQuestionnaire(defaultIdUE, defaultIdQuest)).filteredOn( + Assertions.assertThat(surveyUnitServiceStatic.findByIdsInterrogationAndQuestionnaire(defaultInterrogationId, defaultQuestionnaireId)).filteredOn( surveyUnitDto -> - surveyUnitDto.getInterrogationId().equals(defaultIdUE) - && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) + surveyUnitDto.getInterrogationId().equals(defaultInterrogationId) + && surveyUnitDto.getQuestionnaireId().equals(defaultQuestionnaireId) ).isNotEmpty(); } @Test - void findByIdUETest(){ - Assertions.assertThat(surveyUnitServiceStatic.findByInterrogationId(defaultIdUE)).filteredOn( + void findByInterrogationIdTest(){ + Assertions.assertThat(surveyUnitServiceStatic.findByInterrogationId(defaultInterrogationId)).filteredOn( surveyUnitDto -> - surveyUnitDto.getInterrogationId().equals(defaultIdUE) + surveyUnitDto.getInterrogationId().equals(defaultInterrogationId) ).isNotEmpty(); } @Test void findByQuestionnaireIdTest(){ - Assertions.assertThat(surveyUnitServiceStatic.findByQuestionnaireId(defaultIdQuest)).filteredOn( - surveyUnitDto -> surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) + Assertions.assertThat(surveyUnitServiceStatic.findByQuestionnaireId(defaultQuestionnaireId)).filteredOn( + surveyUnitDto -> surveyUnitDto.getQuestionnaireId().equals(defaultQuestionnaireId) ).isNotEmpty(); } @@ -139,9 +139,9 @@ void findByQuestionnaireIdTest(){ void findLatestByIdAndByModeTest(){ addAdditionnalDtoToMongoStub(); - Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(defaultIdUE, defaultIdQuest)).filteredOn( - surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultIdUE) - && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) + Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(defaultInterrogationId, defaultQuestionnaireId)).filteredOn( + surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultInterrogationId) + && surveyUnitDto.getQuestionnaireId().equals(defaultQuestionnaireId) && surveyUnitDto.getFileDate().getMonth().equals(Month.FEBRUARY) ).isNotEmpty(); } @@ -156,9 +156,9 @@ void findResponsesByUEAndQuestionnaireTest_null_collectedVariables() { ); surveyUnitPersistencePortStub.getMongoStub().getLast().setCollectedVariables(null); - Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(defaultIdUE, defaultIdQuest)).filteredOn( - surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultIdUE) - && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) + Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(defaultInterrogationId, defaultQuestionnaireId)).filteredOn( + surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultInterrogationId) + && surveyUnitDto.getQuestionnaireId().equals(defaultQuestionnaireId) && surveyUnitDto.getFileDate().getMonth().equals(Month.FEBRUARY) ).isNotEmpty(); } @@ -172,25 +172,25 @@ void findResponsesByUEAndQuestionnaireTest_null_externalVariables() { ); surveyUnitPersistencePortStub.getMongoStub().getLast().setExternalVariables(null); - Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(defaultIdUE, defaultIdQuest)).filteredOn( - surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultIdUE) - && surveyUnitDto.getQuestionnaireId().equals(defaultIdQuest) + Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(defaultInterrogationId, defaultQuestionnaireId)).filteredOn( + surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultInterrogationId) + && surveyUnitDto.getQuestionnaireId().equals(defaultQuestionnaireId) && surveyUnitDto.getFileDate().getMonth().equals(Month.FEBRUARY) ).isNotEmpty(); } @Test - void findDistinctIdUEsByQuestionnaireIdTest(){ + void findDistinctInterrogationIdsByQuestionnaireIdTest(){ addAdditionnalDtoToMongoStub(); - Assertions.assertThat(surveyUnitServiceStatic.findDistinctInterrogationIdsByQuestionnaireId(defaultIdQuest)).filteredOn( - surveyUnitId -> surveyUnitId.getInterrogationId().equals(defaultIdUE) + Assertions.assertThat(surveyUnitServiceStatic.findDistinctInterrogationIdsByQuestionnaireId(defaultQuestionnaireId)).filteredOn( + surveyUnitId -> surveyUnitId.getInterrogationId().equals(defaultInterrogationId) ).isNotEmpty().hasSize(1); } @Test - void findIdUEsByQuestionnaireIdTest(){ - Assertions.assertThat(surveyUnitServiceStatic.findModesByQuestionnaireId(defaultIdQuest)).filteredOn( + void findInterrogationIdsByQuestionnaireIdTest(){ + Assertions.assertThat(surveyUnitServiceStatic.findModesByQuestionnaireId(defaultQuestionnaireId)).filteredOn( mode -> mode.equals(Mode.WEB) ).isNotEmpty(); } @@ -199,13 +199,13 @@ void findIdUEsByQuestionnaireIdTest(){ void getQuestionnairesByCampaignTest() { addAdditionnalDtoToMongoStub("TESTQUESTIONNAIRE2"); - Assertions.assertThat(surveyUnitServiceStatic.findQuestionnaireIdsByCampaignId("TESTIDCAMPAIGN")).isNotEmpty().hasSize(2); + Assertions.assertThat(surveyUnitServiceStatic.findQuestionnaireIdsByCampaignId("TESTCAMPAIGNID")).isNotEmpty().hasSize(2); } @Test void getAllCampaignsTest() { - Assertions.assertThat(surveyUnitServiceStatic.findDistinctCampaignIds()).contains("TESTIDCAMPAIGN"); + Assertions.assertThat(surveyUnitServiceStatic.findDistinctCampaignIds()).contains("TESTCAMPAIGNID"); } @Test @@ -239,13 +239,13 @@ void findLatestByIdAndByQuestionnaireIdPerretTest(){ //When SurveyUnitDto surveyUnitDto = surveyUnitServiceStatic.findLatestValuesByStateByIdAndByQuestionnaireId( - defaultIdUE, - defaultIdQuest + defaultInterrogationId, + defaultQuestionnaireId ); //Then - Assertions.assertThat(surveyUnitDto.getSurveyUnitId()).isEqualTo(defaultIdUE); + Assertions.assertThat(surveyUnitDto.getSurveyUnitId()).isEqualTo(defaultInterrogationId); Assertions.assertThat(surveyUnitDto.getCollectedVariables().getFirst().getVariableName()) .isEqualTo("TESTIDVAR"); @@ -308,13 +308,13 @@ void findLatestByIdAndByQuestionnaireIdPerretTest_null_collectedVariables(){ //When SurveyUnitDto surveyUnitDto = surveyUnitServiceStatic.findLatestValuesByStateByIdAndByQuestionnaireId( - defaultIdUE, - defaultIdQuest + defaultInterrogationId, + defaultQuestionnaireId ); //Then - Assertions.assertThat(surveyUnitDto.getSurveyUnitId()).isEqualTo(defaultIdUE); + Assertions.assertThat(surveyUnitDto.getSurveyUnitId()).isEqualTo(defaultInterrogationId); Assertions.assertThat(surveyUnitDto.getCollectedVariables().getFirst().getVariableName()) .isEqualTo("TESTIDVAR"); @@ -367,13 +367,13 @@ void findLatestByIdAndByQuestionnaireIdPerretTest_null_externalVariables(){ //When SurveyUnitDto surveyUnitDto = surveyUnitServiceStatic.findLatestValuesByStateByIdAndByQuestionnaireId( - defaultIdUE, - defaultIdQuest + defaultInterrogationId, + defaultQuestionnaireId ); //Then - Assertions.assertThat(surveyUnitDto.getSurveyUnitId()).isEqualTo(defaultIdUE); + Assertions.assertThat(surveyUnitDto.getSurveyUnitId()).isEqualTo(defaultInterrogationId); Assertions.assertThat(surveyUnitDto.getCollectedVariables().getFirst().getVariableName()) .isEqualTo("TESTIDVAR"); @@ -422,10 +422,10 @@ private void addAdditionnalDtoToMongoStub(){ collectedVariableList.add(collectedVariable); SurveyUnitModel recentDTO = SurveyUnitModel.builder() - .campaignId("TESTIDCAMPAIGN") + .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId(defaultIdUE) - .questionnaireId(defaultIdQuest) + .interrogationId(defaultInterrogationId) + .questionnaireId(defaultQuestionnaireId) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023,2,2,0,0,0)) .recordDate(LocalDateTime.of(2024,2,2,0,0,0)) @@ -435,7 +435,7 @@ private void addAdditionnalDtoToMongoStub(){ surveyUnitPersistencePortStub.getMongoStub().add(recentDTO); } - private void addAdditionnalDtoToMongoStub(String idQuestionnaire) { + private void addAdditionnalDtoToMongoStub(String questionnaireId) { List externalVariableList = new ArrayList<>(); Variable variable = Variable.builder().varId("TESTIDVAR").values(List.of(new String[]{"V1", "V2"})).build(); externalVariableList.add(variable); @@ -445,10 +445,10 @@ private void addAdditionnalDtoToMongoStub(String idQuestionnaire) { collectedVariableList.add(collectedVariable); SurveyUnitModel recentDTO = SurveyUnitModel.builder() - .campaignId("TESTIDCAMPAIGN") + .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId(defaultIdUE) - .questionnaireId(idQuestionnaire) + .interrogationId(defaultInterrogationId) + .questionnaireId(questionnaireId) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023, 2, 2, 0, 0, 0)) .recordDate(LocalDateTime.of(2024, 2, 2, 0, 0, 0)) @@ -472,10 +472,10 @@ private void addAdditionnalDtoToMongoStub(DataState state, collectedVariableList.add(collectedVariable); SurveyUnitModel recentDTO = SurveyUnitModel.builder() - .campaignId("TESTIDCAMPAIGN") + .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId(defaultIdUE) - .questionnaireId(defaultIdQuest) + .interrogationId(defaultInterrogationId) + .questionnaireId(defaultQuestionnaireId) .state(state) .fileDate(fileDate) .recordDate(recordDate) diff --git a/src/test/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitModelMongoAdapterTest.java b/src/test/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitModelMongoAdapterTest.java index d151d803..39da2f0e 100644 --- a/src/test/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitModelMongoAdapterTest.java +++ b/src/test/java/fr/insee/genesis/infrastructure/adapter/SurveyUnitModelMongoAdapterTest.java @@ -39,7 +39,7 @@ class SurveyUnitModelMongoAdapterTest { static void setUp() { surveyUnitMongoAdapter = new SurveyUnitMongoAdapter(mongoRepository, null); suDoc= new SurveyUnitDocument(); - suDoc.setCampaignId("idCampaign"); + suDoc.setCampaignId("campaignId"); suDoc.setInterrogationId("UE1100000001"); suDoc.setQuestionnaireId("TEST2023X01"); suDoc.setState("COLLECTED"); @@ -49,7 +49,7 @@ static void setUp() { suDoc.setExternalVariables(List.of(new ExternalVariable())); suDoc2= new SurveyUnitDocument(); - suDoc2.setCampaignId("idCampaign"); + suDoc2.setCampaignId("campaignId"); suDoc2.setInterrogationId("UE1100000001"); suDoc2.setQuestionnaireId("TEST2023X01"); suDoc2.setState("COLLECTED"); @@ -59,7 +59,7 @@ static void setUp() { suDoc2.setExternalVariables(List.of(new ExternalVariable())); suDoc3= new SurveyUnitDocument(); - suDoc3.setCampaignId("idCampaign"); + suDoc3.setCampaignId("campaignId"); suDoc3.setInterrogationId("UE1100000002"); suDoc3.setQuestionnaireId("TEST2023X01"); suDoc3.setState("COLLECTED"); diff --git a/src/test/java/fr/insee/genesis/infrastructure/mapper/ScheduleDocumentMapperImplTest.java b/src/test/java/fr/insee/genesis/infrastructure/mapper/ScheduleDocumentMapperImplTest.java index da2b7ba6..66213a20 100644 --- a/src/test/java/fr/insee/genesis/infrastructure/mapper/ScheduleDocumentMapperImplTest.java +++ b/src/test/java/fr/insee/genesis/infrastructure/mapper/ScheduleDocumentMapperImplTest.java @@ -28,11 +28,11 @@ static void init(){ scheduleDocumentMapperImplStatic = new ScheduleDocumentMapperImpl(); scheduleDocument = new ScheduleDocument(); - scheduleDocument.setSurveyName("TESTIDCAMPAIGN"); + scheduleDocument.setSurveyName("TESTCAMPAIGNID"); scheduleDocument.setKraftwerkExecutionScheduleList(new ArrayList<>()); scheduleModel = ScheduleModel.builder() - .surveyName("TESTIDCAMPAIGN") + .surveyName("TESTCAMPAIGNID") .kraftwerkExecutionScheduleList(new ArrayList<>()) .build(); @@ -63,7 +63,7 @@ void shouldReturnNull(){ void shouldReturnDocumentDtoFromDocument(){ ScheduleModel scheduleModel1 = scheduleDocumentMapperImplStatic.documentToModel(scheduleDocument); - Assertions.assertThat(scheduleModel1.getSurveyName()).isEqualTo("TESTIDCAMPAIGN"); + Assertions.assertThat(scheduleModel1.getSurveyName()).isEqualTo("TESTCAMPAIGNID"); Assertions.assertThat(scheduleModel1.getLastExecution()).isNull(); Assertions.assertThat(scheduleModel1.getKraftwerkExecutionScheduleList()).hasSize(1); @@ -77,7 +77,7 @@ void shouldReturnDocumentDtoFromDocument(){ void shouldReturnDocumentFromDocumentDto(){ ScheduleDocument scheduleDocument1 = scheduleDocumentMapperImplStatic.modelToDocument(scheduleModel); - Assertions.assertThat(scheduleDocument1.getSurveyName()).isEqualTo("TESTIDCAMPAIGN"); + Assertions.assertThat(scheduleDocument1.getSurveyName()).isEqualTo("TESTCAMPAIGNID"); Assertions.assertThat(scheduleDocument1.getLastExecution()).isNull(); Assertions.assertThat(scheduleDocument1.getKraftwerkExecutionScheduleList()).hasSize(1); @@ -95,7 +95,7 @@ void shouldReturnDocumentLDtoListFromDocumentList(){ List scheduleModelList = scheduleDocumentMapperImplStatic.listDocumentToListModel(scheduleDocumentList); - Assertions.assertThat(scheduleModelList.getFirst().getSurveyName()).isEqualTo("TESTIDCAMPAIGN"); + Assertions.assertThat(scheduleModelList.getFirst().getSurveyName()).isEqualTo("TESTCAMPAIGNID"); Assertions.assertThat(scheduleModelList.getFirst().getLastExecution()).isNull(); Assertions.assertThat(scheduleModelList.getFirst().getKraftwerkExecutionScheduleList()).hasSize(1); @@ -116,7 +116,7 @@ void shouldReturnDocumentListFromDocumentDtoList(){ List scheduleDocumentList = scheduleDocumentMapperImplStatic.listModelToListDocument(scheduleModelList); - Assertions.assertThat(scheduleDocumentList.getFirst().getSurveyName()).isEqualTo("TESTIDCAMPAIGN"); + Assertions.assertThat(scheduleDocumentList.getFirst().getSurveyName()).isEqualTo("TESTCAMPAIGNID"); Assertions.assertThat(scheduleDocumentList.getFirst().getLastExecution()).isNull(); Assertions.assertThat(scheduleDocumentList.getFirst().getKraftwerkExecutionScheduleList()).hasSize(1); diff --git a/src/test/java/fr/insee/genesis/infrastructure/mapper/SurveyUnitDocumentMapperImplTest.java b/src/test/java/fr/insee/genesis/infrastructure/mapper/SurveyUnitDocumentMapperImplTest.java index f88d5334..b9a8ecd3 100644 --- a/src/test/java/fr/insee/genesis/infrastructure/mapper/SurveyUnitDocumentMapperImplTest.java +++ b/src/test/java/fr/insee/genesis/infrastructure/mapper/SurveyUnitDocumentMapperImplTest.java @@ -32,10 +32,10 @@ static void init(){ surveyUnitDocumentMapperImplStatic = new SurveyUnitDocumentMapperImpl(); surveyUnitDocumentStatic = new SurveyUnitDocument(); - surveyUnitDocumentStatic.setCampaignId("TESTIDCAMPAIGN"); + surveyUnitDocumentStatic.setCampaignId("TESTCAMPAIGNID"); surveyUnitDocumentStatic.setMode("WEB"); - surveyUnitDocumentStatic.setInterrogationId("TESTIDUE"); - surveyUnitDocumentStatic.setQuestionnaireId("TESTIDQUESTIONNAIRE"); + surveyUnitDocumentStatic.setInterrogationId("TESTINTERROGATIONID"); + surveyUnitDocumentStatic.setQuestionnaireId("TESTQUESTIONNAIREID"); surveyUnitDocumentStatic.setState("COLLECTED"); surveyUnitDocumentStatic.setFileDate(LocalDateTime.of(2023,1,1,0,0,0)); @@ -63,10 +63,10 @@ static void init(){ surveyUnitStatic = SurveyUnitModel.builder() - .campaignId("TESTIDCAMPAIGN") + .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId("TESTIDUE") - .questionnaireId("TESTIDQUESTIONNAIRE") + .interrogationId("TESTINTERROGATIONID") + .questionnaireId("TESTQUESTIONNAIREID") .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023,1,1,0,0,0)) .recordDate(LocalDateTime.of(2024,1,1,0,0,0)) @@ -91,10 +91,10 @@ void shouldReturnNull(){ void shouldReturnDocumentDtoFromDocument(){ SurveyUnitModel surveyUnit = surveyUnitDocumentMapperImplStatic.documentToModel(surveyUnitDocumentStatic); - Assertions.assertThat(surveyUnit.getCampaignId()).isEqualTo("TESTIDCAMPAIGN"); + Assertions.assertThat(surveyUnit.getCampaignId()).isEqualTo("TESTCAMPAIGNID"); Assertions.assertThat(surveyUnit.getMode()).isEqualTo(Mode.WEB); - Assertions.assertThat(surveyUnit.getInterrogationId()).isEqualTo("TESTIDUE"); - Assertions.assertThat(surveyUnit.getQuestionnaireId()).isEqualTo("TESTIDQUESTIONNAIRE"); + Assertions.assertThat(surveyUnit.getInterrogationId()).isEqualTo("TESTINTERROGATIONID"); + Assertions.assertThat(surveyUnit.getQuestionnaireId()).isEqualTo("TESTQUESTIONNAIREID"); Assertions.assertThat(surveyUnit.getState()).isEqualTo(DataState.COLLECTED); Assertions.assertThat(surveyUnit.getFileDate()).isEqualTo(LocalDateTime.of(2023,1,1,0,0,0)); @@ -115,10 +115,10 @@ void shouldReturnDocumentDtoFromDocument(){ void shouldReturnDocumentFromDocumentDto(){ SurveyUnitDocument surveyUnitDocument = surveyUnitDocumentMapperImplStatic.modelToDocument(surveyUnitStatic); - Assertions.assertThat(surveyUnitDocument.getCampaignId()).isEqualTo("TESTIDCAMPAIGN"); + Assertions.assertThat(surveyUnitDocument.getCampaignId()).isEqualTo("TESTCAMPAIGNID"); Assertions.assertThat(surveyUnitDocument.getMode()).isEqualTo("WEB"); - Assertions.assertThat(surveyUnitDocument.getInterrogationId()).isEqualTo("TESTIDUE"); - Assertions.assertThat(surveyUnitDocument.getQuestionnaireId()).isEqualTo("TESTIDQUESTIONNAIRE"); + Assertions.assertThat(surveyUnitDocument.getInterrogationId()).isEqualTo("TESTINTERROGATIONID"); + Assertions.assertThat(surveyUnitDocument.getQuestionnaireId()).isEqualTo("TESTQUESTIONNAIREID"); Assertions.assertThat(surveyUnitDocument.getState()).isEqualTo("COLLECTED"); Assertions.assertThat(surveyUnitDocument.getFileDate()).isEqualTo(LocalDateTime.of(2023,1,1,0,0,0)); @@ -143,10 +143,10 @@ void shouldReturnDocumentLDtoListFromDocumentList(){ List surveyUnitList = surveyUnitDocumentMapperImplStatic.listDocumentToListModel(surveyUnitDocumentList); - Assertions.assertThat(surveyUnitList.getFirst().getCampaignId()).isEqualTo("TESTIDCAMPAIGN"); + Assertions.assertThat(surveyUnitList.getFirst().getCampaignId()).isEqualTo("TESTCAMPAIGNID"); Assertions.assertThat(surveyUnitList.getFirst().getMode()).isEqualTo(Mode.WEB); - Assertions.assertThat(surveyUnitList.getFirst().getInterrogationId()).isEqualTo("TESTIDUE"); - Assertions.assertThat(surveyUnitList.getFirst().getQuestionnaireId()).isEqualTo("TESTIDQUESTIONNAIRE"); + Assertions.assertThat(surveyUnitList.getFirst().getInterrogationId()).isEqualTo("TESTINTERROGATIONID"); + Assertions.assertThat(surveyUnitList.getFirst().getQuestionnaireId()).isEqualTo("TESTQUESTIONNAIREID"); Assertions.assertThat(surveyUnitList.getFirst().getState()).isEqualTo(DataState.COLLECTED); Assertions.assertThat(surveyUnitList.getFirst().getFileDate()).isEqualTo(LocalDateTime.of(2023,1,1,0,0,0)); @@ -169,10 +169,10 @@ void shouldReturnDocumentListFromDocumentDtoList(){ List surveyUnitDocumentList = surveyUnitDocumentMapperImplStatic.listModelToListDocument(surveyUnitList); - Assertions.assertThat(surveyUnitDocumentList.getFirst().getCampaignId()).isEqualTo("TESTIDCAMPAIGN"); + Assertions.assertThat(surveyUnitDocumentList.getFirst().getCampaignId()).isEqualTo("TESTCAMPAIGNID"); Assertions.assertThat(surveyUnitDocumentList.getFirst().getMode()).isEqualTo("WEB"); - Assertions.assertThat(surveyUnitDocumentList.getFirst().getInterrogationId()).isEqualTo("TESTIDUE"); - Assertions.assertThat(surveyUnitDocumentList.getFirst().getQuestionnaireId()).isEqualTo("TESTIDQUESTIONNAIRE"); + Assertions.assertThat(surveyUnitDocumentList.getFirst().getInterrogationId()).isEqualTo("TESTINTERROGATIONID"); + Assertions.assertThat(surveyUnitDocumentList.getFirst().getQuestionnaireId()).isEqualTo("TESTQUESTIONNAIREID"); Assertions.assertThat(surveyUnitDocumentList.getFirst().getState()).isEqualTo("COLLECTED"); Assertions.assertThat(surveyUnitDocumentList.getFirst().getFileDate()).isEqualTo(LocalDateTime.of(2023,1,1,0,0,0)); From 6c29440d344e365cc398bc11b676aac93d352425 Mon Sep 17 00:00:00 2001 From: QDIBYS Date: Thu, 23 Jan 2025 10:10:40 +0100 Subject: [PATCH 7/7] refactor: use correct name for models/dtos Notably in lambdas functions --- .../genesis/controller/dto/SurveyUnitDto.java | 2 +- .../rest/responses/ResponseController.java | 18 +-- .../surveyunit/SurveyUnitQualityService.java | 4 +- .../service/surveyunit/SurveyUnitService.java | 16 +-- .../genesis/domain/utils/DataVerifier.java | 66 +++++------ .../functional_tests/MainDefinitions.java | 100 ++++++++--------- .../adapter/LunaticXmlAdapterTest.java | 102 ++++++++--------- .../responses/ResponseControllerTest.java | 2 +- .../controller/utils/DataVerifierTest.java | 90 +++++++-------- .../domain/service/SurveyUnitServiceTest.java | 106 +++++++++--------- .../domain/utils/DataVerifierTest.java | 6 +- .../features/do_we_extract_data.feature | 32 +++--- 12 files changed, 272 insertions(+), 272 deletions(-) diff --git a/src/main/java/fr/insee/genesis/controller/dto/SurveyUnitDto.java b/src/main/java/fr/insee/genesis/controller/dto/SurveyUnitDto.java index 249323bb..114670c2 100644 --- a/src/main/java/fr/insee/genesis/controller/dto/SurveyUnitDto.java +++ b/src/main/java/fr/insee/genesis/controller/dto/SurveyUnitDto.java @@ -8,7 +8,7 @@ @Builder @Data public class SurveyUnitDto { - private String surveyUnitId; + private String interrogationId; private List collectedVariables; private List externalVariables; } diff --git a/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java b/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java index 73641cc0..9961119c 100644 --- a/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java +++ b/src/main/java/fr/insee/genesis/controller/rest/responses/ResponseController.java @@ -524,17 +524,17 @@ private ResponseEntity processXmlFileWithMemory(Path filepath, Mode mode return ResponseEntity.status(e.getStatus()).body(e.getMessage()); } - List suDtos = new ArrayList<>(); + List surveyUnitModels = new ArrayList<>(); for (LunaticXmlSurveyUnit su : campaign.getSurveyUnits()) { - suDtos.addAll(LunaticXmlAdapter.convert(su, variablesMap, campaign.getCampaignId(), modeSpecified)); + surveyUnitModels.addAll(LunaticXmlAdapter.convert(su, variablesMap, campaign.getCampaignId(), modeSpecified)); } - surveyUnitQualityService.verifySurveyUnits(suDtos, variablesMap); + surveyUnitQualityService.verifySurveyUnits(surveyUnitModels, variablesMap); - log.debug("Saving {} survey units updates", suDtos.size()); - surveyUnitService.saveSurveyUnits(suDtos); + log.debug("Saving {} survey units updates", surveyUnitModels.size()); + surveyUnitService.saveSurveyUnits(surveyUnitModels); log.debug("Survey units updates saved"); - log.info("File {} processed with {} survey units", filepath.getFileName(), suDtos.size()); + log.info("File {} processed with {} survey units", filepath.getFileName(), surveyUnitModels.size()); return ResponseEntity.ok().build(); } @@ -571,10 +571,10 @@ private ResponseEntity processXmlFileSequentially(Path filepath, Mode mo LunaticXmlSurveyUnit su = parser.readNextSurveyUnit(); while (su != null) { - List suDtos = new ArrayList<>(LunaticXmlAdapter.convert(su, variablesMap, campaign.getCampaignId(), modeSpecified)); + List surveyUnitModels = new ArrayList<>(LunaticXmlAdapter.convert(su, variablesMap, campaign.getCampaignId(), modeSpecified)); - surveyUnitQualityService.verifySurveyUnits(suDtos, variablesMap); - surveyUnitService.saveSurveyUnits(suDtos); + surveyUnitQualityService.verifySurveyUnits(surveyUnitModels, variablesMap); + surveyUnitService.saveSurveyUnits(surveyUnitModels); suCount++; su = parser.readNextSurveyUnit(); diff --git a/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitQualityService.java b/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitQualityService.java index d821b17d..edaab163 100644 --- a/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitQualityService.java +++ b/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitQualityService.java @@ -12,7 +12,7 @@ */ @Service public class SurveyUnitQualityService { - public void verifySurveyUnits(List suDtos, VariablesMap variablesMap) { - DataVerifier.verifySurveyUnits(suDtos,variablesMap); + public void verifySurveyUnits(List surveyUnitModels, VariablesMap variablesMap) { + DataVerifier.verifySurveyUnits(surveyUnitModels,variablesMap); } } diff --git a/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java b/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java index e35b6508..91afd093 100644 --- a/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java +++ b/src/main/java/fr/insee/genesis/domain/service/surveyunit/SurveyUnitService.java @@ -24,8 +24,8 @@ public SurveyUnitService(SurveyUnitPersistencePort surveyUnitPersistencePort) { } @Override - public void saveSurveyUnits(List suDtos) { - surveyUnitPersistencePort.saveAll(suDtos); + public void saveSurveyUnits(List surveyUnitModels) { + surveyUnitPersistencePort.saveAll(surveyUnitModels); } @Override @@ -58,7 +58,7 @@ public List findLatestByIdAndByQuestionnaireId(String interroga List modes = getDistinctsModes(surveyUnitModels); modes.forEach(mode ->{ List suByMode = surveyUnitModels.stream() - .filter(surveyUnitDto -> surveyUnitDto.getMode().equals(mode)) + .filter(surveyUnitModel -> surveyUnitModel.getMode().equals(mode)) .sorted((o1, o2) -> o2.getRecordDate().compareTo(o1.getRecordDate())) //Sorting update by date (latest updates first by date of upload in database) .toList(); @@ -110,7 +110,7 @@ public List findLatestByIdAndByQuestionnaireId(String interroga @Override public SurveyUnitDto findLatestValuesByStateByIdAndByQuestionnaireId(String interrogationId, String questionnaireId) { SurveyUnitDto surveyUnitDto = SurveyUnitDto.builder() - .surveyUnitId(interrogationId) + .interrogationId(interrogationId) .collectedVariables(new ArrayList<>()) .externalVariables(new ArrayList<>()) .build(); @@ -136,7 +136,7 @@ public SurveyUnitDto findLatestValuesByStateByIdAndByQuestionnaireId(String inte public List findDistinctInterrogationIdsByQuestionnaireId(String questionnaireId) { List surveyUnitModels = surveyUnitPersistencePort.findInterrogationIdsByQuestionnaireId(questionnaireId); List suIds = new ArrayList<>(); - surveyUnitModels.forEach(surveyUnitDto -> suIds.add(new InterrogationId(surveyUnitDto.getInterrogationId()))); + surveyUnitModels.forEach(surveyUnitModel -> suIds.add(new InterrogationId(surveyUnitModel.getInterrogationId()))); return suIds.stream().distinct().toList(); } @@ -150,7 +150,7 @@ public List findInterrogationIdsAndModesByQuestionnaireId(Strin public List findModesByQuestionnaireId(String questionnaireId) { List surveyUnitModels = surveyUnitPersistencePort.findInterrogationIdsByQuestionnaireId(questionnaireId); List sources = new ArrayList<>(); - surveyUnitModels.forEach(surveyUnitDto -> sources.add(surveyUnitDto.getMode())); + surveyUnitModels.forEach(surveyUnitModel -> sources.add(surveyUnitModel.getMode())); return sources.stream().distinct().toList(); } @@ -158,7 +158,7 @@ public List findModesByQuestionnaireId(String questionnaireId) { public List findModesByCampaignId(String campaignId) { List surveyUnitModels = surveyUnitPersistencePort.findInterrogationIdsByCampaignId(campaignId); List sources = new ArrayList<>(); - surveyUnitModels.forEach(surveyUnitDto -> sources.add(surveyUnitDto.getMode())); + surveyUnitModels.forEach(surveyUnitModel -> sources.add(surveyUnitModel.getMode())); return sources.stream().distinct().toList(); } @@ -218,7 +218,7 @@ public List findQuestionnairesWithCampaigns() { private static List getDistinctsModes(List surveyUnitModels) { List sources = new ArrayList<>(); - surveyUnitModels.forEach(surveyUnitDto -> sources.add(surveyUnitDto.getMode())); + surveyUnitModels.forEach(surveyUnitModel -> sources.add(surveyUnitModel.getMode())); return sources.stream().distinct().toList(); } diff --git a/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java b/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java index 4e0f8f2b..cd8b6b7c 100644 --- a/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java +++ b/src/main/java/fr/insee/genesis/domain/utils/DataVerifier.java @@ -41,51 +41,51 @@ private DataVerifier() { * Verify data format in all surveyUnits DTOs * If there is at least 1 incorrect variable for a survey unit, a new SurveyUnitDto is created with "FORCED" status * The new surveyUnits are added to the list - * @param suDtosList list of SurveyUnitDtos to verify + * @param surveyUnitModelsList list of SurveyUnitDtos to verify * @param variablesMap VariablesMap containing definitions of each variable */ - public static void verifySurveyUnits(List suDtosList, VariablesMap variablesMap){ - List suDtosListForced = new ArrayList<>(); // Created FORCED SU DTOs + public static void verifySurveyUnits(List surveyUnitModelsList, VariablesMap variablesMap){ + List surveyUnitModelsListForced = new ArrayList<>(); // Created FORCED SU DTOs - for(String interrogationId : getInterrogationIds(suDtosList)) { // For each id of the list - List srcSuDtosOfInterrogationId = suDtosList.stream().filter(element -> element.getInterrogationId().equals(interrogationId)).toList(); + for(String interrogationId : getInterrogationIds(surveyUnitModelsList)) { // For each id of the list + List srcSurveyUnitModelsOfInterrogationId = surveyUnitModelsList.stream().filter(element -> element.getInterrogationId().equals(interrogationId)).toList(); List correctedCollectedVariables = new ArrayList<>(); List correctedExternalVariables = new ArrayList<>(); //Get corrected variables - collectedVariablesManagement(srcSuDtosOfInterrogationId, variablesMap, correctedCollectedVariables); - externalVariablesManagement(srcSuDtosOfInterrogationId, variablesMap, correctedExternalVariables); + collectedVariablesManagement(srcSurveyUnitModelsOfInterrogationId, variablesMap, correctedCollectedVariables); + externalVariablesManagement(srcSurveyUnitModelsOfInterrogationId, variablesMap, correctedExternalVariables); //Create FORCED if any corrected variable if(!correctedCollectedVariables.isEmpty() || !correctedExternalVariables.isEmpty()){ - SurveyUnitModel newForcedSuDto = createForcedDto(suDtosList, interrogationId, correctedCollectedVariables, correctedExternalVariables); - suDtosListForced.add(newForcedSuDto); + SurveyUnitModel newForcedSurveyUnitModel = createForcedDto(surveyUnitModelsList, interrogationId, correctedCollectedVariables, correctedExternalVariables); + surveyUnitModelsListForced.add(newForcedSurveyUnitModel); } } - suDtosList.addAll(suDtosListForced); + surveyUnitModelsList.addAll(surveyUnitModelsListForced); } private static SurveyUnitModel createForcedDto( - List suDtosList, + List surveyUnitModelsList, String interrogationId, List correctedCollectedVariables, List correctedExternalVariables ) { - SurveyUnitModel sampleSuDto = suDtosList.stream().filter(element -> element.getInterrogationId().equals(interrogationId)).toList().getFirst(); - SurveyUnitModel newForcedSuDto = SurveyUnitModel.builder() - .questionnaireId(sampleSuDto.getQuestionnaireId()) - .campaignId(sampleSuDto.getCampaignId()) + SurveyUnitModel sampleSurveyUnitModel = surveyUnitModelsList.stream().filter(element -> element.getInterrogationId().equals(interrogationId)).toList().getFirst(); + SurveyUnitModel newForcedSurveyUnitModel = SurveyUnitModel.builder() + .questionnaireId(sampleSurveyUnitModel.getQuestionnaireId()) + .campaignId(sampleSurveyUnitModel.getCampaignId()) .interrogationId(interrogationId) .state(DataState.FORCED) - .mode(sampleSuDto.getMode()) + .mode(sampleSurveyUnitModel.getMode()) .recordDate(LocalDateTime.now()) - .fileDate(sampleSuDto.getFileDate()) + .fileDate(sampleSurveyUnitModel.getFileDate()) .collectedVariables(new ArrayList<>()) .externalVariables(new ArrayList<>()) .build(); for(CollectedVariable correctedCollectedVariable : correctedCollectedVariables){ - newForcedSuDto.getCollectedVariables().add( + newForcedSurveyUnitModel.getCollectedVariables().add( new CollectedVariable(correctedCollectedVariable.getVarId(), correctedCollectedVariable.getValues() ,correctedCollectedVariable.getLoopId() @@ -95,25 +95,25 @@ private static SurveyUnitModel createForcedDto( } for(Variable correctedExternalVariable : correctedExternalVariables){ - newForcedSuDto.getExternalVariables().add( + newForcedSurveyUnitModel.getExternalVariables().add( Variable.builder() .varId(correctedExternalVariable.getVarId()) .values(correctedExternalVariable.getValues()) .build() ); } - return newForcedSuDto; + return newForcedSurveyUnitModel; } /** * Fetch individual interrogationIds of variable from the list - * @param suDtosList source list + * @param surveyUnitModelsList source list * @return a set of interrogationIds */ - private static Set getInterrogationIds(List suDtosList) { + private static Set getInterrogationIds(List surveyUnitModelsList) { Set interrogationIds = new HashSet<>(); - for(SurveyUnitModel surveyUnitModel : suDtosList){ + for(SurveyUnitModel surveyUnitModel : surveyUnitModelsList){ interrogationIds.add(surveyUnitModel.getInterrogationId()); } @@ -122,20 +122,20 @@ private static Set getInterrogationIds(List suDtosList) /** * Adds the collected variables for the FORCED document - * @param srcSuDtosOfInterrogationId source Survey Unit documents associated with InterrogationId + * @param srcSurveyUnitModelsOfInterrogationId source Survey Unit documents associated with InterrogationId * @param variablesMap variables definitions * @param correctedCollectedVariables FORCED document variables */ - private static void collectedVariablesManagement(List srcSuDtosOfInterrogationId, VariablesMap variablesMap, List correctedCollectedVariables){ + private static void collectedVariablesManagement(List srcSurveyUnitModelsOfInterrogationId, VariablesMap variablesMap, List correctedCollectedVariables){ Set variableNames = new HashSet<>(); List variablesToVerify = new ArrayList<>(); //Sort from more priority to less - List sortedSuDtos = srcSuDtosOfInterrogationId.stream().sorted(Comparator.comparing(surveyUnitDto -> dataStatesPriority.get(surveyUnitDto.getState()))).toList(); + List sortedSurveyUnitModels = srcSurveyUnitModelsOfInterrogationId.stream().sorted(Comparator.comparing(surveyUnitModel -> dataStatesPriority.get(surveyUnitModel.getState()))).toList(); //Get more priority variables to verify - for(SurveyUnitModel srcSuDto : sortedSuDtos){ - for(CollectedVariable collectedVariable : srcSuDto.getCollectedVariables()){ + for(SurveyUnitModel srcSurveyUnitModel : sortedSurveyUnitModels){ + for(CollectedVariable collectedVariable : srcSurveyUnitModel.getCollectedVariables()){ if(!variableNames.contains(collectedVariable.getVarId())){ variableNames.add(collectedVariable.getVarId()); variablesToVerify.add(collectedVariable); @@ -180,15 +180,15 @@ private static CollectedVariable verifyCollectedVariable(CollectedVariable colle ) : null; } - private static void externalVariablesManagement(List srcSuDtosOfInterrogationId, VariablesMap variablesMap, List correctedExternalVariables) { + private static void externalVariablesManagement(List srcSurveyUnitModelsOfInterrogationId, VariablesMap variablesMap, List correctedExternalVariables) { //COLLECTED only - Optional collectedSuDtoOpt = srcSuDtosOfInterrogationId.stream().filter( - suDto -> suDto.getState().equals(DataState.COLLECTED) + Optional collectedSurveyUnitModelOpt = srcSurveyUnitModelsOfInterrogationId.stream().filter( + surveyUnitModel -> surveyUnitModel.getState().equals(DataState.COLLECTED) ).findFirst(); //Verify variables - if(collectedSuDtoOpt.isPresent()){ - for(Variable variable: collectedSuDtoOpt.get().getExternalVariables()){ + if(collectedSurveyUnitModelOpt.isPresent()){ + for(Variable variable: collectedSurveyUnitModelOpt.get().getExternalVariables()){ if(variablesMap.hasVariable(variable.getVarId())) { Variable correctedExternalVariable = verifyExternalVariable( variable, diff --git a/src/test/java/cucumber/functional_tests/MainDefinitions.java b/src/test/java/cucumber/functional_tests/MainDefinitions.java index 8e860318..a39a1911 100644 --- a/src/test/java/cucumber/functional_tests/MainDefinitions.java +++ b/src/test/java/cucumber/functional_tests/MainDefinitions.java @@ -77,8 +77,8 @@ public void init_folder(String directory) throws IOException { Files.createDirectories(inDirectory); } - @When("We create DTOs from file {string} with DDI {string}") - public void get_dtos(String fileName, String ddiName) throws IOException, ParserConfigurationException, + @When("We create survey unit models from file {string} with DDI {string}") + public void get_su_models(String fileName, String ddiName) throws IOException, ParserConfigurationException, SAXException, GenesisException, MetadataParserException { Path filePath = inDirectory.resolve(fileName); Path ddiFilePath = ddiDirectory.resolve(directory).resolve(ddiName); @@ -91,12 +91,12 @@ public void get_dtos(String fileName, String ddiName) throws IOException, Parser ddiFilePath.toFile().toURI().toURL().toString(), new FileInputStream(ddiFilePath.toFile()) ).getVariables(); - List suDtos = new ArrayList<>(); + List suModelList = new ArrayList<>(); for (LunaticXmlSurveyUnit su : campaign.getSurveyUnits()) { - suDtos.addAll(LunaticXmlAdapter.convert(su, variablesMap, campaign.getCampaignId(), Mode.WEB)); + suModelList.addAll(LunaticXmlAdapter.convert(su, variablesMap, campaign.getCampaignId(), Mode.WEB)); } - surveyUnitQualityService.verifySurveyUnits(suDtos,variablesMap); - surveyUnitModels = suDtos; + surveyUnitQualityService.verifySurveyUnits(suModelList,variablesMap); + this.surveyUnitModels = suModelList; } } @@ -108,7 +108,7 @@ public void copy_data_file(String dataFile) throws IOException { } @When("We save data from that directory") - public void get_dtos_from_folder() throws Exception { + public void get_su_models_from_folder() throws Exception { responseController.saveResponsesFromXmlCampaignFolder(this.inDirectory.getFileName().toString(), null, true); } @@ -126,44 +126,44 @@ public void check_surveyunits_by_state(int expectedCount, String expectedStatus) - @Then("For SurveyUnit {string} there should be at least one {string} SurveyUnit DTO") - public void check_expected_datastate_dto(String surveyUnitId, String expectedDataState) { - Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().toString().equals(expectedDataState) - && surveyUnitDto.getInterrogationId().equals(surveyUnitId) + @Then("For SurveyUnit {string} there should be at least one {string} SurveyUnit Model") + public void check_expected_datastate_model(String interrogationId, String expectedDataState) { + Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().toString().equals(expectedDataState) + && surveyUnitModel.getInterrogationId().equals(interrogationId) ).isNotEmpty(); } - @Then("For SurveyUnit {string} there shouldn't be a {string} SurveyUnit DTO") - public void check_unexpected_datastate_dto(String surveyUnitId, String unexpectedDataState) { - Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().toString().equals(unexpectedDataState) - && surveyUnitDto.getInterrogationId().equals(surveyUnitId) + @Then("For SurveyUnit {string} there shouldn't be a {string} SurveyUnit Model") + public void check_unexpected_datastate_model(String interrogationId, String unexpectedDataState) { + Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().toString().equals(unexpectedDataState) + && surveyUnitModel.getInterrogationId().equals(interrogationId) ).isEmpty(); } - @Then("We should have a {string} DTO for survey unit {string} with {string} filled with {string} at index {int}") - public void check_survey_unit_dto_content(String dataState, String surveyUnitId, String variableName, String expectedValue, int expectedIndex) { + @Then("We should have a {string} Survey Unit model with id {string} with {string} filled with {string} at index {int}") + public void check_survey_unit_model_content(String dataState, String interrogationId, String variableName, String expectedValue, int expectedIndex) { //Get DTO - Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().toString().equals(dataState) - && surveyUnitDto.getInterrogationId().equals(surveyUnitId) + Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().toString().equals(dataState) + && surveyUnitModel.getInterrogationId().equals(interrogationId) ).isNotEmpty(); - Optional concernedDtoOptional = this.surveyUnitModels.stream().filter(dto -> + Optional concernedSuModelOptional = this.surveyUnitModels.stream().filter(dto -> dto.getState().toString().equals(dataState) - && dto.getInterrogationId().equals(surveyUnitId) + && dto.getInterrogationId().equals(interrogationId) ).findFirst(); - Assertions.assertThat(concernedDtoOptional).isPresent(); + Assertions.assertThat(concernedSuModelOptional).isPresent(); - SurveyUnitModel concernedDto = concernedDtoOptional.get(); + SurveyUnitModel concernedSuModel = concernedSuModelOptional.get(); //Get Variable - Assertions.assertThat(concernedDto.getCollectedVariables()).filteredOn(collectedVariableDto -> + Assertions.assertThat(concernedSuModel.getCollectedVariables()).filteredOn(collectedVariableDto -> collectedVariableDto.getVarId().equals(variableName)).isNotEmpty(); - Optional concernedVariableOptional = concernedDto.getCollectedVariables().stream().filter(variable -> + Optional concernedVariableOptional = concernedSuModel.getCollectedVariables().stream().filter(variable -> variable.getVarId().equals(variableName) ).findFirst(); @@ -178,27 +178,27 @@ public void check_survey_unit_dto_content(String dataState, String surveyUnitId, } @Then("We should have {int} values for external variable {string} for survey unit {string}") - public void external_variable_volumetric_check(int expectedNumberOfValues, String externalVariableName, String surveyUnitId) { + public void external_variable_volumetric_check(int expectedNumberOfValues, String externalVariableName, String interrogationId) { //Get DTO - Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().equals(DataState.COLLECTED) - && surveyUnitDto.getInterrogationId().equals(surveyUnitId) + Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().equals(DataState.COLLECTED) + && surveyUnitModel.getInterrogationId().equals(interrogationId) ).isNotEmpty(); - Optional concernedDtoOptional = this.surveyUnitModels.stream().filter(dto -> + Optional concernedSuModelOptional = this.surveyUnitModels.stream().filter(dto -> dto.getState().equals(DataState.COLLECTED) - && dto.getInterrogationId().equals(surveyUnitId) + && dto.getInterrogationId().equals(interrogationId) ).findFirst(); - Assertions.assertThat(concernedDtoOptional).isPresent(); + Assertions.assertThat(concernedSuModelOptional).isPresent(); - SurveyUnitModel concernedDto = concernedDtoOptional.get(); + SurveyUnitModel concernedSuModel = concernedSuModelOptional.get(); //Get Variable - Assertions.assertThat(concernedDto.getExternalVariables()).filteredOn(variableDto -> - variableDto.getVarId().equals(externalVariableName)).isNotEmpty(); + Assertions.assertThat(concernedSuModel.getExternalVariables()).filteredOn(variableModel -> + variableModel.getVarId().equals(externalVariableName)).isNotEmpty(); - Optional concernedVariableOptional = concernedDto.getExternalVariables().stream().filter(variable -> + Optional concernedVariableOptional = concernedSuModel.getExternalVariables().stream().filter(variable -> variable.getVarId().equals(externalVariableName) ).findFirst(); @@ -212,27 +212,27 @@ public void external_variable_volumetric_check(int expectedNumberOfValues, Strin } @Then("For external variable {string} in survey unit {string} we should have {string} as value number {int}") - public void external_variable_content_check(String externalVariableName, String surveyUnitId, String expectedValue, int expectedValueIndex) { + public void external_variable_content_check(String externalVariableName, String interrogationId, String expectedValue, int expectedValueIndex) { //Get DTO - Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().equals(DataState.COLLECTED) - && surveyUnitDto.getInterrogationId().equals(surveyUnitId) + Assertions.assertThat(this.surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().equals(DataState.COLLECTED) + && surveyUnitModel.getInterrogationId().equals(interrogationId) ).isNotEmpty(); - Optional concernedDtoOptional = this.surveyUnitModels.stream().filter(dto -> + Optional concernedSuModelOptional = this.surveyUnitModels.stream().filter(dto -> dto.getState().equals(DataState.COLLECTED) - && dto.getInterrogationId().equals(surveyUnitId) + && dto.getInterrogationId().equals(interrogationId) ).findFirst(); - Assertions.assertThat(concernedDtoOptional).isPresent(); + Assertions.assertThat(concernedSuModelOptional).isPresent(); - SurveyUnitModel concernedDto = concernedDtoOptional.get(); + SurveyUnitModel concernedSuModel = concernedSuModelOptional.get(); //Get Variable - Assertions.assertThat(concernedDto.getExternalVariables()).filteredOn(variableDto -> - variableDto.getVarId().equals(externalVariableName)).isNotEmpty(); + Assertions.assertThat(concernedSuModel.getExternalVariables()).filteredOn(variableModel -> + variableModel.getVarId().equals(externalVariableName)).isNotEmpty(); - Optional concernedVariableOptional = concernedDto.getExternalVariables().stream().filter(variable -> + Optional concernedVariableOptional = concernedSuModel.getExternalVariables().stream().filter(variable -> variable.getVarId().equals(externalVariableName) ).findFirst(); diff --git a/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java b/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java index 86af65a8..d06370db 100644 --- a/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java +++ b/src/test/java/fr/insee/genesis/controller/adapter/LunaticXmlAdapterTest.java @@ -203,51 +203,51 @@ void setUp() { @DisplayName("SurveyUnitDto should not be null") void test01() { // When - List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit1, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); + List surveyUnitModels = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit1, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos).isNotNull().isNotEmpty(); + Assertions.assertThat(surveyUnitModels).isNotNull().isNotEmpty(); } @Test @DisplayName("SurveyUnitDto should have the right questionnaireId") void test02() { // When - List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit1, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); + List surveyUnitModels = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit1, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos.getFirst().getQuestionnaireId()).isEqualTo("questionnaireId1"); + Assertions.assertThat(surveyUnitModels.getFirst().getQuestionnaireId()).isEqualTo("questionnaireId1"); } @Test @DisplayName("SurveyUnitDto should have the right id") void test03() { // When - List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit1, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); + List surveyUnitModels = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit1, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos.getFirst().getInterrogationId()).isEqualTo("interrogationId1"); + Assertions.assertThat(surveyUnitModels.getFirst().getInterrogationId()).isEqualTo("interrogationId1"); } @Test @DisplayName("SurveyUnitDto should contains 4 variable state updates") void test04() { // When - List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit1, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); + List surveyUnitModels = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit1, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos.getFirst().getCollectedVariables()).hasSize(4); + Assertions.assertThat(surveyUnitModels.getFirst().getCollectedVariables()).hasSize(4); } @Test @DisplayName("There should be a EDITED DTO with EDITED data") void test05() { // When - List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit2, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); + List surveyUnitModels = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit2, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos).hasSize(2); - Assertions.assertThat(suDtos).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().equals(DataState.EDITED) + Assertions.assertThat(surveyUnitModels).hasSize(2); + Assertions.assertThat(surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().equals(DataState.EDITED) ).isNotEmpty(); - Optional editedDTO = suDtos.stream().filter(surveyUnitDto -> - surveyUnitDto.getState().equals(DataState.EDITED) + Optional editedDTO = surveyUnitModels.stream().filter(surveyUnitModel -> + surveyUnitModel.getState().equals(DataState.EDITED) ).findFirst(); Assertions.assertThat(editedDTO).isPresent(); @@ -261,14 +261,14 @@ void test05() { @DisplayName("There should be both EDITED DTO and FORCED DTO if there is EDITED and FORCED data") void test06() { // When - List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit3, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); + List surveyUnitModels = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit3, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos).hasSize(3); - Assertions.assertThat(suDtos).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().equals(DataState.EDITED) + Assertions.assertThat(surveyUnitModels).hasSize(3); + Assertions.assertThat(surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().equals(DataState.EDITED) ).isNotEmpty(); - Assertions.assertThat(suDtos).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().equals(DataState.FORCED) + Assertions.assertThat(surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().equals(DataState.FORCED) ).isNotEmpty(); } @@ -276,14 +276,14 @@ void test06() { @DisplayName("There should be a EDITED DTO and PREVIOUS DTO if there is EDITED and PREVIOUS data") void test07() { // When - List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit4, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); + List surveyUnitModels = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit4, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos).hasSize(3); - Assertions.assertThat(suDtos).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().equals(DataState.EDITED) + Assertions.assertThat(surveyUnitModels).hasSize(3); + Assertions.assertThat(surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().equals(DataState.EDITED) ).isNotEmpty(); - Assertions.assertThat(suDtos).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().equals(DataState.PREVIOUS) + Assertions.assertThat(surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().equals(DataState.PREVIOUS) ).isNotEmpty(); } @@ -291,17 +291,17 @@ void test07() { @DisplayName("There should be multiple DTOs if there is different data states (all 4)") void test08() { // When - List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit5, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); + List surveyUnitModels = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit5, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos).hasSize(4); - Assertions.assertThat(suDtos).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().equals(DataState.EDITED) + Assertions.assertThat(surveyUnitModels).hasSize(4); + Assertions.assertThat(surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().equals(DataState.EDITED) ).isNotEmpty(); - Assertions.assertThat(suDtos).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().equals(DataState.PREVIOUS) + Assertions.assertThat(surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().equals(DataState.PREVIOUS) ).isNotEmpty(); - Assertions.assertThat(suDtos).filteredOn(surveyUnitDto -> - surveyUnitDto.getState().equals(DataState.INPUTED) + Assertions.assertThat(surveyUnitModels).filteredOn(surveyUnitModel -> + surveyUnitModel.getState().equals(DataState.INPUTED) ).isNotEmpty(); } @@ -309,16 +309,16 @@ void test08() { @DisplayName("If a variable not present in DDI then he is in the root group") void test09() { // When - List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit6, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); + List surveyUnitModels = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit6, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos).hasSize(1); + Assertions.assertThat(surveyUnitModels).hasSize(1); - Assertions.assertThat(suDtos.getFirst().getCollectedVariables()).filteredOn(collectedVariableDto -> + Assertions.assertThat(surveyUnitModels.getFirst().getCollectedVariables()).filteredOn(collectedVariableDto -> collectedVariableDto.getVarId().equals("var3")).isNotEmpty(); - Assertions.assertThat(suDtos.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> + Assertions.assertThat(surveyUnitModels.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals("var3")).toList().getFirst().getParentId()).isNull(); - Assertions.assertThat(suDtos.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> + Assertions.assertThat(surveyUnitModels.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals("var3")).toList().getFirst().getLoopId()).isEqualTo(Constants.ROOT_GROUP_NAME); } @@ -326,16 +326,16 @@ void test09() { @DisplayName("If a variable A not present in DDI and is the extension of a known variable B, then the variable A has B as related and is in the same group") void test10() { // When - List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit7, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); + List surveyUnitModels = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit7, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos).hasSize(1); + Assertions.assertThat(surveyUnitModels).hasSize(1); - Assertions.assertThat(suDtos.getFirst().getCollectedVariables()).filteredOn(collectedVariableDto -> + Assertions.assertThat(surveyUnitModels.getFirst().getCollectedVariables()).filteredOn(collectedVariableDto -> collectedVariableDto.getVarId().equals("var1_MISSING")).isNotEmpty(); - Assertions.assertThat(suDtos.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> + Assertions.assertThat(surveyUnitModels.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals("var1_MISSING")).toList().getFirst().getParentId()).isNotNull().isEqualTo("var1"); - Assertions.assertThat(suDtos.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> + Assertions.assertThat(surveyUnitModels.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals("var1_MISSING")).toList().getFirst().getLoopId()).isNotEqualTo(Constants.ROOT_GROUP_NAME).isEqualTo(LOOP_NAME); } @@ -343,17 +343,17 @@ void test10() { @DisplayName("Value should be affected in the good loop iteration") void test11(){ // When - List suDtos = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit8, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); + List surveyUnitModels = LunaticXmlAdapter.convert(lunaticXmlSurveyUnit8, metadataModel.getVariables(), ID_CAMPAIGN, Mode.WEB); // Then - Assertions.assertThat(suDtos).hasSize(1); - Assertions.assertThat(suDtos.getFirst().getCollectedVariables()).hasSize(3); - Assertions.assertThat(suDtos.getFirst().getCollectedVariables()).filteredOn(collectedVariableDto -> + Assertions.assertThat(surveyUnitModels).hasSize(1); + Assertions.assertThat(surveyUnitModels.getFirst().getCollectedVariables()).hasSize(3); + Assertions.assertThat(surveyUnitModels.getFirst().getCollectedVariables()).filteredOn(collectedVariableDto -> collectedVariableDto.getVarId().equals("var1")).isNotEmpty(); - Assertions.assertThat(suDtos.getFirst().getCollectedVariables()).filteredOn(collectedVariableDto -> + Assertions.assertThat(surveyUnitModels.getFirst().getCollectedVariables()).filteredOn(collectedVariableDto -> collectedVariableDto.getLoopId().equals("BOUCLE1_1")).isEmpty(); - Assertions.assertThat(suDtos.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> + Assertions.assertThat(surveyUnitModels.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getLoopId().equals("BOUCLE1_2")).toList().getFirst().getValues().getFirst()).isEqualTo("1"); - Assertions.assertThat(suDtos.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> + Assertions.assertThat(surveyUnitModels.getFirst().getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getLoopId().equals("BOUCLE1_3")).toList().getFirst().getValues().getFirst()).isEqualTo("2"); } diff --git a/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java b/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java index c7e7edc9..25920b82 100644 --- a/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java +++ b/src/test/java/fr/insee/genesis/controller/rest/responses/ResponseControllerTest.java @@ -326,7 +326,7 @@ void getLatestByStatesSurveyDataTest(){ SurveyUnitDto surveyUnitDto = response.getBody(); Assertions.assertThat(surveyUnitDto).isNotNull(); - Assertions.assertThat(surveyUnitDto.getSurveyUnitId()).isEqualTo(DEFAULT_INTERROGATION_ID); + Assertions.assertThat(surveyUnitDto.getInterrogationId()).isEqualTo(DEFAULT_INTERROGATION_ID); Assertions.assertThat(surveyUnitDto.getCollectedVariables().getFirst().getVariableName()) .isEqualTo("TESTIDVAR"); diff --git a/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java b/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java index 751ecb64..ae7f16d7 100644 --- a/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java +++ b/src/test/java/fr/insee/genesis/controller/utils/DataVerifierTest.java @@ -88,43 +88,43 @@ static void setUp() { //Manual modifications //Valid 2nd variable on 5th and 13th case - SurveyUnitModel suDto = testSurveyUnitModels.stream().filter(surveyUnitDto -> - surveyUnitDto.getInterrogationId().equals("TestUE5") + SurveyUnitModel surveyUnitModel = testSurveyUnitModels.stream().filter(surveyUnitModel1 -> + surveyUnitModel1.getInterrogationId().equals("TestUE5") ).toList().getFirst(); - suDto.getCollectedVariables().get(1).getValues().set(0,"1"); + surveyUnitModel.getCollectedVariables().get(1).getValues().set(0,"1"); - suDto = testSurveyUnitModels.stream().filter(surveyUnitDto -> - surveyUnitDto.getInterrogationId().equals("TestUE13") + surveyUnitModel = testSurveyUnitModels.stream().filter(surveyUnitModel1 -> + surveyUnitModel1.getInterrogationId().equals("TestUE13") ).toList().getFirst(); - suDto.getCollectedVariables().get(1).getValues().set(0,"1"); - suDto.getExternalVariables().get(1).getValues().set(0,"1"); + surveyUnitModel.getCollectedVariables().get(1).getValues().set(0,"1"); + surveyUnitModel.getExternalVariables().get(1).getValues().set(0,"1"); //Valid EDITED variables on 3rd and 7th case for priority test - SurveyUnitModel suDtoEdited = testSurveyUnitModels.stream().filter(surveyUnitDto -> - surveyUnitDto.getInterrogationId().equals("TestUE3") - && surveyUnitDto.getState().equals(DataState.EDITED) + SurveyUnitModel surveyUnitModelEdited = testSurveyUnitModels.stream().filter(surveyUnitModel1 -> + surveyUnitModel1.getInterrogationId().equals("TestUE3") + && surveyUnitModel1.getState().equals(DataState.EDITED) ).toList().getFirst(); - suDtoEdited.getCollectedVariables().getFirst().getValues().set(0,"1"); + surveyUnitModelEdited.getCollectedVariables().getFirst().getValues().set(0,"1"); - suDtoEdited = testSurveyUnitModels.stream().filter(surveyUnitDto -> - surveyUnitDto.getInterrogationId().equals("TestUE7") - && surveyUnitDto.getState().equals(DataState.EDITED) + surveyUnitModelEdited = testSurveyUnitModels.stream().filter(surveyUnitModel1 -> + surveyUnitModel1.getInterrogationId().equals("TestUE7") + && surveyUnitModel1.getState().equals(DataState.EDITED) ).toList().getFirst(); - suDtoEdited.getCollectedVariables().get(0).getValues().set(0,"1"); - suDtoEdited.getCollectedVariables().get(1).getValues().set(0,"1"); + surveyUnitModelEdited.getCollectedVariables().get(0).getValues().set(0,"1"); + surveyUnitModelEdited.getCollectedVariables().get(1).getValues().set(0,"1"); //Remove EDITED variable on 8th case - suDtoEdited = testSurveyUnitModels.stream().filter(surveyUnitDto -> - surveyUnitDto.getInterrogationId().equals("TestUE8") - && surveyUnitDto.getState().equals(DataState.EDITED) + surveyUnitModelEdited = testSurveyUnitModels.stream().filter(surveyUnitModel1 -> + surveyUnitModel1.getInterrogationId().equals("TestUE8") + && surveyUnitModel1.getState().equals(DataState.EDITED) ).toList().getFirst(); - suDtoEdited.getCollectedVariables().remove(1); + surveyUnitModelEdited.getCollectedVariables().remove(1); //When DataVerifier.verifySurveyUnits(testSurveyUnitModels,metadataModel.getVariables()); @@ -200,80 +200,80 @@ private void assertForcedExistence(List testSurveyUnitModels, S private void assertCollectedVariableContent(List testSurveyUnitModels, String interrogationId, String variableName, int valueIndex, String expectedContent) { assertForcedExistence(testSurveyUnitModels,interrogationId,true); - Optional suDtoOpt = testSurveyUnitModels.stream().filter(surveyUnit -> + Optional surveyUnitModelOpt = testSurveyUnitModels.stream().filter(surveyUnit -> surveyUnit.getInterrogationId().equals(interrogationId) && surveyUnit.getState() == DataState.FORCED).findFirst(); - assertThat(suDtoOpt).isPresent(); + assertThat(surveyUnitModelOpt).isPresent(); - SurveyUnitModel suDto = suDtoOpt.get(); + SurveyUnitModel surveyUnitModel = surveyUnitModelOpt.get(); - assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> + assertThat(surveyUnitModel.getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals(variableName) )).isNotEmpty(); - assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> + assertThat(surveyUnitModel.getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals(variableName) ).findFirst()).isPresent(); - assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> + assertThat(surveyUnitModel.getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals(variableName) ).findFirst().get().getValues().get(valueIndex)).isEqualTo(expectedContent); } private void assertForcedCollectedVariableExistence(List testSurveyUnitModels, String interrogationId, String variableName, boolean hasToExist) { assertForcedExistence(testSurveyUnitModels,interrogationId, true); - Optional suDtoOpt = testSurveyUnitModels.stream().filter(surveyUnit -> + Optional surveyUnitModelOpt = testSurveyUnitModels.stream().filter(surveyUnit -> surveyUnit.getInterrogationId().equals(interrogationId) && surveyUnit.getState() == DataState.FORCED).findFirst(); - assertThat(suDtoOpt).isPresent(); + assertThat(surveyUnitModelOpt).isPresent(); - SurveyUnitModel suDto = suDtoOpt.get(); + SurveyUnitModel surveyUnitModel = surveyUnitModelOpt.get(); if(hasToExist) - assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals(variableName)).toList()).isNotEmpty(); + assertThat(surveyUnitModel.getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals(variableName)).toList()).isNotEmpty(); else - assertThat(suDto.getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals(variableName)).toList()).isEmpty(); + assertThat(surveyUnitModel.getCollectedVariables().stream().filter(collectedVariableDto -> collectedVariableDto.getVarId().equals(variableName)).toList()).isEmpty(); } private void assertForcedExternalVariableExistence(List testSurveyUnitModels, String interrogationId, String variableName, boolean hasToExist) { assertForcedExistence(testSurveyUnitModels,interrogationId, true); - Optional suDtoOpt = testSurveyUnitModels.stream().filter(surveyUnit -> + Optional surveyUnitModelOpt = testSurveyUnitModels.stream().filter(surveyUnit -> surveyUnit.getInterrogationId().equals(interrogationId) && surveyUnit.getState() == DataState.FORCED).findFirst(); - assertThat(suDtoOpt).isPresent(); + assertThat(surveyUnitModelOpt).isPresent(); - SurveyUnitModel suDto = suDtoOpt.get(); + SurveyUnitModel surveyUnitModel = surveyUnitModelOpt.get(); if(hasToExist) - assertThat(suDto.getExternalVariables().stream().filter(variableDto -> variableDto.getVarId().equals(variableName)).toList()).isNotEmpty(); + assertThat(surveyUnitModel.getExternalVariables().stream().filter(variableModel -> variableModel.getVarId().equals(variableName)).toList()).isNotEmpty(); else - assertThat(suDto.getExternalVariables().stream().filter(variableDto -> variableDto.getVarId().equals(variableName)).toList()).isEmpty(); + assertThat(surveyUnitModel.getExternalVariables().stream().filter(variableModel -> variableModel.getVarId().equals(variableName)).toList()).isEmpty(); } private void assertExternalVariableContent(List testSurveyUnitModels, String interrogationId, String variableName, int valueIndex, String expectedContent) { assertForcedExistence(testSurveyUnitModels,interrogationId,true); - Optional suDtoOpt = testSurveyUnitModels.stream().filter(surveyUnit -> + Optional surveyUnitModelOpt = testSurveyUnitModels.stream().filter(surveyUnit -> surveyUnit.getInterrogationId().equals(interrogationId) && surveyUnit.getState() == DataState.FORCED).findFirst(); - assertThat(suDtoOpt).isPresent(); + assertThat(surveyUnitModelOpt).isPresent(); - SurveyUnitModel suDto = suDtoOpt.get(); + SurveyUnitModel surveyUnitModel = surveyUnitModelOpt.get(); - assertThat(suDto.getExternalVariables().stream().filter(variableDto -> - variableDto.getVarId().equals(variableName) + assertThat(surveyUnitModel.getExternalVariables().stream().filter(variableModel -> + variableModel.getVarId().equals(variableName) )).isNotEmpty(); - assertThat(suDto.getExternalVariables().stream().filter(variableDto -> - variableDto.getVarId().equals(variableName) + assertThat(surveyUnitModel.getExternalVariables().stream().filter(variableModel -> + variableModel.getVarId().equals(variableName) ).findFirst()).isPresent(); - assertThat(suDto.getExternalVariables().stream().filter(variableDto -> - variableDto.getVarId().equals(variableName) + assertThat(surveyUnitModel.getExternalVariables().stream().filter(variableModel -> + variableModel.getVarId().equals(variableName) ).findFirst().get().getValues().get(valueIndex)).isEqualTo(expectedContent); } diff --git a/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java b/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java index bb1f0f9a..d68e1594 100644 --- a/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java +++ b/src/test/java/fr/insee/genesis/domain/service/SurveyUnitServiceTest.java @@ -29,8 +29,8 @@ class SurveyUnitServiceTest { static SurveyUnitPersistencePortStub surveyUnitPersistencePortStub; //Constants - static final String defaultInterrogationId = "TESTINTERROGATIONID"; - static final String defaultQuestionnaireId = "TESTQUESTIONNAIREID"; + static final String DEFAULT_INTERROGATION_ID = "TESTINTERROGATIONID"; + static final String DEFAULT_QUESTIONNAIRE_ID = "TESTQUESTIONNAIREID"; @BeforeAll static void init(){ @@ -52,8 +52,8 @@ void reset(){ surveyUnitPersistencePortStub.getMongoStub().add(SurveyUnitModel.builder() .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId(defaultInterrogationId) - .questionnaireId(defaultQuestionnaireId) + .interrogationId(DEFAULT_INTERROGATION_ID) + .questionnaireId(DEFAULT_QUESTIONNAIRE_ID) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023,1,1,0,0,0)) .recordDate(LocalDateTime.of(2024,1,1,0,0,0)) @@ -81,7 +81,7 @@ void saveAllTest(){ .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) .interrogationId("TESTINTERROGATIONID2") - .questionnaireId(defaultQuestionnaireId) + .questionnaireId(DEFAULT_QUESTIONNAIRE_ID) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023,1,1,0,0,0)) .recordDate(LocalDateTime.of(2024,1,1,0,0,0)) @@ -92,19 +92,19 @@ void saveAllTest(){ surveyUnitServiceStatic.saveSurveyUnits(newSurveyUnitModelList); - Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub()).filteredOn(surveyUnitDto -> - surveyUnitDto.getCampaignId().equals("TESTCAMPAIGNID") - && surveyUnitDto.getMode().equals(Mode.WEB) - && surveyUnitDto.getInterrogationId().equals("TESTINTERROGATIONID2") - && surveyUnitDto.getQuestionnaireId().equals(defaultQuestionnaireId) - && surveyUnitDto.getState().equals(DataState.COLLECTED) - && surveyUnitDto.getFileDate().equals(LocalDateTime.of(2023,1,1,0,0,0)) - && surveyUnitDto.getRecordDate().equals(LocalDateTime.of(2024,1,1,0,0,0)) - && !surveyUnitDto.getExternalVariables().stream().filter( + Assertions.assertThat(surveyUnitPersistencePortStub.getMongoStub()).filteredOn(surveyUnitModel -> + surveyUnitModel.getCampaignId().equals("TESTCAMPAIGNID") + && surveyUnitModel.getMode().equals(Mode.WEB) + && surveyUnitModel.getInterrogationId().equals("TESTINTERROGATIONID2") + && surveyUnitModel.getQuestionnaireId().equals(DEFAULT_QUESTIONNAIRE_ID) + && surveyUnitModel.getState().equals(DataState.COLLECTED) + && surveyUnitModel.getFileDate().equals(LocalDateTime.of(2023,1,1,0,0,0)) + && surveyUnitModel.getRecordDate().equals(LocalDateTime.of(2024,1,1,0,0,0)) + && !surveyUnitModel.getExternalVariables().stream().filter( externalVariable -> externalVariable.getVarId().equals("TESTIDVAR") && externalVariable.getValues().containsAll(List.of(new String[]{"V1", "V2"})) ).toList().isEmpty() - && !surveyUnitDto.getCollectedVariables().stream().filter( + && !surveyUnitModel.getCollectedVariables().stream().filter( collectedVariable -> collectedVariable.getVarId().equals("TESTIDVAR") && collectedVariable.getValues().containsAll(List.of(new String[]{"V1", "V2"})) ).toList().isEmpty() @@ -113,25 +113,25 @@ void saveAllTest(){ @Test void findByIdsUEAndQuestionnaireTest(){ - Assertions.assertThat(surveyUnitServiceStatic.findByIdsInterrogationAndQuestionnaire(defaultInterrogationId, defaultQuestionnaireId)).filteredOn( - surveyUnitDto -> - surveyUnitDto.getInterrogationId().equals(defaultInterrogationId) - && surveyUnitDto.getQuestionnaireId().equals(defaultQuestionnaireId) + Assertions.assertThat(surveyUnitServiceStatic.findByIdsInterrogationAndQuestionnaire(DEFAULT_INTERROGATION_ID, DEFAULT_QUESTIONNAIRE_ID)).filteredOn( + surveyUnitModel -> + surveyUnitModel.getInterrogationId().equals(DEFAULT_INTERROGATION_ID) + && surveyUnitModel.getQuestionnaireId().equals(DEFAULT_QUESTIONNAIRE_ID) ).isNotEmpty(); } @Test void findByInterrogationIdTest(){ - Assertions.assertThat(surveyUnitServiceStatic.findByInterrogationId(defaultInterrogationId)).filteredOn( - surveyUnitDto -> - surveyUnitDto.getInterrogationId().equals(defaultInterrogationId) + Assertions.assertThat(surveyUnitServiceStatic.findByInterrogationId(DEFAULT_INTERROGATION_ID)).filteredOn( + surveyUnitModel -> + surveyUnitModel.getInterrogationId().equals(DEFAULT_INTERROGATION_ID) ).isNotEmpty(); } @Test void findByQuestionnaireIdTest(){ - Assertions.assertThat(surveyUnitServiceStatic.findByQuestionnaireId(defaultQuestionnaireId)).filteredOn( - surveyUnitDto -> surveyUnitDto.getQuestionnaireId().equals(defaultQuestionnaireId) + Assertions.assertThat(surveyUnitServiceStatic.findByQuestionnaireId(DEFAULT_QUESTIONNAIRE_ID)).filteredOn( + surveyUnitModel -> surveyUnitModel.getQuestionnaireId().equals(DEFAULT_QUESTIONNAIRE_ID) ).isNotEmpty(); } @@ -139,10 +139,10 @@ void findByQuestionnaireIdTest(){ void findLatestByIdAndByModeTest(){ addAdditionnalDtoToMongoStub(); - Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(defaultInterrogationId, defaultQuestionnaireId)).filteredOn( - surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultInterrogationId) - && surveyUnitDto.getQuestionnaireId().equals(defaultQuestionnaireId) - && surveyUnitDto.getFileDate().getMonth().equals(Month.FEBRUARY) + Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(DEFAULT_INTERROGATION_ID, DEFAULT_QUESTIONNAIRE_ID)).filteredOn( + surveyUnitModel -> surveyUnitModel.getInterrogationId().equals(DEFAULT_INTERROGATION_ID) + && surveyUnitModel.getQuestionnaireId().equals(DEFAULT_QUESTIONNAIRE_ID) + && surveyUnitModel.getFileDate().getMonth().equals(Month.FEBRUARY) ).isNotEmpty(); } @@ -156,10 +156,10 @@ void findResponsesByUEAndQuestionnaireTest_null_collectedVariables() { ); surveyUnitPersistencePortStub.getMongoStub().getLast().setCollectedVariables(null); - Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(defaultInterrogationId, defaultQuestionnaireId)).filteredOn( - surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultInterrogationId) - && surveyUnitDto.getQuestionnaireId().equals(defaultQuestionnaireId) - && surveyUnitDto.getFileDate().getMonth().equals(Month.FEBRUARY) + Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(DEFAULT_INTERROGATION_ID, DEFAULT_QUESTIONNAIRE_ID)).filteredOn( + surveyUnitModel -> surveyUnitModel.getInterrogationId().equals(DEFAULT_INTERROGATION_ID) + && surveyUnitModel.getQuestionnaireId().equals(DEFAULT_QUESTIONNAIRE_ID) + && surveyUnitModel.getFileDate().getMonth().equals(Month.FEBRUARY) ).isNotEmpty(); } @Test @@ -172,10 +172,10 @@ void findResponsesByUEAndQuestionnaireTest_null_externalVariables() { ); surveyUnitPersistencePortStub.getMongoStub().getLast().setExternalVariables(null); - Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(defaultInterrogationId, defaultQuestionnaireId)).filteredOn( - surveyUnitDto -> surveyUnitDto.getInterrogationId().equals(defaultInterrogationId) - && surveyUnitDto.getQuestionnaireId().equals(defaultQuestionnaireId) - && surveyUnitDto.getFileDate().getMonth().equals(Month.FEBRUARY) + Assertions.assertThat(surveyUnitServiceStatic.findLatestByIdAndByQuestionnaireId(DEFAULT_INTERROGATION_ID, DEFAULT_QUESTIONNAIRE_ID)).filteredOn( + surveyUnitModel -> surveyUnitModel.getInterrogationId().equals(DEFAULT_INTERROGATION_ID) + && surveyUnitModel.getQuestionnaireId().equals(DEFAULT_QUESTIONNAIRE_ID) + && surveyUnitModel.getFileDate().getMonth().equals(Month.FEBRUARY) ).isNotEmpty(); } @@ -183,14 +183,14 @@ void findResponsesByUEAndQuestionnaireTest_null_externalVariables() { void findDistinctInterrogationIdsByQuestionnaireIdTest(){ addAdditionnalDtoToMongoStub(); - Assertions.assertThat(surveyUnitServiceStatic.findDistinctInterrogationIdsByQuestionnaireId(defaultQuestionnaireId)).filteredOn( - surveyUnitId -> surveyUnitId.getInterrogationId().equals(defaultInterrogationId) + Assertions.assertThat(surveyUnitServiceStatic.findDistinctInterrogationIdsByQuestionnaireId(DEFAULT_QUESTIONNAIRE_ID)).filteredOn( + interrogationId -> interrogationId.getInterrogationId().equals(DEFAULT_INTERROGATION_ID) ).isNotEmpty().hasSize(1); } @Test void findInterrogationIdsByQuestionnaireIdTest(){ - Assertions.assertThat(surveyUnitServiceStatic.findModesByQuestionnaireId(defaultQuestionnaireId)).filteredOn( + Assertions.assertThat(surveyUnitServiceStatic.findModesByQuestionnaireId(DEFAULT_QUESTIONNAIRE_ID)).filteredOn( mode -> mode.equals(Mode.WEB) ).isNotEmpty(); } @@ -239,13 +239,13 @@ void findLatestByIdAndByQuestionnaireIdPerretTest(){ //When SurveyUnitDto surveyUnitDto = surveyUnitServiceStatic.findLatestValuesByStateByIdAndByQuestionnaireId( - defaultInterrogationId, - defaultQuestionnaireId + DEFAULT_INTERROGATION_ID, + DEFAULT_QUESTIONNAIRE_ID ); //Then - Assertions.assertThat(surveyUnitDto.getSurveyUnitId()).isEqualTo(defaultInterrogationId); + Assertions.assertThat(surveyUnitDto.getInterrogationId()).isEqualTo(DEFAULT_INTERROGATION_ID); Assertions.assertThat(surveyUnitDto.getCollectedVariables().getFirst().getVariableName()) .isEqualTo("TESTIDVAR"); @@ -308,13 +308,13 @@ void findLatestByIdAndByQuestionnaireIdPerretTest_null_collectedVariables(){ //When SurveyUnitDto surveyUnitDto = surveyUnitServiceStatic.findLatestValuesByStateByIdAndByQuestionnaireId( - defaultInterrogationId, - defaultQuestionnaireId + DEFAULT_INTERROGATION_ID, + DEFAULT_QUESTIONNAIRE_ID ); //Then - Assertions.assertThat(surveyUnitDto.getSurveyUnitId()).isEqualTo(defaultInterrogationId); + Assertions.assertThat(surveyUnitDto.getInterrogationId()).isEqualTo(DEFAULT_INTERROGATION_ID); Assertions.assertThat(surveyUnitDto.getCollectedVariables().getFirst().getVariableName()) .isEqualTo("TESTIDVAR"); @@ -367,13 +367,13 @@ void findLatestByIdAndByQuestionnaireIdPerretTest_null_externalVariables(){ //When SurveyUnitDto surveyUnitDto = surveyUnitServiceStatic.findLatestValuesByStateByIdAndByQuestionnaireId( - defaultInterrogationId, - defaultQuestionnaireId + DEFAULT_INTERROGATION_ID, + DEFAULT_QUESTIONNAIRE_ID ); //Then - Assertions.assertThat(surveyUnitDto.getSurveyUnitId()).isEqualTo(defaultInterrogationId); + Assertions.assertThat(surveyUnitDto.getInterrogationId()).isEqualTo(DEFAULT_INTERROGATION_ID); Assertions.assertThat(surveyUnitDto.getCollectedVariables().getFirst().getVariableName()) .isEqualTo("TESTIDVAR"); @@ -424,8 +424,8 @@ private void addAdditionnalDtoToMongoStub(){ SurveyUnitModel recentDTO = SurveyUnitModel.builder() .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId(defaultInterrogationId) - .questionnaireId(defaultQuestionnaireId) + .interrogationId(DEFAULT_INTERROGATION_ID) + .questionnaireId(DEFAULT_QUESTIONNAIRE_ID) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023,2,2,0,0,0)) .recordDate(LocalDateTime.of(2024,2,2,0,0,0)) @@ -447,7 +447,7 @@ private void addAdditionnalDtoToMongoStub(String questionnaireId) { SurveyUnitModel recentDTO = SurveyUnitModel.builder() .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId(defaultInterrogationId) + .interrogationId(DEFAULT_INTERROGATION_ID) .questionnaireId(questionnaireId) .state(DataState.COLLECTED) .fileDate(LocalDateTime.of(2023, 2, 2, 0, 0, 0)) @@ -474,8 +474,8 @@ private void addAdditionnalDtoToMongoStub(DataState state, SurveyUnitModel recentDTO = SurveyUnitModel.builder() .campaignId("TESTCAMPAIGNID") .mode(Mode.WEB) - .interrogationId(defaultInterrogationId) - .questionnaireId(defaultQuestionnaireId) + .interrogationId(DEFAULT_INTERROGATION_ID) + .questionnaireId(DEFAULT_QUESTIONNAIRE_ID) .state(state) .fileDate(fileDate) .recordDate(recordDate) diff --git a/src/test/java/fr/insee/genesis/domain/utils/DataVerifierTest.java b/src/test/java/fr/insee/genesis/domain/utils/DataVerifierTest.java index c558f0c5..50bc4b7d 100644 --- a/src/test/java/fr/insee/genesis/domain/utils/DataVerifierTest.java +++ b/src/test/java/fr/insee/genesis/domain/utils/DataVerifierTest.java @@ -52,13 +52,13 @@ void setUp() { @Test void shouldHandleEmptyValuesList() { - List suDtosList = new ArrayList<>(); + List surveyUnitModelsList = new ArrayList<>(); // When - DataVerifier.verifySurveyUnits(suDtosList, null); + DataVerifier.verifySurveyUnits(surveyUnitModelsList, null); // Then - assertTrue(suDtosList.isEmpty()); // Empty list, nothing invalid, so should return null + assertTrue(surveyUnitModelsList.isEmpty()); // Empty list, nothing invalid, so should return null } @Test diff --git a/src/test/resources/features/do_we_extract_data.feature b/src/test/resources/features/do_we_extract_data.feature index 8b1483c8..65ba76da 100644 --- a/src/test/resources/features/do_we_extract_data.feature +++ b/src/test/resources/features/do_we_extract_data.feature @@ -3,18 +3,18 @@ Feature: Do we extract data ? Scenario Outline: Collected data extraction (COLLECTED only) Given We have data in directory "SAMPLETEST-PARADATA-v1" - When We create DTOs from file "reponse-platine/data.complete.validated.STPDv1.20231122164209.xml" with DDI "ddi-SAMPLETEST-PARADATA-v1.xml" - Then For SurveyUnit "" there should be at least one "" SurveyUnit DTO + When We create survey unit models from file "reponse-platine/data.complete.validated.STPDv1.20231122164209.xml" with DDI "ddi-SAMPLETEST-PARADATA-v1.xml" + Then For SurveyUnit "" there should be at least one "" SurveyUnit Model Examples: - | SurveyUnitId | ExpectedStatus | + | InterrogationId | ExpectedStatus | | 0000007 | COLLECTED | Scenario Outline: Collected data extraction (COLLECTED only) Given We have data in directory "SAMPLETEST-PARADATA-v1" - When We create DTOs from file "reponse-platine/data.complete.validated.STPDv1.20231122164209.xml" with DDI "ddi-SAMPLETEST-PARADATA-v1.xml" - Then For SurveyUnit "" there shouldn't be a "" SurveyUnit DTO + When We create survey unit models from file "reponse-platine/data.complete.validated.STPDv1.20231122164209.xml" with DDI "ddi-SAMPLETEST-PARADATA-v1.xml" + Then For SurveyUnit "" there shouldn't be a "" SurveyUnit Model Examples: - | SurveyUnitId | UnexpectedStatus | + | InterrogationId | UnexpectedStatus | | 0000007 | EDITED | | 0000007 | FORCED | | 0000007 | INPUTED | @@ -24,10 +24,10 @@ Feature: Do we extract data ? Scenario Outline: Collected data extraction (all states) Given We have data in directory "SAMPLETEST-PARADATA-v2" - When We create DTOs from file "reponse-platine/data.complete.validated.STPDv2.20231122164209.xml" with DDI "ddi-SAMPLETEST-PARADATA-v2.xml" - Then For SurveyUnit "" there should be at least one "" SurveyUnit DTO + When We create survey unit models from file "reponse-platine/data.complete.validated.STPDv2.20231122164209.xml" with DDI "ddi-SAMPLETEST-PARADATA-v2.xml" + Then For SurveyUnit "" there should be at least one "" SurveyUnit Model Examples: - | SurveyUnitId | ExpectedStatus | + | InterrogationId | ExpectedStatus | | 0000007 | COLLECTED | | 0000007 | EDITED | | 0000007 | FORCED | @@ -36,10 +36,10 @@ Feature: Do we extract data ? Scenario Outline: Collected data extraction content Given We have data in directory "" - When We create DTOs from file "" with DDI "" - Then We should have a "" DTO for survey unit "" with "" filled with "" at index + When We create survey unit models from file "" with DDI "" + Then We should have a "" Survey Unit model with id "" with "" filled with "" at index Examples: - | Directory | FileName | DDIFileName | ExpectedDataState | SurveyUnitId | VariableName | ExpectedValue | ExpectedIndex | + | Directory | FileName | DDIFileName | ExpectedDataState | InterrogationId | VariableName | ExpectedValue | ExpectedIndex | | SAMPLETEST-PARADATA-v1 | reponse-platine/data.complete.validated.STPDv1.20231122164209.xml |ddi-SAMPLETEST-PARADATA-v1.xml | COLLECTED | 0000007 | PRENOM_C | TESTPRENOM7 | 0 | | SAMPLETEST-PARADATA-v2 | reponse-platine/data.complete.validated.STPDv2.20231122164209.xml |ddi-SAMPLETEST-PARADATA-v2.xml | COLLECTED | 0000007 | PRENOM_C | TESTPRENOM7 | 0 | | SAMPLETEST-PARADATA-v2 | reponse-platine/data.complete.validated.STPDv2.20231122164209.xml |ddi-SAMPLETEST-PARADATA-v2.xml | EDITED | 0000007 | SANTE_ENFLOG71 | TESTSANTE7E | 0 | @@ -50,11 +50,11 @@ Feature: Do we extract data ? Scenario Outline: External data extraction Given We have data in directory "" - When We create DTOs from file "" with DDI "" - Then We should have values for external variable "" for survey unit "" - And For external variable "" in survey unit "" we should have "" as value number + When We create survey unit models from file "" with DDI "" + Then We should have values for external variable "" for survey unit "" + And For external variable "" in survey unit "" we should have "" as value number Examples: - | Directory | FileName | DDIFileName | ExpectedNumberOfValues | ExternalVariableName | SurveyUnitId | ExpectedValue | ExpectedValueIndex | + | Directory | FileName | DDIFileName | ExpectedNumberOfValues | ExternalVariableName | InterrogationId | ExpectedValue | ExpectedValueIndex | | SAMPLETEST-PARADATA-v1 | reponse-platine/data.complete.validated.STPDv1.20231122164209.xml |ddi-SAMPLETEST-PARADATA-v1.xml | 1 | RPANAISCONJ | 0000007 | 1986 | 0 | | SAMPLETEST-PARADATA-v1 | reponse-platine/data.complete.validated.STPDv1.20231122164209.xml |ddi-SAMPLETEST-PARADATA-v1.xml | 2 | RPPRENOM | 0000007 | TESTRPRENOM7_2 | 0 | | SAMPLETEST-PARADATA-v1 | reponse-platine/data.complete.validated.STPDv1.20231122164209.xml |ddi-SAMPLETEST-PARADATA-v1.xml | 2 | RPPRENOM | 0000007 | TESTRPRENOM7PAR1 | 1 |