Package org.ametys.cms.workflow.purge
Class PurgeContentsEngine
- java.lang.Object
-
- org.ametys.cms.workflow.purge.PurgeContentsEngine
-
- All Implemented Interfaces:
Runnable
public class PurgeContentsEngine extends Object implements Runnable
Runnable engine that removes old versions of contents.
-
-
Field Summary
Fields Modifier and Type Field Description protected AmetysObjectResolver
_ametysResolver
The ametys object resolver.protected String
_baseUrl
The server base URL.protected Context
_context
The avalon context.protected Context
_environmentContext
The cocoon environment context.protected int
_firstVersionsToKeep
The count of oldest versions to keep.protected I18nUtils
_i18nUtils
The i18n utils.protected boolean
_initialized
Is the engine initialized ?protected static org.slf4j.Logger
_LOGGER
The logger.protected String
_mailFrom
The content of "from" field in emails.protected ServiceManager
_manager
The service manager.protected SourceResolver
_sourceResolver
The avalon source resolver.protected String
_sysadminMail
The sysadmin mail address, to which will be sent the report e-mail.protected Map<String,Long>
_validationStepId
A Map of the validation step ID by workflow name.protected PurgeVersionsManager
_versionPurger
The version purger.protected WorkflowProvider
_workflowProvider
The workflow provider
-
Constructor Summary
Constructors Constructor Description PurgeContentsEngine()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkInitialization()
Check the initialization and throw an exception if not initialized.void
configure(Configuration configuration)
Configure the engine (called by the scheduler).protected Map<String,Long>
configureValidationStepId(Configuration configuration)
Get the validation step ID by workflow from the component configuration.protected void
dispose()
Dispose of the resources and looked-up components.protected Map<String,String>
getEmailParams(Date startDate, Date endDate, int totalContentsPurged, int totalVersionsPurged)
Get the report e-mail parameters.protected Map<String,String>
getErrorEmailParams(Date startDate, Throwable throwable)
Get the error e-mail parameters.protected String
getErrorMailUri(Map<String,String> parameters)
Get the pipeline uri for error mail body.protected String
getMailBody(Map<String,String> parameters)
Get a mail part.protected String
getMailUri(Map<String,String> parameters)
Get the pipeline uri for mail bodyvoid
initialize(ServiceManager manager, Context context)
Initialize the purge engine.protected void
purgeContents()
Get all the contents and purge the old versions.void
run()
protected void
sendErrorMail(Date startDate, Throwable throwable)
Send the error e-mail.protected void
sendMail(Date startDate, Date endDate, int totalContentsPurged, int totalVersionsPurged)
Send the purge report e-mail.
-
-
-
Field Detail
-
_LOGGER
protected static final org.slf4j.Logger _LOGGER
The logger.
-
_manager
protected ServiceManager _manager
The service manager.
-
_initialized
protected boolean _initialized
Is the engine initialized ?
-
_environmentContext
protected Context _environmentContext
The cocoon environment context.
-
_ametysResolver
protected AmetysObjectResolver _ametysResolver
The ametys object resolver.
-
_sourceResolver
protected SourceResolver _sourceResolver
The avalon source resolver.
-
_versionPurger
protected PurgeVersionsManager _versionPurger
The version purger.
-
_workflowProvider
protected WorkflowProvider _workflowProvider
The workflow provider
-
_i18nUtils
protected I18nUtils _i18nUtils
The i18n utils.
-
_validationStepId
protected Map<String,Long> _validationStepId
A Map of the validation step ID by workflow name.
-
_firstVersionsToKeep
protected int _firstVersionsToKeep
The count of oldest versions to keep.
-
_sysadminMail
protected String _sysadminMail
The sysadmin mail address, to which will be sent the report e-mail.
-
-
Constructor Detail
-
PurgeContentsEngine
public PurgeContentsEngine()
-
-
Method Detail
-
initialize
public void initialize(ServiceManager manager, Context context) throws ContextException, ServiceException
Initialize the purge engine.- Parameters:
manager
- the avalon service manager.context
- the avalon context.- Throws:
ContextException
- If an error occurredServiceException
- If an error occurred
-
configure
public void configure(Configuration configuration) throws ConfigurationException
Configure the engine (called by the scheduler).- Parameters:
configuration
- the component configuration.- Throws:
ConfigurationException
- If an error occurred
-
configureValidationStepId
protected Map<String,Long> configureValidationStepId(Configuration configuration) throws ConfigurationException
Get the validation step ID by workflow from the component configuration.- Parameters:
configuration
- the component configuration.- Returns:
- a Map of the validation step ID by workflow.
- Throws:
ConfigurationException
- If an error occurred
-
checkInitialization
protected void checkInitialization()
Check the initialization and throw an exception if not initialized.
-
dispose
protected void dispose()
Dispose of the resources and looked-up components.
-
purgeContents
protected void purgeContents() throws AmetysRepositoryException
Get all the contents and purge the old versions.- Throws:
AmetysRepositoryException
- if an error occurs.
-
sendMail
protected void sendMail(Date startDate, Date endDate, int totalContentsPurged, int totalVersionsPurged)
Send the purge report e-mail.- Parameters:
startDate
- the purge start date.endDate
- the purge end date.totalContentsPurged
- the total count of contents of which versions were purged.totalVersionsPurged
- the total count of content versions removed.
-
sendErrorMail
protected void sendErrorMail(Date startDate, Throwable throwable)
Send the error e-mail.- Parameters:
startDate
- the purge start date.throwable
- the error.
-
getEmailParams
protected Map<String,String> getEmailParams(Date startDate, Date endDate, int totalContentsPurged, int totalVersionsPurged)
Get the report e-mail parameters.- Parameters:
startDate
- the purge start date.endDate
- the purge end date.totalContentsPurged
- the total count of contents of which versions were purged.totalVersionsPurged
- the total count of content versions removed.- Returns:
- the e-mail parameters.
-
getErrorEmailParams
protected Map<String,String> getErrorEmailParams(Date startDate, Throwable throwable)
Get the error e-mail parameters.- Parameters:
startDate
- the purge start date.throwable
- the error.- Returns:
- the e-mail parameters.
-
getMailBody
protected String getMailBody(Map<String,String> parameters) throws IOException
Get a mail part.- Parameters:
parameters
- the pipeline parameters.- Returns:
- the mail part.
- Throws:
IOException
- If an error occurred
-
getMailUri
protected String getMailUri(Map<String,String> parameters)
Get the pipeline uri for mail body- Parameters:
parameters
- the mail parameters- Returns:
- a pipeline uri
-
getErrorMailUri
protected String getErrorMailUri(Map<String,String> parameters)
Get the pipeline uri for error mail body.- Parameters:
parameters
- the mail parameters- Returns:
- a pipeline uri
-
-