Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>fr.insee.pearljam</groupId>
<artifactId>pearljam-batch</artifactId>
<version>3.9.0</version>
<version>3.9.1</version>
<packaging>jar</packaging>
<name>pearljam-batch</name>
<description>PearlJam Batch</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package fr.insee.pearljam.batch.service;

import fr.insee.pearljam.batch.Constants;
import fr.insee.pearljam.batch.campaign.Campaign;
import fr.insee.pearljam.batch.campaign.CommunicationTemplateType;
import fr.insee.pearljam.batch.campaign.SurveyUnitType;
import fr.insee.pearljam.batch.campaign.*;
import fr.insee.pearljam.batch.config.ApplicationConfig;
import fr.insee.pearljam.batch.dao.CampaignDao;
import fr.insee.pearljam.batch.dao.CommunicationTemplateDaoImpl;
Expand Down Expand Up @@ -36,6 +34,9 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -64,6 +65,9 @@
private static final Logger logger = LogManager.getLogger(PilotageLauncherService.class);
private static final String CAMPAIGN_PATH_IN = "/campaign/campaign.xml";

@Value("${application.feature.sampleprocessing.allowwhenidentificationstarted}")
private boolean allowWhenIdentificationStarted;

/**
* Global function that structure the batch execution depends on batchOption
*
Expand Down Expand Up @@ -343,9 +347,21 @@

List<InterrogationDataCollectionDto> interrogations = new ArrayList<>();
Map<String, SurveyUnitType> oldSuMap = new HashMap<>();
for(Questionnaire questionnaire : questionnaires) {

Check warning on line 350 in src/main/java/fr/insee/pearljam/batch/service/PilotageLauncherService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Reduce the total number of break and continue statements in this loop to use at most one.

See more on https://sonarcloud.io/project/issues?id=InseeFr_Pearl-Jam-Batch&issues=AZ8oWd13CHzoWq8OG1D-&open=AZ8oWd13CHzoWq8OG1D-&pullRequest=116
String interrogationId = questionnaire.getIdInterrogation();
if (steps.contains(Constants.PILOTAGE)) {

try
{
isIntegrationFeasible(campaignId, interrogationId);
}
catch (BatchException e)
{
logger.log(Level.WARN, e.getMessage());
returnCode = BatchErrorCode.KO_FONCTIONAL_ERROR;
continue;
}

boolean pilotageValidate = campaignService.validateInput(mapPilotageSu.get(interrogationId), campaignId);
if(!pilotageValidate) {
logger.log(Level.WARN, "Interrogation {} is invalid", interrogationId);
Expand Down Expand Up @@ -399,6 +415,38 @@
return returnCode;
}

private void isIntegrationFeasible(String campaignId, String interrogationId) throws BatchException {
if(allowWhenIdentificationStarted)
{
return;
}

Campaign campaign = campaignDao.findById(campaignId);
OrganizationalUnitsType organizationalUnitType = campaign.getOrganizationalUnits();


boolean afterIdentificationStarted = false;
if(organizationalUnitType != null)
{
LocalDate localDate = LocalDate.now();

Check warning on line 431 in src/main/java/fr/insee/pearljam/batch/service/PilotageLauncherService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Explicitly specify the time zone by passing a ZoneId or a Clock to the .now() method.

See more on https://sonarcloud.io/project/issues?id=InseeFr_Pearl-Jam-Batch&issues=AZ82TWGuS7zv00u2Fmt6&open=AZ82TWGuS7zv00u2Fmt6&pullRequest=116
afterIdentificationStarted = organizationalUnitType.getOrganizationalUnit().stream().anyMatch(
ou ->
{
long epochMilliSeconds = Long.parseLong(ou.getIdentificationPhaseStartDate());
LocalDate date = Instant.ofEpochMilli(epochMilliSeconds)
.atZone(ZoneOffset.UTC)
.toLocalDate();

return localDate.isAfter(date);
});
}

if(afterIdentificationStarted)
{
throw new BatchException(String.format("Can not integrate sample processing, idendification start date for %s already in the past", interrogationId));
}
}


private void moveFilesInOutFolders(BatchErrorCode returnCode) throws IOException, ValidateException {
if(new File(appConfig.folderIn() + CAMPAIGN_PATH_IN).exists()) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ api:

logging:
level:
fr.insee.lunatic.utils.XslTransformation: WARN
fr.insee.lunatic.utils.XslTransformation: WARN

application:
feature:
sampleprocessing:
allowwhenidentificationstarted: true
7 changes: 6 additions & 1 deletion src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ api:
datacollection:
url: http://localhost:9999
bulk:
size: 500
size: 500

application:
feature:
sampleprocessing:
allowwhenidentificationstarted: true
Loading