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);
}
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);
}
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 = " ";
}
}
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;
}
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);
}
Aggregations