Class AutomaticNewslettersEngine
- java.lang.Object
-
- org.ametys.plugins.newsletter.auto.AutomaticNewslettersEngine
-
- All Implemented Interfaces:
Runnable
public class AutomaticNewslettersEngine extends Object implements Runnable
Runnable engine that creates the automatic newsletter contents.
-
-
Field Summary
Fields Modifier and Type Field Description protected AutomaticNewsletterExtensionPoint_autoNewsletterEPThe automatic newsletter extension point.protected CategoryProviderExtensionPoint_categoryEPThe newsletter category provider extension point.protected ContentFilterExtensionPoint_contentFilterEPThe content filter extension point.protected ContentFilterHelper_contentFilterHelperThe content filter helper.protected Context_contextThe avalon context.protected Context_environmentContextThe cocoon environment context.protected Map<String,List<String>>_filterContentIdCacheA map of the content IDs by filter, reset on each run.protected I18nUtils_i18nUtilsThe i18n utils.protected boolean_initializedIs the engine initialized ?protected static org.slf4j.Logger_LOGGERThe logger.protected ServiceManager_managerThe service manager.protected static String_NEWSLETTER_CONTENT_TYPEThe newsletter content type.protected AmetysObjectResolver_resolverThe ametys object resolver.protected Date_runDateThe instant the engine was started.protected SiteManager_siteManagerThe site manager.protected int_wfInitialActionIdThe workflow initial action ID.protected List<Integer>_wfValidateActionIdsA list of action IDs to validate a newsletter from initial step.protected String_workflowNameThe newsletter workflow name.protected WorkflowProvider_workflowProviderThe workflow provider.
-
Constructor Summary
Constructors Constructor Description AutomaticNewslettersEngine()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckInitialization()Check the initialization and throw an exception if not initialized.voidconfigure(Configuration configuration)Configure the engine (to be called by the scheduler or the action).protected voidcreateAndValidateAutomaticNewsletter(String siteName, String sitemapName, Category category, CategoryProvider provider, AutomaticNewsletter autoNewsletter)Create an automatic newsletter content in a category.protected voidcreateAutomaticNewsletters()Launch the creation process for each site and sitemap.protected voidcreateAutomaticNewsletters(String siteName, String sitemapName)Test each category in a site and sitemap and launch the newsletter creation if needed.protected WorkflowAwareContentcreateNewsletterContent(String siteName, String language, Category category, AutomaticNewsletter autoNewsletter, long newsletterNumber, Map<String,AutomaticNewsletterFilterResult> filterResults)Create the newsletter content.protected booleancreateNow(AutomaticNewsletter autoNewsletter)Test if an automatic newsletter content has to be created now.protected voiddispose()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 StringgetNewsletterTitle(String language, Category category, AutomaticNewsletter autoNewsletter, long newsletterNumber)Compute the newsletter title.protected longgetNextNumber(Category category, CategoryProvider provider, String siteName, String language)Compute the newsletter number.protected booleanhasResults(Collection<AutomaticNewsletterFilterResult> results)Test if there is at least one content in a collection of filter results.voidinitialize(ServiceManager manager, Context context)Initialize the engine.voidrun()protected booleantestMonth(Collection<Integer> dayNumbers, ZonedDateTime runDate)Test if we are in the configured month creation period.protected booleantestWeek(Collection<Integer> dayNumbers, ZonedDateTime runDate)Test if we are in the configured week creation period.protected voidvalidateNewsletter(WorkflowAwareContent newsletterContent)Validate the newly created newsletter.
-
-
-
Field Detail
-
_LOGGER
protected static final org.slf4j.Logger _LOGGER
The logger.
-
_NEWSLETTER_CONTENT_TYPE
protected static final String _NEWSLETTER_CONTENT_TYPE
The newsletter content type.- See Also:
- Constant Field Values
-
_manager
protected ServiceManager _manager
The service manager.
-
_initialized
protected boolean _initialized
Is the engine initialized ?
-
_workflowName
protected String _workflowName
The newsletter workflow name.
-
_wfInitialActionId
protected int _wfInitialActionId
The workflow initial action ID.
-
_wfValidateActionIds
protected List<Integer> _wfValidateActionIds
A list of action IDs to validate a newsletter from initial step.
-
_filterContentIdCache
protected Map<String,List<String>> _filterContentIdCache
A map of the content IDs by filter, reset on each run.
-
_environmentContext
protected Context _environmentContext
The cocoon environment context.
-
_resolver
protected AmetysObjectResolver _resolver
The ametys object resolver.
-
_siteManager
protected SiteManager _siteManager
The site manager.
-
_workflowProvider
protected WorkflowProvider _workflowProvider
The workflow provider.
-
_autoNewsletterEP
protected AutomaticNewsletterExtensionPoint _autoNewsletterEP
The automatic newsletter extension point.
-
_categoryEP
protected CategoryProviderExtensionPoint _categoryEP
The newsletter category provider extension point.
-
_contentFilterEP
protected ContentFilterExtensionPoint _contentFilterEP
The content filter extension point.
-
_contentFilterHelper
protected ContentFilterHelper _contentFilterHelper
The content filter helper.
-
_i18nUtils
protected I18nUtils _i18nUtils
The i18n utils.
-
-
Constructor Detail
-
AutomaticNewslettersEngine
public AutomaticNewslettersEngine()
-
-
Method Detail
-
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
public void configure(Configuration configuration) throws ConfigurationException
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
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.
-
createAutomaticNewsletters
protected void createAutomaticNewsletters()
Launch the creation process for each site and sitemap.
-
createAutomaticNewsletters
protected void createAutomaticNewsletters(String siteName, String sitemapName)
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.WorkflowException
Create 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
protected boolean hasResults(Collection<AutomaticNewsletterFilterResult> results)
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
protected boolean createNow(AutomaticNewsletter autoNewsletter)
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
protected boolean testMonth(Collection<Integer> dayNumbers, ZonedDateTime runDate)
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
protected boolean testWeek(Collection<Integer> dayNumbers, ZonedDateTime runDate)
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.
-
-