Search in sources :

Example 6 with NotificationFilter

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

the class DefaultNotificationFilterDisplayerTest method displayWithCustomTemplate.

@Test
public void displayWithCustomTemplate() throws Exception {
    Template fakeTemplate = mock(Template.class);
    when(templateManager.getTemplate(any(String.class))).thenReturn(fakeTemplate);
    NotificationFilter filter = mock(NotificationFilter.class);
    when(filter.getName()).thenReturn("filterName");
    mocker.getComponentUnderTest().display(filter, mock(NotificationFilterPreference.class));
    verify(templateManager, times(1)).execute(eq(fakeTemplate));
}
Also used : NotificationFilterPreference(org.xwiki.notifications.filters.NotificationFilterPreference) NotificationFilter(org.xwiki.notifications.filters.NotificationFilter) Template(org.xwiki.template.Template) Test(org.junit.Test)

Example 7 with NotificationFilter

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

the class DefaultNotificationFilterManagerTest method getFiltersWithMatchingFilters.

@Test
public void getFiltersWithMatchingFilters() throws Exception {
    NotificationFilter fakeFilter1 = mock(NotificationFilter.class);
    NotificationPreference preference = mock(NotificationPreference.class);
    when(componentManager.getInstanceMap(NotificationFilter.class)).thenReturn(Collections.singletonMap("1", fakeFilter1));
    when(fakeFilter1.matchesPreference(preference)).thenReturn(true);
    Collection<NotificationFilter> filters = mocker.getComponentUnderTest().getFilters(testUser, preference);
    assertEquals(1, filters.size());
    assertTrue(filters.contains(fakeFilter1));
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) NotificationFilter(org.xwiki.notifications.filters.NotificationFilter) Test(org.junit.Test)

Example 8 with NotificationFilter

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

the class DefaultNotificationFilterManagerTest method getFiltersWithOneBadFilter.

@Test
public void getFiltersWithOneBadFilter() throws Exception {
    NotificationFilter fakeFilter1 = mock(NotificationFilter.class);
    NotificationPreference preference = mock(NotificationPreference.class);
    when(componentManager.getInstanceMap(NotificationFilter.class)).thenReturn(Collections.singletonMap("1", fakeFilter1));
    when(fakeFilter1.matchesPreference(preference)).thenReturn(false);
    Collection<NotificationFilter> filters = mocker.getComponentUnderTest().getFilters(testUser, preference);
    assertEquals(0, filters.size());
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) NotificationFilter(org.xwiki.notifications.filters.NotificationFilter) Test(org.junit.Test)

Example 9 with NotificationFilter

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

the class DefaultNotificationFilterManagerTest method testFilterPreferencesWithFilter.

@Test
public void testFilterPreferencesWithFilter() throws Exception {
    NotificationFilterPreference filterPreference1 = mock(NotificationFilterPreference.class);
    when(filterPreference1.getFilterName()).thenReturn("someFilter");
    NotificationFilterPreference filterPreference2 = mock(NotificationFilterPreference.class);
    when(filterPreference2.getFilterName()).thenReturn("fakeFilter");
    when(testProvider.getFilterPreferences(testUser)).thenReturn(Sets.newSet(filterPreference1, filterPreference2));
    NotificationFilter fakeFilter = mock(NotificationFilter.class);
    when(fakeFilter.getName()).thenReturn("fakeFilter");
    Set<NotificationFilterPreference> resultSet = mocker.getComponentUnderTest().getFilterPreferences(testUser, fakeFilter);
    assertTrue(resultSet.contains(filterPreference2));
    assertEquals(1, resultSet.size());
}
Also used : NotificationFilterPreference(org.xwiki.notifications.filters.NotificationFilterPreference) NotificationFilter(org.xwiki.notifications.filters.NotificationFilter) Test(org.junit.Test)

Example 10 with NotificationFilter

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

the class DefaultLiveMimeMessageIterator method retrieveCompositeEventList.

/**
 * For the given user, we will have to check that the composite event that we have to send matches the user
 * preferences.
 *
 * If, for any reason, one of the events of the original composite event is not meant for the user, we clone
 * the original composite event and remove the incriminated event.
 */
@Override
protected List<CompositeEvent> retrieveCompositeEventList(DocumentReference user) throws NotificationException {
    CompositeEvent resultCompositeEvent = new CompositeEvent(this.compositeEvent);
    if (this.hasCorrespondingNotificationPreference(user, resultCompositeEvent)) {
        // Apply the filters that the user has defined in its notification preferences
        // If one of the events present in the composite event does not match a user filter, remove the event
        List<NotificationFilter> filters = new ArrayList<>(notificationFilterManager.getAllFilters(user));
        Collections.sort(filters);
        Iterator<Event> it = resultCompositeEvent.getEvents().iterator();
        while (it.hasNext()) {
            Event event = it.next();
            if (isEventFiltered(filters, event, user)) {
                it.remove();
            }
        }
        if (resultCompositeEvent.getEvents().size() == 0) {
            return Collections.emptyList();
        }
        return Collections.singletonList(resultCompositeEvent);
    }
    return Collections.emptyList();
}
Also used : ArrayList(java.util.ArrayList) CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) CompositeEvent(org.xwiki.notifications.CompositeEvent) 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