use of com.yahoo.elide.core.Path in project elide by yahoo.
the class DefaultQueryValidator method validateWhereClause.
@Override
public void validateWhereClause(Query query) {
FilterExpression whereClause = query.getWhereFilter();
if (whereClause == null) {
return;
}
whereClause.accept(new PredicateExtractionVisitor()).forEach(predicate -> {
Path path = predicate.getPath();
if (path.getPathElements().size() > 1) {
throw new InvalidOperationException("Relationship traversal not supported for analytic queries.");
}
validatePredicate(query, predicate);
});
}
use of com.yahoo.elide.core.Path in project elide by yahoo.
the class DefaultQueryValidator method validateSorting.
@Override
public void validateSorting(Query query) {
Sorting sorting = query.getSorting();
if (sorting == null) {
return;
}
Map<Path, Sorting.SortOrder> sortClauses = sorting.getSortingPaths();
Set<String> allFields = query.getColumnProjections().stream().map(ColumnProjection::getAlias).collect(Collectors.toCollection(LinkedHashSet::new));
sortClauses.keySet().forEach((path) -> validateSortingPath(path, allFields));
}
use of com.yahoo.elide.core.Path in project elide by yahoo.
the class InMemoryStoreTransactionTest method testFilteringRequiresInMemoryPagination.
@Test
public void testFilteringRequiresInMemoryPagination() {
FilterExpression expression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Literary Fiction");
PaginationImpl pagination = new PaginationImpl(ClassType.of(Book.class), 0, 2, 10, 10, true, false);
EntityProjection projection = EntityProjection.builder().type(Book.class).filterExpression(expression).pagination(pagination).build();
DataStoreIterable filterInMemory = new DataStoreIterableBuilder(books).filterInMemory(true).build();
when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(filterInMemory);
Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
verify(wrappedTransaction, times(1)).loadObjects(any(EntityProjection.class), eq(scope));
assertEquals(2, loaded.size());
assertTrue(loaded.contains(book1));
assertTrue(loaded.contains(book3));
assertEquals(2, pagination.getPageTotals());
}
use of com.yahoo.elide.core.Path in project elide by yahoo.
the class VerifyFieldAccessFilterExpressionVisitorTest method testReject.
@Test
public void testReject() {
Path p1Path = new Path(Arrays.asList(new PathElement(Book.class, Author.class, AUTHORS), new PathElement(Author.class, String.class, NAME)));
FilterPredicate p1 = new InPredicate(p1Path, "foo", "bar");
Path p2Path = new Path(Arrays.asList(new PathElement(Book.class, String.class, HOME)));
FilterPredicate p2 = new InPredicate(p2Path, "blah");
Path p3Path = new Path(Arrays.asList(new PathElement(Book.class, String.class, GENRE)));
FilterPredicate p3 = new InPredicate(p3Path, SCIFI);
// P4 is a duplicate of P3
Path p4Path = new Path(Arrays.asList(new PathElement(Book.class, String.class, GENRE)));
FilterPredicate p4 = new InPredicate(p4Path, SCIFI);
OrFilterExpression or = new OrFilterExpression(p2, p3);
AndFilterExpression and1 = new AndFilterExpression(or, p1);
AndFilterExpression and2 = new AndFilterExpression(and1, p4);
NotFilterExpression not = new NotFilterExpression(and2);
Book book = new Book();
Author author = new Author();
book.setAuthors(Collections.singleton(author));
author.setBooks(Collections.singleton(book));
PersistentResource<Book> resource = new PersistentResource<>(book, "", scope);
PermissionExecutor permissionExecutor = scope.getPermissionExecutor();
when(permissionExecutor.checkSpecificFieldPermissions(resource, null, ReadPermission.class, HOME)).thenThrow(ForbiddenAccessException.class);
VerifyFieldAccessFilterExpressionVisitor visitor = new VerifyFieldAccessFilterExpressionVisitor(resource);
// restricted HOME field
assertFalse(not.accept(visitor));
assertFalse(and1.accept(visitor));
assertFalse(and2.accept(visitor));
assertFalse(or.accept(visitor));
assertFalse(p2.accept(visitor));
// unrestricted fields
assertTrue(p1.accept(visitor));
assertTrue(p3.accept(visitor));
assertTrue(p4.accept(visitor));
verify(permissionExecutor, times(8)).evaluateFilterJoinUserChecks(any(), any());
verify(permissionExecutor, times(5)).checkSpecificFieldPermissions(resource, null, ReadPermission.class, HOME);
verify(permissionExecutor, times(9)).checkUserPermissions(any(), any(), isA(String.class));
verify(permissionExecutor, times(5)).handleFilterJoinReject(any(), any(), any());
}
use of com.yahoo.elide.core.Path in project elide by yahoo.
the class OperatorTest method constructPath.
private Path constructPath(Class<?> rootEntity, String pathString) {
List<Path.PathElement> pathElementsList = new ArrayList<>();
Type prevEntity = ClassType.of(rootEntity);
for (String field : pathString.split("\\.")) {
Type<?> fieldType = ("id".equals(field.toLowerCase(Locale.ENGLISH))) ? dictionary.getIdType(prevEntity) : dictionary.getParameterizedType(prevEntity, field);
Path.PathElement pathElement = new Path.PathElement(prevEntity, fieldType, field);
pathElementsList.add(pathElement);
prevEntity = fieldType;
}
return new Path(pathElementsList);
}
Aggregations