Search in sources :

Example 1 with DslExpression

use of io.vertigo.dynamox.search.dsl.model.DslExpression 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 2 with DslExpression

use of io.vertigo.dynamox.search.dsl.model.DslExpression 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 3 with DslExpression

use of io.vertigo.dynamox.search.dsl.model.DslExpression in project vertigo by KleeGroup.

the class DslListFilterBuilder method appendCompactFields.

private void appendCompactFields(final StringBuilder query, final DslExpression expressionDefinition, final StringBuilder expressionQuery, final DslQuery dslQuery) {
    String expressionSep = "";
    final DslMultiField dslMultiField = expressionDefinition.getMultiField().get();
    for (final DslField dslField : dslMultiField.getFields()) {
        final DslField monoFieldDefinition = new DslField(firstNotEmpty(dslField.getPreBody(), dslMultiField.getPreBody()), dslField.getFieldName(), firstNotEmpty(dslField.getPostBody(), dslMultiField.getPostBody()));
        final DslExpression monoFieldExpressionDefinition = new DslExpression(concat(expressionSep, expressionDefinition.getPreBody()), Optional.of(monoFieldDefinition), Optional.empty(), dslQuery, expressionDefinition.getPostBody());
        appendTermQuery(expressionQuery, (DslTermQuery) dslQuery, monoFieldExpressionDefinition, query);
        flushExpressionToQuery(query, monoFieldExpressionDefinition, expressionQuery);
        expressionSep = " ";
    }
}
Also used : DslMultiField(io.vertigo.dynamox.search.dsl.model.DslMultiField) DslExpression(io.vertigo.dynamox.search.dsl.model.DslExpression) DslField(io.vertigo.dynamox.search.dsl.model.DslField)

Example 4 with DslExpression

use of io.vertigo.dynamox.search.dsl.model.DslExpression in project vertigo by KleeGroup.

the class DslListFilterBuilder method flattenMultiToMonoFieldExpressionDefinition.

private static List<DslExpression> flattenMultiToMonoFieldExpressionDefinition(final DslTermQuery dslTermDefinition, final DslUserCriteria userCriteria, final String criteriaValue, final DslMultiField dslMultiField) {
    final List<DslExpression> monoFieldExpressionDefinitions = new ArrayList<>();
    for (final DslField dslField : dslMultiField.getFields()) {
        final DslField monoFieldDefinition = new DslField(firstNotEmpty(dslField.getPreBody(), dslMultiField.getPreBody()), dslField.getFieldName(), "");
        final DslExpression monoFieldExpressionDefinition = new DslExpression(monoFieldExpressionDefinitions.isEmpty() ? "" : " ", Optional.of(monoFieldDefinition), Optional.empty(), new DslFixedQuery(concat(criteriaValue, firstNotEmpty(userCriteria.getOverridedPostModifier(), dslTermDefinition.getPostTerm()))), firstNotEmpty(dslField.getPostBody(), dslMultiField.getPostBody()));
        monoFieldExpressionDefinitions.add(monoFieldExpressionDefinition);
    }
    return monoFieldExpressionDefinitions;
}
Also used : DslFixedQuery(io.vertigo.dynamox.search.dsl.model.DslFixedQuery) DslExpression(io.vertigo.dynamox.search.dsl.model.DslExpression) ArrayList(java.util.ArrayList) DslField(io.vertigo.dynamox.search.dsl.model.DslField)

Example 5 with DslExpression

use of io.vertigo.dynamox.search.dsl.model.DslExpression in project vertigo by KleeGroup.

the class DslListFilterBuilder method appendMultiExpression.

private void appendMultiExpression(final StringBuilder query, final DslMultiExpression multiExpressionDefinition) {
    final StringBuilder multiExpressionQuery = new StringBuilder();
    for (final DslExpression expression : multiExpressionDefinition.getExpressions()) {
        appendExpression(multiExpressionQuery, expression);
    }
    for (final DslMultiExpression multiExpression : multiExpressionDefinition.getMultiExpressions()) {
        appendMultiExpression(multiExpressionQuery, multiExpression);
    }
    flushSubQueryToQuery(query, multiExpressionDefinition.getPreBody(), multiExpressionDefinition.getPostBody(), multiExpressionDefinition.isBlock(), multiExpressionQuery);
}
Also used : DslMultiExpression(io.vertigo.dynamox.search.dsl.model.DslMultiExpression) DslExpression(io.vertigo.dynamox.search.dsl.model.DslExpression)

Aggregations

DslExpression (io.vertigo.dynamox.search.dsl.model.DslExpression)5 DslField (io.vertigo.dynamox.search.dsl.model.DslField)3 PegChoice (io.vertigo.commons.peg.PegChoice)2 DslMultiExpression (io.vertigo.dynamox.search.dsl.model.DslMultiExpression)2 DslMultiField (io.vertigo.dynamox.search.dsl.model.DslMultiField)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DslFixedQuery (io.vertigo.dynamox.search.dsl.model.DslFixedQuery)1 DslQuery (io.vertigo.dynamox.search.dsl.model.DslQuery)1 Optional (java.util.Optional)1