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
,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
Fields Modifier and Type Field Description protected CurrentUserProvider
_currentUserProvider
Current user providerprotected I18nUtils
_i18nUtils
The utils for i18nprotected String
_mailSender
Mail senderprotected String
_sysadminMail
Sys admin mailprotected UserHelper
_userHelper
User helper-
Fields inherited from class org.ametys.plugins.core.impl.schedule.AbstractStaticSchedulable
_acceptConcurrentExecution, _context, _description, _iconGlyph, _iconLarge, _iconMedium, _iconSmall, _id, _label, _parameters, _pluginName, _private, _schedulableParameterTypeExtensionPoint, _smanager, _userManager
-
-
Constructor Summary
Constructors Constructor Description AbstractSendingMailSchedulable()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
_doExecute(JobExecutionContext context)
Executes the schedulable.protected abstract I18nizableText
_getErrorMailBody(JobExecutionContext context, Throwable throwable)
Retrieves the body of the error mailprotected abstract I18nizableText
_getErrorMailSubject(JobExecutionContext context)
Retrieves the subject of the error mailprotected Optional<String>
_getRecipient(JobExecutionContext context)
Retrieves the optional recipient of the mailprotected abstract I18nizableText
_getSuccessMailBody(JobExecutionContext context)
Retrieves the body of the success mailprotected abstract I18nizableText
_getSuccessMailSubject(JobExecutionContext context)
Retrieves the subject of the success mailprotected boolean
_isMailBodyInHTML(JobExecutionContext context)
Determines if the mail body is in HTMLprotected void
_sendMail(I18nizableText subject, I18nizableText body, String recipient, JobExecutionContext context)
Send an emailvoid
execute(JobExecutionContext context)
The action to perform when a trigger is fired.void
initialize()
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, isPrivate, setPluginInfo
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
_i18nUtils
protected I18nUtils _i18nUtils
The utils for i18n
-
_mailSender
protected String _mailSender
Mail sender
-
_sysadminMail
protected String _sysadminMail
Sys admin mail
-
_currentUserProvider
protected CurrentUserProvider _currentUserProvider
Current user provider
-
_userHelper
protected UserHelper _userHelper
User helper
-
-
Constructor Detail
-
AbstractSendingMailSchedulable
public AbstractSendingMailSchedulable()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractStaticSchedulable
- Throws:
ServiceException
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
execute
public void execute(JobExecutionContext context) 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
- Specified by:
execute
in classAbstractStaticSchedulable
- Parameters:
context
- the context- Throws:
Exception
- if an error occured
-
_doExecute
protected abstract void _doExecute(JobExecutionContext context) throws Exception
Executes the schedulable.- Parameters:
context
- the context- Throws:
Exception
- if an error occurred
-
_getRecipient
protected Optional<String> _getRecipient(JobExecutionContext context)
Retrieves the optional recipient of the mail- Parameters:
context
- the context- Returns:
- the optional recipient of the mail
-
_isMailBodyInHTML
protected boolean _isMailBodyInHTML(JobExecutionContext context) throws Exception
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
protected abstract I18nizableText _getSuccessMailBody(JobExecutionContext context) throws Exception
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 I18nizableText _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, I18nizableText body, String recipient, JobExecutionContext context)
Send an email- Parameters:
subject
- the email's subjectbody
- the email's bodyrecipient
- the recipient addresscontext
- the context
-
-