use of com.querydsl.core.types.Operator in project querydsl by querydsl.
the class JavaTemplatesTest method mappings.
@Test
public void mappings() {
Templates templates = new JavaTemplates();
int matched = 0;
for (Operator operator : Ops.values()) {
++matched;
assertNotNull(templates.getTemplate(operator));
}
assertTrue(matched > 0);
}
use of com.querydsl.core.types.Operator in project midpoint by Evolveum.
the class NaryLogicalFilterProcessor method process.
@Override
public Predicate process(NaryLogicalFilter filter) throws RepositoryException {
Predicate predicate = null;
Operator operator = (filter instanceof AndFilter) ? Ops.AND : Ops.OR;
for (ObjectFilter subfilter : filter.getConditions()) {
Predicate right = context.process(subfilter);
if (right != null) {
predicate = predicate != null ? ExpressionUtils.predicate(operator, predicate, right) : right;
}
}
return predicate;
}
use of com.querydsl.core.types.Operator in project kylo by Teradata.
the class GenericQueryDslFilter method buildFilter.
/**
* build the Filter for the base QueryDSL class and the passed in filter list
*
* @param filters name:test, age>10
*/
public static <T> BooleanBuilder buildFilter(EntityPathBase basePath, List<SearchCriteria> filters) {
BooleanBuilder booleanBuilder = new BooleanBuilder();
if (filters != null && !filters.isEmpty()) {
filters.stream().forEach(filter -> {
Path p = buildPathFromFilterColumn(basePath, filter.getKey());
if (p != null) {
Object value = filter.getValue();
Operator op = operators.get(filter.getOperation());
if (validateOperatorPath(op, p, filter.getKey(), value)) {
if (Ops.LIKE_IC.equals(op) && value instanceof String && value != null && !((String) value).endsWith("%")) {
value = ((String) value) + "%";
}
if (value == null || (value instanceof String && ((String) value).equalsIgnoreCase(NULL_FILTER))) {
op = Ops.IS_NULL;
value = null;
} else if (value instanceof String && ((String) value).equalsIgnoreCase(NOT_NULL_FILTER)) {
op = Ops.IS_NOT_NULL;
value = null;
}
if (value != null) {
Object convertedValue = getValueForQuery(p, filter.getKey(), op, value);
if (convertedValue != null && convertedValue instanceof Collection) {
op = Ops.IN;
}
if (convertedValue != null) {
Expression e = null;
if (convertedValue instanceof Comparable) {
e = Expressions.asComparable((Comparable) convertedValue);
} else {
e = Expressions.constant(convertedValue);
}
// reset the operator if looking for UUID
if (convertedValue instanceof UUID || convertedValue instanceof Enum) {
op = Ops.EQ;
}
if (filter.isOrFilter()) {
booleanBuilder.or(Expressions.predicate(op, p, e));
} else {
booleanBuilder.and(Expressions.predicate(op, p, e));
}
}
} else {
if (filter.isOrFilter()) {
booleanBuilder.or(Expressions.predicate(op, p));
} else {
booleanBuilder.and(Expressions.predicate(op, p));
}
}
}
}
});
}
return booleanBuilder;
}
use of com.querydsl.core.types.Operator in project kylo by Teradata.
the class GenericQueryDslFilter method parseFilterString.
/**
* convert a passed in filter string to a list of criteria objects
*
* @param filterString a filter, <column><operator><value> Example: jobinstance.name==jobName,jobExcutionId>=200. that will search for all jobs named 'jobName' and jobExecutionId >= 200
* @return a list of criteria objects
*/
public static List<SearchCriteria> parseFilterString(String filterString) {
List<SearchCriteria> searchCriterias = new ArrayList<>();
if (StringUtils.isNotBlank(filterString)) {
// first match and split on , for various filters
String[] filterConditions = filterString.split(",(?=(?:[^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)");
List<String> filterConditionsList = Arrays.asList(filterConditions);
// Pattern used to match the <column><operator><value>
String validOperatorsRegEx = operators.keySet().stream().map(key -> key).collect(Collectors.joining("|"));
Pattern columnOperatorValuePattern = Pattern.compile("(.*)(" + validOperatorsRegEx + ")(.*)");
filterConditionsList.stream().forEach(filter -> {
Matcher matcher = columnOperatorValuePattern.matcher(filter);
while (matcher.find()) {
String field = matcher.group(1);
String operator = matcher.group(2);
String value = matcher.group(3);
searchCriterias.add(new SearchCriteria(field, operator, value));
}
});
}
return searchCriterias;
}
use of com.querydsl.core.types.Operator in project querydsl by querydsl.
the class DefaultQueryEngine method project.
private List<?> project(QueryMetadata metadata, List<Expression<?>> sources, List<?> list) {
Expression<?> projection = metadata.getProjection();
Operator aggregator = null;
if (projection instanceof Operation && Ops.aggOps.contains(((Operation) projection).getOperator())) {
Operation<?> aggregation = (Operation<?>) projection;
aggregator = aggregation.getOperator();
projection = aggregation.getArg(0);
}
Evaluator projectionEvaluator = evaluatorFactory.create(metadata, sources, projection);
EvaluatorFunction<Object, Object> transformer = new EvaluatorFunction(projectionEvaluator);
List target = list.stream().map(transformer).collect(Collectors.toList());
if (aggregator != null) {
return Collections.singletonList(CollQueryFunctions.aggregate(target, projection, aggregator));
} else {
return target;
}
}
Aggregations