Search in sources :

Example 16 with NotificationFilter

use of org.xwiki.notifications.filters.NotificationFilter in project xwiki-platform by xwiki.

the class DefaultNotificationFilterManager method getFilters.

@Override
public Set<NotificationFilter> getFilters(DocumentReference user, NotificationPreference preference) throws NotificationException {
    Set<NotificationFilter> filters = getAllFilters(user);
    Iterator<NotificationFilter> it = filters.iterator();
    while (it.hasNext()) {
        NotificationFilter filter = it.next();
        if (!filter.matchesPreference(preference)) {
            it.remove();
        }
    }
    return filters;
}
Also used : NotificationFilter(org.xwiki.notifications.filters.NotificationFilter)

Example 17 with NotificationFilter

use of org.xwiki.notifications.filters.NotificationFilter in project xwiki-platform by xwiki.

the class DefaultNotificationFilterManager method getToggleableFilters.

@Override
public Set<NotificationFilter> getToggleableFilters(DocumentReference user) throws NotificationException {
    Set<NotificationFilter> userFilters = fetchAllFilters(user);
    Iterator<NotificationFilter> it = userFilters.iterator();
    while (it.hasNext()) {
        NotificationFilter filter = it.next();
        if (!(filter instanceof ToggleableNotificationFilter)) {
            it.remove();
        }
    }
    return userFilters;
}
Also used : NotificationFilter(org.xwiki.notifications.filters.NotificationFilter)

Example 18 with NotificationFilter

use of org.xwiki.notifications.filters.NotificationFilter in project xwiki-platform by xwiki.

the class DefaultNotificationFilterManager method removeDisabledFilters.

/**
 * Goes through every given {@link NotificationFilter}. One of the filters implements
 * {@link ToggleableNotificationFilter}, checks if the given user has disabled this filter. If so, remove the
 * filter from the set.
 *
 * @param user the user to use
 * @param filters the filters that should be examined
 * @return a set of filters that are not marked as disabled by the user
 * @throws NotificationException if an error occurs
 *
 * @since 9.7RC1
 */
private Set<NotificationFilter> removeDisabledFilters(DocumentReference user, Set<NotificationFilter> filters) throws NotificationException {
    Iterator<NotificationFilter> it = filters.iterator();
    Map<String, Boolean> filterActivations = modelBridge.getToggeableFilterActivations(user);
    while (it.hasNext()) {
        NotificationFilter filter = it.next();
        if (filter instanceof ToggleableNotificationFilter && filterActivations.containsKey(filter.getName()) && !filterActivations.get(filter.getName())) {
            it.remove();
        }
    }
    return filters;
}
Also used : NotificationFilter(org.xwiki.notifications.filters.NotificationFilter)

Aggregations

NotificationFilter (org.xwiki.notifications.filters.NotificationFilter)18 Test (org.junit.Test)10 NotificationFilterPreference (org.xwiki.notifications.filters.NotificationFilterPreference)5 NotificationPreference (org.xwiki.notifications.preferences.NotificationPreference)5 DocumentReference (org.xwiki.model.reference.DocumentReference)4 ArrayList (java.util.ArrayList)3 NotificationException (org.xwiki.notifications.NotificationException)3 ExpressionNode (org.xwiki.notifications.filters.expression.ExpressionNode)3 HashMap (java.util.HashMap)2 AndNode (org.xwiki.notifications.filters.expression.AndNode)2 EqualsNode (org.xwiki.notifications.filters.expression.EqualsNode)2 PropertyValueNode (org.xwiki.notifications.filters.expression.PropertyValueNode)2 StringValueNode (org.xwiki.notifications.filters.expression.StringValueNode)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 Collection (java.util.Collection)1 Date (java.util.Date)1