-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Construction de l'étape d'obtention de la prochaine demande de supp…
…ression
- Loading branch information
1 parent
e2bce7c
commit 5f3fcbd
Showing
6 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
batch/src/main/java/fr/abes/item/batch/traitement/GetNextDemandeSupprTasklet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package fr.abes.item.batch.traitement; | ||
|
||
import fr.abes.item.core.configuration.factory.StrategyFactory; | ||
import fr.abes.item.core.constant.Constant; | ||
import fr.abes.item.core.constant.TYPE_DEMANDE; | ||
import fr.abes.item.core.entities.item.DemandeSupp; | ||
import fr.abes.item.core.exception.DemandeCheckingException; | ||
import fr.abes.item.core.service.IDemandeService; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.hibernate.exception.ConstraintViolationException; | ||
import org.hibernate.exception.JDBCConnectionException; | ||
import org.springframework.batch.core.ExitStatus; | ||
import org.springframework.batch.core.StepContribution; | ||
import org.springframework.batch.core.StepExecution; | ||
import org.springframework.batch.core.StepExecutionListener; | ||
import org.springframework.batch.core.scope.context.ChunkContext; | ||
import org.springframework.batch.core.step.tasklet.Tasklet; | ||
import org.springframework.batch.repeat.RepeatStatus; | ||
import org.springframework.dao.DataAccessException; | ||
|
||
import java.sql.SQLException; | ||
|
||
@Slf4j | ||
public class GetNextDemandeSupprTasklet implements Tasklet, StepExecutionListener { | ||
private final StrategyFactory strategyFactory; | ||
private DemandeSupp demande; | ||
private final int minHour; | ||
private final int maxHour; | ||
|
||
public GetNextDemandeSupprTasklet(StrategyFactory strategyFactory, int minHour, int maxHour) { | ||
this.strategyFactory = strategyFactory; | ||
this.minHour = minHour; | ||
this.maxHour = maxHour; | ||
} | ||
|
||
@Override | ||
public void beforeStep(@NonNull StepExecution stepExecution) { | ||
log.info(Constant.JOB_TRAITER_LIGNE_FICHIER_START_MODIF); | ||
} | ||
|
||
@Override | ||
public ExitStatus afterStep(StepExecution stepExecution) { | ||
if (stepExecution.getExitStatus().equals(ExitStatus.COMPLETED)) { | ||
stepExecution.getJobExecution().getExecutionContext().put("demandeId", this.demande.getId()); | ||
stepExecution.getJobExecution().getExecutionContext().put("typeDemande", this.demande.getTypeDemande().toString()); | ||
} | ||
return stepExecution.getExitStatus(); | ||
} | ||
|
||
@Override | ||
public RepeatStatus execute(@NonNull StepContribution stepContribution, @NonNull ChunkContext chunkContext) throws Exception { | ||
log.info(Constant.ENTER_EXECUTE_FROM_GETNEXTDEMANDESUPPRTASKLET); | ||
try{ | ||
IDemandeService service = strategyFactory.getStrategy(IDemandeService.class, TYPE_DEMANDE.SUPP); | ||
this.demande = (DemandeSupp) service.getIdNextDemandeToProceed(this.minHour, this.maxHour); | ||
if (this.demande == null) { | ||
log.warn(Constant.NO_DEMANDE_TO_PROCESS); | ||
stepContribution.setExitStatus(new ExitStatus("AUCUNE DEMANDE")); | ||
return RepeatStatus.FINISHED; | ||
} | ||
service.changeState(this.demande, Constant.ETATDEM_ENCOURS); | ||
} catch (DemandeCheckingException e) { | ||
log.error(Constant.ERROR_PASSERENCOURS_FROM_GETNEXTDEMANDESUPPRTASKLET | ||
+ e); | ||
stepContribution.setExitStatus(ExitStatus.FAILED); | ||
return RepeatStatus.FINISHED; | ||
} catch (JDBCConnectionException | ConstraintViolationException j){ | ||
log.error("Erreur hibernate JDBC"); | ||
log.error(j.toString()); | ||
} catch (DataAccessException d){ | ||
log.error("GetNextDemandeRecouvTasklet : Erreur d'accès à la base de donnée"); | ||
if(d.getRootCause() instanceof SQLException sqlEx){ | ||
log.error("Erreur SQL : " + sqlEx.getErrorCode()); | ||
log.error(sqlEx.getSQLState() + "|" + sqlEx.getMessage() + "|" + sqlEx.getLocalizedMessage()); | ||
} | ||
} | ||
return RepeatStatus.FINISHED; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters