Package org.ametys.cms.schedule
Class AbstractSendingMailSchedulable
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.core.impl.schedule.AbstractStaticSchedulable
org.ametys.cms.schedule.AbstractSendingMailSchedulable
- All Implemented Interfaces:
Schedulable
,LogEnabled
,PluginAware
,Initializable
,Component
,Configurable
,Contextualizable
,Serviceable
- Direct Known Subclasses:
AbstractRebuildLiveWorkspaceSchedulable
,CatalogPDFExportSchedulable
,CopyCatalogSchedulable
,DeleteCatalogSchedulable
,DuplicateContentsDetectionSchedulable
,EducationalBookletSchedulable
,ExecuteExtractionSchedulable
,GlobalWorkspaceIndexerSchedulable
,MCCValidatedPDFSchedulable
,OdfRefTableDataSynchronizationSchedulable
,SendInvitationsSchedulable
,SiteIndexerSchedulable
public abstract class AbstractSendingMailSchedulable
extends AbstractStaticSchedulable
implements Initializable
Abstract schedulable that send an email at the end of the execution
By default, the email is sent to the user that launched the schedulable. This behavior can be overridden thanks to the
_getRecipient(JobExecutionContext)
method
If this user has no email address and there is an error during the execution, an email is sent to the system administrator-
Nested Class Summary
Nested classes/interfaces inherited from class org.ametys.plugins.core.impl.schedule.AbstractStaticSchedulable
AbstractStaticSchedulable.SchedulableParameterParser
-
Field Summary
Modifier and TypeFieldDescriptionprotected CurrentUserProvider
Current user providerprotected I18nUtils
The utils for i18nprotected String
Mail senderprotected String
Sys admin mailprotected UserHelper
User helperFields inherited from class org.ametys.plugins.core.impl.schedule.AbstractStaticSchedulable
_acceptConcurrentExecution, _context, _description, _iconGlyph, _iconLarge, _iconMedium, _iconSmall, _id, _label, _parameters, _pluginName, _private, _schedulableParameterTypeExtensionPoint, _smanager, _startTime, _userManager, PROGRESSION_TRACKER
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
_doExecute
(JobExecutionContext context, ContainerProgressionTracker progressionTracker) Executes the schedulable.protected abstract String
_getErrorMailBody
(JobExecutionContext context, Throwable throwable) Retrieves the body of the error mailprotected abstract I18nizableText
_getErrorMailSubject
(JobExecutionContext context) Retrieves the subject of the error mail_getRecipient
(JobExecutionContext context) Retrieves the optional recipient of the mailprotected abstract String
_getSuccessMailBody
(JobExecutionContext context) Retrieves the body of the success mailprotected abstract I18nizableText
Retrieves the subject of the success mailprotected boolean
_isMailBodyInHTML
(JobExecutionContext context) Determines if the mail body is in HTMLprotected void
_sendMail
(I18nizableText subject, String body, String recipient, JobExecutionContext context) Send an emailvoid
execute
(JobExecutionContext context, ContainerProgressionTracker progressionTracker) The action to perform when a trigger is fired.void
void
service
(ServiceManager manager) Methods inherited from class org.ametys.plugins.core.impl.schedule.AbstractStaticSchedulable
acceptConcurrentExecution, configure, contextualize, getDescription, getIconGlyph, getIconLarge, getIconMedium, getIconSmall, getId, getLabel, getParameters, getProgressionTracker, isPrivate, setPluginInfo
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
_i18nUtils
The utils for i18n -
_mailSender
Mail sender -
_sysadminMail
Sys admin mail -
_currentUserProvider
Current user provider -
_userHelper
User helper
-
-
Constructor Details
-
AbstractSendingMailSchedulable
public AbstractSendingMailSchedulable()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractStaticSchedulable
- Throws:
ServiceException
-
initialize
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
execute
public void execute(JobExecutionContext context, ContainerProgressionTracker progressionTracker) throws Exception Description copied from interface:Schedulable
The action to perform when a trigger is fired. Do not manually call this method.- Specified by:
execute
in interfaceSchedulable
- Parameters:
context
- the contextprogressionTracker
- The progression tracker- Throws:
Exception
- if an error occurred
-
_doExecute
protected abstract void _doExecute(JobExecutionContext context, ContainerProgressionTracker progressionTracker) throws Exception Executes the schedulable.- Parameters:
context
- the contextprogressionTracker
- The progression tracker- Throws:
Exception
- if an error occurred
-
_getRecipient
Retrieves the optional recipient of the mail- Parameters:
context
- the context- Returns:
- the optional recipient of the mail
-
_isMailBodyInHTML
Determines if the mail body is in HTML- Parameters:
context
- the context- Returns:
true
if the mail body is in HTML,false
otherwise- Throws:
Exception
- If an error occurs while retrieving if mail body should be HTML
-
_getSuccessMailSubject
protected abstract I18nizableText _getSuccessMailSubject(JobExecutionContext context) throws Exception Retrieves the subject of the success mail- Parameters:
context
- the context- Returns:
- the subject of the success mail
- Throws:
Exception
- If an error occurs while building the mail subject
-
_getSuccessMailBody
Retrieves the body of the success mail- Parameters:
context
- the context- Returns:
- the body of the success mail
- Throws:
Exception
- If an error occurs while building the mail body
-
_getErrorMailSubject
protected abstract I18nizableText _getErrorMailSubject(JobExecutionContext context) throws Exception Retrieves the subject of the error mail- Parameters:
context
- the context- Returns:
- the subject of the error mail
- Throws:
Exception
- If an error occurs while building the mail subject
-
_getErrorMailBody
protected abstract String _getErrorMailBody(JobExecutionContext context, Throwable throwable) throws Exception Retrieves the body of the error mail- Parameters:
context
- the contextthrowable
- the error- Returns:
- the body of the error mail
- Throws:
Exception
- If an error occurs while building the mail body
-
_sendMail
protected void _sendMail(I18nizableText subject, String body, String recipient, JobExecutionContext context) Send an email- Parameters:
subject
- the email's subjectbody
- the email's body (to HTML or text format depending on_isMailBodyInHTML(JobExecutionContext)
recipient
- the recipient addresscontext
- the context
-