Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item 447 aiguillage des demandes en fonction de le taille #117

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class GetNextDemandeTasklet implements Tasklet, StepExecutionListener {
private final TYPE_DEMANDE typeDemande;
private final int minHour;
private final int maxHour;
private boolean bigVolume = false;

public GetNextDemandeTasklet(StrategyFactory strategyFactory, int minHour, int maxHour, TYPE_DEMANDE typeDemande) {
this.strategyFactory = strategyFactory;
Expand All @@ -36,12 +37,20 @@ public GetNextDemandeTasklet(StrategyFactory strategyFactory, int minHour, int m
this.typeDemande = typeDemande;
}

@Override
public void beforeStep(@NonNull StepExecution stepExecution) {
log.info(Constant.JOB_TRAITER_LIGNE_FICHIER_START + Utilitaires.getLabelTypeDemande(this.typeDemande));
if (System.getProperty("bigVolume") != null) {
this.bigVolume = Boolean.parseBoolean(System.getProperty("bigVolume"));
}
}

@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
log.info(Constant.ENTER_EXECUTE_FROM_GETNEXTDEMANDETASKLET);
try {
IDemandeService service = strategyFactory.getStrategy(IDemandeService.class, this.typeDemande);
this.demande = service.getIdNextDemandeToProceed(minHour, maxHour);
this.demande = service.getIdNextDemandeToProceed(minHour, maxHour, bigVolume);
if (this.demande == null) {
log.info(Constant.NO_DEMANDE_TO_PROCESS);
stepContribution.setExitStatus(new ExitStatus("AUCUNE DEMANDE"));
Expand All @@ -61,12 +70,6 @@ public RepeatStatus execute(StepContribution stepContribution, ChunkContext chun
return RepeatStatus.FINISHED;
}

@Override
public void beforeStep(@NonNull StepExecution stepExecution) {
log.info(Constant.JOB_TRAITER_LIGNE_FICHIER_START + Utilitaires.getLabelTypeDemande(this.typeDemande));
}


@Override
public ExitStatus afterStep(StepExecution stepExecution) {
if (stepExecution.getExitStatus().equals(ExitStatus.COMPLETED)) {
Expand Down
3 changes: 0 additions & 3 deletions batch/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ sudoc.port=
sudoc.login=
sudoc.pass=

batch.min.hour=8
batch.max.hour=20

# Configuration des logs
logging.level.root=INFO
logging.level.fr.abes.item=INFO
3 changes: 0 additions & 3 deletions batch/src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ sudoc.port=
sudoc.login=
sudoc.pass=

batch.min.hour=8
batch.max.hour=20

spring.batch.jdbc.initialize-schema=never

# Configuration des logs
Expand Down
3 changes: 0 additions & 3 deletions batch/src/main/resources/application-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ sudoc.port=
sudoc.login=
sudoc.pass=

batch.min.hour=8
batch.max.hour=20

spring.batch.jdbc.initialize-schema=never

# Configuration des logs
Expand Down
4 changes: 4 additions & 0 deletions batch/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ mail.admin=item@abes.fr
files.upload.path=/workdir/
files.upload.statistiques.path=/stat/

batch.min.hour=8
batch.max.hour=20
batch.bigVolume.limit=5000

# Configuration des logs
logging.config=classpath:log4j2.xml
spring.main.banner-mode=off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
@Repository
@ItemConfiguration
public interface IDemandeExempDao extends JpaRepository<DemandeExemp, Integer> {
@Query("select d from DemandeExemp d where d.etatDemande.numEtat = 5 order by d.dateModification asc")
List<DemandeExemp> getNextDemandeToProceed();
@Query("select d from DemandeExemp d join d.ligneFichierExemps l where d.etatDemande.numEtat = 5 group by d having count(l) > :limite order by d.dateModification")
List<DemandeExemp> getDemandesEnAttenteGrosVolume(@Param("limite") int limite);

@Query("select d from DemandeExemp d where d.etatDemande.numEtat = 5 and d.indexRecherche.code != 'DAT' order by d.dateModification asc")
List<DemandeExemp> getNextDemandeToProceedWithoutDAT();
@Query("select d from DemandeExemp d join d.ligneFichierExemps l where d.etatDemande.numEtat = 5 group by d having count(l) <= :limite order by d.dateModification")
List<DemandeExemp> getDemandesEnAttentePetitVolume(@Param("limite") int limite);

@Query("select d from DemandeExemp d join d.ligneFichierExemps l where d.etatDemande.numEtat = 5 and d.indexRecherche.code != 'DAT' group by d having count(l) > :limite order by d.dateModification asc")
List<DemandeExemp> getDemandesToProceedWithoutDATGrosVolume(@Param("limite") int limite);

@Query("select d from DemandeExemp d join d.ligneFichierExemps l where d.etatDemande.numEtat = 5 and d.indexRecherche.code != 'DAT' group by d having count(l) <= :limite order by d.dateModification asc")
List<DemandeExemp> getDemandesToProceedWithoutDATPetitVolume(@Param("limite") int limite);

@Query("select e from TypeExemp e where e.numTypeExemp in (select d.typeExemp.numTypeExemp from DemandeExemp d where d.numDemande = :numDemande)")
TypeExemp getTypeExemp(@Param("numDemande") Integer numDemande);
Expand Down Expand Up @@ -54,5 +60,4 @@ public interface IDemandeExempDao extends JpaRepository<DemandeExemp, Integer> {
List<DemandeExemp> getNextDemandeToDelete();

boolean existsDemandeExempByEtatDemande_Id(Integer etatDemande);

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ public interface IDemandeModifDao extends JpaRepository<DemandeModif, Integer> {
@Query("select new fr.abes.item.core.dto.DemandeDto(d, COUNT(l)) from DemandeModif d JOIN d.ligneFichierModifs l where d.etatDemande.numEtat = 9 GROUP BY d")
List<DemandeDto> getAllArchivedDemandesModifExtended();

@Query("select d from DemandeModif d where d.etatDemande.numEtat = 5 order by d.dateModification asc")
List<DemandeModif> getNextDemandeToProceed();
@Query("select d from DemandeModif d join d.ligneFichierModifs l where d.etatDemande.numEtat = 5 group by d having count(l) > :limite order by d.dateModification")
List<DemandeModif> getDemandesEnAttenteGrosVolume(@Param("limite") int limite);

@Query("select d from DemandeModif d join d.ligneFichierModifs l where d.etatDemande.numEtat = 5 group by d having count(l) <= :limite order by d.dateModification")
List<DemandeModif> getDemandesEnAttentePetitVolume(@Param("limite") int limite);

@Query("select d from DemandeModif d where d.etatDemande.numEtat = 10 order by d.dateModification asc")
List<DemandeModif> getListDemandesToClean();
Expand All @@ -55,5 +58,4 @@ public interface IDemandeModifDao extends JpaRepository<DemandeModif, Integer> {
List<DemandeModif> getNextDemandeToDelete();

boolean existsDemandeModifByEtatDemande_Id(Integer etatDemande);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@
@Repository
@ItemConfiguration
public interface IDemandeRecouvDao extends JpaRepository<DemandeRecouv, Integer> {
@Query("select d from DemandeRecouv d where d.etatDemande.numEtat = 5 order by d.dateModification asc")
List<DemandeRecouv> getNextDemandeToProceed();

@Query("select d from DemandeRecouv d join d.ligneFichierRecouvs l where d.etatDemande.numEtat = 5 group by d having count(l) > :limite order by d.dateModification")
List<DemandeRecouv> getDemandesEnAttenteGrosVolume(@Param("limite") int limite);

@Query("select d from DemandeRecouv d join d.ligneFichierRecouvs l where d.etatDemande.numEtat = 5 group by d having count(l) <= :limite order by d.dateModification")
List<DemandeRecouv> getDemandesEnAttentePetitVolume(@Param("limite") int limite);

@Query("select d from DemandeRecouv d join d.ligneFichierRecouvs l where d.etatDemande.numEtat = 5 and d.indexRecherche.code != 'DAT' group by d having count(l) > :limite order by d.dateModification asc")
List<DemandeRecouv> getDemandesToProceedWithoutDATGrosVolume(@Param("limite") int limite);

@Query("select d from DemandeRecouv d join d.ligneFichierRecouvs l where d.etatDemande.numEtat = 5 and d.indexRecherche.code != 'DAT' group by d having count(l) <= :limite order by d.dateModification asc")
List<DemandeRecouv> getDemandesToProceedWithoutDATPetitVolume(@Param("limite") int limite);

@Query("select d from DemandeRecouv d where d.etatDemande.numEtat = 10 order by d.dateModification asc")
List<DemandeRecouv> getNextDemandeToClean();

@Query("select d from DemandeRecouv d where d.etatDemande.numEtat = 5 and d.indexRecherche.code != 'DAT' order by d.dateModification asc")
List<DemandeRecouv> getNextDemandeToProceedWithoutDAT();

@Query("select d from DemandeRecouv d where d.iln = :iln and d.etatDemande.numEtat not in (9, 10)")
List<DemandeRecouv> getActiveDemandesRecouvForUserExceptedPreparedStatus(@Param("iln") String iln);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import fr.abes.item.core.configuration.ItemConfiguration;
import fr.abes.item.core.dto.DemandeDto;
import fr.abes.item.core.entities.item.DemandeSupp;
import fr.abes.item.core.entities.item.EtatDemande;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotNull;
import java.util.List;

@Repository
Expand All @@ -31,7 +29,11 @@ public interface IDemandeSuppDao extends JpaRepository<DemandeSupp, Integer> {
@Query("select new fr.abes.item.core.dto.DemandeDto(d, COUNT(l)) FROM DemandeSupp d JOIN d.ligneFichierSupps l where d.etatDemande.numEtat = 9 GROUP BY d")
List<DemandeDto> getAllArchivedDemandesSuppExtended();

List<DemandeSupp> findDemandeSuppsByEtatDemande_IdOrderByDateModificationAsc(Integer id);
@Query("select d from DemandeSupp d join d.ligneFichierSupps l where d.etatDemande.numEtat = 5 group by d having count(l) > :limite order by d.dateModification")
List<DemandeSupp> getDemandesEnAttenteGrosVolume(@Param("limite") int limite);

@Query("select d from DemandeSupp d join d.ligneFichierSupps l where d.etatDemande.numEtat = 5 group by d having count(l) <= :limite order by d.dateModification")
List<DemandeSupp> getDemandesEnAttentePetitVolume(@Param("limite") int limite);

@Query("select d from DemandeSupp d where d.etatDemande.numEtat = 7 and (day(current_date) - day(d.dateModification)) > 90 order by d.dateModification asc")
List<DemandeSupp> getNextDemandeToArchive();
Expand All @@ -52,5 +54,4 @@ public interface IDemandeSuppDao extends JpaRepository<DemandeSupp, Integer> {
int getNbLigneFichierSuccessByDemande(@Param("numDemande") Integer numDemande);

boolean existsDemandeSuppByEtatDemande_Id(Integer etatDemande);

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface IDemandeService {

List<DemandeDto> getActiveDemandesForUser(String iln);

Demande getIdNextDemandeToProceed(int minHour, int maxHour);
Demande getIdNextDemandeToProceed(int minHour, int maxHour, boolean bigVolume);

String getInfoHeaderFichierResultat(Demande demande, LocalDateTime dateDebut);

Expand All @@ -61,4 +61,6 @@ public interface IDemandeService {
void refreshEntity(Demande demande);

Boolean checkDemandesEnAttente();

Boolean checkDemandesEnAttenteBigVolume(Boolean bigVolume);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class DemandeExempService extends DemandeService implements IDemandeServi
@Value("${files.upload.path}")
private String uploadPath;

@Value("${batch.bigVolume.limit}")
private int limite;

public DemandeExempService(ILibProfileDao libProfileDao, IDemandeExempDao demandeExempDao, FileSystemStorageService storageService, LigneFichierExempService ligneFichierExempService, ReferenceService referenceService, JournalService journalService, TraitementService traitementService, UtilisateurService utilisateurService, IZonesAutoriseesDao zonesAutoriseesDao, ILigneFichierExempDao ligneFichierExempDao, @Qualifier("itemEntityManager") EntityManager entityManager) {
super(libProfileDao, entityManager);
this.demandeExempDao = demandeExempDao;
Expand Down Expand Up @@ -335,14 +338,20 @@ public Demande closeDemande(Demande demande) throws DemandeCheckingException {
* @return demande récupérée dans la base
*/
@Override
public Demande getIdNextDemandeToProceed(int minHour, int maxHour) {
public Demande getIdNextDemandeToProceed(int minHour, int maxHour, boolean bigVolume) {
int currentHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);

List<DemandeExemp> listeDemandes;
if (currentHour >= minHour && currentHour < maxHour) {
listeDemandes = demandeExempDao.getNextDemandeToProceedWithoutDAT();
if (bigVolume)
listeDemandes = demandeExempDao.getDemandesToProceedWithoutDATGrosVolume(limite);
else
listeDemandes = demandeExempDao.getDemandesToProceedWithoutDATPetitVolume(limite);
} else {
listeDemandes = demandeExempDao.getNextDemandeToProceed();
if (bigVolume)
listeDemandes = demandeExempDao.getDemandesEnAttenteGrosVolume(limite);
else
listeDemandes = demandeExempDao.getDemandesEnAttentePetitVolume(limite);
}
if (!listeDemandes.isEmpty())
return listeDemandes.get(0);
Expand Down Expand Up @@ -470,7 +479,15 @@ public void cleanLignesFichierDemande(Demande demande) {
ligneFichierService.deleteByDemande(demandeExemp);
}

@Override
public Boolean checkDemandesEnAttente(){
return demandeExempDao.existsDemandeExempByEtatDemande_Id(Constant.ETATDEM_ATTENTE);
}

@Override
public Boolean checkDemandesEnAttenteBigVolume(Boolean bigVolume) {
return bigVolume ?
!demandeExempDao.getDemandesEnAttenteGrosVolume(limite).isEmpty() :
!demandeExempDao.getDemandesEnAttentePetitVolume(limite).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class DemandeModifService extends DemandeService implements IDemandeServi
@Value("${files.upload.path}")
private String uploadPath;

@Value("${batch.bigVolume.limit}")
private int limite;

private FichierInitial fichierInit;
private FichierPrepare fichierPrepare;

Expand Down Expand Up @@ -360,8 +363,13 @@ public Demande changeState(Demande demande, int etatDemande) throws DemandeCheck
}

@Override
public Demande getIdNextDemandeToProceed(int minHour, int maxHour) {
List<DemandeModif> demandes = demandeModifDao.getNextDemandeToProceed();
public Demande getIdNextDemandeToProceed(int minHour, int maxHour, boolean bigVolume) {
List<DemandeModif> demandes;
if (bigVolume) {
demandes = demandeModifDao.getDemandesEnAttenteGrosVolume(limite);
} else {
demandes = demandeModifDao.getDemandesEnAttentePetitVolume(limite);
}
if (!demandes.isEmpty())
return demandes.get(0);
return null;
Expand Down Expand Up @@ -541,7 +549,15 @@ public void refreshEntity(Demande demande) {
entityManager.refresh(demande);
}

@Override
public Boolean checkDemandesEnAttente(){
return demandeModifDao.existsDemandeModifByEtatDemande_Id(Constant.ETATDEM_ATTENTE);
}

@Override
public Boolean checkDemandesEnAttenteBigVolume(Boolean bigVolume) {
return bigVolume ?
!demandeModifDao.getDemandesEnAttenteGrosVolume(limite).isEmpty() :
!demandeModifDao.getDemandesEnAttentePetitVolume(limite).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class DemandeRecouvService extends DemandeService implements IDemandeServ
@Value("${files.upload.path}")
private String uploadPath;

@Value("${batch.bigVolume.limit}")
private int limite;

public DemandeRecouvService(ILibProfileDao libProfileDao, IDemandeRecouvDao demandeRecouvDao, FileSystemStorageService storageService, ReferenceService referenceService, LigneFichierRecouvService ligneFichierRecouvService, UtilisateurService utilisateurService, @Qualifier("itemEntityManager") EntityManager entityManager, JournalService journalService) {
super(libProfileDao, entityManager);
this.demandeRecouvDao = demandeRecouvDao;
Expand Down Expand Up @@ -167,13 +170,19 @@ public Demande closeDemande(Demande demande) throws DemandeCheckingException {
}

@Override
public Demande getIdNextDemandeToProceed(int minHour, int maxHour) {
public Demande getIdNextDemandeToProceed(int minHour, int maxHour, boolean bigVolume) {
int currentHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
List<DemandeRecouv> listeDemandes;
if (currentHour >= minHour && currentHour <= maxHour) {
listeDemandes = demandeRecouvDao.getNextDemandeToProceedWithoutDAT();
if (bigVolume)
listeDemandes = demandeRecouvDao.getDemandesEnAttenteGrosVolume(limite);
else
listeDemandes = demandeRecouvDao.getDemandesEnAttentePetitVolume(limite);
} else {
listeDemandes = demandeRecouvDao.getNextDemandeToProceed();
if (bigVolume)
listeDemandes = demandeRecouvDao.getDemandesToProceedWithoutDATGrosVolume(limite);
else
listeDemandes = demandeRecouvDao.getDemandesToProceedWithoutDATPetitVolume(limite);
}
if (!listeDemandes.isEmpty())
return listeDemandes.get(0);
Expand Down Expand Up @@ -359,7 +368,15 @@ public void refreshEntity(Demande demande) {
entityManager.refresh(demande);
}

@Override
public Boolean checkDemandesEnAttente(){
return demandeRecouvDao.existsDemandeRecouvByEtatDemande_Id(Constant.ETATDEM_ATTENTE);
}

@Override
public Boolean checkDemandesEnAttenteBigVolume(Boolean bigVolume) {
return bigVolume ?
!demandeRecouvDao.getDemandesEnAttenteGrosVolume(limite).isEmpty() :
!demandeRecouvDao.getDemandesEnAttentePetitVolume(limite).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class DemandeSuppService extends DemandeService implements IDemandeServic
@Value("${files.upload.path}")
private String uploadPath;

@Value("${batch.bigVolume.limit}")
private int limite;

public DemandeSuppService(ILibProfileDao libProfileDao, IDemandeSuppDao demandeSuppDao, FileSystemStorageService storageService, ReferenceService referenceService, UtilisateurService utilisateurService, Ppntoepn procStockeePpnToEpn, Epntoppn procStockeeEpnToPpn, LigneFichierSuppService ligneFichierSuppService, @Qualifier("itemEntityManager") EntityManager entityManager, JournalService journalService) {
super(libProfileDao, entityManager);
this.demandeSuppDao = demandeSuppDao;
Expand Down Expand Up @@ -249,8 +252,13 @@ public List<DemandeDto> getActiveDemandesForUser(String iln) {
}

@Override
public Demande getIdNextDemandeToProceed(int minHour, int maxHour) {
List<DemandeSupp> demandesSupp = this.demandeSuppDao.findDemandeSuppsByEtatDemande_IdOrderByDateModificationAsc(Constant.ETATDEM_ATTENTE);
public Demande getIdNextDemandeToProceed(int minHour, int maxHour, boolean bigVolume) {
List<DemandeSupp> demandesSupp;
if (bigVolume) {
demandesSupp = this.demandeSuppDao.getDemandesEnAttenteGrosVolume(limite);
} else {
demandesSupp = this.demandeSuppDao.getDemandesEnAttentePetitVolume(limite);
}
return demandesSupp.isEmpty() ? null : demandesSupp.get(0);
}

Expand Down Expand Up @@ -414,7 +422,15 @@ public void cleanLignesFichierDemande(Demande demande) {
ligneFichierService.deleteByDemande(demandeSupp);
}

@Override
public Boolean checkDemandesEnAttente(){
return demandeSuppDao.existsDemandeSuppByEtatDemande_Id(Constant.ETATDEM_ATTENTE);
}

@Override
public Boolean checkDemandesEnAttenteBigVolume(Boolean bigVolume) {
return bigVolume ?
!demandeSuppDao.getDemandesEnAttenteGrosVolume(limite).isEmpty() :
!demandeSuppDao.getDemandesEnAttentePetitVolume(limite).isEmpty();
}
}
Loading
Loading