use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class InMemoryStoreTransactionTest method testDataStoreRequiresInMemorySorting.
@Test
public void testDataStoreRequiresInMemorySorting() {
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).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(bookTitles, Lists.newArrayList("Book 3", "Book 2", "Book 1"));
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class InMemoryStoreTransactionTest method testSortingPushDown.
@Test
public void testSortingPushDown() {
Map<String, Sorting.SortOrder> sortOrder = new HashMap<>();
sortOrder.put("title", Sorting.SortOrder.asc);
Sorting sorting = new SortingImpl(sortOrder, Book.class, dictionary);
EntityProjection projection = EntityProjection.builder().type(Book.class).sorting(sorting).build();
DataStoreIterable expected = new DataStoreIterableBuilder<>(books).build();
when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(expected);
DataStoreIterable actual = inMemoryStoreTransaction.loadObjects(projection, scope);
verify(wrappedTransaction, times(1)).loadObjects(eq(projection), eq(scope));
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class InMemoryStoreTransactionTest method testPaginationPushDown.
@Test
public void testPaginationPushDown() {
PaginationImpl pagination = new PaginationImpl(ClassType.of(Book.class), 0, 1, 10, 10, false, false);
EntityProjection projection = EntityProjection.builder().type(Book.class).pagination(pagination).build();
ArgumentCaptor<EntityProjection> projectionArgument = ArgumentCaptor.forClass(EntityProjection.class);
when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(new DataStoreIterableBuilder<>(books).build());
Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
verify(wrappedTransaction, times(1)).loadObjects(projectionArgument.capture(), eq(scope));
assertEquals(pagination, projectionArgument.getValue().getPagination());
assertEquals(3, loaded.size());
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class JSONAPITableExportOperation method getProjections.
@Override
public Collection<EntityProjection> getProjections(TableExport export, RequestScope scope) {
EntityProjection projection = null;
try {
URIBuilder uri = new URIBuilder(export.getQuery());
Elide elide = getService().getElide();
projection = new EntityProjectionMaker(elide.getElideSettings().getDictionary(), scope).parsePath(JSONAPIAsyncQueryOperation.getPath(uri));
} catch (URISyntaxException e) {
throw new BadRequestException(e.getMessage());
}
return Collections.singletonList(projection);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class TableExportOperation method call.
@Override
public AsyncAPIResult call() {
log.debug("TableExport Object from request: {}", exportObj);
Elide elide = service.getElide();
TableExportResult exportResult = new TableExportResult();
UUID requestId = UUID.fromString(exportObj.getRequestId());
try (DataStoreTransaction tx = elide.getDataStore().beginTransaction()) {
// Do Not Cache Export Results
Map<String, List<String>> requestHeaders = new HashMap<String, List<String>>();
requestHeaders.put("bypasscache", new ArrayList<String>(Arrays.asList("true")));
RequestScope requestScope = getRequestScope(exportObj, scope, tx, requestHeaders);
Collection<EntityProjection> projections = getProjections(exportObj, requestScope);
validateProjections(projections);
EntityProjection projection = projections.iterator().next();
Observable<PersistentResource> observableResults = Observable.empty();
elide.getTransactionRegistry().addRunningTransaction(requestId, tx);
// TODO - we need to add the baseUrlEndpoint to the queryObject.
// TODO - Can we have projectionInfo as null?
requestScope.setEntityProjection(projection);
if (projection != null) {
projection.setPagination(null);
observableResults = PersistentResource.loadRecords(projection, Collections.emptyList(), requestScope);
}
Observable<String> results = Observable.empty();
String preResult = formatter.preFormat(projection, exportObj);
results = observableResults.map(resource -> {
this.recordNumber++;
return formatter.format(resource, recordNumber);
});
String postResult = formatter.postFormat(projection, exportObj);
// Stitch together Pre-Formatted, Formatted, Post-Formatted results of Formatter in single observable.
Observable<String> interimResults = concatStringWithObservable(preResult, results, true);
Observable<String> finalResults = concatStringWithObservable(postResult, interimResults, false);
TableExportResult result = storeResults(exportObj, engine, finalResults);
if (result != null && result.getMessage() != null) {
throw new IllegalStateException(result.getMessage());
}
exportResult.setUrl(new URL(generateDownloadURL(exportObj, scope)));
exportResult.setRecordCount(recordNumber);
tx.flush(requestScope);
elide.getAuditLogger().commit();
tx.commit(requestScope);
} catch (BadRequestException e) {
exportResult.setMessage(e.getMessage());
} catch (MalformedURLException e) {
exportResult.setMessage("Download url generation failure.");
} catch (IOException e) {
log.error("IOException during TableExport", e);
exportResult.setMessage(e.getMessage());
} catch (Exception e) {
exportResult.setMessage(e.getMessage());
} finally {
// Follows same flow as GraphQL. The query may result in failure but request was successfully processed.
exportResult.setHttpStatus(200);
exportResult.setCompletedOn(new Date());
elide.getTransactionRegistry().removeRunningTransaction(requestId);
elide.getAuditLogger().clear();
}
return exportResult;
}
Aggregations