use of org.xwiki.notifications.filters.expression.DateValueNode in project xwiki-platform by xwiki.
the class QueryGenerator method generateQueryExpression.
/**
* Generate the query.
*
* @param user user interested in the notifications
* @param format only match notifications enabled for that format
* @param endDate do not return events happened after this date
* @param startDate do not return events happened before this date. Note that since 9.7RC1, this start date is
* completely optional, {@link NotificationPreference#getStartDate()} should be used for more granular control on
* notifications
* @param blackList list of ids of blacklisted events to not return (to not get already known events again)
* @return the query to execute
*
* @throws NotificationException if error happens
* @throws QueryException if error happens
*
* @since 9.8RC1
*/
public ExpressionNode generateQueryExpression(DocumentReference user, NotificationFormat format, Date endDate, Date startDate, List<String> blackList) throws NotificationException, QueryException {
// First: get the active preferences of the given user
List<NotificationPreference> preferences = notificationPreferenceManager.getPreferences(user, true, format);
// Ensure that we have at least one filter preference that is active
if (preferences.isEmpty() && notificationFilterManager.getFilterPreferences(user).stream().noneMatch(NotificationFilterPreference::isActive)) {
return null;
}
AbstractOperatorNode topNode = null;
// Condition 1: (maybe) events have happened after the given start date
if (startDate != null) {
topNode = new GreaterThanNode(new PropertyValueNode(EventProperty.DATE), new DateValueNode(startDate));
}
// Condition 2: handle other preferences
AbstractOperatorNode preferencesNode = handleEventPreferences(user, preferences);
// Condition 3: handle exclusive global notification filters
AbstractOperatorNode globalExclusiveFiltersNode = handleExclusiveGlobalFilters(user, format);
if (globalExclusiveFiltersNode != null) {
if (preferencesNode == null) {
preferencesNode = globalExclusiveFiltersNode;
} else {
preferencesNode = preferencesNode.and(globalExclusiveFiltersNode);
}
}
// Condition 4: handle inclusive global notification filters
AbstractOperatorNode globalInclusiveFiltersNode = handleInclusiveGlobalFilters(user, format);
if (globalInclusiveFiltersNode != null) {
if (preferencesNode == null) {
preferencesNode = globalInclusiveFiltersNode;
} else {
preferencesNode = preferencesNode.or(globalInclusiveFiltersNode);
}
}
// Mix all these conditions
if (preferencesNode != null) {
if (topNode != null) {
topNode = topNode.and(preferencesNode);
} else {
topNode = preferencesNode;
}
}
// Other basic filters
topNode = handleBlackList(blackList, topNode);
topNode = handleEndDate(endDate, topNode);
topNode = handleHiddenEvents(topNode);
topNode = handleWiki(user, topNode);
topNode = handleOrder(topNode);
return topNode;
}
use of org.xwiki.notifications.filters.expression.DateValueNode in project xwiki-platform by xwiki.
the class ExpressionNodeToHQLConverterTest method parseDateNode.
@Test
public void parseDateNode() {
Date date = new Date(0);
AbstractNode testAST = new DateValueNode(date);
ExpressionNodeToHQLConverter.HQLQuery result = parser.parse(testAST);
assertEquals(":date_688218ea2b05763819a1e155109e4bf1e8921dd72e8b43d4c89c89133d4a5357", result.getQuery());
assertEquals(date, result.getQueryParameters().get("date_688218ea2b05763819a1e155109e4bf1e8921dd72e8b43d4c89c89133d4a5357"));
}
Aggregations