Skip to content

Commit

Permalink
Refactor : suppression dialect bdd dans properties
Browse files Browse the repository at this point in the history
Modif architecture spring batch
Interfaçage de certaines méthodes dans DemandeService
  • Loading branch information
pierre-maraval committed Jun 14, 2024
1 parent fc86d28 commit a4ba068
Show file tree
Hide file tree
Showing 40 changed files with 414 additions and 438 deletions.
285 changes: 151 additions & 134 deletions batch/src/main/java/fr/abes/item/batch/JobConfiguration.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

import fr.abes.item.batch.mail.IMailer;
import fr.abes.item.core.configuration.factory.Strategy;
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.Demande;
import fr.abes.item.core.entities.item.DemandeExemp;
import fr.abes.item.core.service.ILigneFichierService;
import fr.abes.item.core.service.impl.LigneFichierExempService;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

Expand All @@ -19,14 +18,13 @@
@Service
@Strategy(type = IMailer.class, typeDemande = TYPE_DEMANDE.EXEMP)
public class MailerExemp extends Mailer implements IMailer {

private final Environment env;
private final LigneFichierExempService service;

private final StrategyFactory strategy;

public MailerExemp(Environment env, StrategyFactory strategy) {
public MailerExemp(Environment env, LigneFichierExempService service) {
this.env = env;
this.strategy = strategy;
this.service = service;
}

/**
Expand All @@ -47,7 +45,6 @@ public void mailDebutTraitement(String mailDestinataire, Demande demande){
@Override
public void mailFinTraitement(String mailDestinataire, Demande demande, File f, LocalDateTime dateDebut, LocalDateTime dateFin) {
DecimalFormat df = new DecimalFormat("0.00");
ILigneFichierService service = strategy.getStrategy(ILigneFichierService.class, TYPE_DEMANDE.EXEMP);
DemandeExemp demandeExemp = (DemandeExemp) demande;
int nbExempCree = service.getNbLigneFichierSuccessByDemande(demandeExemp);
int nbRechercheTotal = service.getNbLigneFichierTotalByDemande(demandeExemp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import fr.abes.item.batch.mail.IMailer;
import fr.abes.item.core.configuration.factory.Strategy;
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.Demande;
import fr.abes.item.core.service.ILigneFichierService;
import fr.abes.item.core.service.impl.LigneFichierModifService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
Expand All @@ -20,10 +19,10 @@
public class MailerModif extends Mailer implements IMailer {
private final Environment env;

private final StrategyFactory strategy;
public MailerModif(Environment env, StrategyFactory strategy) {
private final LigneFichierModifService service;
public MailerModif(Environment env, LigneFichierModifService service) {
this.env = env;
this.strategy = strategy;
this.service = service;
}

/**
Expand All @@ -43,7 +42,6 @@ public void mailDebutTraitement(String mailDestinataire, Demande demande){
@Override
public void mailFinTraitement(String mailDestinataire, Demande demande, File f, LocalDateTime dateDebut, LocalDateTime dateFin) {
int numDemande = demande.getId();
ILigneFichierService service = strategy.getStrategy(ILigneFichierService.class, TYPE_DEMANDE.MODIF);
String requestJson = mailToJSON(mailDestinataire, Constant.DEMANDE_MODIFICATION_START + numDemande + " terminée - ILN " + demande.getIln(),
"Bonjour,<br />Votre demande " + numDemande + " de modification d'exemplaires a bien été traitée.<br />" +
"Nombre d'exemplaires traités : " + service.getNbLigneFichierTraiteeByDemande(demande) + Constant.HTML_BALISE_BR +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import fr.abes.item.batch.mail.IMailer;
import fr.abes.item.core.configuration.factory.Strategy;
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.Demande;
import fr.abes.item.core.service.ILigneFichierService;
import fr.abes.item.core.service.impl.LigneFichierRecouvService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;

Expand All @@ -19,11 +18,11 @@
public class MailerRecouv extends Mailer implements IMailer {

private final Environment env;
private final StrategyFactory strategy;
private final LigneFichierRecouvService service;

public MailerRecouv(Environment env, StrategyFactory strategy) {
public MailerRecouv(Environment env, LigneFichierRecouvService service) {
this.env = env;
this.strategy = strategy;
this.service = service;
}

/**
Expand All @@ -43,7 +42,6 @@ public void mailDebutTraitement(String mailDestinataire, Demande demande) {
@Override
public void mailFinTraitement(String mailDestinataire, Demande demande, File f, LocalDateTime dateDebut, LocalDateTime dateFin) {
int numDemande = demande.getId();
ILigneFichierService service = strategy.getStrategy(ILigneFichierService.class, TYPE_DEMANDE.RECOUV);
int nbRechercheTotal = service.getNbLigneFichierTotalByDemande(demande);
int nbNoticesTrouvees = service.getNbReponseTrouveesByDemande(demande);
int nbZeroReponse = service.getNbZeroReponseByDemande(demande);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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.Demande;
import fr.abes.item.core.entities.item.DemandeExemp;
import fr.abes.item.core.exception.DemandeCheckingException;
import fr.abes.item.core.service.impl.DemandeExempService;
import fr.abes.item.core.service.IDemandeService;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.ExitStatus;
Expand All @@ -14,27 +16,29 @@
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.beans.factory.annotation.Autowired;

import java.util.List;

@Slf4j
public class ChangeInArchivedStatusAllDemandesExempFinishedForMoreThanThreeMonthsTasklet implements Tasklet, StepExecutionListener {
@Autowired
private DemandeExempService demandeExempService;
public class ArchiveDemandesExempTakslet implements Tasklet, StepExecutionListener {
private final StrategyFactory strategyFactory;

List<DemandeExemp> demandes;

public ArchiveDemandesExempTakslet(StrategyFactory strategyFactory) {
this.strategyFactory = strategyFactory;
}

@Override
public void beforeStep(@NonNull StepExecution stepExecution) {
log.info("Archivage automatique des demandes d'exemplarisation, modification et recouvrement lancé");
}

@Override
public RepeatStatus execute(@NonNull StepContribution stepContribution, @NonNull ChunkContext chunkContext) throws Exception {
log.warn(Constant.ENTER_EXECUTE_FROM_GETNEXTDEMANDEEXEMPTOARCHIVETASKLET);
try {
this.demandes = demandeExempService.getIdNextDemandeToArchive();
IDemandeService service = strategyFactory.getStrategy(IDemandeService.class, TYPE_DEMANDE.EXEMP);
this.demandes = (List<DemandeExemp>) service.getIdNextDemandeToArchive();
if (this.demandes == null) {
log.warn(Constant.NO_DEMANDE_TO_PROCESS);
stepContribution.setExitStatus(new ExitStatus("AUCUNE DEMANDE"));
Expand All @@ -43,7 +47,7 @@ public RepeatStatus execute(@NonNull StepContribution stepContribution, @NonNull
//Iteration sur chaque demande pour en modifier le statut
for (Demande demande : this.demandes) {
log.info("Passage de la demande d'exemplarisation " + demande.getNumDemande() + "au statut" + Constant.ETATDEM_ARCHIVEE);
demandeExempService.changeState(demande, Constant.ETATDEM_ARCHIVEE);
service.changeState(demande, Constant.ETATDEM_ARCHIVEE);
}
stepContribution.setExitStatus(ExitStatus.COMPLETED);
} catch (DemandeCheckingException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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.Demande;
import fr.abes.item.core.entities.item.DemandeModif;
import fr.abes.item.core.exception.DemandeCheckingException;
import fr.abes.item.core.service.impl.DemandeModifService;
import fr.abes.item.core.service.IDemandeService;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.ExitStatus;
Expand All @@ -14,25 +16,26 @@
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.beans.factory.annotation.Autowired;

import java.util.List;

@Slf4j
public class ChangeInArchivedStatusAllDemandesModifFinishedForMoreThanThreeMonthsTasklet implements Tasklet, StepExecutionListener {
@Autowired
DemandeModifService demandeModifService;

public class ArchiveDemandesModifTasklet implements Tasklet, StepExecutionListener {
private final StrategyFactory strategyFactory;
List<DemandeModif> demandes;

public ArchiveDemandesModifTasklet(StrategyFactory strategyFactory) {
this.strategyFactory = strategyFactory;
}

@Override
public void beforeStep(@NonNull StepExecution stepExecution) {}

@Override
public RepeatStatus execute(@NonNull StepContribution stepContribution, @NonNull ChunkContext chunkContext) throws Exception {
log.warn("entrée dans execute de ChangeInArchivedStatusAllDemandesModifFinishedForMoreThanThreeMonthsTasklet...");
try {
this.demandes = demandeModifService.getIdNextDemandeToArchive();
IDemandeService service = strategyFactory.getStrategy(IDemandeService.class, TYPE_DEMANDE.MODIF);
this.demandes = (List<DemandeModif>) service.getIdNextDemandeToArchive();
if (this.demandes == null) {
log.warn(Constant.NO_DEMANDE_TO_PROCESS);
stepContribution.setExitStatus(new ExitStatus("AUCUNE DEMANDE"));
Expand All @@ -41,7 +44,7 @@ public RepeatStatus execute(@NonNull StepContribution stepContribution, @NonNull
//Iteration sur chaque demande pour en modifier le statut
for (Demande demande : this.demandes) {
log.info("Passage de la demande de modification" + demande.getNumDemande() + "au statut" + Constant.ETATDEM_ARCHIVEE);
demandeModifService.changeState(demande, Constant.ETATDEM_ARCHIVEE);
service.changeState(demande, Constant.ETATDEM_ARCHIVEE);
}
stepContribution.setExitStatus(ExitStatus.COMPLETED);
} catch (DemandeCheckingException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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.Demande;
import fr.abes.item.core.entities.item.DemandeRecouv;
import fr.abes.item.core.exception.DemandeCheckingException;
import fr.abes.item.core.service.impl.DemandeRecouvService;
import fr.abes.item.core.service.IDemandeService;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.ExitStatus;
Expand All @@ -14,25 +16,26 @@
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.beans.factory.annotation.Autowired;

import java.util.List;

@Slf4j
public class ChangeInArchivedStatusAllDemandesRecouvFinishedForMoreThanThreeMonthsTasklet implements Tasklet, StepExecutionListener {
@Autowired
DemandeRecouvService demandeRecouvService;

public class ArchiveDemandesRecouvTasklet implements Tasklet, StepExecutionListener {
private final StrategyFactory strategyFactory;
List<DemandeRecouv> demandes;

public ArchiveDemandesRecouvTasklet(StrategyFactory strategyFactory) {
this.strategyFactory = strategyFactory;
}

@Override
public void beforeStep(@NonNull StepExecution stepExecution) {}

@Override
public RepeatStatus execute(@NonNull StepContribution stepContribution, @NonNull ChunkContext chunkContext) throws Exception {
log.warn("entrée dans execute de ChangeInArchivedStatusAllDemandesRecouvFinishedForMoreThanThreeMonthsTasklet...");
try {
this.demandes = demandeRecouvService.getIdNextDemandeToArchive();
IDemandeService service = strategyFactory.getStrategy(IDemandeService.class, TYPE_DEMANDE.RECOUV);
this.demandes = (List<DemandeRecouv>) service.getIdNextDemandeToArchive();
if (this.demandes == null) {
log.warn(Constant.NO_DEMANDE_TO_PROCESS);
stepContribution.setExitStatus(new ExitStatus("AUCUNE DEMANDE"));
Expand All @@ -41,7 +44,7 @@ public RepeatStatus execute(@NonNull StepContribution stepContribution, @NonNull
//Iteration sur chaque demande pour en modifier le statut
for (Demande demande : this.demandes) {
log.info("Passage de la demande de recouvrement " + demande.getNumDemande() + "au statut" + Constant.ETATDEM_ARCHIVEE);
demandeRecouvService.changeState(demande, Constant.ETATDEM_ARCHIVEE);
service.changeState(demande, Constant.ETATDEM_ARCHIVEE);
}
stepContribution.setExitStatus(ExitStatus.COMPLETED);
} catch (DemandeCheckingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DataAccessException;

import java.sql.SQLException;
Expand All @@ -28,24 +26,22 @@

@Slf4j
public class AuthentifierSurSudocTasklet implements Tasklet, StepExecutionListener {
@Autowired
StrategyFactory factory;

private final StrategyFactory factory;
private IMailer mailer;

private List<LigneFichierDto> lignesFichier;
@Value("${mail.admin}")
private String mailAdmin;
@Autowired
ProxyRetry proxyRetry;

private final String mailAdmin;
private final ProxyRetry proxyRetry;
private IDemandeService demandeService;

private List<LigneFichierDto> lignesFichier;
private String email;
private Demande demande;

private LocalDateTime dateDebut;

public AuthentifierSurSudocTasklet(StrategyFactory factory, String mailAdmin, ProxyRetry proxyRetry) {
this.factory = factory;
this.mailAdmin = mailAdmin;
this.proxyRetry = proxyRetry;
}

@Override
public void beforeStep(StepExecution stepExecution) {
ExecutionContext executionContext = stepExecution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
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.Demande;
import fr.abes.item.core.entities.item.DemandeExemp;
import fr.abes.item.core.service.impl.DemandeExempService;
import fr.abes.item.core.service.FileSystemStorageService;
import fr.abes.item.core.service.IDemandeService;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.ExitStatus;
Expand All @@ -13,26 +16,33 @@
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.beans.factory.annotation.Autowired;

import java.nio.file.Paths;
import java.util.List;

@Slf4j
public class DeleteAllDemandesExempInDeletedStatusForMoreThanSevenMonthsTasklet implements Tasklet, StepExecutionListener {
@Autowired
DemandeExempService demandeExempService;
public class DeleteDemandesExempTasklet implements Tasklet, StepExecutionListener {
private final StrategyFactory strategyFactory;
private final FileSystemStorageService storageService;

private final String uploadPath;
List<DemandeExemp> demandes;

public DeleteDemandesExempTasklet(StrategyFactory strategyFactory, FileSystemStorageService storageService, String uploadPath) {
this.strategyFactory = strategyFactory;
this.storageService = storageService;
this.uploadPath = uploadPath;
}

@Override
public void beforeStep(@NonNull StepExecution stepExecution) {
log.info("Suppression déifnitive des demandes en base d'exemplarisation, modification et recouvrement");
}

@Override
public RepeatStatus execute(@NonNull StepContribution stepContribution, @NonNull ChunkContext chunkContext) throws Exception {
log.warn("entrée dans execute de DeleteAllDemandesExempInDeletedStatusForMoreThanSevenMonthsTasklet...");
this.demandes = demandeExempService.getIdNextDemandeToDelete();
IDemandeService service = strategyFactory.getStrategy(IDemandeService.class, TYPE_DEMANDE.EXEMP);
this.demandes = (List<DemandeExemp>) service.getIdNextDemandeToDelete();
if (this.demandes == null) {
log.warn(Constant.NO_DEMANDE_TO_PROCESS);
stepContribution.setExitStatus(new ExitStatus("AUCUNE DEMANDE"));
Expand All @@ -41,7 +51,9 @@ public RepeatStatus execute(@NonNull StepContribution stepContribution, @NonNull
//Iteration sur chaque demande pour en modifier le statut
for (Demande demande : this.demandes) {
log.info("Suppression définitive de la demande d'exemplarisation " + demande.getNumDemande());
demandeExempService.deleteById(demande.getId());
service.deleteById(demande.getId());
storageService.changePath(Paths.get(uploadPath + demande.getId()));
storageService.deleteAll();
}
stepContribution.setExitStatus(ExitStatus.COMPLETED);
return RepeatStatus.FINISHED;
Expand Down
Loading

0 comments on commit a4ba068

Please sign in to comment.