Search in sources :

Example 1 with InListOfReadEventsNode

use of org.xwiki.notifications.filters.internal.status.InListOfReadEventsNode in project xwiki-platform by xwiki.

the class ExpressionNodeToHQLConverterTest method parseWithInListOfReadEventsNode.

@Test
public void parseWithInListOfReadEventsNode() {
    DocumentReference user = new DocumentReference("xwiki", "XWiki", "userA");
    when(serializer.serialize(user)).thenReturn("xwiki:XWiki.UserA");
    AbstractNode testAST = new NotNode(new InListOfReadEventsNode(user));
    ExpressionNodeToHQLConverter.HQLQuery result = parser.parse(testAST);
    assertEquals(" NOT (" + "event IN (select status.activityEvent from ActivityEventStatusImpl status " + "where status.activityEvent = event and status.entityId = :userStatusRead " + "and status.read = true))", result.getQuery());
    assertEquals("xwiki:XWiki.UserA", result.getQueryParameters().get("userStatusRead"));
}
Also used : NotNode(org.xwiki.notifications.filters.expression.NotNode) AbstractNode(org.xwiki.notifications.filters.expression.generics.AbstractNode) InListOfReadEventsNode(org.xwiki.notifications.filters.internal.status.InListOfReadEventsNode) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 2 with InListOfReadEventsNode

use of org.xwiki.notifications.filters.internal.status.InListOfReadEventsNode in project xwiki-platform by xwiki.

the class ExpressionNodeToHQLConverter method parseOtherOperation.

private String parseOtherOperation(AbstractOperatorNode operator, HQLQuery result) {
    String returnValue;
    if (operator instanceof InNode) {
        InNode inOperator = (InNode) operator;
        StringBuilder builder = new StringBuilder(parseBlock(inOperator.getLeftOperand(), result));
        builder.append(" IN (");
        String separator = "";
        for (AbstractValueNode value : inOperator.getValues()) {
            builder.append(separator);
            builder.append(parseBlock(value, result));
            separator = ", ";
        }
        builder.append(")");
        returnValue = builder.toString();
    } else if (operator instanceof OrderByNode) {
        OrderByNode orderByNode = (OrderByNode) operator;
        returnValue = String.format("%s ORDER BY %s %s", parseBlock(orderByNode.getQuery(), result), parseBlock(orderByNode.getProperty(), result), orderByNode.getOrder().name());
    } else if (operator instanceof InListOfReadEventsNode) {
        InListOfReadEventsNode inList = (InListOfReadEventsNode) operator;
        returnValue = String.format("event IN (select status.activityEvent from ActivityEventStatusImpl status " + "where status.activityEvent = event and status.entityId = :userStatusRead and status.read = true)");
        result.getQueryParameters().put("userStatusRead", serializer.serialize(inList.getUser()));
    } else {
        returnValue = StringUtils.EMPTY;
    }
    return returnValue;
}
Also used : InNode(org.xwiki.notifications.filters.expression.InNode) AbstractValueNode(org.xwiki.notifications.filters.expression.generics.AbstractValueNode) InListOfReadEventsNode(org.xwiki.notifications.filters.internal.status.InListOfReadEventsNode)

Aggregations

InListOfReadEventsNode (org.xwiki.notifications.filters.internal.status.InListOfReadEventsNode)2 Test (org.junit.Test)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 InNode (org.xwiki.notifications.filters.expression.InNode)1 NotNode (org.xwiki.notifications.filters.expression.NotNode)1 AbstractNode (org.xwiki.notifications.filters.expression.generics.AbstractNode)1 AbstractValueNode (org.xwiki.notifications.filters.expression.generics.AbstractValueNode)1