Search in sources :

Example 6 with PegChoice

use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.

the class DslMultiQueryRule method handle.

/**
 * {@inheritDoc}
 */
@Override
protected DslBlockQuery handle(final List<Object> parsing) {
    final String preQuery = (String) parsing.get(0);
    final List<DslQuery> queryDefinitions = new ArrayList<>();
    final String postQuery = (String) parsing.get(4);
    final List<PegChoice> manyQueries = (List<PegChoice>) parsing.get(2);
    for (final PegChoice item : manyQueries) {
        queryDefinitions.add((DslQuery) item.getValue());
    }
    return new DslBlockQuery(preQuery, queryDefinitions, postQuery);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DslBlockQuery(io.vertigo.dynamox.search.dsl.model.DslBlockQuery) PegChoice(io.vertigo.commons.peg.PegChoice) DslQuery(io.vertigo.dynamox.search.dsl.model.DslQuery)

Example 7 with PegChoice

use of io.vertigo.commons.peg.PegChoice 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 8 with PegChoice

use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.

the class DslDefinitionBodyRule method createMainRule.

private static PegRule<List<Object>> createMainRule(final DslEntity entity) {
    Assertion.checkNotNull(entity);
    final List<String> attributeNames = new ArrayList<>();
    final List<PegRule<?>> innerDefinitionRules = new ArrayList<>();
    for (final DslEntityField dslEntityField : entity.getFields()) {
        attributeNames.add(dslEntityField.getName());
        final DslEntity dslEntity;
        if (dslEntityField.getType() instanceof DslEntity) {
            dslEntity = DslEntity.class.cast(dslEntityField.getType());
        } else if (dslEntityField.getType() instanceof DslEntityLink) {
            dslEntity = DslEntityLink.class.cast(dslEntityField.getType()).getEntity();
        } else {
            // case property
            dslEntity = null;
        }
        if (dslEntity != null) {
            innerDefinitionRules.add(new DslInnerDefinitionRule(dslEntityField.getName(), dslEntity));
        }
    }
    final DslPropertyDeclarationRule propertyDeclarationRule = new DslPropertyDeclarationRule(entity.getPropertyNames());
    final DslDefinitionEntryRule xDefinitionEntryRule = new DslDefinitionEntryRule(attributeNames);
    final PegRule<PegChoice> firstOfRule = PegRules.choice(// 0
    propertyDeclarationRule, // 1
    xDefinitionEntryRule, // 2,
    PegRules.choice(innerDefinitionRules), SPACES);
    final PegRule<List<PegChoice>> manyRule = PegRules.zeroOrMore(firstOfRule, false);
    return PegRules.sequence(OBJECT_START, SPACES, // 2
    manyRule, SPACES, OBJECT_END);
}
Also used : DslEntityLink(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityLink) ArrayList(java.util.ArrayList) PegChoice(io.vertigo.commons.peg.PegChoice) PegRule(io.vertigo.commons.peg.PegRule) DslEntity(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity) DslEntityField(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityField) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with PegChoice

use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.

the class DslDefinitionEntryRule method handle.

@Override
protected DslDefinitionEntry handle(final List<Object> parsing) {
    final String fieldName = (String) ((PegChoice) parsing.get(0)).getValue();
    final List<String> definitionKeys;
    final PegChoice definitionChoice = (PegChoice) parsing.get(4);
    switch(definitionChoice.getChoiceIndex()) {
        case 1:
            // Déclaration d'une liste de définitions identifiée par leurs clés
            definitionKeys = (List<String>) definitionChoice.getValue();
            break;
        case 0:
            // Déclaration d'une définition identifiée par sa clé
            final String value = (String) definitionChoice.getValue();
            definitionKeys = java.util.Collections.singletonList(value);
            break;
        default:
            throw new IllegalStateException();
    }
    return new DslDefinitionEntry(fieldName, definitionKeys);
}
Also used : PegChoice(io.vertigo.commons.peg.PegChoice) DslDefinitionEntry(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry)

Example 10 with PegChoice

use of io.vertigo.commons.peg.PegChoice in project vertigo by KleeGroup.

the class DslKspRule method handle.

@Override
protected Dummy handle(final List<Object> parsing) {
    final String packageName = (String) parsing.get(1);
    final List<PegChoice> declarationChoices = (List<PegChoice>) parsing.get(3);
    for (final PegChoice declarationChoice : declarationChoices) {
        // - à des gestion de droits.
        switch(declarationChoice.getChoiceIndex()) {
            case 0:
                // On positionne le Package
                final DslDefinition oldDynamicDefinition = (DslDefinition) declarationChoice.getValue();
                final DslDefinition newDynamicDefinition = DslDefinition.builder(oldDynamicDefinition.getName(), oldDynamicDefinition.getEntity()).withPackageName(packageName).merge(oldDynamicDefinition).build();
                handleDefinitionRule(newDynamicDefinition);
                break;
            case 1:
                handleTemplateRule((DslDefinition) declarationChoice.getValue());
                break;
            default:
                throw new IllegalArgumentException("case " + declarationChoice.getChoiceIndex() + " not implemented");
        }
    }
    return Dummy.INSTANCE;
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) List(java.util.List) PegChoice(io.vertigo.commons.peg.PegChoice)

Aggregations

PegChoice (io.vertigo.commons.peg.PegChoice)10 List (java.util.List)8 ArrayList (java.util.ArrayList)5 DslQuery (io.vertigo.dynamox.search.dsl.model.DslQuery)3 DslDefinitionEntry (io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry)2 DslExpression (io.vertigo.dynamox.search.dsl.model.DslExpression)2 Optional (java.util.Optional)2 RuleExpression (io.vertigo.account.authorization.metamodel.rulemodel.RuleExpression)1 RuleMultiExpression (io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression)1 BoolOperator (io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression.BoolOperator)1 PegRule (io.vertigo.commons.peg.PegRule)1 DslDefinition (io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition)1 DslEntity (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity)1 DslEntityField (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityField)1 DslEntityLink (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityLink)1 DslDefinitionBody (io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody)1 DslPropertyEntry (io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslPropertyEntry)1 DslBlockQuery (io.vertigo.dynamox.search.dsl.model.DslBlockQuery)1 DslField (io.vertigo.dynamox.search.dsl.model.DslField)1 DslFixedQuery (io.vertigo.dynamox.search.dsl.model.DslFixedQuery)1