Search in sources :

Example 1 with PegChoice

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

the class DslTermQueryRule method handle.

/**
 * {@inheritDoc}
 */
@Override
protected DslTermQuery handle(final List<Object> parsing) {
    final String preSpaces = (String) parsing.get(0);
    final String preQuery = (String) parsing.get(1);
    final List<Object> term = (List<Object>) parsing.get(2);
    final String preTerm = (String) term.get(1);
    final String termField = (String) term.get(2);
    final String postTerm = (String) term.get(3);
    final Optional<PegChoice> escapeRule = (Optional<PegChoice>) term.get(5);
    final EscapeMode escapeMode;
    if (escapeRule.isPresent()) {
        switch(escapeRule.get().getChoiceIndex()) {
            case 0:
                escapeMode = EscapeMode.remove;
                break;
            case 1:
                escapeMode = EscapeMode.escape;
                break;
            default:
                throw new IllegalArgumentException("case " + escapeRule.get().getChoiceIndex() + " not implemented");
        }
    } else {
        escapeMode = EscapeMode.none;
    }
    final Optional<List<Object>> defaultRuleOpt = (Optional<List<Object>>) term.get(6);
    final Optional<String> defaultValue = defaultRuleOpt.map(defaultRule -> (String) defaultRule.get(1));
    final String postQuery = (String) parsing.get(3);
    // final String postSpaces = (String) parsing.get(4);
    return new DslTermQuery(DslUtil.concat(preSpaces, preQuery), preTerm, termField, postTerm, escapeMode, defaultValue, postQuery);
}
Also used : Optional(java.util.Optional) EscapeMode(io.vertigo.dynamox.search.dsl.model.DslTermQuery.EscapeMode) List(java.util.List) DslTermQuery(io.vertigo.dynamox.search.dsl.model.DslTermQuery) PegChoice(io.vertigo.commons.peg.PegChoice)

Example 2 with PegChoice

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

the class DslExpressionRule method handle.

/**
 * {@inheritDoc}
 */
@Override
protected DslExpression handle(final List<Object> parsing) {
    String preExpression = ((Optional<String>) parsing.get(0)).orElse("") + parsing.get(1);
    final String postExpression;
    final Optional<DslField> field;
    final Optional<DslMultiField> multiField;
    final PegChoice fields = (PegChoice) parsing.get(2);
    switch(fields.getChoiceIndex()) {
        case 0:
            field = Optional.of((DslField) fields.getValue());
            multiField = Optional.empty();
            postExpression = "";
            break;
        case 1:
            final List<Object> multiFieldParsing = (List<Object>) fields.getValue();
            preExpression = DslUtil.concat(preExpression, (String) multiFieldParsing.get(0));
            multiField = Optional.of((DslMultiField) multiFieldParsing.get(1));
            postExpression = (String) multiFieldParsing.get(2);
            field = Optional.empty();
            break;
        default:
            throw new IllegalArgumentException("case " + fields.getChoiceIndex() + " not implemented");
    }
    final PegChoice queries = (PegChoice) parsing.get(4);
    final DslQuery query = (DslQuery) queries.getValue();
    return new DslExpression(preExpression, field, multiField, query, postExpression);
}
Also used : DslMultiField(io.vertigo.dynamox.search.dsl.model.DslMultiField) DslExpression(io.vertigo.dynamox.search.dsl.model.DslExpression) List(java.util.List) DslField(io.vertigo.dynamox.search.dsl.model.DslField) PegChoice(io.vertigo.commons.peg.PegChoice) DslQuery(io.vertigo.dynamox.search.dsl.model.DslQuery)

Example 3 with PegChoice

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

the class DslMultiExpressionRule method handle.

/**
 * {@inheritDoc}
 */
@Override
protected DslMultiExpression handle(final PegChoice parsing) {
    final String preMultiExpression;
    final String postMultiExpression;
    // ---
    final List<PegChoice> many;
    switch(parsing.getChoiceIndex()) {
        case 0:
            final List<?> blockExpression = (List<?>) parsing.getValue();
            preMultiExpression = ((Optional<String>) blockExpression.get(0)).orElse("") + blockExpression.get(1);
            many = (List<PegChoice>) blockExpression.get(3);
            postMultiExpression = (String) blockExpression.get(5);
            break;
        case 1:
            preMultiExpression = "";
            many = (List<PegChoice>) parsing.getValue();
            postMultiExpression = "";
            break;
        default:
            throw new IllegalArgumentException("case " + parsing.getChoiceIndex() + " not implemented");
    }
    final List<DslExpression> expressionDefinitions = new ArrayList<>();
    final List<DslMultiExpression> multiExpressionDefinitions = new ArrayList<>();
    // On récupère le produit de la règle many
    for (final PegChoice item : many) {
        switch(item.getChoiceIndex()) {
            case 0:
                expressionDefinitions.add((DslExpression) item.getValue());
                break;
            case 1:
                multiExpressionDefinitions.add((DslMultiExpression) item.getValue());
                break;
            default:
                throw new IllegalArgumentException("case " + item.getChoiceIndex() + " not implemented");
        }
    }
    final boolean block = parsing.getChoiceIndex() == 0;
    // ---
    return new DslMultiExpression(preMultiExpression, block, expressionDefinitions, multiExpressionDefinitions, postMultiExpression);
}
Also used : DslMultiExpression(io.vertigo.dynamox.search.dsl.model.DslMultiExpression) Optional(java.util.Optional) ArrayList(java.util.ArrayList) PegChoice(io.vertigo.commons.peg.PegChoice) DslExpression(io.vertigo.dynamox.search.dsl.model.DslExpression) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with PegChoice

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

the class DslDefinitionBodyRule method handle.

@Override
protected DslDefinitionBody handle(final List<Object> parsing) {
    final List<PegChoice> many = (List<PegChoice>) parsing.get(2);
    final List<DslDefinitionEntry> fieldDefinitionEntries = new ArrayList<>();
    final List<DslPropertyEntry> fieldPropertyEntries = new ArrayList<>();
    for (final PegChoice item : many) {
        switch(item.getChoiceIndex()) {
            case 0:
                // Soit on est en présence d'une propriété standard
                final DslPropertyEntry propertyEntry = (DslPropertyEntry) item.getValue();
                fieldPropertyEntries.add(propertyEntry);
                break;
            case 1:
                final DslDefinitionEntry xDefinitionEntry = (DslDefinitionEntry) item.getValue();
                fieldDefinitionEntries.add(xDefinitionEntry);
                break;
            case 2:
                final PegChoice subTuple = (PegChoice) item.getValue();
                fieldDefinitionEntries.add((DslDefinitionEntry) subTuple.getValue());
                break;
            case 3:
                break;
            default:
                throw new IllegalArgumentException("Type of rule not supported");
        }
    }
    return new DslDefinitionBody(fieldDefinitionEntries, fieldPropertyEntries);
}
Also used : DslDefinitionBody(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DslPropertyEntry(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslPropertyEntry) PegChoice(io.vertigo.commons.peg.PegChoice) DslDefinitionEntry(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry)

Example 5 with PegChoice

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

the class DslRangeQueryRule method handle.

/**
 * {@inheritDoc}
 */
@Override
protected DslRangeQuery handle(final List<Object> parsing) {
    final String preQuery = (String) parsing.get(0);
    final PegChoice startChoice = (PegChoice) parsing.get(1);
    final PegChoice startTermQuery = (PegChoice) parsing.get(2);
    final DslQuery startQueryDefinitions;
    if (startTermQuery.getChoiceIndex() == 0) {
        startQueryDefinitions = new DslFixedQuery("*");
    } else {
        startQueryDefinitions = (DslQuery) startTermQuery.getValue();
    }
    final PegChoice endTermQuery = (PegChoice) parsing.get(6);
    final DslQuery endQueryDefinitions;
    if (endTermQuery.getChoiceIndex() == 0) {
        endQueryDefinitions = new DslFixedQuery("*");
    } else {
        endQueryDefinitions = (DslQuery) endTermQuery.getValue();
    }
    final PegChoice endChoice = (PegChoice) parsing.get(8);
    final String postQuery = (String) parsing.get(9);
    final String startRange = (String) startChoice.getValue();
    final String endRange = (String) endChoice.getValue();
    return new DslRangeQuery(preQuery, startRange, startQueryDefinitions, endQueryDefinitions, endRange, postQuery);
}
Also used : DslFixedQuery(io.vertigo.dynamox.search.dsl.model.DslFixedQuery) DslRangeQuery(io.vertigo.dynamox.search.dsl.model.DslRangeQuery) PegChoice(io.vertigo.commons.peg.PegChoice) DslQuery(io.vertigo.dynamox.search.dsl.model.DslQuery)

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