Skip to content
Snippets Groups Projects
Commit e012b377 authored by Clément Aubin's avatar Clément Aubin
Browse files

XWIKI-14597: Add UI for "Location" and "Global Notification Preferences"

in the Notification Center
* Add javadoc
parent 2dc4edb7
No related branches found
No related tags found
No related merge requests found
Showing with 36 additions and 10 deletions
...@@ -29,6 +29,12 @@ ...@@ -29,6 +29,12 @@
/** /**
* Enable or disable notifications from the event stream (for customization purpose). * Enable or disable notifications from the event stream (for customization purpose).
* A {@link NotificationFilter} has two goals :
* <ul>
* <li>Pre-Filtering : Generate a query (made with {@link AbstractNode}) that will be used to retrieve a specific
* subset of notifications from a provider.</li>
* <li>Post-Filtering : given an {@link Event}, determine if this event should be filtered or not.</li>
* </ul>
* *
* @version $Id$ * @version $Id$
* @since 9.5RC1 * @since 9.5RC1
...@@ -39,7 +45,7 @@ public interface NotificationFilter ...@@ -39,7 +45,7 @@ public interface NotificationFilter
{ {
/** /**
* Enable or disable an event in the notification list (post-filter). * Enable or disable an event in the notification list (post-filter).
* *For a given {@link NotificationPreference}, generate a filter associated with this preference
* @param event an event * @param event an event
* @param user the user interested in the notification * @param user the user interested in the notification
* @param format format of the notification * @param format format of the notification
...@@ -82,6 +88,10 @@ public interface NotificationFilter ...@@ -82,6 +88,10 @@ public interface NotificationFilter
AbstractNode filterExpression(DocumentReference user); AbstractNode filterExpression(DocumentReference user);
/** /**
* Get the name of the filter. This is useful as {@link NotificationFilterPreference} will be able to be linked to
* this filter using its name. If the {@link NotificationFilter} is used as a component, consider defining
* the hint of this component as the name of the filter.
*
* @return the name of the filter * @return the name of the filter
* *
* @since 9.7RC1 * @since 9.7RC1
......
...@@ -194,6 +194,10 @@ public String getName() ...@@ -194,6 +194,10 @@ public String getName()
* Given a {@link NotificationFilterPreference} and the current filtering context (defined by a * Given a {@link NotificationFilterPreference} and the current filtering context (defined by a
* {@link NotificationPreference}), determine if a the current filter should apply with the given scope. * {@link NotificationPreference}), determine if a the current filter should apply with the given scope.
* *
* Note that we allow the {@link NotificationPreference} to be null and the
* {@link NotificationFilterPreference} to have an empty {@link NotificationPreferenceProperty#EVENT_TYPE} property.
* This is done to allow the filter to be applied globally and match all events.
*
* @param filterPreference the reference scope * @param filterPreference the reference scope
* @param preference the related notification preference, can be null * @param preference the related notification preference, can be null
* @return true if the filter should be applied to the given scope. * @return true if the filter should be applied to the given scope.
...@@ -201,15 +205,14 @@ public String getName() ...@@ -201,15 +205,14 @@ public String getName()
private boolean scopeMatchesFilteringContext(NotificationFilterPreference filterPreference, private boolean scopeMatchesFilteringContext(NotificationFilterPreference filterPreference,
NotificationPreference preference) NotificationPreference preference)
{ {
return ((preference == null return ((preference == null && filterPreference.getProperties(NotificationFilterProperty.EVENT_TYPE).isEmpty())
|| preference.getProperties().containsKey(NotificationPreferenceProperty.EVENT_TYPE)) || (preference.getProperties().containsKey(NotificationPreferenceProperty.EVENT_TYPE)
&& (filterPreference.getProperties(NotificationFilterProperty.EVENT_TYPE).isEmpty() && filterPreference.getProperties(NotificationFilterProperty.EVENT_TYPE).contains(
|| filterPreference.getProperties(NotificationFilterProperty.EVENT_TYPE).contains(
preference.getProperties().get(NotificationPreferenceProperty.EVENT_TYPE)))); preference.getProperties().get(NotificationPreferenceProperty.EVENT_TYPE))));
} }
/** /**
* Given {@link ScopeNotificationFilterPreference}, generate the associated node restriction. * Given {@link ScopeNotificationFilterPreference}, generate the associated scope restriction.
* *
* @param filterPreferenceScope the preference to use * @param filterPreferenceScope the preference to use
* @return the generated node * @return the generated node
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
* Define notification filters that are activated by default on every user and that filter the notifications * Define notification filters that are activated by default on every user and that filter the notifications
* coming from the system user. * coming from the system user.
* *
* This filter is not bound to any {@link NotificationPreference} and should be applied globally.
*
* @version $Id$ * @version $Id$
* @since 9.7RC1 * @since 9.7RC1
*/ */
...@@ -80,7 +82,7 @@ protected boolean filterEventByFilterType(Event event, DocumentReference user, N ...@@ -80,7 +82,7 @@ protected boolean filterEventByFilterType(Event event, DocumentReference user, N
protected AbstractNode generateFilterExpression(DocumentReference user, NotificationPreference preference, protected AbstractNode generateFilterExpression(DocumentReference user, NotificationPreference preference,
NotificationFilterType filterType) NotificationFilterType filterType)
{ {
if (filterType.equals(NotificationFilterType.EXCLUSIVE)) { if (preference == null && filterType.equals(NotificationFilterType.EXCLUSIVE)) {
return new NotEqualsNode( return new NotEqualsNode(
new PropertyValueNode(NotificationFilterProperty.USER), new PropertyValueNode(NotificationFilterProperty.USER),
new StringValueNode(serializer.serialize(systemUser))); new StringValueNode(serializer.serialize(systemUser)));
...@@ -92,7 +94,8 @@ protected AbstractNode generateFilterExpression(DocumentReference user, Notifica ...@@ -92,7 +94,8 @@ protected AbstractNode generateFilterExpression(DocumentReference user, Notifica
@Override @Override
public boolean matchesPreference(NotificationPreference preference) public boolean matchesPreference(NotificationPreference preference)
{ {
return true; // As the filter is applied globally, it’s not bound to any preference
return false;
} }
@Override @Override
......
...@@ -99,13 +99,13 @@ public void generateFilterExpression() throws Exception ...@@ -99,13 +99,13 @@ public void generateFilterExpression() throws Exception
new PropertyValueNode(NotificationFilterProperty.USER), new PropertyValueNode(NotificationFilterProperty.USER),
new StringValueNode("serializedSystemUser")), new StringValueNode("serializedSystemUser")),
mocker.getComponentUnderTest().generateFilterExpression( mocker.getComponentUnderTest().generateFilterExpression(
randomUser, fakePreference, NotificationFilterType.EXCLUSIVE)); randomUser, null, NotificationFilterType.EXCLUSIVE));
} }
@Test @Test
public void matchesPreference() throws Exception public void matchesPreference() throws Exception
{ {
assertTrue(mocker.getComponentUnderTest().matchesPreference(mock(NotificationPreference.class))); assertFalse(mocker.getComponentUnderTest().matchesPreference(mock(NotificationPreference.class)));
} }
@Test @Test
......
...@@ -167,6 +167,16 @@ public Query generateQuery(DocumentReference user, NotificationFormat format, bo ...@@ -167,6 +167,16 @@ public Query generateQuery(DocumentReference user, NotificationFormat format, bo
return query; return query;
} }
/**
* Generate a part of the query using each of the {@link NotificationFilter} retrieved from the
* {@link NotificationFilterManager}. Each {@link NotificationFilter} is called without any associated
* {@link NotificationPreference}.
*
* @param user the user used to retrieve the {@link NotificationFilter}
* @param hql the {@link StringBuilder} used for the query
* @return a list of maps of parameters that should be used for the query
* @throws NotificationException
*/
private List<Map<String, String>> handleGlobalFilters(DocumentReference user, StringBuilder hql) private List<Map<String, String>> handleGlobalFilters(DocumentReference user, StringBuilder hql)
throws NotificationException throws NotificationException
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment