use of com.yahoo.elide.async.models.TableExport in project elide by yahoo.
the class JsonAPITableExportOperationTest method dataPrep.
/**
* Prepping and Storing an TableExport entry to be queried later on.
* @throws IOException IOException
*/
private void dataPrep() throws IOException {
TableExport temp = new TableExport();
DataStoreTransaction tx = dataStore.beginTransaction();
RequestScope scope = new RequestScope(null, null, NO_VERSION, null, tx, user, null, Collections.emptyMap(), UUID.randomUUID(), elide.getElideSettings());
tx.save(temp, scope);
tx.commit(scope);
tx.close();
}
use of com.yahoo.elide.async.models.TableExport 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;
}
use of com.yahoo.elide.async.models.TableExport in project elide by yahoo.
the class GraphQLTableExportOperationTest method testProcessQueryWithMultipleProjection.
@Test
public void testProcessQueryWithMultipleProjection() {
TableExport queryObj = new TableExport();
String query = "{\"query\":\"{ tableExport { edges { node { principalName } } } asyncQuery { edges { node { principalName } } } }\",\"variables\":null}";
String id = "edc4a871-dff2-4094-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
queryObj.setResultType(ResultType.CSV);
GraphQLTableExportOperation graphQLOperation = new GraphQLTableExportOperation(new JSONExportFormatter(elide), asyncExecutorService, queryObj, requestScope, engine);
TableExportResult queryResultObj = (TableExportResult) graphQLOperation.call();
assertEquals(200, queryResultObj.getHttpStatus());
assertEquals("Export is only supported for single Query with one root projection.", queryResultObj.getMessage());
assertNull(queryResultObj.getRecordCount());
assertNull(queryResultObj.getUrl());
}
use of com.yahoo.elide.async.models.TableExport in project elide by yahoo.
the class GraphQLTableExportOperationTest method testProcessQueryWithRelationship.
@Test
public void testProcessQueryWithRelationship() {
TableExport queryObj = new TableExport();
String query = "{\"query\":\"{ group { edges { node { name products {edges { node { name } } } } } } }\", \"variables\":null}";
String id = "edc4a871-dff2-4194-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
queryObj.setResultType(ResultType.CSV);
GraphQLTableExportOperation graphQLOperation = new GraphQLTableExportOperation(new JSONExportFormatter(elide), asyncExecutorService, queryObj, requestScope, engine);
TableExportResult queryResultObj = (TableExportResult) graphQLOperation.call();
assertEquals(200, queryResultObj.getHttpStatus());
assertEquals("Export is not supported for Query that requires traversing Relationships.", queryResultObj.getMessage());
assertNull(queryResultObj.getRecordCount());
assertNull(queryResultObj.getUrl());
}
use of com.yahoo.elide.async.models.TableExport in project elide by yahoo.
the class GraphQLTableExportOperationTest method testProcessBadQuery.
@Test
public void testProcessBadQuery() throws IOException {
dataPrep();
TableExport queryObj = new TableExport();
String query = "{\"query\":\"{ tableExport { edges { node { id principalName} } }\",\"variables\":null}";
String id = "edc4a871-dff2-4054-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
queryObj.setResultType(ResultType.CSV);
GraphQLTableExportOperation graphQLOperation = new GraphQLTableExportOperation(new JSONExportFormatter(elide), asyncExecutorService, queryObj, requestScope, engine);
TableExportResult queryResultObj = (TableExportResult) graphQLOperation.call();
assertEquals(200, queryResultObj.getHttpStatus());
assertEquals("Bad Request Body'Can't parse query: { tableExport { edges { node { id principalName} } }'", queryResultObj.getMessage());
}
Aggregations