Search in sources :

Example 1 with LiteralExpression

use of com.pogeyan.cmis.api.uri.expression.LiteralExpression in project copper-cms by PogeyanOSS.

the class MongoExpressionVisitor method visitBinary.

@Override
public Object visitBinary(BinaryExpression binaryExpression, BinaryOperator operator, Object leftSide, Object rightSide) {
    if (leftSide instanceof BinaryExpression) {
        // needs brackets to show the higher priority
        if (BinaryOperator.AND.equals(((BinaryExpression) binaryExpression).getOperator()) || BinaryOperator.OR.equals(((BinaryExpression) binaryExpression).getOperator())) {
        }
    } else if (leftSide instanceof PropertyExpression) {
        PropertyExpression leftOp = (PropertyExpression) leftSide;
        String rightSideValue = null;
        if (rightSide instanceof PropertyExpression) {
            PropertyExpression rightOp = (PropertyExpression) rightSide;
            rightSideValue = rightOp.getUriLiteral();
        } else if (rightSide instanceof LiteralExpression) {
            LiteralExpression rightOp = (LiteralExpression) rightSide;
            rightSideValue = rightOp.getUriLiteral();
        } else if (rightSide instanceof String) {
            rightSideValue = rightSide.toString();
        }
        switch(operator) {
            case EQ:
                return this.query.criteria(getQueryName(leftOp.getUriLiteral())).equal(getStringObjectValue(rightSideValue));
            case NE:
                return this.query.criteria(getQueryName(leftOp.getUriLiteral())).notEqual(getStringObjectValue(rightSideValue));
            case GE:
                return this.query.criteria(getQueryName(leftOp.getUriLiteral())).greaterThanOrEq(getNumberObjectValue(rightSideValue));
            case GT:
                return this.query.criteria(getQueryName(leftOp.getUriLiteral())).greaterThan(getNumberObjectValue(rightSideValue));
            case LE:
                return this.query.criteria(getQueryName(leftOp.getUriLiteral())).lessThanOrEq(getNumberObjectValue(rightSideValue));
            case LT:
                return this.query.criteria(getQueryName(leftOp.getUriLiteral())).lessThan(getNumberObjectValue(rightSideValue));
            default:
                // Other operators are not supported for SQL Statements
                throw new UnsupportedOperationException("Unsupported operator: " + operator.toUriLiteral());
        }
    } else {
        ArrayList<Criteria> operands = new ArrayList<>();
        if (leftSide.getClass() == CriteriaContainerImpl.class) {
            operands.add((Criteria) leftSide);
        }
        if (rightSide.getClass() == CriteriaContainerImpl.class) {
            operands.add((Criteria) rightSide);
        }
        switch(operator) {
            case OR:
                this.query.or(operands.toArray(new Criteria[operands.size()]));
                break;
            case AND:
                this.query.and(operands.toArray(new Criteria[operands.size()]));
                break;
            default:
                // Other operators are not supported for SQL Statements
                throw new UnsupportedOperationException("Unsupported operator: " + operator.toUriLiteral());
        }
    }
    // return the binary statement
    return this.query;
}
Also used : BinaryExpression(com.pogeyan.cmis.api.uri.expression.BinaryExpression) LiteralExpression(com.pogeyan.cmis.api.uri.expression.LiteralExpression) ArrayList(java.util.ArrayList) PropertyExpression(com.pogeyan.cmis.api.uri.expression.PropertyExpression) Criteria(org.mongodb.morphia.query.Criteria) CriteriaContainerImpl(org.mongodb.morphia.query.CriteriaContainerImpl)

Example 2 with LiteralExpression

use of com.pogeyan.cmis.api.uri.expression.LiteralExpression in project copper-cms by PogeyanOSS.

the class FilterParserImpl method readElement.

/**
 * Reads: Unary operators, Methods, Properties, ... but not binary operators
 * which are handelt in {@link #readElements(CommonExpression, int)}
 *
 * @param leftExpression
 *            Used while parsing properties. In this case ( e.g. parsing
 *            "a/b") the property "a" ( as leftExpression of "/") is
 *            relevant to verify whether the property "b" exists inside the
 *            edm
 * @return a CommonExpression
 * @throws ExpressionParserException
 * @throws ExpressionParserInternalError
 * @throws TokenizerMessage
 */
protected CommonExpression readElement(final CommonExpression leftExpression, final ActualBinaryOperator leftOperator) throws ExpressionParserException, ExpressionParserInternalError {
    CommonExpression node = null;
    Token token;
    Token lookToken;
    lookToken = tokenList.lookToken();
    if (lookToken == null) {
        return null;
    }
    switch(lookToken.getKind()) {
        case OPENPAREN:
            node = readParenthesis();
            return node;
        // ')' finishes a parenthesis (it is no extra token)" +
        case CLOSEPAREN:
        case // . " ',' is a separator for function parameters (it is no
        COMMA:
            // extra token)" +
            return null;
        default:
    }
    // -->Check if the token is a unary operator
    InfoUnaryOperator unaryOperator = isUnaryOperator(lookToken);
    if (unaryOperator != null) {
        return readUnaryoperator(lookToken, unaryOperator);
    }
    // ---expect the look ahead token
    token = tokenList.expectToken(lookToken.getUriLiteral(), true);
    lookToken = tokenList.lookToken();
    // -->Check if the token is a method
    // To avoid name clashes between method names and property names we
    // accept here only method names if a "(" follows.
    // Hence the parser accepts a property named "concat"
    InfoMethod methodOperator = isMethod(token, lookToken);
    if (methodOperator != null) {
        return readMethod(token, methodOperator);
    }
    // 1.25D"
    if (token.getKind() == TokenKind.SIMPLE_TYPE) {
        LiteralExpression literal = new LiteralExpressionImpl(token.getUriLiteral(), token.getJavaLiteral());
        return literal;
    }
    // -->Check if token is a property, e.g. "name" or "address"
    if (token.getKind() == TokenKind.LITERAL) {
        PropertyExpressionImpl property = new PropertyExpressionImpl(token.getUriLiteral());
        // leftOperator);
        return property;
    }
    // not Tested, should not occur
    throw ExpressionParserInternalError.createCOMMON();
}
Also used : CommonExpression(com.pogeyan.cmis.api.uri.expression.CommonExpression) LiteralExpression(com.pogeyan.cmis.api.uri.expression.LiteralExpression)

Aggregations

LiteralExpression (com.pogeyan.cmis.api.uri.expression.LiteralExpression)2 BinaryExpression (com.pogeyan.cmis.api.uri.expression.BinaryExpression)1 CommonExpression (com.pogeyan.cmis.api.uri.expression.CommonExpression)1 PropertyExpression (com.pogeyan.cmis.api.uri.expression.PropertyExpression)1 ArrayList (java.util.ArrayList)1 Criteria (org.mongodb.morphia.query.Criteria)1 CriteriaContainerImpl (org.mongodb.morphia.query.CriteriaContainerImpl)1