Skip to content

Commit

Permalink
asit-asso#202 - Email de rappel si demande en attente de validation d…
Browse files Browse the repository at this point in the history
…epuis > x jours
  • Loading branch information
arxit-ygr committed Mar 19, 2024
1 parent 1a65e80 commit dbfe513
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 10 deletions.
14 changes: 14 additions & 0 deletions extract/src/main/java/ch/asit_asso/extract/domain/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
*/
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;
import ch.asit_asso.extract.email.EmailSettings;
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;
Expand All @@ -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;



/**
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -182,6 +184,7 @@ public final void scheduleJobs() {
this.scheduleTaskExportJob();
this.scheduleProcessMatchingJob();
this.scheduleTasksExecutionManagementJob();
this.scheduleRequestNotifierJob();
}


Expand All @@ -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());
}


Expand Down Expand Up @@ -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());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public interface SystemParametersRepository extends CrudRepository<SystemParamet
String SMTP_SSL_KEY = "smtp_ssl";


String STANDBY_REMINDER_DAYS = "standby_reminder_days";


String VALIDATION_FOCUS_PROPERTIES_KEY = "validation_focus_properties";


Expand Down Expand Up @@ -235,6 +238,9 @@ public interface SystemParametersRepository extends CrudRepository<SystemParamet
String getSmtpSSL();


String getStandbyReminderDays();



/**
* Gets the value that defines whether the application must send e-mail notifications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public final String updateParameters(
SystemParametersRepository.SMTP_PASSWORD_KEY, SystemParametersRepository.SMTP_PORT_KEY,
SystemParametersRepository.SMTP_SERVER_KEY, SystemParametersRepository.SMTP_USER_KEY,
SystemParametersRepository.SMTP_SSL_KEY, SystemParametersRepository.ENABLE_MAIL_NOTIFICATIONS,
SystemParametersRepository.VALIDATION_FOCUS_PROPERTIES_KEY
SystemParametersRepository.VALIDATION_FOCUS_PROPERTIES_KEY, SystemParametersRepository.STANDBY_REMINDER_DAYS
};

if (bindingResult.hasErrors()) {
Expand Down Expand Up @@ -261,6 +261,10 @@ public final String updateParameters(
systemParameter.setValue(parameterModel.getSslType().name());
break;

case SystemParametersRepository.STANDBY_REMINDER_DAYS:
systemParameter.setValue(parameterModel.getStandbyReminderDays());
break;

case SystemParametersRepository.ENABLE_MAIL_NOTIFICATIONS:
final String mailEnabledValue = (parameterModel.isMailEnabled())
? SystemParametersController.ON_STRING
Expand Down Expand Up @@ -330,6 +334,7 @@ public final String viewPage(final ModelMap model) {
systemParameterModel.setSmtpServer(systemParametersRepository.getSmtpServer());
systemParameterModel.setSmtpUser(systemParametersRepository.getSmtpUser());
systemParameterModel.setSslType(systemParametersRepository.getSmtpSSL());
systemParameterModel.setStandbyReminderDays(systemParametersRepository.getStandbyReminderDays());
final String mailEnabledValue = systemParametersRepository.isEmailNotificationEnabled();
systemParameterModel.setMailEnabled(SystemParametersController.ON_STRING.equals(mailEnabledValue));
systemParameterModel.setValidationFocusProperties(systemParametersRepository.getValidationFocusProperties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public class SystemParameterModel extends PluginItemModel {
private SslType sslType;


private String standbyReminderDays;


private String validationFocusProperties;


Expand Down Expand Up @@ -435,6 +438,13 @@ public final void setSslType(final String connectionTypeString) {



public final String getStandbyReminderDays() { return this.standbyReminderDays; }


public final void setStandbyReminderDays(final String days) { this.standbyReminderDays = days; }



/**
* Obtains whether the application must send e-mail notifications.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class SystemParameterValidator extends BaseValidator {
*/
private static final int MINIMUM_SCHEDULER_FREQUENCY = 1;

private static final int MINIMUM_STANDBY_REMINDER_DAYS = 0;

/**
* The smallest number that is acceptable as an HTTP port.
*/
Expand Down Expand Up @@ -118,6 +120,7 @@ public void validate(final Object target, final Errors errors) {
this.validateDashboardFrequency(systemParameterModel.getDashboardFrequency(), errors);
this.validateSchedulerFrequency(systemParameterModel.getSchedulerFrequency(), errors);
this.validateSmtpPort(systemParameterModel.getSmtpPort(), errors);
this.validateStandbyReminderDays(systemParameterModel.getStandbyReminderDays(), errors);

if (!this.validateEmail(systemParameterModel.getSmtpFromMail())) {
errors.rejectValue("smtpFromMail", "parameters.errors.smtpfrommail.invalid");
Expand Down Expand Up @@ -242,6 +245,24 @@ private boolean validateSmtpPort(final String valueString, final Errors errors)
}


private boolean validateStandbyReminderDays(final String valueString, final Errors errors) {

if (!this.validateInteger(valueString)) {
errors.rejectValue("standbyReminderDays", "parameters.errors.standbyReminder.invalid");
return false;
}

final int days = Integer.valueOf(valueString);

if (days < SystemParameterValidator.MINIMUM_STANDBY_REMINDER_DAYS) {
errors.rejectValue("smtpPort", "parameters.errors.standbyReminder.negative");
return false;
}

return true;
}



/**
* Ensures that an e-mail address is correctly formed.
Expand Down
7 changes: 7 additions & 0 deletions extract/src/main/resources/static/lang/fr/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ parameters.fields.mail.label=Email de l'\u00e9metteur
parameters.fields.smtppassword.label=Mot de passe SMTP
parameters.fields.smtpuser.label=Utilisateur SMTP
parameters.fields.smtpssl.label=Type de connexion SSL
parameters.fields.standbyReminder.label=Intervalle entre les rappels de validation (0 pour d\u00e9sactiver)
parameters.remarks.manage.button=G\u00e9rer les mod\u00e8les
parameters.remarks.manage.text=G\u00e9rer les mod\u00e8les de remarques \u00e0 utiliser pour valider ou annuler une demande
parameters.remarks.properties.label=Propri\u00e9t\u00e9s \u00e0 mettre en avant lors de la validation
Expand Down Expand Up @@ -582,6 +583,8 @@ parameters.errors.smtpserver.required=Le serveur SMTP est requis.
parameters.errors.smtpport.invalid=Le port SMTP n'est pas un entier valide.
parameters.errors.smtpfrommail.invalid=L'email de l'\u00e9metteur n'est pas valide.
parameters.errors.ssltype.required=Le type de connexion SSL est requis.
parameters.errors.standbyReminder.invalid=Le nombre de jours avant le rappel des requ\u00eates en attente de validation n'est pas un entier valide
parameters.errors.standbyReminder.negative=Le nombre de jours avant le rappel des requ\u00eates en attente de validation doit \u00eatre sup\u00e9rieur ou \u00e9gal \u00e0 0.

#Predefined remarks details page
remarkDetails.body.text.explain=D\u00e9finissez ici un message qui pourra \u00eatre utilis\u00e9 par un op\u00e9rateur lors d'une \u00e9tape de validation d'un traitement.
Expand Down Expand Up @@ -756,6 +759,10 @@ email.taskStandby.action=Veuillez consulter le tableau de bord d'Extract pour pl
email.taskStandby.description=Un \u00e9l\u00e9ment du traitement "{0}" pour le produit "{1}" de la commande "{2}" est en attente de validation.
email.taskStandby.subject=Extract\u00a0\u2013 Le traitement "{0}" est en attente de validation

email.taskStandbyNotification.action=Veuillez consulter le tableau de bord d'Extract pour plus de d\u00e9tails\u00a0:
email.taskStandbyNotification.description=Un \u00e9l\u00e9ment du traitement "{0}" pour le produit "{1}" de la commande "{2}" est toujours en attente de validation.
email.taskStandbyNotification.subject=Extract\u00a0\u2013 Le traitement "{0}" est toujours en attente de validation

#Request not associated with any process message
email.unmatchedRequest.action=Veuillez consulter le tableau de bord d'Extract pour plus de d\u00e9tails\u00a0:
email.unmatchedRequest.import.nomatch=Apr\u00e8s import, aucune r\u00e8gle d\u00e9finie dans le connecteur "{0}" n\u2019'est applicable \u00e0 l'\u2019\u00e9l\u00e9ment de requ\u00eate "{1}". Par cons\u00e9quent, aucun traitement ad hoc ne peut \u00eatre lanc\u00e9.
Expand Down
16 changes: 16 additions & 0 deletions extract/src/main/resources/templates/pages/parameters/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ <h1 class="page-header" th:text="#{parameters.body.title}">{Configuration de l'a
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="form-group form-group-with-label"
th:classappend="${#fields.hasErrors('standbyReminderDays')} ? 'has-error'">
<label th:text="#{parameters.fields.standbyReminder.label}"
class="form-label col-form-label">
{Port SMTP}
</label>
<span class="mandatory" data-bs-toggle="tooltip"
th:title="#{field.mandatory.tooltip}"></span>
<input type="number" class="form-control" th:field="*{standbyReminderDays}"
th:title="${#fields.hasErrors('standbyReminderDays')} ? ${#fields.errors('standbyReminderDays')[0]}"
value="{standbyReminderDays}" min="0" step="1" data-bs-toggle="tooltip" />
</div>
</div>
</div>
</div>
</div>
<div class="card card-default">
Expand Down

0 comments on commit dbfe513

Please sign in to comment.