Class AutomaticNewslettersEngine
java.lang.Object
org.ametys.plugins.newsletter.auto.AutomaticNewslettersEngine
- All Implemented Interfaces:
Runnable
Runnable engine that creates the automatic newsletter contents.
-
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.protected Context
The avalon context.protected Context
The cocoon environment context.A map of the content IDs by filter, reset on each run.protected I18nUtils
The i18n utils.protected boolean
Is the engine initialized ?protected static final Logger
The logger.protected ServiceManager
The service manager.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. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Check the initialization and throw an exception if not initialized.void
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
Launch the creation process for each site and sitemap.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.protected void
dispose()
Dispose of the resources and looked-up components.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
initialize
(ServiceManager manager, Context context) Initialize the engine.void
run()
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.
-
Field Details
-
_LOGGER
The logger. -
_NEWSLETTER_CONTENT_TYPE
The newsletter content type.- See Also:
-
_context
The avalon context. -
_manager
The service manager. -
_initialized
Is the engine initialized ? -
_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. -
_environmentContext
The cocoon environment context. -
_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
-
AutomaticNewslettersEngine
public AutomaticNewslettersEngine()
-
-
Method Details
-
initialize
public void initialize(ServiceManager manager, Context context) throws ContextException, ServiceException Initialize the engine.- Parameters:
manager
- the avalon service manager.context
- the avalon context.- Throws:
ContextException
- if an error occurredServiceException
- if an error occurred
-
configure
Configure the engine (to be called by the scheduler or the action).- Parameters:
configuration
- the component configuration.- Throws:
ConfigurationException
- if an error occurs in the configuration.
-
checkInitialization
Check the initialization and throw an exception if not initialized. -
run
-
dispose
Dispose of the resources and looked-up components. -
createAutomaticNewsletters
Launch the creation process for each site and sitemap. -
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.
-