use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class FilterExpressionCheckEvaluationVisitor method visitOrExpression.
@Override
public Boolean visitOrExpression(OrFilterExpression expression) {
FilterExpression left = expression.getLeft();
FilterExpression right = expression.getRight();
return left.accept(this) || right.accept(this);
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class FilterExpressionNormalizationVisitor method visitOrExpression.
@Override
public FilterExpression visitOrExpression(OrFilterExpression expression) {
FilterExpression left = expression.getLeft();
FilterExpression right = expression.getRight();
return new OrFilterExpression(left.accept(this), right.accept(this));
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class FilterExpressionNormalizationVisitor method visitNotExpression.
@Override
public FilterExpression visitNotExpression(NotFilterExpression fe) {
FilterExpression inner = fe.getNegated();
if (inner instanceof AndFilterExpression) {
AndFilterExpression and = (AndFilterExpression) inner;
FilterExpression left = new NotFilterExpression(and.getLeft()).accept(this);
FilterExpression right = new NotFilterExpression(and.getRight()).accept(this);
return new OrFilterExpression(left, right);
}
if (inner instanceof OrFilterExpression) {
OrFilterExpression or = (OrFilterExpression) inner;
FilterExpression left = new NotFilterExpression(or.getLeft()).accept(this);
FilterExpression right = new NotFilterExpression(or.getRight()).accept(this);
return new AndFilterExpression(left, right);
}
if (inner instanceof NotFilterExpression) {
NotFilterExpression not = (NotFilterExpression) inner;
return (not.getNegated()).accept(this);
}
if (inner instanceof FilterPredicate) {
FilterPredicate filter = (FilterPredicate) inner;
return filter.negate();
}
return inner;
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class RSQLFilterDialect method parseTypedExpression.
@Override
public Map<String, FilterExpression> parseTypedExpression(String path, MultivaluedMap<String, String> filterParams, String apiVersion) throws ParseException {
Map<String, FilterExpression> expressionByType = new HashMap<>();
for (MultivaluedMap.Entry<String, List<String>> entry : filterParams.entrySet()) {
String paramName = entry.getKey();
List<String> paramValues = entry.getValue();
Matcher matcher = TYPED_FILTER_PATTERN.matcher(paramName);
if (matcher.find()) {
String typeName = matcher.group(1);
if (paramValues.size() != 1) {
throw new ParseException("Exactly one RSQL expression must be defined for type : " + typeName);
}
Type entityType = dictionary.getEntityClass(typeName, apiVersion);
if (entityType == null) {
throw new ParseException(INVALID_QUERY_PARAMETER + paramName);
}
String expressionText = paramValues.get(0);
FilterExpression filterExpression = parseFilterExpression(expressionText, entityType, true);
expressionByType.put(typeName, filterExpression);
} else {
throw new ParseException(INVALID_QUERY_PARAMETER + paramName);
}
}
return expressionByType;
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class PermissionExpressionBuilder method buildAnyFieldFilterExpression.
/**
* Build an expression representing any field on an entity.
*
* @param forType Resource class
* @param requestScope requestScope
* @return Expressions
*/
public FilterExpression buildAnyFieldFilterExpression(Type<?> forType, RequestScope requestScope, Set<String> requestedFields) {
Class<? extends Annotation> annotationClass = ReadPermission.class;
ParseTree classPermissions = entityDictionary.getPermissionsForClass(forType, annotationClass);
FilterExpression entityFilter = filterExpressionFromParseTree(classPermissions, forType, requestScope);
// case where the permissions does not have ANY filterExpressionCheck
if (entityFilter == FALSE_USER_CHECK_EXPRESSION || entityFilter == NO_EVALUATION_EXPRESSION || entityFilter == TRUE_USER_CHECK_EXPRESSION) {
entityFilter = null;
}
FilterExpression allFieldsFilterExpression = entityFilter;
List<String> fields = entityDictionary.getAllExposedFields(forType).stream().filter(field -> requestedFields == null || requestedFields.contains(field)).collect(Collectors.toList());
for (String field : fields) {
ParseTree fieldPermissions = entityDictionary.getPermissionsForField(forType, field, annotationClass);
FilterExpression fieldExpression = filterExpressionFromParseTree(fieldPermissions, forType, requestScope);
if (fieldExpression == null && entityFilter == null) {
// this field will be visible across all instances
return null;
}
if (fieldExpression == null || fieldExpression == FALSE_USER_CHECK_EXPRESSION) {
// In either case this field is not useful for filtering when loading records
continue;
}
if (fieldExpression == NO_EVALUATION_EXPRESSION || fieldExpression == TRUE_USER_CHECK_EXPRESSION) {
// When the expression is TRUE_USER_CHECK_EXPRESSION all records can be loaded
return null;
}
if (allFieldsFilterExpression != null) {
allFieldsFilterExpression = new OrFilterExpression(allFieldsFilterExpression, fieldExpression);
} else {
allFieldsFilterExpression = fieldExpression;
}
}
return allFieldsFilterExpression;
}
Aggregations