Class EventsFilterHelper
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.plugins.calendar.events.EventsFilterHelper
-
- All Implemented Interfaces:
Component
,LogEnabled
,Serviceable
public class EventsFilterHelper extends AbstractLogEnabled implements Serviceable, Component
Helper for events filter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
EventsFilterHelper.DateRange
Class representing a date range.
-
Field Summary
Fields Modifier and Type Field Description protected AmetysObjectResolver
_ametysResolver
The Ametys object resolverprotected ContentTypeExtensionPoint
_contentTypeEP
Extension point for content typeprotected ContentFilterExtensionPoint
_filterExtPt
Extension point for content filtersprotected JSONUtils
_jsonUtils
The JSON utilsprotected SiteManager
_siteManager
The site managerprotected TagProviderExtensionPoint
_tagProviderEP
The tag provider extension point.static String
END_DATE_META
The end date metadata.static String
EVENTS_FILTER_ID
The events filter ID.static String
ROLE
The avalon rolestatic String
START_DATE_META
The start date metadata.
-
Constructor Summary
Constructors Constructor Description EventsFilterHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Calendar
_getDate(int year, int month, int day)
Get a date object from a year-month-day set.protected EventsFilterHelper.DateRange
_getDateRange(int monthsBefore, int monthsAfter)
Get a date range from a period (x months before now and x months after).protected EventsFilterHelper.DateRange
_getDateRange(Calendar date, int monthsBefore, int monthsAfter)
Get a date range from a period, around a given date (x months before and x months after the date).protected EventsFilterHelper.DateRange
_getDateRange(Calendar date, String rangeType)
Get a date range from a date and a range type.protected Expression
_getMetadataExpression(Date date)
Get a metadata expression from a single date.protected Expression
_getMetadataExpression(EventsFilterHelper.DateRange dateRange)
Get a metadata expression from a date range.protected void
_setSearchContext(EventsFilter filter, List<Map<String,Object>> searchContextValues, Set<String> orTags)
Get the search parameters from the search values.void
configureFilter(EventsFilter eventsFilter, Expression expression, Collection<String> contentTypes, List<Map<String,Object>> searchContexts, Set<String> orTags, String view, boolean maskOrphan, WebContentFilter.AccessLimitation accessLimitation)
Configure the filter to return the wanted contents.EventsFilter
createEventsFilter(String id)
Create a events filter from the static "events" filterEventsFilter
generateEventFilter(EventsFilterHelper.DateRange dateRange, ZoneItem zoneItem, String view, String type, Set<String> filteredCategories, List<Map<String,Object>> searchContexts)
Generate the filterWebContentFilter.AccessLimitation
getAccessLimitation(ZoneItem zoneItem)
Get the access limitation policy.Set<String>
getAllTags(Collection<? extends Tag> tags)
Get all the descendant tags belonging to a collection of input tags.protected Set<Tag>
getAllTags(Tag tag)
Get all the descendant tags belonging to a single tag.Set<String>
getContentTypes(ZoneItem zoneItem)
Get the content types through the service parameters.EventsFilterHelper.DateRange
getDateRange(String type, int year, int month, int day, int monthsBefore, int monthsAfter, String rangeType)
Get the date range from the calendar type and parameters.EventsFilterHelper.DateRange
getDateRange(Date startDate, Date endDate)
Create a DateRange between 2 datesString
getDefaultRangeType(ZoneItem zoneItem)
Get the default range type parameter value.Expression
getExpression(String type, EventsFilterHelper.DateRange dateRange)
Get the metadata expression from the calendar type and date range.Set<String>
getFilteredCategories(List<Map<String,Object>> searchContexts, String[] requestedCategories, ZoneItem zoneItem, String siteName)
Filter a list of categories depending on the service parameters (categoriesArray) and request tags (requestedCategoriesArray)protected boolean
getIcalDownload(ZoneItem zoneItem)
Is there an iCalendar export link on the service?protected int
getLastDayOfWeek(Calendar cal)
Get last day of the week at a given date.String
getLink(ZoneItem zoneItem)
Get the link.String
getLinkTitle(ZoneItem zoneItem)
Get the link title.boolean
getMaskOrphan(ZoneItem zoneItem)
Mask orphan?protected boolean
getPdfDownload(ZoneItem zoneItem)
Is there a PDF download link on the service?List<Map<String,Object>>
getSearchContext(ZoneItem zoneItem, List<Map<String,Object>> inputSearchContexts)
Set the search contexts in a filter from a service instance attributes.Set<Tag>
getTagCategories(ZoneItem zoneItem, List<Map<String,Object>> searchContexts, String currentSiteName)
Get the all selected tags to be used as categories from the search contextsSet<String>
getTags(ZoneItem zoneItem, List<Map<String,Object>> searchContexts)
Get the all tags from the search contextsString
getTitle(ZoneItem zoneItem)
Get the service title.void
service(ServiceManager manager)
-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
START_DATE_META
public static final String START_DATE_META
The start date metadata.- See Also:
- Constant Field Values
-
END_DATE_META
public static final String END_DATE_META
The end date metadata.- See Also:
- Constant Field Values
-
EVENTS_FILTER_ID
public static final String EVENTS_FILTER_ID
The events filter ID.- See Also:
- Constant Field Values
-
_tagProviderEP
protected TagProviderExtensionPoint _tagProviderEP
The tag provider extension point.
-
_filterExtPt
protected ContentFilterExtensionPoint _filterExtPt
Extension point for content filters
-
_ametysResolver
protected AmetysObjectResolver _ametysResolver
The Ametys object resolver
-
_contentTypeEP
protected ContentTypeExtensionPoint _contentTypeEP
Extension point for content type
-
_siteManager
protected SiteManager _siteManager
The site manager
-
_jsonUtils
protected JSONUtils _jsonUtils
The JSON utils
-
-
Constructor Detail
-
EventsFilterHelper
public EventsFilterHelper()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
createEventsFilter
public EventsFilter createEventsFilter(String id)
Create a events filter from the static "events" filter- Parameters:
id
- the id of filter to create- Returns:
- the created events filter
-
getTitle
public String getTitle(ZoneItem zoneItem)
Get the service title.- Parameters:
zoneItem
- the zone item.- Returns:
- the service title.
-
getLink
public String getLink(ZoneItem zoneItem)
Get the link.- Parameters:
zoneItem
- the zone item.- Returns:
- the link.
-
getLinkTitle
public String getLinkTitle(ZoneItem zoneItem)
Get the link title.- Parameters:
zoneItem
- the zone item.- Returns:
- the link title.
-
getDefaultRangeType
public String getDefaultRangeType(ZoneItem zoneItem)
Get the default range type parameter value.- Parameters:
zoneItem
- the zone item.- Returns:
- the default range type.
-
getMaskOrphan
public boolean getMaskOrphan(ZoneItem zoneItem)
Mask orphan?- Parameters:
zoneItem
- the zone item.- Returns:
- mask orphan.
-
getAccessLimitation
public WebContentFilter.AccessLimitation getAccessLimitation(ZoneItem zoneItem)
Get the access limitation policy.- Parameters:
zoneItem
- the zone item.- Returns:
- the access limitation policy.
-
getPdfDownload
protected boolean getPdfDownload(ZoneItem zoneItem)
Is there a PDF download link on the service?- Parameters:
zoneItem
- the zone item.- Returns:
- true if a PDF download link will be present, false otherwise.
-
getIcalDownload
protected boolean getIcalDownload(ZoneItem zoneItem)
Is there an iCalendar export link on the service?- Parameters:
zoneItem
- the zone item.- Returns:
- true if an iCalendar export link will be present, false otherwise.
-
getContentTypes
public Set<String> getContentTypes(ZoneItem zoneItem)
Get the content types through the service parameters.- Parameters:
zoneItem
- the zone item.- Returns:
- the content types.
-
getTags
public Set<String> getTags(ZoneItem zoneItem, List<Map<String,Object>> searchContexts)
Get the all tags from the search contexts- Parameters:
zoneItem
- the zone item.searchContexts
- the search contexts- Returns:
- the tags.
-
getTagCategories
public Set<Tag> getTagCategories(ZoneItem zoneItem, List<Map<String,Object>> searchContexts, String currentSiteName)
Get the all selected tags to be used as categories from the search contexts- Parameters:
zoneItem
- the zone item.searchContexts
- the search contextscurrentSiteName
- the current site name.- Returns:
- the tags categories.
-
getAllTags
public Set<String> getAllTags(Collection<? extends Tag> tags)
Get all the descendant tags belonging to a collection of input tags.- Parameters:
tags
- the collection of input tag.- Returns:
- an exhaustive set of the tags.
-
getAllTags
protected Set<Tag> getAllTags(Tag tag)
Get all the descendant tags belonging to a single tag.- Parameters:
tag
- the tag.- Returns:
- an exhaustive set of the tags.
-
getDateRange
public EventsFilterHelper.DateRange getDateRange(String type, int year, int month, int day, int monthsBefore, int monthsAfter, String rangeType)
Get the date range from the calendar type and parameters.- Parameters:
type
- the calendar mode: "calendar", "single-day" or "agenda".year
- the year.month
- the month.day
- the day.monthsBefore
- get x months before.monthsAfter
- get x months after.rangeType
- the range type, "month" or "week".- Returns:
- the date range.
-
getDateRange
public EventsFilterHelper.DateRange getDateRange(Date startDate, Date endDate)
Create a DateRange between 2 dates- Parameters:
startDate
- stard dateendDate
- end date- Returns:
- the DateRange between those dates
-
_getDateRange
protected EventsFilterHelper.DateRange _getDateRange(int monthsBefore, int monthsAfter)
Get a date range from a period (x months before now and x months after).- Parameters:
monthsBefore
- the wanted number of months before the current month.monthsAfter
- the wanted number of months after the current month.- Returns:
- the date range.
-
_getDateRange
protected EventsFilterHelper.DateRange _getDateRange(Calendar date, int monthsBefore, int monthsAfter)
Get a date range from a period, around a given date (x months before and x months after the date).- Parameters:
date
- the date.monthsBefore
- the wanted number of months before the current month.monthsAfter
- the wanted number of months after the current month.- Returns:
- the date range.
-
_getDateRange
protected EventsFilterHelper.DateRange _getDateRange(Calendar date, String rangeType)
Get a date range from a date and a range type.- Parameters:
date
- the date around which the range is to be.rangeType
- the range type, "month" or "week".- Returns:
- the date range.
-
_getDate
protected Calendar _getDate(int year, int month, int day)
Get a date object from a year-month-day set.- Parameters:
year
- the year.month
- the month (1 to 12).day
- the day (1 to 31).- Returns:
- the date object.
-
getExpression
public Expression getExpression(String type, EventsFilterHelper.DateRange dateRange)
Get the metadata expression from the calendar type and date range.- Parameters:
type
- the calendar type, may be "calendar", "single-day", "agenda" or "period" (agenda = calendar = period).dateRange
- the date range. Only the start date is used for "single-day" type.- Returns:
- the metadata Expression on contents.
-
_getMetadataExpression
protected Expression _getMetadataExpression(EventsFilterHelper.DateRange dateRange)
Get a metadata expression from a date range.- Parameters:
dateRange
- the date range.- Returns:
- the date range metadata expression.
-
_getMetadataExpression
protected Expression _getMetadataExpression(Date date)
Get a metadata expression from a single date.- Parameters:
date
- the date.- Returns:
- the date metadata expression.
-
getLastDayOfWeek
protected int getLastDayOfWeek(Calendar cal)
Get last day of the week at a given date.- Parameters:
cal
- the date as a Calendar.- Returns:
- the last day of the week.
-
getFilteredCategories
public Set<String> getFilteredCategories(List<Map<String,Object>> searchContexts, String[] requestedCategories, ZoneItem zoneItem, String siteName)
Filter a list of categories depending on the service parameters (categoriesArray) and request tags (requestedCategoriesArray)- Parameters:
searchContexts
- the search contextsrequestedCategories
- list of requested categories (can be "all" to get all the categories from the service, or a list of categories)zoneItem
- zone ItemsiteName
- site name- Returns:
- a set of tags
-
generateEventFilter
public EventsFilter generateEventFilter(EventsFilterHelper.DateRange dateRange, ZoneItem zoneItem, String view, String type, Set<String> filteredCategories, List<Map<String,Object>> searchContexts)
Generate the filter- Parameters:
dateRange
- range of dates to searchzoneItem
- used to get the tagsview
- metadataset usedtype
- calendar, agenda, period (same thing) or "single-day" to get a single dayfilteredCategories
- list of categories filtered by those requested by the usersearchContexts
- the search contexts- Returns:
- an EventFilter to match the parameters
-
configureFilter
public void configureFilter(EventsFilter eventsFilter, Expression expression, Collection<String> contentTypes, List<Map<String,Object>> searchContexts, Set<String> orTags, String view, boolean maskOrphan, WebContentFilter.AccessLimitation accessLimitation)
Configure the filter to return the wanted contents.- Parameters:
eventsFilter
- the events filter.expression
- the metadata Expression, can be null.contentTypes
- a list of content types that will restrict the scope of the request.searchContexts
- the input searchContextorTags
- a list of tags among which only one is required for the content to match.view
- the view.maskOrphan
- true to prevent getting orphan contents.accessLimitation
- The access limitation policy.
-
getSearchContext
public List<Map<String,Object>> getSearchContext(ZoneItem zoneItem, List<Map<String,Object>> inputSearchContexts)
Set the search contexts in a filter from a service instance attributes.- Parameters:
zoneItem
- the service parameters data holder.inputSearchContexts
- the input search contexts- Returns:
- a list of search context
-
_setSearchContext
protected void _setSearchContext(EventsFilter filter, List<Map<String,Object>> searchContextValues, Set<String> orTags)
Get the search parameters from the search values.- Parameters:
filter
- the filter to configure.searchContextValues
- the input searchContextorTags
- a list of tags among which only one is required for the content to match.
-
-