Skip to content

Commit

Permalink
feat: add interrogation id
Browse files Browse the repository at this point in the history
  • Loading branch information
davdarras committed Oct 18, 2024
1 parent 9d7ebd6 commit 2673360
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ target/
/.nb-gradle/
build/

application-*.properties
application-*.yaml
application-*.yml
### VS Code ###
.vscode/

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.insee.pearljam</groupId>
<artifactId>pearljam-batch</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
<packaging>jar</packaging>
<name>pearljam-batch</name>
<description>PearlJam Batch</description>
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/fr/insee/pearljam/batch/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -103,7 +103,8 @@ public void setSurveyUnitOrganizationUnitAffectation(String surveyUnitId, String
private static final class SurveyUnitTypeMapper implements RowMapper<SurveyUnitType> {
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<String> steps = sampleProcessing.getSteps().getStep().stream().map(Step::getName).collect(Collectors.toList());
List<String> surveyUnits = sampleProcessing.getQuestionnaires().getQuestionnaire().stream().map(su -> su.getInformationsGenerales().getUniteEnquetee().getIdentifiant()).collect(Collectors.toList());
List<String> surveyUnits = sampleProcessing
.getQuestionnaires()
.getQuestionnaire()
.stream()
.map(Campagne.Questionnaires.Questionnaire::getIdInterrogation)
.toList();

logger.log(Level.INFO, "Start split sample processing content");
Map<String, SurveyUnit> mapDataCollectionSu = extractAndValidateDatacollectionFromSamplProcessing(steps, campaignId, sampleProcessing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/fr/insee/pearljam/batch/utils/XmlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/xsd/campaign.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<xs:complexType name="SurveyUnitType">
<xs:all>
<xs:element name="Id" type="xs:string" />
<xs:element name="DisplayName" type="xs:string" minOccurs="0" />
<xs:element minOccurs="0" maxOccurs="1" name="InterviewerId" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="OrganizationalUnitId" type="xs:string" />
<xs:element name="Priority" type="xs:boolean" />
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/xsd/sampleProcessing.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
</xs:element>
</xs:sequence>
<xs:attribute name="idModele" type="xs:string" use="required" />
<xs:attribute name="idInterrogation" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
</Step>
</Steps>
<Questionnaires>
<Questionnaire idModele="simpsons">
<Questionnaire idModele="simpsons" idInterrogation="SIM1234">
<!--[WEB]<Questionnaire idModele="SIMPSON" idVague="1" idLot="1"> -->
<InformationsGenerales>
<UniteEnquetee>
<test></test>
<Identifiant>SIM1234</Identifiant>
<Identifiant>business-id-SIM1234</Identifiant>
<Prioritaire>true</Prioritaire>
<IdentifiantsInsee>
<Bs>0</Bs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</Step>
</Steps>
<Questionnaires>
<Questionnaire idModele="simpsons">
<Questionnaire idModele="simpsons" idInterrogation="SIM1234">
<!--[WEB]<Questionnaire idModele="SIMPSON" idVague="1" idLot="1"> -->
<InformationsGenerales>
<UniteEnquetee>
<Identifiant>SIM1234</Identifiant>
<Identifiant>business-id-SIM1234</Identifiant>
<Prioritaire>true</Prioritaire>
<IdentifiantsInsee>
<Bs>0</Bs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</Step>
</Steps>
<Questionnaires>
<Questionnaire idModele="simpsons">
<Questionnaire idModele="simpsons" idInterrogation="SIM1234">
<!--[WEB]<Questionnaire idModele="SIMPSON" idVague="1" idLot="1"> -->
<InformationsGenerales>
<UniteEnquetee>
<Identifiant>SIM1234</Identifiant>
<Identifiant>business-id-SIM1234</Identifiant>
<Prioritaire>true</Prioritaire>
<IdentifiantsInsee>
<Bs>0</Bs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</Step>
</Steps>
<Questionnaires>
<Questionnaire idModele="simpsons">
<Questionnaire idModele="simpsons" idInterrogation="SIM1234">
<!--[WEB]<Questionnaire idModele="SIMPSON" idVague="1" idLot="1"> -->
<InformationsGenerales>
<UniteEnquetee>
<Identifiant>SIM1234</Identifiant>
<Identifiant>business-id-SIM1234</Identifiant>
<Prioritaire>true</Prioritaire>
<IdentifiantsInsee>
<Bs>0</Bs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</Step>
</Steps>
<Questionnaires>
<Questionnaire idModele="simpsons">
<Questionnaire idModele="simpsons" idInterrogation="SIM1234">
<!--[WEB]<Questionnaire idModele="SIMPSON" idVague="1" idLot="1"> -->
<InformationsGenerales>
<UniteEnquetee>
<Identifiant>SIM1234</Identifiant>
<Identifiant>business-id-SIM1234</Identifiant>
<Prioritaire>true</Prioritaire>
<IdentifiantsInsee>
<Bs>0</Bs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</Step>
</Steps>
<Questionnaires>
<Questionnaire idModele="simpsons">
<Questionnaire idModele="simpsons" idInterrogation="SIM1234">
<!--[WEB]<Questionnaire idModele="SIMPSON" idVague="1" idLot="1"> -->
<InformationsGenerales>
<UniteEnquetee>
<Identifiant>SIM1234</Identifiant>
<Identifiant>business-id-SIM1234</Identifiant>
<Prioritaire>true</Prioritaire>
<IdentifiantsInsee>
<Bs>0</Bs>
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/sql/masterPilotage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@

<!-- move mail/tel to visibility -->
<include file="pilotage/546_update_communication_information.xml" relativeToChangelogFile="true" />

<!-- add business id -->
<include file="pilotage/550_add_business_id.xml" relativeToChangelogFile="true" />
</databaseChangeLog>
18 changes: 18 additions & 0 deletions src/test/resources/sql/pilotage/550_add_business_id.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="davdar" id="550-1">
<addColumn tableName="survey_unit">
<column name="display_name" type="VARCHAR(50)"/>
</addColumn>
</changeSet>

<changeSet author="davdar" id="550-2">
<update tableName="survey_unit">
<column name="display_name" valueComputed="id"/>
</update>
</changeSet>
</databaseChangeLog>
28 changes: 14 additions & 14 deletions src/test/resources/sql/pilotage/reinit-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit 2673360

Please sign in to comment.