Search in sources :

Example 1 with InNode

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

the class ExpressionNodeToHQLConverterTest method parseWithInNode.

@Test
public void parseWithInNode() {
    AbstractNode testAST = new InNode(new PropertyValueNode(EventProperty.PAGE), Arrays.asList(new StringValueNode(TEST_VALUE_1), new StringValueNode(TEST_VALUE_2)));
    ExpressionNodeToHQLConverter.HQLQuery result = parser.parse(testAST);
    assertEquals(String.format("event.page IN (:%s, :%s)", TEST_VALUE_1_IDENTIFIER, TEST_VALUE_2_IDENTIFIER), result.getQuery());
    assertEquals(TEST_VALUE_1, result.getQueryParameters().get(TEST_VALUE_1_IDENTIFIER));
    assertEquals(TEST_VALUE_2, result.getQueryParameters().get(TEST_VALUE_2_IDENTIFIER));
}
Also used : InNode(org.xwiki.notifications.filters.expression.InNode) AbstractNode(org.xwiki.notifications.filters.expression.generics.AbstractNode) StringValueNode(org.xwiki.notifications.filters.expression.StringValueNode) PropertyValueNode(org.xwiki.notifications.filters.expression.PropertyValueNode) Test(org.junit.Test)

Example 2 with InNode

use of org.xwiki.notifications.filters.expression.InNode 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

InNode (org.xwiki.notifications.filters.expression.InNode)2 Test (org.junit.Test)1 PropertyValueNode (org.xwiki.notifications.filters.expression.PropertyValueNode)1 StringValueNode (org.xwiki.notifications.filters.expression.StringValueNode)1 AbstractNode (org.xwiki.notifications.filters.expression.generics.AbstractNode)1 AbstractValueNode (org.xwiki.notifications.filters.expression.generics.AbstractValueNode)1 InListOfReadEventsNode (org.xwiki.notifications.filters.internal.status.InListOfReadEventsNode)1