From 26733609f9c5b1689b540f9079744b2b941e5bce Mon Sep 17 00:00:00 2001 From: davdarras Date: Mon, 14 Oct 2024 11:26:30 +0200 Subject: [PATCH] feat: add interrogation id --- .gitignore | 3 ++ pom.xml | 2 +- .../fr/insee/pearljam/batch/Launcher.java | 21 ++++++++------ .../pearljam/batch/dao/SurveyUnitDaoImpl.java | 7 +++-- .../service/PilotageLauncherService.java | 11 +++++++- .../batch/utils/DataCollectionMapper.java | 2 +- .../pearljam/batch/utils/PilotageMapper.java | 3 +- .../insee/pearljam/batch/utils/XmlUtils.java | 1 + 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 +++++++++---------- 19 files changed, 83 insertions(+), 42 deletions(-) create mode 100644 src/test/resources/sql/pilotage/550_add_business_id.xml diff --git a/.gitignore b/.gitignore index 302fd6fe..bbcf1ba2 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,9 @@ target/ /.nb-gradle/ build/ +application-*.properties +application-*.yaml +application-*.yml ### VS Code ### .vscode/ diff --git a/pom.xml b/pom.xml index eff355b5..4a676b3b 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 fr.insee.pearljam pearljam-batch - 3.1.1 + 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 f2beb68f..dbd06e6c 100644 --- a/src/main/java/fr/insee/pearljam/batch/Launcher.java +++ b/src/main/java/fr/insee/pearljam/batch/Launcher.java @@ -152,15 +152,18 @@ public static BatchErrorCode runBatch(String[] options) } logger.log(Level.INFO, "Batch is running with option {}", batchOption.getLabel()); switch(batchOption) { - case DAILYUPDATE: - triggerService = context.getBean(TriggerService.class); - return triggerService.updateStates(); - case SYNCHRONIZE: - logger.log(Level.INFO, "Running synchronization with context referential"); - triggerService = context.getBean(TriggerService.class); - return triggerService.synchronizeWithOpale(FOLDER_OUT); - default: - return pilotageLauncherService.validateLoadClean(batchOption, FOLDER_IN, FOLDER_OUT); + // Update states of survey units based on the visibility dates + case DAILYUPDATE: + triggerService = context.getBean(TriggerService.class); + return triggerService.updateStates(); + // synchronize interviewers and survey unit affectations for the interviewers + case SYNCHRONIZE: + logger.log(Level.INFO, "Running synchronization with context referential"); + triggerService = context.getBean(TriggerService.class); + return triggerService.synchronizeWithOpale(FOLDER_OUT); + // use pilotage launcher + default: + return 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 902995c4..6b95f243 100644 --- a/src/main/java/fr/insee/pearljam/batch/dao/SurveyUnitDaoImpl.java +++ b/src/main/java/fr/insee/pearljam/batch/dao/SurveyUnitDaoImpl.java @@ -53,9 +53,9 @@ public void deleteSurveyUnitByCampaignId(String 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 (?, ?, ?, ?, ?, ?, ?)"; + 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(), + pilotageJdbcTemplate.update(qString, surveyUnit.getId(), surveyUnit.getDisplayName(), surveyUnit.isPriority(), addressId, campaignId, interviewerId, sampleIdentifierId, organizationUnitId); } @@ -103,7 +103,8 @@ public void setSurveyUnitOrganizationUnitAffectation(String surveyUnitId, String private static final class SurveyUnitTypeMapper implements RowMapper { public SurveyUnitType mapRow(ResultSet rs, int rowNum) throws SQLException { SurveyUnitType su = new SurveyUnitType(); - su.setId(rs.getString("id")); + su.setId(rs.getString("id")); + su.setDisplayName(rs.getString("display_name")); su.setPriority(rs.getBoolean("priority")); su.setInterviewerId(rs.getString("interviewer_id")); su.setOrganizationalUnitId(rs.getString("organization_unit_id")); diff --git a/src/main/java/fr/insee/pearljam/batch/service/PilotageLauncherService.java b/src/main/java/fr/insee/pearljam/batch/service/PilotageLauncherService.java index 361f2d8b..e88df051 100644 --- a/src/main/java/fr/insee/pearljam/batch/service/PilotageLauncherService.java +++ b/src/main/java/fr/insee/pearljam/batch/service/PilotageLauncherService.java @@ -171,12 +171,16 @@ private String getName(BatchOption batchOption) { */ public BatchErrorCode load(BatchOption batchOption, String in, String out, String processing) throws SQLException, DataBaseException, ValidateException, SynchronizationException, IOException, BatchException, ParserConfigurationException, SAXException { switch(batchOption) { + // Delete campaign case DELETECAMPAIGN: return deleteCampaign(in, out); + // extract campaign data case EXTRACT: return extractCampaign(in, out); + // Create context when empty database case LOADCONTEXT: return loadContext(in); + // Create/Update survey units case SAMPLEPROCESSING: return loadSampleProcessing(in, processing); default: @@ -389,7 +393,12 @@ public BatchErrorCode loadSampleProcessing(String in, String processing) throws // Extract campaignId, list of steps and list of survey-unit id from sampleprocessing String campaignId = sampleProcessing.getIdSource() + sampleProcessing.getMillesime() + sampleProcessing.getIdPeriode(); List 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/java/fr/insee/pearljam/batch/utils/XmlUtils.java b/src/main/java/fr/insee/pearljam/batch/utils/XmlUtils.java index 7c0b9969..5e7dbbc6 100644 --- a/src/main/java/fr/insee/pearljam/batch/utils/XmlUtils.java +++ b/src/main/java/fr/insee/pearljam/batch/utils/XmlUtils.java @@ -165,6 +165,7 @@ public static File objectToXML(String filename, Object object) throws BatchExcep jaxbMarshaller.marshal(object, file); return file; }catch (JAXBException e) { + e.printStackTrace(); throw new BatchException("Error during transfo object to xml : " + e.getMessage()); } } diff --git a/src/main/resources/xsd/campaign.xsd b/src/main/resources/xsd/campaign.xsd index 54ac4f10..ed9b6620 100644 --- a/src/main/resources/xsd/campaign.xsd +++ b/src/main/resources/xsd/campaign.xsd @@ -131,6 +131,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'),