Search in sources :

Example 1 with BatchHisto

use of fr.univlorraine.ecandidat.entities.ecandidat.BatchHisto in project esup-ecandidat by EsupPortail.

the class CandidatureGestionController method launchBatchDestructDossier.

/**
 * Lance le batch de destruction des dossiers
 */
public void launchBatchDestructDossier(final BatchHisto batchHisto) throws FileException {
    final Boolean deleteFileManualy = enableDeleteFileManuallyBatchDestruct != null && enableDeleteFileManuallyBatchDestruct;
    final Boolean deleteRootManualy = enableDeleteRootFolderManuallyBatchDestruct != null && enableDeleteRootFolderManuallyBatchDestruct;
    final List<Campagne> listeCamp = campagneController.getCampagnes().stream().filter(e -> (e.getDatDestructEffecCamp() == null && e.getDatArchivCamp() != null)).collect(Collectors.toList());
    batchController.addDescription(batchHisto, "Lancement batch de destruction");
    batchController.addDescription(batchHisto, "Batch de destruction, option enableDeleteFileManuallyBatchDestruct=" + deleteFileManualy);
    batchController.addDescription(batchHisto, "Batch de destruction, option enableDeleteRootFolderManuallyBatchDestruct=" + deleteRootManualy);
    for (final Campagne campagne : listeCamp) {
        if (campagneController.getDateDestructionDossier(campagne).isBefore(LocalDateTime.now())) {
            batchController.addDescription(batchHisto, "Batch de destruction, destruction dossiers campagne : " + campagne.getCodCamp() + " - " + campagne.getCompteMinimas().size() + " comptes à supprimer");
            Integer i = 0;
            Integer cpt = 0;
            for (final CompteMinima cptMin : campagne.getCompteMinimas()) {
                if (cptMin.getCandidat() != null) {
                    for (final Candidature candidature : cptMin.getCandidat().getCandidatures()) {
                        for (final PjCand pjCand : candidature.getPjCands()) {
                            if (deleteFileManualy) {
                                candidaturePieceController.removeFileToPjManually(pjCand);
                            } else {
                                candidaturePieceController.removeFileToPj(pjCand);
                            }
                        }
                    }
                }
                compteMinimaRepository.delete(cptMin);
                i++;
                cpt++;
                if (i.equals(ConstanteUtils.BATCH_LOG_NB_LONG)) {
                    batchController.addDescription(batchHisto, "Batch de destruction, destruction de " + cpt + " comptes ok");
                    i = 0;
                }
            }
            /* Lancement du batch de fiabilisation des fichiers */
            fileController.launchFiabilisationFichier(campagne.getDatArchivCamp());
            /* Destruction du dossier de la campagne et les sous-repertoire */
            if (!deleteRootManualy) {
                batchController.addDescription(batchHisto, "Batch de destruction, destruction dossier root campagne : " + campagne.getCodCamp());
                fileController.deleteCampagneFolder(campagne.getCodCamp());
            }
            campagneController.saveDateDestructionCampagne(campagne);
            /* Enregistre la date de suppression */
            batchController.addDescription(batchHisto, "Batch de destruction, fin destruction campagne : " + campagne.getCodCamp() + ", " + cpt + " comptes supprimés");
        }
        batchController.addDescription(batchHisto, "Fin batch de destruction");
    }
}
Also used : TypeDecision_(fr.univlorraine.ecandidat.entities.ecandidat.TypeDecision_) Join(javax.persistence.criteria.Join) Order(org.springframework.data.domain.Sort.Order) SiScolGenericService(fr.univlorraine.ecandidat.services.siscol.SiScolGenericService) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) PdfAttachement(fr.univlorraine.ecandidat.utils.PdfAttachement) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) CompteMinimaRepository(fr.univlorraine.ecandidat.repositories.CompteMinimaRepository) Predicate(javax.persistence.criteria.Predicate) NomenclatureUtils(fr.univlorraine.ecandidat.utils.NomenclatureUtils) CompteMinima(fr.univlorraine.ecandidat.entities.ecandidat.CompteMinima) CompteMinima_(fr.univlorraine.ecandidat.entities.ecandidat.CompteMinima_) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Candidat_(fr.univlorraine.ecandidat.entities.ecandidat.Candidat_) Sort(org.springframework.data.domain.Sort) Direction(org.springframework.data.domain.Sort.Direction) BatchHisto(fr.univlorraine.ecandidat.entities.ecandidat.BatchHisto) FileException(fr.univlorraine.ecandidat.services.file.FileException) Root(javax.persistence.criteria.Root) TypeDecisionCandidatureRepository(fr.univlorraine.ecandidat.repositories.TypeDecisionCandidatureRepository) Campagne(fr.univlorraine.ecandidat.entities.ecandidat.Campagne) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Logger(org.slf4j.Logger) Candidature_(fr.univlorraine.ecandidat.entities.ecandidat.Candidature_) ConstanteUtils(fr.univlorraine.ecandidat.utils.ConstanteUtils) TypeDecisionCandidature_(fr.univlorraine.ecandidat.entities.ecandidat.TypeDecisionCandidature_) Resource(javax.annotation.Resource) TypeDecisionCandidature(fr.univlorraine.ecandidat.entities.ecandidat.TypeDecisionCandidature) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) List(java.util.List) Component(org.springframework.stereotype.Component) Specification(org.springframework.data.jpa.domain.Specification) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) CandidatureRepository(fr.univlorraine.ecandidat.repositories.CandidatureRepository) Optional(java.util.Optional) FormationRepository(fr.univlorraine.ecandidat.repositories.FormationRepository) Candidature(fr.univlorraine.ecandidat.entities.ecandidat.Candidature) Subquery(javax.persistence.criteria.Subquery) Formation(fr.univlorraine.ecandidat.entities.ecandidat.Formation) InputStream(java.io.InputStream) PjCand(fr.univlorraine.ecandidat.entities.ecandidat.PjCand) CompteMinima(fr.univlorraine.ecandidat.entities.ecandidat.CompteMinima) PjCand(fr.univlorraine.ecandidat.entities.ecandidat.PjCand) TypeDecisionCandidature(fr.univlorraine.ecandidat.entities.ecandidat.TypeDecisionCandidature) Candidature(fr.univlorraine.ecandidat.entities.ecandidat.Candidature) Campagne(fr.univlorraine.ecandidat.entities.ecandidat.Campagne)

Example 2 with BatchHisto

use of fr.univlorraine.ecandidat.entities.ecandidat.BatchHisto in project esup-ecandidat by EsupPortail.

the class BatchController method runJob.

/**
 * Lance un batch
 * @param batch
 */
private void runJob(Batch batch) {
    logger.trace("Début du log");
    BatchHisto batchHisto = new BatchHisto();
    batchHisto.setDateDebBatchHisto(LocalDateTime.now());
    batchHisto.setBatch(batch);
    batchHisto.setStateBatchHisto(ConstanteUtils.BATCH_RUNNING);
    batchHisto = batchHistoRepository.saveAndFlush(batchHisto);
    batch.setLastDatExecutionBatch(LocalDateTime.now());
    batch = batchRepository.save(batch);
    try {
        if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_SI_SCOL)) {
            siScolController.syncSiScol(batchHisto);
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_NETTOYAGE)) {
            nettoyageBatch(4);
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_APP_EN_MAINT)) {
            parametreController.changeMaintenanceParam(true);
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_APP_EN_SERVICE)) {
            parametreController.changeMaintenanceParam(false);
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_NETTOYAGE_CPT)) {
            candidatController.nettoyageCptMinInvalides(batchHisto);
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_ARCHIVAGE)) {
            campagneController.archiveCampagne(batchHisto);
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_SYNCHRO_LIMESURVEY)) {
            formulaireController.launchBatchSyncLimeSurvey();
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_DESTRUCT_DOSSIER)) {
            candidatureGestionController.launchBatchDestructDossier(batchHisto);
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_ASYNC_OPI)) {
            opiController.launchBatchAsyncOPI(batchHisto);
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_DESTRUCT_HISTO)) {
            cleanHistoBatch();
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_DEMO) && demoController.getDemoMode()) {
            demoController.launchDemoBatch();
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_ASYNC_OPI_PJ)) {
            opiController.launchBatchAsyncOPIPj(batchHisto);
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_DESIST_AUTO)) {
            candidatureGestionController.desistAutoCandidature(batchHisto);
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_RELANCE_FAVO)) {
            candidatureGestionController.relanceFavorableNotConfirm(batchHisto);
        } else if (batch.getCodBatch().equals(NomenclatureUtils.BATCH_CALCUL_RANG_LC)) {
            candidatureGestionController.calculRangLcAllFormation(batchHisto);
        }
        batchHisto.setStateBatchHisto(ConstanteUtils.BATCH_FINISH);
    } catch (final Exception e) {
        logger.error("Erreur de lancement du batch " + batch.getCodBatch(), e);
        batchHisto.setStateBatchHisto(ConstanteUtils.BATCH_ERROR);
    }
    batchHisto.setDateFinBatchHisto(LocalDateTime.now());
    batchHistoRepository.saveAndFlush(batchHisto);
    batch.setLastDatExecutionBatch(LocalDateTime.now());
    batch = batchRepository.save(batch);
    logger.trace("Fin du log");
}
Also used : BatchHisto(fr.univlorraine.ecandidat.entities.ecandidat.BatchHisto)

Example 3 with BatchHisto

use of fr.univlorraine.ecandidat.entities.ecandidat.BatchHisto in project esup-ecandidat by EsupPortail.

the class BatchController method runImmediatly.

/**
 * Lancement immediat du batch
 * @param batch
 */
public void runImmediatly(final Batch batch) {
    final ConfirmWindow win = new ConfirmWindow(applicationContext.getMessage("batch.immediat.ok", new Object[] { batch.getCodBatch() }, UI.getCurrent().getLocale()));
    win.addBtnOuiListener(e -> {
        final BatchHisto histo = batchHistoRepository.findByBatchCodBatchAndStateBatchHisto(batch.getCodBatch(), ConstanteUtils.BATCH_RUNNING);
        if (histo == null) {
            batch.setTemIsLaunchImediaBatch(true);
            batchRepository.saveAndFlush(batch);
            Notification.show(applicationContext.getMessage("batch.immediat.launch", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
        } else {
            Notification.show(applicationContext.getMessage("batch.immediat.nok", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
        }
    });
    UI.getCurrent().addWindow(win);
}
Also used : ConfirmWindow(fr.univlorraine.ecandidat.views.windows.ConfirmWindow) BatchHisto(fr.univlorraine.ecandidat.entities.ecandidat.BatchHisto)

Example 4 with BatchHisto

use of fr.univlorraine.ecandidat.entities.ecandidat.BatchHisto in project esup-ecandidat by EsupPortail.

the class BatchController method checkBatchRun.

/**
 * Vérifie si un batch doit etre lancé depuis la dernière date de verification
 */
@Scheduled(fixedDelayString = "${batch.fixedRate}")
public void checkBatchRun() {
    if (!loadBalancingController.isLoadBalancingCandidatMode()) {
        final List<BatchRun> liste = batchRunRepository.findAll();
        if (liste != null && liste.size() == 1) {
            final BatchRun lastBatchRun = liste.get(0);
            final List<Batch> listeBatch = batchRepository.findByTesBatch(true);
            logger.trace("Vérification lancement lastChek = " + lastBatchRun.getDatLastCheckRun() + " - Now = " + LocalDateTime.now());
            /* Suppression du dernier batch run */
            nettoyageBatchRun();
            listeBatch.forEach(batch -> {
                final BatchHisto histo = batchHistoRepository.findByBatchCodBatchAndStateBatchHisto(batch.getCodBatch(), ConstanteUtils.BATCH_RUNNING);
                if (histo == null && isNeededToLaunch(batch, lastBatchRun.getDatLastCheckRun())) {
                    logger.debug("Le batch " + batch.getCodBatch() + " doit être lancé");
                    runJob(batch);
                }
            });
        } else {
            nettoyageBatchRun();
        }
    }
}
Also used : Batch(fr.univlorraine.ecandidat.entities.ecandidat.Batch) BatchHisto(fr.univlorraine.ecandidat.entities.ecandidat.BatchHisto) BatchRun(fr.univlorraine.ecandidat.entities.ecandidat.BatchRun) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 5 with BatchHisto

use of fr.univlorraine.ecandidat.entities.ecandidat.BatchHisto in project esup-ecandidat by EsupPortail.

the class BatchController method nettoyageBatch.

/**
 * Batch de nettoyage des batchs
 */
public void nettoyageBatch(final Integer plusHour) {
    final List<BatchHisto> listHisto = batchHistoRepository.findByStateBatchHisto(ConstanteUtils.BATCH_RUNNING);
    listHisto.forEach(batchHisto -> {
        if (plusHour.equals(0)) {
            interruptBatch(batchHisto);
        } else {
            final LocalDateTime histPlusHour = batchHisto.getDateDebBatchHisto().plusHours(Long.valueOf(plusHour));
            if (histPlusHour.isBefore(LocalDateTime.now())) {
                interruptBatch(batchHisto);
            }
        }
    });
}
Also used : LocalDateTime(java.time.LocalDateTime) BatchHisto(fr.univlorraine.ecandidat.entities.ecandidat.BatchHisto)

Aggregations

BatchHisto (fr.univlorraine.ecandidat.entities.ecandidat.BatchHisto)7 Batch (fr.univlorraine.ecandidat.entities.ecandidat.Batch)2 Campagne (fr.univlorraine.ecandidat.entities.ecandidat.Campagne)2 Formation (fr.univlorraine.ecandidat.entities.ecandidat.Formation)2 ConfirmWindow (fr.univlorraine.ecandidat.views.windows.ConfirmWindow)2 LocalDateTime (java.time.LocalDateTime)2 BatchRun (fr.univlorraine.ecandidat.entities.ecandidat.BatchRun)1 Candidat_ (fr.univlorraine.ecandidat.entities.ecandidat.Candidat_)1 Candidature (fr.univlorraine.ecandidat.entities.ecandidat.Candidature)1 Candidature_ (fr.univlorraine.ecandidat.entities.ecandidat.Candidature_)1 Commission (fr.univlorraine.ecandidat.entities.ecandidat.Commission)1 CompteMinima (fr.univlorraine.ecandidat.entities.ecandidat.CompteMinima)1 CompteMinima_ (fr.univlorraine.ecandidat.entities.ecandidat.CompteMinima_)1 I18n (fr.univlorraine.ecandidat.entities.ecandidat.I18n)1 I18nTraduction (fr.univlorraine.ecandidat.entities.ecandidat.I18nTraduction)1 Mail (fr.univlorraine.ecandidat.entities.ecandidat.Mail)1 Parametre (fr.univlorraine.ecandidat.entities.ecandidat.Parametre)1 PjCand (fr.univlorraine.ecandidat.entities.ecandidat.PjCand)1 SchemaVersion (fr.univlorraine.ecandidat.entities.ecandidat.SchemaVersion)1 TypeDecision (fr.univlorraine.ecandidat.entities.ecandidat.TypeDecision)1