From dbfe513ce2a335f64bd3e44610f23c6ec0b8ede3 Mon Sep 17 00:00:00 2001 From: Yves Grasset Date: Tue, 19 Mar 2024 15:45:44 +0100 Subject: [PATCH] #202 - Email de rappel si demande en attente de validation depuis > x jours --- .../ch/asit_asso/extract/domain/Request.java | 14 ++++++ .../extract/domain/SystemParameter.java | 2 + .../ApplicationParametersInitializer.java | 4 ++ .../RequestsProcessingScheduler.java | 49 +++++++++++++++---- .../SystemParametersRepository.java | 6 +++ .../SystemParametersController.java | 7 ++- .../web/model/SystemParameterModel.java | 10 ++++ .../validators/SystemParameterValidator.java | 21 ++++++++ .../static/lang/fr/messages.properties | 7 +++ .../templates/pages/parameters/details.html | 16 ++++++ 10 files changed, 126 insertions(+), 10 deletions(-) diff --git a/extract/src/main/java/ch/asit_asso/extract/domain/Request.java b/extract/src/main/java/ch/asit_asso/extract/domain/Request.java index 610b29d7..31704204 100644 --- a/extract/src/main/java/ch/asit_asso/extract/domain/Request.java +++ b/extract/src/main/java/ch/asit_asso/extract/domain/Request.java @@ -225,6 +225,14 @@ public class Request implements Serializable { @Column(name = "p_external_url") private String externalUrl; + /** + * When this order was imported. + */ + @Column(name = "last_reminder") + @Temporal(TemporalType.TIMESTAMP) + private Calendar lastReminder; + + /** * The set of tasks attached to this data item order to produce the requested data. */ @@ -944,6 +952,12 @@ public void setExternalUrl(final String url) { } + public Calendar getLastReminder() { return this.lastReminder; } + + + + public void setLastReminder(Calendar lastReminder) { this.lastReminder = lastReminder; } + /** * Obtains whether this data item order has yet to be completed. diff --git a/extract/src/main/java/ch/asit_asso/extract/domain/SystemParameter.java b/extract/src/main/java/ch/asit_asso/extract/domain/SystemParameter.java index c8248267..19e004d6 100644 --- a/extract/src/main/java/ch/asit_asso/extract/domain/SystemParameter.java +++ b/extract/src/main/java/ch/asit_asso/extract/domain/SystemParameter.java @@ -61,6 +61,8 @@ query = "SELECT s.value FROM SystemParameter s WHERE s.key = 'smtp_user'"), @NamedQuery(name = "SystemParameter.getSmtpSSL", query = "SELECT s.value FROM SystemParameter s WHERE s.key = 'smtp_ssl'"), + @NamedQuery(name = "SystemParameter.getStandbyReminderDays", + query = "SELECT s.value FROM SystemParameter s WHERE s.key = 'standby_reminder_days'"), @NamedQuery(name = "SystemParameter.getDashboardRefreshInterval", query = "SELECT s.value FROM SystemParameter s WHERE s.key = 'dashboard_interval'"), @NamedQuery(name = "SystemParameter.isEmailNotificationEnabled", diff --git a/extract/src/main/java/ch/asit_asso/extract/initializers/ApplicationParametersInitializer.java b/extract/src/main/java/ch/asit_asso/extract/initializers/ApplicationParametersInitializer.java index 3bc68c3a..e07931ff 100644 --- a/extract/src/main/java/ch/asit_asso/extract/initializers/ApplicationParametersInitializer.java +++ b/extract/src/main/java/ch/asit_asso/extract/initializers/ApplicationParametersInitializer.java @@ -111,6 +111,8 @@ class ApplicationParametersInitializer { */ private static final EmailSettings.SslType DEFAULT_SSL_TYPE = EmailSettings.SslType.NONE; + private static final String DEFAULT_STANDBY_REMINDER_DAYS = "0"; + /** * The writer to the application logs. */ @@ -170,6 +172,8 @@ public final void ensureInitialized() { ApplicationParametersInitializer.DEFAULT_SCHEDULER_MODE); this.ensureParameterInitialized(SystemParametersRepository.SCHEDULER_RANGES, ApplicationParametersInitializer.DEFAULT_SCHEDULER_RANGES); + this.ensureParameterInitialized(SystemParametersRepository.STANDBY_REMINDER_DAYS, + ApplicationParametersInitializer.DEFAULT_STANDBY_REMINDER_DAYS); this.ensureParameterInitialized(SystemParametersRepository.VALIDATION_FOCUS_PROPERTIES_KEY, ""); this.ensureParameterInitialized(SystemParametersRepository.DISPLAY_TEMP_FOLDER, diff --git a/extract/src/main/java/ch/asit_asso/extract/orchestrator/schedulers/RequestsProcessingScheduler.java b/extract/src/main/java/ch/asit_asso/extract/orchestrator/schedulers/RequestsProcessingScheduler.java index 473ca354..009d1297 100644 --- a/extract/src/main/java/ch/asit_asso/extract/orchestrator/schedulers/RequestsProcessingScheduler.java +++ b/extract/src/main/java/ch/asit_asso/extract/orchestrator/schedulers/RequestsProcessingScheduler.java @@ -16,6 +16,11 @@ */ package ch.asit_asso.extract.orchestrator.schedulers; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import ch.asit_asso.extract.connectors.implementation.ConnectorDiscovererWrapper; import ch.asit_asso.extract.domain.Request; import ch.asit_asso.extract.domain.RequestHistoryRecord; @@ -23,6 +28,7 @@ import ch.asit_asso.extract.orchestrator.OrchestratorSettings; import ch.asit_asso.extract.orchestrator.runners.ExportRequestsJobRunner; import ch.asit_asso.extract.orchestrator.runners.RequestMatcherJobRunner; +import ch.asit_asso.extract.orchestrator.runners.RequestNotificationJobRunner; import ch.asit_asso.extract.orchestrator.runners.RequestTaskRunner; import ch.asit_asso.extract.orchestrator.runners.TaskCompleteListener; import ch.asit_asso.extract.persistence.ApplicationRepositories; @@ -35,12 +41,6 @@ import org.springframework.scheduling.config.ScheduledTask; import org.springframework.scheduling.config.ScheduledTaskRegistrar; -import java.util.List; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - /** @@ -92,6 +92,8 @@ public class RequestsProcessingScheduler extends JobScheduler implements TaskCom */ private ScheduledTask processMatchingScheduledTask; + private ScheduledTask requestNotificationScheduledTask; + /** * A collection of request that have a task currently running. */ @@ -182,6 +184,7 @@ public final void scheduleJobs() { this.scheduleTaskExportJob(); this.scheduleProcessMatchingJob(); this.scheduleTasksExecutionManagementJob(); + this.scheduleRequestNotifierJob(); } @@ -195,6 +198,21 @@ public final void unscheduleJobs() { this.unscheduleTaskExportJob(); this.unscheduleProcessMatchingJob(); this.unscheduleTaskExecutionManagementJob(); + this.unscheduleRequestNotifierJob(); + } + + + + /** + * Starts the batch process that will export requests results at a given interval. + */ + private void scheduleRequestNotifierJob() { + this.logger.debug("Scheduling the request notification job."); + final RequestNotificationJobRunner notificationJobRunner = new RequestNotificationJobRunner( + this.applicationRepositories, this.emailSettings, this.applicationLangague); + final var recurringTask = new FixedDelayTask(notificationJobRunner, this.getSchedulingStepInMilliseconds(), 0); + this.requestNotificationScheduledTask = this.getTaskRegistrar().scheduleFixedDelayTask(recurringTask); + this.logger.debug("The request notification job is scheduled with a {} second(s) delay.", this.getSchedulingStep()); } @@ -271,12 +289,25 @@ private void unscheduleProcessMatchingJob() { */ private void scheduleTasksExecutionManagementJob() { this.logger.debug("Scheduling the requests task execution management job."); + + if (this.requestNotificationScheduledTask == null) { + this.logger.debug("The request notification job is not scheduled, so nothing done."); + return; + } + + this.taskExecutionScheduledTask.cancel(); + this.logger.debug("The request notification job has been unscheduled."); + } + + + private void unscheduleRequestNotifierJob() { + this.logger.debug("Scheduling the requests notification management job."); final var recurringTask = new FixedDelayTask(this::manageTaskProcessingJobs, this.getSchedulingStepInMilliseconds(), 0); - this.taskExecutionScheduledTask = this.getTaskRegistrar().scheduleFixedDelayTask(recurringTask); + this.requestNotificationScheduledTask = this.getTaskRegistrar().scheduleFixedDelayTask(recurringTask); - this.logger.debug("The request task execution management job is scheduled with a {} second(s) delay.", - this.getSchedulingStep()); + this.logger.debug("The request notification job is scheduled with a {} second(s) delay.", + this.getSchedulingStep()); } diff --git a/extract/src/main/java/ch/asit_asso/extract/persistence/SystemParametersRepository.java b/extract/src/main/java/ch/asit_asso/extract/persistence/SystemParametersRepository.java index 8fb41585..fa1d858c 100644 --- a/extract/src/main/java/ch/asit_asso/extract/persistence/SystemParametersRepository.java +++ b/extract/src/main/java/ch/asit_asso/extract/persistence/SystemParametersRepository.java @@ -102,6 +102,9 @@ public interface SystemParametersRepository extends CrudRepository{Configuration de l'a +
+
+
+ + + +
+
+