Class EventsFilterHelper
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.ametys.plugins.calendar.events.EventsFilterHelper
- All Implemented Interfaces:
Component
,LogEnabled
,Serviceable
Helper for events filter
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
Date range between two dates -
Field Summary
Modifier and TypeFieldDescriptionprotected AmetysObjectResolver
The Ametys object resolverprotected ContentTypeExtensionPoint
Extension point for content typeprotected ContentFilterExtensionPoint
Extension point for content filtersprotected JSONUtils
The JSON utilsprotected SiteManager
The site managerprotected TagProviderExtensionPoint
The tag provider extension point.static final String
The end date metadata.static final String
The events filter ID.static final String
The avalon rolestatic final String
The start date metadata. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected LocalDate
_getDate
(int year, int month, int day) Get a date object from a year-month-day set.protected EventsFilterHelper.DateTimeRange
_getDateRange
(int monthsBefore, int monthsAfter) Get a date range from a period (x months before now and x months after).protected EventsFilterHelper.DateTimeRange
_getDateRange
(LocalDate localDate, 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 Expression
_getMetadataExpression
(Date date) Get a metadata expression from a single date.protected Expression
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.Create a events filter from the static "events" filtergenerateEventFilter
(EventsFilterHelper.DateTimeRange dateRange, ZoneItem zoneItem, String view, String type, Set<String> filteredCategories, List<Map<String, Object>> searchContexts) Generate the filtergetAccessLimitation
(ZoneItem zoneItem) Get the access limitation policy.getAllTags
(Collection<? extends Tag> tags) Get all the descendant tags belonging to a collection of input tags.getAllTags
(Tag tag) Get all the descendant tags belonging to a single tag.getContentTypes
(ZoneItem zoneItem) Get the content types through the service parameters.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.getDefaultRangeType
(ZoneItem zoneItem) Get the default range type parameter value.getExpression
(String type, EventsFilterHelper.DateTimeRange dateRange) Get the metadata expression from the calendar type and date range.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.Get the link.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?Set the search contexts in a filter from a service instance attributes.getTagCategories
(ZoneItem zoneItem, List<Map<String, Object>> searchContexts, String currentSiteName) Get the all selected tags to be used as categories from the search contextsGet the all tags from the search contextsGet the service title.void
service
(ServiceManager manager) Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Field Details
-
ROLE
The avalon role -
START_DATE_META
The start date metadata.- See Also:
-
END_DATE_META
The end date metadata.- See Also:
-
EVENTS_FILTER_ID
The events filter ID.- See Also:
-
_tagProviderEP
The tag provider extension point. -
_filterExtPt
Extension point for content filters -
_ametysResolver
The Ametys object resolver -
_contentTypeEP
Extension point for content type -
_siteManager
The site manager -
_jsonUtils
The JSON utils
-
-
Constructor Details
-
EventsFilterHelper
public EventsFilterHelper()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
createEventsFilter
Create a events filter from the static "events" filter- Parameters:
id
- the id of filter to create- Returns:
- the created events filter
-
getTitle
Get the service title.- Parameters:
zoneItem
- the zone item.- Returns:
- the service title.
-
getLink
Get the link.- Parameters:
zoneItem
- the zone item.- Returns:
- the link.
-
getLinkTitle
Get the link title.- Parameters:
zoneItem
- the zone item.- Returns:
- the link title.
-
getDefaultRangeType
Get the default range type parameter value.- Parameters:
zoneItem
- the zone item.- Returns:
- the default range type.
-
getMaskOrphan
Mask orphan?- Parameters:
zoneItem
- the zone item.- Returns:
- mask orphan.
-
getAccessLimitation
Get the access limitation policy.- Parameters:
zoneItem
- the zone item.- Returns:
- the access limitation policy.
-
getPdfDownload
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
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
Get the content types through the service parameters.- Parameters:
zoneItem
- the zone item.- Returns:
- the content types.
-
getTags
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
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
Get all the descendant tags belonging to a single tag.- Parameters:
tag
- the tag.- Returns:
- an exhaustive set of the tags.
-
getDateRange
public EventsFilterHelper.DateTimeRange 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
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.DateTimeRange _getDateRange(LocalDate localDate, 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:
localDate
- 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.
-
_getDate
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
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
Get a metadata expression from a date range.- Parameters:
dateRange
- the date range.- Returns:
- the date range metadata expression.
-
_getMetadataExpression
Get a metadata expression from a single date.- Parameters:
date
- the date.- Returns:
- the date metadata expression.
-
getLastDayOfWeek
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.DateTimeRange 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.
-