Class AutomaticNewslettersSchedulable
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.core.impl.schedule.AbstractStaticSchedulable
org.ametys.plugins.newsletter.auto.AutomaticNewslettersSchedulable
- All Implemented Interfaces:
Schedulable
,LogEnabled
,PluginAware
,Component
,Configurable
,Contextualizable
,Serviceable
Runnable engine that creates the automatic newsletter contents.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.ametys.plugins.core.impl.schedule.AbstractStaticSchedulable
AbstractStaticSchedulable.SchedulableParameterParser
-
Field Summary
Modifier and TypeFieldDescriptionprotected AutomaticNewsletterExtensionPoint
The automatic newsletter extension point.protected CategoryProviderExtensionPoint
The newsletter category provider extension point.protected ContentFilterExtensionPoint
The content filter extension point.protected ContentFilterHelper
The content filter helper.A map of the content IDs by filter, reset on each run.protected I18nUtils
The i18n utils.protected static final String
The newsletter content type.protected AmetysObjectResolver
The ametys object resolver.protected Date
The instant the engine was started.protected SiteManager
The site manager.protected int
The workflow initial action ID.A list of action IDs to validate a newsletter from initial step.protected String
The newsletter workflow name.protected WorkflowProvider
The workflow provider.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, _startTime, _userManager, PROGRESSION_TRACKER
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
configure
(Configuration configuration) Configure the engine (to be called by the scheduler or the action).protected void
createAndValidateAutomaticNewsletter
(String siteName, String sitemapName, Category category, CategoryProvider provider, AutomaticNewsletter autoNewsletter) Create an automatic newsletter content in a category.protected void
createAutomaticNewsletters
(String siteName, String sitemapName) Test each category in a site and sitemap and launch the newsletter creation if needed.protected WorkflowAwareContent
createNewsletterContent
(String siteName, String language, Category category, AutomaticNewsletter autoNewsletter, long newsletterNumber, Map<String, AutomaticNewsletterFilterResult> filterResults) Create the newsletter content.protected boolean
createNow
(AutomaticNewsletter autoNewsletter) Test if an automatic newsletter content has to be created now.void
execute
(JobExecutionContext context, ContainerProgressionTracker progressionTracker) The action to perform when a trigger is fired.protected Map<String,
AutomaticNewsletterFilterResult> getFilterResults
(String siteName, String sitemapName, AutomaticNewsletter autoNewsletter) Get the list of contents for the automatic newsletter filters.protected String
getNewsletterTitle
(String language, Category category, AutomaticNewsletter autoNewsletter, long newsletterNumber) Compute the newsletter title.protected long
getNextNumber
(Category category, CategoryProvider provider, String siteName, String language) Compute the newsletter number.protected boolean
Test if there is at least one content in a collection of filter results.void
service
(ServiceManager manager) protected boolean
testMonth
(Collection<Integer> dayNumbers, ZonedDateTime runDate) Test if we are in the configured month creation period.protected boolean
testWeek
(Collection<Integer> dayNumbers, ZonedDateTime runDate) Test if we are in the configured week creation period.protected void
validateNewsletter
(WorkflowAwareContent newsletterContent) Validate the newly created newsletter.Methods inherited from class org.ametys.plugins.core.impl.schedule.AbstractStaticSchedulable
acceptConcurrentExecution, 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
-
_NEWSLETTER_CONTENT_TYPE
The newsletter content type.- See Also:
-
_runDate
The instant the engine was started. -
_workflowName
The newsletter workflow name. -
_wfInitialActionId
The workflow initial action ID. -
_wfValidateActionIds
A list of action IDs to validate a newsletter from initial step. -
_filterContentIdCache
A map of the content IDs by filter, reset on each run. -
_resolver
The ametys object resolver. -
_siteManager
The site manager. -
_workflowProvider
The workflow provider. -
_autoNewsletterEP
The automatic newsletter extension point. -
_categoryEP
The newsletter category provider extension point. -
_contentFilterEP
The content filter extension point. -
_contentFilterHelper
The content filter helper. -
_i18nUtils
The i18n utils.
-
-
Constructor Details
-
AutomaticNewslettersSchedulable
public AutomaticNewslettersSchedulable()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractStaticSchedulable
- Throws:
ServiceException
-
configure
Configure the engine (to be called by the scheduler or the action).- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classAbstractStaticSchedulable
- Parameters:
configuration
- the component configuration.- Throws:
ConfigurationException
- if an error occurs in the configuration.
-
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.- Parameters:
context
- the contextprogressionTracker
- The progression tracker- Throws:
Exception
- if an error occurred
-
createAutomaticNewsletters
Test each category in a site and sitemap and launch the newsletter creation if needed.- Parameters:
siteName
- the site name.sitemapName
- the sitemap name.
-
createAndValidateAutomaticNewsletter
protected void createAndValidateAutomaticNewsletter(String siteName, String sitemapName, Category category, CategoryProvider provider, AutomaticNewsletter autoNewsletter) Create an automatic newsletter content in a category.- Parameters:
sitemapName
- the sitemap name.siteName
- the site name.category
- the newsletter category.provider
- the category provider.autoNewsletter
- the associated automatic newsletter.
-
getFilterResults
protected Map<String,AutomaticNewsletterFilterResult> getFilterResults(String siteName, String sitemapName, AutomaticNewsletter autoNewsletter) Get the list of contents for the automatic newsletter filters.- Parameters:
siteName
- the site name.sitemapName
- the sitemap name.autoNewsletter
- the automatic newsletter.- Returns:
- the results, indexed by filter name (in the auto newsletter).
-
createNewsletterContent
protected WorkflowAwareContent createNewsletterContent(String siteName, String language, Category category, AutomaticNewsletter autoNewsletter, long newsletterNumber, Map<String, AutomaticNewsletterFilterResult> filterResults) throws com.opensymphony.workflow.WorkflowExceptionCreate the newsletter content.- Parameters:
siteName
- the site name.language
- the language.category
- the category.autoNewsletter
- the automatic newsletter.newsletterNumber
- the newsletter number.filterResults
- the filter results (content IDs for each filter).- Returns:
- The newly created newsletter content.
- Throws:
com.opensymphony.workflow.WorkflowException
- if a workflow error occurs.
-
validateNewsletter
protected void validateNewsletter(WorkflowAwareContent newsletterContent) throws com.opensymphony.workflow.WorkflowException Validate the newly created newsletter.- Parameters:
newsletterContent
- the newsletter content, must be in draft state.- Throws:
com.opensymphony.workflow.WorkflowException
- if a workflow error occurs.
-
getNewsletterTitle
protected String getNewsletterTitle(String language, Category category, AutomaticNewsletter autoNewsletter, long newsletterNumber) Compute the newsletter title.- Parameters:
language
- the language.category
- the newsletter category.autoNewsletter
- the automatic newsletter.newsletterNumber
- the newsletter number.- Returns:
- the newsletter title.
-
getNextNumber
protected long getNextNumber(Category category, CategoryProvider provider, String siteName, String language) Compute the newsletter number.- Parameters:
category
- the newsletter category.provider
- the category provider.siteName
- the site name.language
- the language.- Returns:
- the newsletter number.
-
hasResults
Test if there is at least one content in a collection of filter results.- Parameters:
results
- a collection of filter results.- Returns:
- true if at least one filter yielded a result, false otherwise.
-
createNow
Test if an automatic newsletter content has to be created now.- Parameters:
autoNewsletter
- the automatic newsletter.- Returns:
- true if an automatic newsletter content has to be created now, false otherwise.
-
testMonth
Test if we are in the configured month creation period.- Parameters:
dayNumbers
- the days in the month on which a newsletter is to be created.runDate
- the instant the engine was launched.- Returns:
- true if we are in the configured month creation period, false otherwise.
-
testWeek
Test if we are in the configured week creation period.- Parameters:
dayNumbers
- the days in the month on which a newsletter is to be created.runDate
- the instant the engine was launched.- Returns:
- true if we are in the configured week creation period, false otherwise.
-