use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class EntityProjectionTranslator method resolveNonTimeDimensions.
/**
* Gets dimensions except time dimensions based on relationships and attributes from {@link EntityProjection}.
*/
private Set<DimensionProjection> resolveNonTimeDimensions() {
Set<DimensionProjection> attributes = entityProjection.getAttributes().stream().filter(attribute -> queriedTable.getTimeDimension(attribute.getName()) == null).map(dimAttr -> {
Dimension dimension = queriedTable.getDimension(dimAttr.getName());
return dimension == null ? null : engine.constructDimensionProjection(dimension, dimAttr.getAlias(), getArgumentMapFromArgumentSet(dimAttr.getArguments()));
}).filter(Objects::nonNull).collect(Collectors.toSet());
Set<DimensionProjection> relationships = entityProjection.getRelationships().stream().map(dimAttr -> {
Dimension dimension = queriedTable.getDimension(dimAttr.getName());
return dimension == null ? null : engine.constructDimensionProjection(dimension, dimAttr.getAlias(), Collections.emptyMap());
}).filter(Objects::nonNull).collect(Collectors.toSet());
return Sets.union(attributes, relationships);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class InMemoryStoreTransactionTest method testSortOnComplexAttribute.
@Test
public void testSortOnComplexAttribute() {
Map<String, Sorting.SortOrder> sortOrder = new HashMap<>();
sortOrder.put("homeAddress.street1", Sorting.SortOrder.asc);
Sorting sorting = new SortingImpl(sortOrder, Author.class, dictionary);
EntityProjection projection = EntityProjection.builder().type(Author.class).sorting(sorting).build();
DataStoreIterable sortInMemory = new DataStoreIterableBuilder(Arrays.asList(author1, author2)).sortInMemory(true).build();
when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(sortInMemory);
Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
assertEquals(2, loaded.size());
Object[] sorted = loaded.toArray();
assertEquals(author2, sorted[0]);
assertEquals(author1, sorted[1]);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class InMemoryStoreTransactionTest method testSortingRequiresInMemoryPagination.
@Test
public void testSortingRequiresInMemoryPagination() {
PaginationImpl pagination = new PaginationImpl(ClassType.of(Book.class), 0, 3, 10, 10, true, false);
Map<String, Sorting.SortOrder> sortOrder = new HashMap<>();
sortOrder.put("title", Sorting.SortOrder.desc);
Sorting sorting = new SortingImpl(sortOrder, Book.class, dictionary);
EntityProjection projection = EntityProjection.builder().type(Book.class).sorting(sorting).pagination(pagination).build();
DataStoreIterable sortInMemory = new DataStoreIterableBuilder(books).sortInMemory(true).build();
when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(sortInMemory);
Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
verify(wrappedTransaction, times(1)).loadObjects(any(EntityProjection.class), eq(scope));
assertEquals(3, loaded.size());
List<String> bookTitles = loaded.stream().map((o) -> ((Book) o).getTitle()).collect(Collectors.toList());
assertEquals(Lists.newArrayList("Book 3", "Book 2", "Book 1"), bookTitles);
assertEquals(3, pagination.getPageTotals());
}
use of com.yahoo.elide.core.request.EntityProjection 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.request.EntityProjection in project elide by yahoo.
the class PersistentResourceTest method testLoadRecordForbidden.
@Test
public void testLoadRecordForbidden() {
NoReadEntity noRead = new NoReadEntity();
noRead.setId(1);
EntityProjection collection = EntityProjection.builder().type(NoReadEntity.class).build();
when(tx.loadObject(eq(collection), eq(1L), any())).thenReturn(noRead);
RequestScope goodScope = buildRequestScope(tx, goodUser);
goodScope.setEntityProjection(collection);
assertThrows(ForbiddenAccessException.class, () -> PersistentResource.loadRecord(EntityProjection.builder().type(NoReadEntity.class).build(), "1", goodScope));
}
Aggregations