From b7e86a4c728b196c281140c03b458c93e62126cd Mon Sep 17 00:00:00 2001 From: David Darras <117278497+davdarras@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:37:20 +0100 Subject: [PATCH] feat: add business id (display name) to survey unit (#76) --- .gitignore | 4 +++ pom.xml | 2 +- .../fr/insee/pearljam/batch/Launcher.java | 4 +++ .../pearljam/batch/dao/SurveyUnitDaoImpl.java | 15 +++++----- .../service/PilotageLauncherService.java | 11 +++++++- .../batch/utils/DataCollectionMapper.java | 2 +- .../pearljam/batch/utils/PilotageMapper.java | 3 +- src/main/resources/xsd/campaign.xsd | 1 + src/main/resources/xsd/sampleProcessing.xsd | 1 + .../sampleProcessing.xml | 4 +-- .../sampleProcessing.xml | 4 +-- .../sampleProcessing.xml | 4 +-- .../sampleProcessing.xml | 4 +-- .../sampleProcessing.xml | 4 +-- .../sampleProcessing.xml | 4 +-- src/test/resources/sql/masterPilotage.xml | 3 ++ .../sql/pilotage/550_add_business_id.xml | 18 ++++++++++++ .../resources/sql/pilotage/reinit-data.sql | 28 +++++++++---------- 18 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 src/test/resources/sql/pilotage/550_add_business_id.xml diff --git a/.gitignore b/.gitignore index 7d09b4ae..b6af7f8f 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,10 @@ target/ build/ src/test/resources/out src/test/resources/**/testScenarios + +application-*.properties +application-*.yaml +application-*.yml ### VS Code ### .vscode/ diff --git a/pom.xml b/pom.xml index 81603a7f..18fb28c2 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 fr.insee.pearljam pearljam-batch - 3.1.2 + 3.2.0 jar pearljam-batch PearlJam Batch diff --git a/src/main/java/fr/insee/pearljam/batch/Launcher.java b/src/main/java/fr/insee/pearljam/batch/Launcher.java index 21066a7c..b52656b8 100644 --- a/src/main/java/fr/insee/pearljam/batch/Launcher.java +++ b/src/main/java/fr/insee/pearljam/batch/Launcher.java @@ -164,8 +164,11 @@ public BatchErrorCode runBatch(String[] options) logger.log(Level.INFO, "Batch is running with option {}", batchOption.getLabel()); return switch (batchOption) { + // Update states of survey units based on the visibility dates case DAILYUPDATE -> triggerService.updateStates(); + // synchronize interviewers and survey unit affectations for the interviewers case SYNCHRONIZE -> triggerService.synchronizeWithOpale(FOLDER_OUT); + // send communications case COMMUNICATION -> { try { yield communicationService.handleCommunications(); @@ -173,6 +176,7 @@ public BatchErrorCode runBatch(String[] options) yield BatchErrorCode.KO_TECHNICAL_ERROR; } } + // use pilotage launcher default -> pilotageLauncherService.validateLoadClean(batchOption, FOLDER_IN, FOLDER_OUT); }; diff --git a/src/main/java/fr/insee/pearljam/batch/dao/SurveyUnitDaoImpl.java b/src/main/java/fr/insee/pearljam/batch/dao/SurveyUnitDaoImpl.java index 1ee563ec..925ae60c 100644 --- a/src/main/java/fr/insee/pearljam/batch/dao/SurveyUnitDaoImpl.java +++ b/src/main/java/fr/insee/pearljam/batch/dao/SurveyUnitDaoImpl.java @@ -50,14 +50,14 @@ public void deleteSurveyUnitByCampaignId(String campaignId) { pilotageJdbcTemplate.update(qString, campaignId); } - @Override - public void createSurveyUnit(String campaignId, SurveyUnitType surveyUnit, Long addressId, - Long sampleIdentifierId, String interviewerId, String organizationUnitId) { - String qString = "INSERT INTO survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) VALUES (?, ?, ?, ?, ?, ?, ?)"; + @Override + public void createSurveyUnit(String campaignId, SurveyUnitType surveyUnit, Long addressId, + Long sampleIdentifierId, String interviewerId, String organizationUnitId) { + String qString = "INSERT INTO survey_unit (id, display_name, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; - pilotageJdbcTemplate.update(qString, surveyUnit.getId(), surveyUnit.isPriority(), - addressId, campaignId, interviewerId, sampleIdentifierId, organizationUnitId); - } + pilotageJdbcTemplate.update(qString, surveyUnit.getId(), surveyUnit.getDisplayName(), surveyUnit.isPriority(), + addressId, campaignId, interviewerId, sampleIdentifierId, organizationUnitId); + } @Override public List getAllSurveyUnitByCampaignId(String campaignId) { @@ -111,6 +111,7 @@ private static final class SurveyUnitTypeMapper implements RowMapper steps = sampleProcessing.getSteps().getStep().stream().map(Step::getName).collect(Collectors.toList()); - List surveyUnits = sampleProcessing.getQuestionnaires().getQuestionnaire().stream().map(su -> su.getInformationsGenerales().getUniteEnquetee().getIdentifiant()).collect(Collectors.toList()); + List surveyUnits = sampleProcessing + .getQuestionnaires() + .getQuestionnaire() + .stream() + .map(Campagne.Questionnaires.Questionnaire::getIdInterrogation) + .toList(); logger.log(Level.INFO, "Start split sample processing content"); Map mapDataCollectionSu = extractAndValidateDatacollectionFromSamplProcessing(steps, campaignId, sampleProcessing); diff --git a/src/main/java/fr/insee/pearljam/batch/utils/DataCollectionMapper.java b/src/main/java/fr/insee/pearljam/batch/utils/DataCollectionMapper.java index 4d3d00ba..b7c7dc65 100644 --- a/src/main/java/fr/insee/pearljam/batch/utils/DataCollectionMapper.java +++ b/src/main/java/fr/insee/pearljam/batch/utils/DataCollectionMapper.java @@ -28,7 +28,7 @@ public static fr.insee.queen.batch.sample.Campaign mapSampleProcessingToDataColl campaign.getSurveyUnits().getSurveyUnit().addAll( c.getQuestionnaires().getQuestionnaire().stream().map(su -> { fr.insee.queen.batch.sample.SurveyUnitType surveyUnitType = new fr.insee.queen.batch.sample.SurveyUnitType(); - surveyUnitType.setId(su.getInformationsGenerales().getUniteEnquetee().getIdentifiant()); + surveyUnitType.setId(su.getIdInterrogation()); surveyUnitType.setQuestionnaireModelId(su.getIdModele()); surveyUnitType.setData(su.getInformationsPersonnalisees().getData()); return surveyUnitType; diff --git a/src/main/java/fr/insee/pearljam/batch/utils/PilotageMapper.java b/src/main/java/fr/insee/pearljam/batch/utils/PilotageMapper.java index 6b37476a..17306d8e 100644 --- a/src/main/java/fr/insee/pearljam/batch/utils/PilotageMapper.java +++ b/src/main/java/fr/insee/pearljam/batch/utils/PilotageMapper.java @@ -46,7 +46,8 @@ public static Campaign mapSampleProcessingToPilotageCampaign(Campagne c) { campaign.getSurveyUnits().getSurveyUnit().addAll( c.getQuestionnaires().getQuestionnaire().stream().map(su -> { SurveyUnitType surveyUnitType = new SurveyUnitType(); - surveyUnitType.setId(su.getInformationsGenerales().getUniteEnquetee().getIdentifiant()); + surveyUnitType.setId(su.getIdInterrogation()); + surveyUnitType.setDisplayName(su.getInformationsGenerales().getUniteEnquetee().getIdentifiant()); surveyUnitType.setPriority(su.getInformationsGenerales().getUniteEnquetee().isPrioritaire()); surveyUnitType.setInterviewerId( su.getInformationsGenerales().getUniteEnquetee().getAffectation().getEnqueteurId()); diff --git a/src/main/resources/xsd/campaign.xsd b/src/main/resources/xsd/campaign.xsd index 0859baff..ab2c43bd 100644 --- a/src/main/resources/xsd/campaign.xsd +++ b/src/main/resources/xsd/campaign.xsd @@ -139,6 +139,7 @@ + diff --git a/src/main/resources/xsd/sampleProcessing.xsd b/src/main/resources/xsd/sampleProcessing.xsd index 5126ac89..75e21905 100644 --- a/src/main/resources/xsd/sampleProcessing.xsd +++ b/src/main/resources/xsd/sampleProcessing.xsd @@ -166,6 +166,7 @@ + diff --git a/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario1/sampleProcessing.xml b/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario1/sampleProcessing.xml index a4b18758..344f136e 100644 --- a/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario1/sampleProcessing.xml +++ b/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario1/sampleProcessing.xml @@ -11,12 +11,12 @@ - + - SIM1234 + business-id-SIM1234 true 0 diff --git a/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario2/sampleProcessing.xml b/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario2/sampleProcessing.xml index 21cbb74a..79452a99 100644 --- a/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario2/sampleProcessing.xml +++ b/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario2/sampleProcessing.xml @@ -11,11 +11,11 @@ - + - SIM1234 + business-id-SIM1234 true 0 diff --git a/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario3/sampleProcessing.xml b/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario3/sampleProcessing.xml index 0337ed9a..e7ca8869 100644 --- a/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario3/sampleProcessing.xml +++ b/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario3/sampleProcessing.xml @@ -11,11 +11,11 @@ - + - SIM1234 + business-id-SIM1234 true 0 diff --git a/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario4/sampleProcessing.xml b/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario4/sampleProcessing.xml index f10f288e..8e1fd22d 100644 --- a/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario4/sampleProcessing.xml +++ b/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario4/sampleProcessing.xml @@ -11,11 +11,11 @@ - + - SIM1234 + business-id-SIM1234 true 0 diff --git a/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario5/sampleProcessing.xml b/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario5/sampleProcessing.xml index 32c96177..cecd3c71 100644 --- a/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario5/sampleProcessing.xml +++ b/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario5/sampleProcessing.xml @@ -11,11 +11,11 @@ - + - SIM1234 + business-id-SIM1234 true 0 diff --git a/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario6/sampleProcessing.xml b/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario6/sampleProcessing.xml index dbc49b27..667bf446 100644 --- a/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario6/sampleProcessing.xml +++ b/src/test/resources/in/sampleprocessing/init/sampleprocessingScenario6/sampleProcessing.xml @@ -11,11 +11,11 @@ - + - SIM1234 + business-id-SIM1234 true 0 diff --git a/src/test/resources/sql/masterPilotage.xml b/src/test/resources/sql/masterPilotage.xml index a01ffd13..cfc8b75f 100644 --- a/src/test/resources/sql/masterPilotage.xml +++ b/src/test/resources/sql/masterPilotage.xml @@ -62,4 +62,7 @@ + + + \ No newline at end of file diff --git a/src/test/resources/sql/pilotage/550_add_business_id.xml b/src/test/resources/sql/pilotage/550_add_business_id.xml new file mode 100644 index 00000000..bd49550b --- /dev/null +++ b/src/test/resources/sql/pilotage/550_add_business_id.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/sql/pilotage/reinit-data.sql b/src/test/resources/sql/pilotage/reinit-data.sql index 7ff50f75..cd81a695 100644 --- a/src/test/resources/sql/pilotage/reinit-data.sql +++ b/src/test/resources/sql/pilotage/reinit-data.sql @@ -136,20 +136,20 @@ INSERT INTO public.state ("date","type",survey_unit_id) VALUES (1590504478334,'NVM','26'), (1590504478334,'NVM','27'), (1590504478334,'NVM','28'); -INSERT INTO public.survey_unit (id,priority,address_id,campaign_id,interviewer_id,sample_identifier_id,organization_unit_id,viewed,"move") VALUES - ('11',true,1,'SIMPSONS2020X00','INTW1',1,'OU-NORTH',false,NULL), - ('12',true,2,'SIMPSONS2020X00','INTW1',2,'OU-NORTH',false,NULL), - ('13',false,3,'SIMPSONS2020X00','INTW2',3,'OU-SOUTH',false,NULL), - ('14',false,4,'SIMPSONS2020X00','INTW3',4,'OU-SOUTH',false,NULL), - ('20',true,5,'VQS2021X00','INTW1',5,'OU-NORTH',false,NULL), - ('21',true,6,'VQS2021X00','INTW2',6,'OU-NORTH',false,NULL), - ('22',false,7,'VQS2021X00','INTW4',7,'OU-NORTH',false,NULL), - ('23',true,8,'VQS2021X00','INTW4',8,'OU-NORTH',false,NULL), - ('24',false,9,'STATE2020X00','INTW1',9,'OU-NORTH',false,NULL), - ('25',true,10,'STATE2021X00','INTW1',10,'OU-NORTH',false,NULL), - ('26',true,11,'STATE2022X00','INTW1',11,'OU-NORTH',false,NULL), - ('27',false,12,'STATE2023X00','INTW1',12,'OU-NORTH',false,NULL), - ('28',true,13,'STATE2024X00','INTW1',13,'OU-NORTH',false,NULL); +INSERT INTO public.survey_unit (id, display_name, priority,address_id,campaign_id,interviewer_id,sample_identifier_id,organization_unit_id,viewed,"move") VALUES + ('11','business-id-11',true,1,'SIMPSONS2020X00','INTW1',1,'OU-NORTH',false,NULL), + ('12','business-id-12',true,2,'SIMPSONS2020X00','INTW1',2,'OU-NORTH',false,NULL), + ('13','business-id-13',false,3,'SIMPSONS2020X00','INTW2',3,'OU-SOUTH',false,NULL), + ('14','business-id-14',false,4,'SIMPSONS2020X00','INTW3',4,'OU-SOUTH',false,NULL), + ('20','business-id-20',true,5,'VQS2021X00','INTW1',5,'OU-NORTH',false,NULL), + ('21','business-id-21',true,6,'VQS2021X00','INTW2',6,'OU-NORTH',false,NULL), + ('22','business-id-22',false,7,'VQS2021X00','INTW4',7,'OU-NORTH',false,NULL), + ('23','business-id-23',true,8,'VQS2021X00','INTW4',8,'OU-NORTH',false,NULL), + ('24','business-id-24',false,9,'STATE2020X00','INTW1',9,'OU-NORTH',false,NULL), + ('25','business-id-25',true,10,'STATE2021X00','INTW1',10,'OU-NORTH',false,NULL), + ('26','business-id-26',true,11,'STATE2022X00','INTW1',11,'OU-NORTH',false,NULL), + ('27','business-id-27',false,12,'STATE2023X00','INTW1',12,'OU-NORTH',false,NULL), + ('28','business-id-28',true,13,'STATE2024X00','INTW1',13,'OU-NORTH',false,NULL); INSERT INTO public."user" (id,first_name,last_name,organization_unit_id) VALUES ('ABC','Melinda','Webb','OU-NORTH'), ('DEF','Everett','Juste','OU-NORTH'),