Skip to content

Commit b7e86a4

Browse files
authored
feat: add business id (display name) to survey unit (#76)
1 parent 09c08e6 commit b7e86a4

File tree

18 files changed

+79
-37
lines changed

18 files changed

+79
-37
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ target/
2828
build/
2929
src/test/resources/out
3030
src/test/resources/**/testScenarios
31+
32+
application-*.properties
33+
application-*.yaml
34+
application-*.yml
3135
### VS Code ###
3236
.vscode/
3337

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>fr.insee.pearljam</groupId>
77
<artifactId>pearljam-batch</artifactId>
8-
<version>3.1.2</version>
8+
<version>3.2.0</version>
99
<packaging>jar</packaging>
1010
<name>pearljam-batch</name>
1111
<description>PearlJam Batch</description>

src/main/java/fr/insee/pearljam/batch/Launcher.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,19 @@ public BatchErrorCode runBatch(String[] options)
164164
logger.log(Level.INFO, "Batch is running with option {}", batchOption.getLabel());
165165

166166
return switch (batchOption) {
167+
// Update states of survey units based on the visibility dates
167168
case DAILYUPDATE -> triggerService.updateStates();
169+
// synchronize interviewers and survey unit affectations for the interviewers
168170
case SYNCHRONIZE -> triggerService.synchronizeWithOpale(FOLDER_OUT);
171+
// send communications
169172
case COMMUNICATION -> {
170173
try {
171174
yield communicationService.handleCommunications();
172175
} catch (SynchronizationException | MissingCommunicationException e) {
173176
yield BatchErrorCode.KO_TECHNICAL_ERROR;
174177
}
175178
}
179+
// use pilotage launcher
176180
default -> pilotageLauncherService.validateLoadClean(batchOption, FOLDER_IN, FOLDER_OUT);
177181
};
178182

src/main/java/fr/insee/pearljam/batch/dao/SurveyUnitDaoImpl.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public void deleteSurveyUnitByCampaignId(String campaignId) {
5050
pilotageJdbcTemplate.update(qString, campaignId);
5151
}
5252

53-
@Override
54-
public void createSurveyUnit(String campaignId, SurveyUnitType surveyUnit, Long addressId,
55-
Long sampleIdentifierId, String interviewerId, String organizationUnitId) {
56-
String qString = "INSERT INTO survey_unit (id, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) VALUES (?, ?, ?, ?, ?, ?, ?)";
53+
@Override
54+
public void createSurveyUnit(String campaignId, SurveyUnitType surveyUnit, Long addressId,
55+
Long sampleIdentifierId, String interviewerId, String organizationUnitId) {
56+
String qString = "INSERT INTO survey_unit (id, display_name, priority, address_id, campaign_id, interviewer_id, sample_identifier_id, organization_unit_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
5757

58-
pilotageJdbcTemplate.update(qString, surveyUnit.getId(), surveyUnit.isPriority(),
59-
addressId, campaignId, interviewerId, sampleIdentifierId, organizationUnitId);
60-
}
58+
pilotageJdbcTemplate.update(qString, surveyUnit.getId(), surveyUnit.getDisplayName(), surveyUnit.isPriority(),
59+
addressId, campaignId, interviewerId, sampleIdentifierId, organizationUnitId);
60+
}
6161

6262
@Override
6363
public List<String> getAllSurveyUnitByCampaignId(String campaignId) {
@@ -111,6 +111,7 @@ private static final class SurveyUnitTypeMapper implements RowMapper<SurveyUnitT
111111
public SurveyUnitType mapRow(ResultSet rs, int rowNum) throws SQLException {
112112
SurveyUnitType su = new SurveyUnitType();
113113
su.setId(rs.getString("id"));
114+
su.setDisplayName(rs.getString("display_name"));
114115
su.setPriority(rs.getBoolean("priority"));
115116
su.setInterviewerId(rs.getString("interviewer_id"));
116117
su.setOrganizationalUnitId(rs.getString("organization_unit_id"));

src/main/java/fr/insee/pearljam/batch/service/PilotageLauncherService.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,16 @@ private String getName(BatchOption batchOption) {
173173
*/
174174
public BatchErrorCode load(BatchOption batchOption, String in, String out, String processing) throws SQLException, DataBaseException, ValidateException, SynchronizationException, IOException, BatchException, ParserConfigurationException, SAXException {
175175
switch(batchOption) {
176+
// Delete campaign
176177
case DELETECAMPAIGN:
177178
return deleteCampaign(in, out);
179+
// extract campaign data
178180
case EXTRACT:
179181
return extractCampaign(in, out);
182+
// Create context when empty database
180183
case LOADCONTEXT:
181184
return loadContext(in);
185+
// Create/Update survey units
182186
case SAMPLEPROCESSING:
183187
return loadSampleProcessing(in, processing);
184188
default:
@@ -391,7 +395,12 @@ public BatchErrorCode loadSampleProcessing(String in, String processing) throws
391395
// Extract campaignId, list of steps and list of survey-unit id from sampleprocessing
392396
String campaignId = sampleProcessing.getIdSource() + sampleProcessing.getMillesime() + sampleProcessing.getIdPeriode();
393397
List<String> steps = sampleProcessing.getSteps().getStep().stream().map(Step::getName).collect(Collectors.toList());
394-
List<String> surveyUnits = sampleProcessing.getQuestionnaires().getQuestionnaire().stream().map(su -> su.getInformationsGenerales().getUniteEnquetee().getIdentifiant()).collect(Collectors.toList());
398+
List<String> surveyUnits = sampleProcessing
399+
.getQuestionnaires()
400+
.getQuestionnaire()
401+
.stream()
402+
.map(Campagne.Questionnaires.Questionnaire::getIdInterrogation)
403+
.toList();
395404

396405
logger.log(Level.INFO, "Start split sample processing content");
397406
Map<String, SurveyUnit> mapDataCollectionSu = extractAndValidateDatacollectionFromSamplProcessing(steps, campaignId, sampleProcessing);

src/main/java/fr/insee/pearljam/batch/utils/DataCollectionMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static fr.insee.queen.batch.sample.Campaign mapSampleProcessingToDataColl
2828
campaign.getSurveyUnits().getSurveyUnit().addAll(
2929
c.getQuestionnaires().getQuestionnaire().stream().map(su -> {
3030
fr.insee.queen.batch.sample.SurveyUnitType surveyUnitType = new fr.insee.queen.batch.sample.SurveyUnitType();
31-
surveyUnitType.setId(su.getInformationsGenerales().getUniteEnquetee().getIdentifiant());
31+
surveyUnitType.setId(su.getIdInterrogation());
3232
surveyUnitType.setQuestionnaireModelId(su.getIdModele());
3333
surveyUnitType.setData(su.getInformationsPersonnalisees().getData());
3434
return surveyUnitType;

src/main/java/fr/insee/pearljam/batch/utils/PilotageMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public static Campaign mapSampleProcessingToPilotageCampaign(Campagne c) {
4646
campaign.getSurveyUnits().getSurveyUnit().addAll(
4747
c.getQuestionnaires().getQuestionnaire().stream().map(su -> {
4848
SurveyUnitType surveyUnitType = new SurveyUnitType();
49-
surveyUnitType.setId(su.getInformationsGenerales().getUniteEnquetee().getIdentifiant());
49+
surveyUnitType.setId(su.getIdInterrogation());
50+
surveyUnitType.setDisplayName(su.getInformationsGenerales().getUniteEnquetee().getIdentifiant());
5051
surveyUnitType.setPriority(su.getInformationsGenerales().getUniteEnquetee().isPrioritaire());
5152
surveyUnitType.setInterviewerId(
5253
su.getInformationsGenerales().getUniteEnquetee().getAffectation().getEnqueteurId());

src/main/resources/xsd/campaign.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
<xs:complexType name="SurveyUnitType">
140140
<xs:all>
141141
<xs:element name="Id" type="xs:string" />
142+
<xs:element name="DisplayName" type="xs:string" minOccurs="0" />
142143
<xs:element minOccurs="0" maxOccurs="1" name="InterviewerId" type="xs:string" />
143144
<xs:element minOccurs="0" maxOccurs="1" name="OrganizationalUnitId" type="xs:string" />
144145
<xs:element minOccurs="0" maxOccurs="1" name="CampaignId" type="xs:string" />

src/main/resources/xsd/sampleProcessing.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
</xs:element>
167167
</xs:sequence>
168168
<xs:attribute name="idModele" type="xs:string" use="required" />
169+
<xs:attribute name="idInterrogation" type="xs:string" use="required" />
169170
</xs:complexType>
170171
</xs:element>
171172
</xs:sequence>

src/test/resources/in/sampleprocessing/init/sampleprocessingScenario1/sampleProcessing.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
</Step>
1212
</Steps>
1313
<Questionnaires>
14-
<Questionnaire idModele="simpsons">
14+
<Questionnaire idModele="simpsons" idInterrogation="SIM1234">
1515
<!--[WEB]<Questionnaire idModele="SIMPSON" idVague="1" idLot="1"> -->
1616
<InformationsGenerales>
1717
<UniteEnquetee>
1818
<test></test>
19-
<Identifiant>SIM1234</Identifiant>
19+
<Identifiant>business-id-SIM1234</Identifiant>
2020
<Prioritaire>true</Prioritaire>
2121
<IdentifiantsInsee>
2222
<Bs>0</Bs>

src/test/resources/in/sampleprocessing/init/sampleprocessingScenario2/sampleProcessing.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
</Step>
1212
</Steps>
1313
<Questionnaires>
14-
<Questionnaire idModele="simpsons">
14+
<Questionnaire idModele="simpsons" idInterrogation="SIM1234">
1515
<!--[WEB]<Questionnaire idModele="SIMPSON" idVague="1" idLot="1"> -->
1616
<InformationsGenerales>
1717
<UniteEnquetee>
18-
<Identifiant>SIM1234</Identifiant>
18+
<Identifiant>business-id-SIM1234</Identifiant>
1919
<Prioritaire>true</Prioritaire>
2020
<IdentifiantsInsee>
2121
<Bs>0</Bs>

src/test/resources/in/sampleprocessing/init/sampleprocessingScenario3/sampleProcessing.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
</Step>
1212
</Steps>
1313
<Questionnaires>
14-
<Questionnaire idModele="simpsons">
14+
<Questionnaire idModele="simpsons" idInterrogation="SIM1234">
1515
<!--[WEB]<Questionnaire idModele="SIMPSON" idVague="1" idLot="1"> -->
1616
<InformationsGenerales>
1717
<UniteEnquetee>
18-
<Identifiant>SIM1234</Identifiant>
18+
<Identifiant>business-id-SIM1234</Identifiant>
1919
<Prioritaire>true</Prioritaire>
2020
<IdentifiantsInsee>
2121
<Bs>0</Bs>

src/test/resources/in/sampleprocessing/init/sampleprocessingScenario4/sampleProcessing.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
</Step>
1212
</Steps>
1313
<Questionnaires>
14-
<Questionnaire idModele="simpsons">
14+
<Questionnaire idModele="simpsons" idInterrogation="SIM1234">
1515
<!--[WEB]<Questionnaire idModele="SIMPSON" idVague="1" idLot="1"> -->
1616
<InformationsGenerales>
1717
<UniteEnquetee>
18-
<Identifiant>SIM1234</Identifiant>
18+
<Identifiant>business-id-SIM1234</Identifiant>
1919
<Prioritaire>true</Prioritaire>
2020
<IdentifiantsInsee>
2121
<Bs>0</Bs>

src/test/resources/in/sampleprocessing/init/sampleprocessingScenario5/sampleProcessing.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
</Step>
1212
</Steps>
1313
<Questionnaires>
14-
<Questionnaire idModele="simpsons">
14+
<Questionnaire idModele="simpsons" idInterrogation="SIM1234">
1515
<!--[WEB]<Questionnaire idModele="SIMPSON" idVague="1" idLot="1"> -->
1616
<InformationsGenerales>
1717
<UniteEnquetee>
18-
<Identifiant>SIM1234</Identifiant>
18+
<Identifiant>business-id-SIM1234</Identifiant>
1919
<Prioritaire>true</Prioritaire>
2020
<IdentifiantsInsee>
2121
<Bs>0</Bs>

src/test/resources/in/sampleprocessing/init/sampleprocessingScenario6/sampleProcessing.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
</Step>
1212
</Steps>
1313
<Questionnaires>
14-
<Questionnaire idModele="simpsons">
14+
<Questionnaire idModele="simpsons" idInterrogation="SIM1234">
1515
<!--[WEB]<Questionnaire idModele="SIMPSON" idVague="1" idLot="1"> -->
1616
<InformationsGenerales>
1717
<UniteEnquetee>
18-
<Identifiant>SIM1234</Identifiant>
18+
<Identifiant>business-id-SIM1234</Identifiant>
1919
<Prioritaire>true</Prioritaire>
2020
<IdentifiantsInsee>
2121
<Bs>0</Bs>

src/test/resources/sql/masterPilotage.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,7 @@
6262

6363
<!-- move mail/tel to visibility -->
6464
<include file="pilotage/546_update_communication_information.xml" relativeToChangelogFile="true" />
65+
66+
<!-- add business id -->
67+
<include file="pilotage/550_add_business_id.xml" relativeToChangelogFile="true" />
6568
</databaseChangeLog>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
3+
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
4+
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
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">
7+
<changeSet author="davdar" id="550-1">
8+
<addColumn tableName="survey_unit">
9+
<column name="display_name" type="VARCHAR(50)"/>
10+
</addColumn>
11+
</changeSet>
12+
13+
<changeSet author="davdar" id="550-2">
14+
<update tableName="survey_unit">
15+
<column name="display_name" valueComputed="id"/>
16+
</update>
17+
</changeSet>
18+
</databaseChangeLog>

src/test/resources/sql/pilotage/reinit-data.sql

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,20 @@ INSERT INTO public.state ("date","type",survey_unit_id) VALUES
136136
(1590504478334,'NVM','26'),
137137
(1590504478334,'NVM','27'),
138138
(1590504478334,'NVM','28');
139-
INSERT INTO public.survey_unit (id,priority,address_id,campaign_id,interviewer_id,sample_identifier_id,organization_unit_id,viewed,"move") VALUES
140-
('11',true,1,'SIMPSONS2020X00','INTW1',1,'OU-NORTH',false,NULL),
141-
('12',true,2,'SIMPSONS2020X00','INTW1',2,'OU-NORTH',false,NULL),
142-
('13',false,3,'SIMPSONS2020X00','INTW2',3,'OU-SOUTH',false,NULL),
143-
('14',false,4,'SIMPSONS2020X00','INTW3',4,'OU-SOUTH',false,NULL),
144-
('20',true,5,'VQS2021X00','INTW1',5,'OU-NORTH',false,NULL),
145-
('21',true,6,'VQS2021X00','INTW2',6,'OU-NORTH',false,NULL),
146-
('22',false,7,'VQS2021X00','INTW4',7,'OU-NORTH',false,NULL),
147-
('23',true,8,'VQS2021X00','INTW4',8,'OU-NORTH',false,NULL),
148-
('24',false,9,'STATE2020X00','INTW1',9,'OU-NORTH',false,NULL),
149-
('25',true,10,'STATE2021X00','INTW1',10,'OU-NORTH',false,NULL),
150-
('26',true,11,'STATE2022X00','INTW1',11,'OU-NORTH',false,NULL),
151-
('27',false,12,'STATE2023X00','INTW1',12,'OU-NORTH',false,NULL),
152-
('28',true,13,'STATE2024X00','INTW1',13,'OU-NORTH',false,NULL);
139+
INSERT INTO public.survey_unit (id, display_name, priority,address_id,campaign_id,interviewer_id,sample_identifier_id,organization_unit_id,viewed,"move") VALUES
140+
('11','business-id-11',true,1,'SIMPSONS2020X00','INTW1',1,'OU-NORTH',false,NULL),
141+
('12','business-id-12',true,2,'SIMPSONS2020X00','INTW1',2,'OU-NORTH',false,NULL),
142+
('13','business-id-13',false,3,'SIMPSONS2020X00','INTW2',3,'OU-SOUTH',false,NULL),
143+
('14','business-id-14',false,4,'SIMPSONS2020X00','INTW3',4,'OU-SOUTH',false,NULL),
144+
('20','business-id-20',true,5,'VQS2021X00','INTW1',5,'OU-NORTH',false,NULL),
145+
('21','business-id-21',true,6,'VQS2021X00','INTW2',6,'OU-NORTH',false,NULL),
146+
('22','business-id-22',false,7,'VQS2021X00','INTW4',7,'OU-NORTH',false,NULL),
147+
('23','business-id-23',true,8,'VQS2021X00','INTW4',8,'OU-NORTH',false,NULL),
148+
('24','business-id-24',false,9,'STATE2020X00','INTW1',9,'OU-NORTH',false,NULL),
149+
('25','business-id-25',true,10,'STATE2021X00','INTW1',10,'OU-NORTH',false,NULL),
150+
('26','business-id-26',true,11,'STATE2022X00','INTW1',11,'OU-NORTH',false,NULL),
151+
('27','business-id-27',false,12,'STATE2023X00','INTW1',12,'OU-NORTH',false,NULL),
152+
('28','business-id-28',true,13,'STATE2024X00','INTW1',13,'OU-NORTH',false,NULL);
153153
INSERT INTO public."user" (id,first_name,last_name,organization_unit_id) VALUES
154154
('ABC','Melinda','Webb','OU-NORTH'),
155155
('DEF','Everett','Juste','OU-NORTH'),

0 commit comments

Comments
 (0)