Search in sources :

Example 1 with RuleExpression

use of io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression in project vertigo by KleeGroup.

the class DslExpressionRule method handle.

/**
 * {@inheritDoc}
 */
@Override
protected RuleExpression handle(final List<Object> parsing) {
    final String fieldName = (String) parsing.get(1);
    final ValueOperator operator = (ValueOperator) parsing.get(3);
    final RuleValue value = (RuleValue) ((PegChoice) parsing.get(5)).getValue();
    return new RuleExpression(fieldName, operator, value);
}
Also used : ValueOperator(io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression.ValueOperator) RuleExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression) RuleValue(io.vertigo.account.authorization.metamodel.rulemodel.RuleValue)

Example 2 with RuleExpression

use of io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression in project vertigo by KleeGroup.

the class SearchSecurityRuleTranslator method appendMultiExpression.

private void appendMultiExpression(final StringBuilder query, final RuleMultiExpression multiExpressionDefinition) {
    String sep = "";
    String boolSep;
    if (multiExpressionDefinition.getBoolOperator() == BoolOperator.AND) {
        boolSep = "+";
    } else {
        boolSep = "";
    }
    for (final RuleExpression expression : multiExpressionDefinition.getExpressions()) {
        query.append(sep).append(boolSep);
        appendExpression(query, expression);
        sep = " ";
    }
    for (final RuleMultiExpression multiExpression : multiExpressionDefinition.getMultiExpressions()) {
        query.append(sep).append(boolSep).append('(');
        appendMultiExpression(query, multiExpression);
        query.append(')');
        sep = " ";
    }
}
Also used : RuleExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression) RuleMultiExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression)

Example 3 with RuleExpression

use of io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression in project vertigo by KleeGroup.

the class SqlSecurityRuleTranslator method appendMultiExpression.

private void appendMultiExpression(final StringBuilder query, final RuleMultiExpression multiExpressionDefinition) {
    String sep = "";
    final String boolSep = " " + multiExpressionDefinition.getBoolOperator() + " ";
    if (multiExpressionDefinition.isBlock()) {
        query.append('(');
    }
    for (final RuleExpression expression : multiExpressionDefinition.getExpressions()) {
        query.append(sep);
        appendExpression(query, expression);
        sep = boolSep;
    }
    for (final RuleMultiExpression multiExpression : multiExpressionDefinition.getMultiExpressions()) {
        query.append(sep);
        appendMultiExpression(query, multiExpression);
        sep = boolSep;
    }
    if (multiExpressionDefinition.isBlock()) {
        query.append(')');
    }
}
Also used : RuleExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression) RuleMultiExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression)

Example 4 with RuleExpression

use of io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression in project vertigo by KleeGroup.

the class DslMultiExpressionRule method handle.

/**
 * {@inheritDoc}
 */
@Override
protected RuleMultiExpression handle(final PegChoice parsing) {
    final List<Object> innerBlock;
    switch(parsing.getChoiceIndex()) {
        case 0:
            final List<?> blockExpression = (List<?>) parsing.getValue();
            innerBlock = (List<Object>) blockExpression.get(2);
            break;
        case 1:
            innerBlock = (List<Object>) parsing.getValue();
            break;
        default:
            throw new IllegalArgumentException("case " + parsing.getChoiceIndex() + " not implemented");
    }
    final List<RuleExpression> expressionDefinitions = new ArrayList<>();
    final List<RuleMultiExpression> multiExpressionDefinitions = new ArrayList<>();
    // first (expression1|multiExpression1)
    final PegChoice firstExpressionChoice = (PegChoice) innerBlock.get(1);
    switch(firstExpressionChoice.getChoiceIndex()) {
        case 0:
            expressionDefinitions.add((RuleExpression) firstExpressionChoice.getValue());
            break;
        case 1:
            multiExpressionDefinitions.add((RuleMultiExpression) firstExpressionChoice.getValue());
            break;
        default:
            throw new IllegalArgumentException("case " + parsing.getChoiceIndex() + " not implemented");
    }
    // manyNextExpressionsRule
    final List<List<Object>> many = (List<List<Object>>) innerBlock.get(3);
    // On récupère le produit de la règle many
    BoolOperator operator = null;
    for (final List<Object> item : many) {
        if (operator != null && operator != item.get(1)) {
            throw new IllegalArgumentException("Can't use different operator in same block, attempt to find " + operator);
        }
        operator = (BoolOperator) item.get(1);
        // next (expression2|multiExpression2)
        final PegChoice nextExpressionChoice = (PegChoice) item.get(3);
        switch(nextExpressionChoice.getChoiceIndex()) {
            case 0:
                expressionDefinitions.add((RuleExpression) nextExpressionChoice.getValue());
                break;
            case 1:
                multiExpressionDefinitions.add((RuleMultiExpression) nextExpressionChoice.getValue());
                break;
            default:
                throw new IllegalArgumentException("case " + nextExpressionChoice.getChoiceIndex() + " not implemented");
        }
    }
    final boolean block = parsing.getChoiceIndex() == 0;
    // ---
    return new RuleMultiExpression(block, operator != null ? operator : BoolOperator.AND, expressionDefinitions, multiExpressionDefinitions);
}
Also used : RuleMultiExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression) ArrayList(java.util.ArrayList) PegChoice(io.vertigo.commons.peg.PegChoice) RuleExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression) List(java.util.List) ArrayList(java.util.ArrayList) BoolOperator(io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression.BoolOperator)

Example 5 with RuleExpression

use of io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression in project vertigo by KleeGroup.

the class CriteriaSecurityRuleTranslator method toCriteria.

private Criteria<E> toCriteria(final RuleMultiExpression multiExpression) {
    if (multiExpression.isAlwaysTrue()) {
        return Criterions.alwaysTrue();
    }
    Criteria<E> mainCriteria = null;
    for (final RuleExpression expression : multiExpression.getExpressions()) {
        if (multiExpression.getBoolOperator() == BoolOperator.AND) {
            mainCriteria = andCriteria(mainCriteria, toCriteria(expression));
        } else {
            mainCriteria = orCriteria(mainCriteria, toCriteria(expression));
        }
    }
    for (final RuleMultiExpression expression : multiExpression.getMultiExpressions()) {
        if (multiExpression.getBoolOperator() == BoolOperator.AND) {
            mainCriteria = andCriteria(mainCriteria, toCriteria(expression));
        } else {
            mainCriteria = orCriteria(mainCriteria, toCriteria(expression));
        }
    }
    // can be null ?
    Assertion.checkNotNull(mainCriteria);
    return mainCriteria;
}
Also used : RuleExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression) RuleMultiExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression)

Aggregations

RuleExpression (io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression)5 RuleMultiExpression (io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression)4 ValueOperator (io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression.ValueOperator)1 BoolOperator (io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression.BoolOperator)1 RuleValue (io.vertigo.account.authorization.metamodel.rulemodel.RuleValue)1 PegChoice (io.vertigo.commons.peg.PegChoice)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1