use of org.xwiki.notifications.filters.expression.EqualsNode in project xwiki-platform by xwiki.
the class QueryGenerator method handleEventPreferences.
/**
* For each notification preference of the given user, add a constraint on the events to
* - have one of the notification types that have been subscribed by the user;
* - have a date superior to the start date corresponding to this type;
* - match the custom defined user filters.
*
* @param user the current user
* @param preferences a list of the user preferences
* @return a list of maps that contains query parameters
* @throws NotificationException if an error occurred
*/
private AbstractOperatorNode handleEventPreferences(DocumentReference user, List<NotificationPreference> preferences) throws NotificationException {
AbstractOperatorNode preferencesNode = null;
// Filter the notification preferences that are not bound to a specific EVENT_TYPE
Iterator<NotificationPreference> it = preferences.stream().filter(pref -> pref.getProperties().containsKey(NotificationPreferenceProperty.EVENT_TYPE)).iterator();
while (it.hasNext()) {
NotificationPreference preference = it.next();
AbstractOperatorNode preferenceTypeNode = new AndNode(new EqualsNode(value(EventProperty.TYPE), value((String) preference.getProperties().get(NotificationPreferenceProperty.EVENT_TYPE))), new GreaterThanNode(value(EventProperty.DATE), value(preference.getStartDate())));
// Get the notification filters that can be applied to the current preference
Collection<NotificationFilter> filters = notificationFilterManager.getFilters(user, preference);
for (NotificationFilter filter : filters) {
ExpressionNode node = filter.filterExpression(user, preference);
if (node != null && node instanceof AbstractOperatorNode) {
preferenceTypeNode = preferenceTypeNode.and((AbstractOperatorNode) node);
}
}
if (preferencesNode == null) {
preferencesNode = preferenceTypeNode;
} else {
preferencesNode = preferencesNode.or(preferenceTypeNode);
}
}
return preferencesNode;
}
use of org.xwiki.notifications.filters.expression.EqualsNode in project xwiki-platform by xwiki.
the class ExpressionNodeToHQLConverterTest method parseWithNotNode.
@Test
public void parseWithNotNode() {
AbstractNode testAST = new NotNode(new EqualsNode(new StringValueNode(TEST_VALUE_1), new StringValueNode(TEST_VALUE_2)));
assertEquals(String.format(" NOT (:%s = :%s)", TEST_VALUE_1_IDENTIFIER, TEST_VALUE_2_IDENTIFIER), parser.parse(testAST).getQuery());
}
use of org.xwiki.notifications.filters.expression.EqualsNode in project xwiki-platform by xwiki.
the class ExpressionNodeToHQLConverterTest method parseWithEqualsNode.
@Test
public void parseWithEqualsNode() {
AbstractNode testAST = new EqualsNode(new StringValueNode(TEST_VALUE_1), new StringValueNode(TEST_VALUE_2));
assertEquals(String.format(":%s = :%s", TEST_VALUE_1_IDENTIFIER, TEST_VALUE_2_IDENTIFIER), parser.parse(testAST).getQuery());
}
use of org.xwiki.notifications.filters.expression.EqualsNode in project xwiki-platform by xwiki.
the class ExpressionNodeToHQLConverterTest method parseWithOrderBy.
@Test
public void parseWithOrderBy() {
AbstractNode testAST = new OrderByNode(new EqualsNode(new PropertyValueNode(EventProperty.SPACE), new PropertyValueNode(EventProperty.PAGE)), new PropertyValueNode(EventProperty.DATE), OrderByNode.Order.ASC);
ExpressionNodeToHQLConverter.HQLQuery result = parser.parse(testAST);
assertEquals("event.space = event.page ORDER BY event.date ASC", result.getQuery());
}
use of org.xwiki.notifications.filters.expression.EqualsNode in project xwiki-platform by xwiki.
the class QueryGeneratorTest method generateQueryWithFilters.
@Test
public void generateQueryWithFilters() throws Exception {
// Mocks
NotificationFilter notificationFilter1 = mock(NotificationFilter.class);
NotificationFilter notificationFilter2 = mock(NotificationFilter.class);
when(notificationFilterManager.getFilters(any(DocumentReference.class), any(NotificationPreference.class))).thenReturn(Sets.newSet(notificationFilter1, notificationFilter2));
when(notificationFilter1.filterExpression(any(DocumentReference.class), any(NotificationPreference.class))).thenReturn(new AndNode(new EqualsNode(new PropertyValueNode(EventProperty.PAGE), new StringValueNode("someValue1")), new EqualsNode(new StringValueNode("1"), new StringValueNode("1"))));
when(notificationFilter2.filterExpression(any(DocumentReference.class), any(NotificationPreference.class))).thenReturn(new AndNode(new EqualsNode(new PropertyValueNode(EventProperty.TYPE), new StringValueNode("someValue2")), new EqualsNode(new StringValueNode("2"), new StringValueNode("2"))));
when(notificationFilter1.matchesPreference(any(NotificationPreference.class))).thenReturn(true);
when(notificationFilter2.matchesPreference(any(NotificationPreference.class))).thenReturn(true);
// Test
ExpressionNode node = mocker.getComponentUnderTest().generateQueryExpression(new DocumentReference("xwiki", "XWiki", "UserA"), NotificationFormat.ALERT, null, startDate, Arrays.asList("event1", "event2"));
assertEquals("(((DATE >= \"Thu Jan 01 01:00:00 CET 1970\" " + "AND (((TYPE = \"create\" AND DATE >= \"Fri Jan 02 04:46:40 CET 1970\") " + "AND (PAGE = \"someValue1\" AND \"1\" = \"1\")) " + "AND (TYPE = \"someValue2\" AND \"2\" = \"2\"))) " + "AND NOT (ID IN (\"event1\", \"event2\"))) " + "AND HIDDEN <> true) " + "ORDER BY DATE DESC", node.toString());
}
Aggregations