use of com.yahoo.elide.core.filter.expression.OrFilterExpression 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.OrFilterExpression 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.OrFilterExpression 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.OrFilterExpression 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;
}
use of com.yahoo.elide.core.filter.expression.OrFilterExpression in project elide by yahoo.
the class MatchesTemplateVisitor method matches.
private boolean matches(FilterExpression a, FilterExpression b) {
if (!a.getClass().equals(b.getClass())) {
return false;
}
if (a instanceof AndFilterExpression) {
AndFilterExpression andA = (AndFilterExpression) a;
AndFilterExpression andB = (AndFilterExpression) b;
return matches(andA.getLeft(), andB.getLeft()) && matches(andA.getRight(), andB.getRight());
}
if (a instanceof OrFilterExpression) {
OrFilterExpression orA = (OrFilterExpression) a;
OrFilterExpression orB = (OrFilterExpression) b;
return matches(orA.getLeft(), orB.getLeft()) && matches(orA.getRight(), orB.getRight());
}
if (a instanceof NotFilterExpression) {
NotFilterExpression notA = (NotFilterExpression) a;
NotFilterExpression notB = (NotFilterExpression) b;
return matches(notA.getNegated(), notB.getNegated());
}
FilterPredicate predicateA = (FilterPredicate) a;
FilterPredicate predicateB = (FilterPredicate) b;
boolean valueMatches = predicateA.getValues().equals(predicateB.getValues());
boolean operatorMatches = predicateA.getOperator().equals(predicateB.getOperator());
boolean pathMatches = pathMatches(predicateA.getPath(), predicateB.getPath());
boolean usingTemplate = false;
if (predicateA.getValues().size() == 1) {
String value = predicateA.getValues().get(0).toString();
Matcher matcher = TEMPLATE_PATTERN.matcher(value);
usingTemplate = matcher.matches();
if (usingTemplate && pathMatches & operatorMatches) {
String argumentName = matcher.group(1);
arguments.put(argumentName, Argument.builder().name(argumentName).value(predicateB.getValues().size() == 1 ? predicateB.getValues().get(0) : predicateB.getValues()).build());
}
}
return (operatorMatches && pathMatches && (valueMatches || usingTemplate));
}
Aggregations