use of com.yahoo.elide.async.models.TableExport in project elide by yahoo.
the class JSONExportFormatterTest method testFormat.
@Test
public void testFormat() {
JSONExportFormatter formatter = new JSONExportFormatter(elide);
TableExport queryObj = new TableExport();
String query = "{ tableExport { edges { node { query queryType createdOn} } } }";
String id = "edc4a871-dff2-4054-804e-d80075cf827d";
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
queryObj.setResultType(ResultType.CSV);
String start = "{\"query\":\"{ tableExport { edges { node { query queryType createdOn} } } }\"," + "\"queryType\":\"GRAPHQL_V1_0\",\"createdOn\":\"" + FORMATTER.format(queryObj.getCreatedOn()) + "\"}";
// Prepare EntityProjection
Set<Attribute> attributes = new LinkedHashSet<>();
attributes.add(Attribute.builder().type(TableExport.class).name("query").alias("query").build());
attributes.add(Attribute.builder().type(TableExport.class).name("queryType").build());
attributes.add(Attribute.builder().type(TableExport.class).name("createdOn").build());
EntityProjection projection = EntityProjection.builder().type(TableExport.class).attributes(attributes).build();
Map<String, Object> resourceAttributes = new LinkedHashMap<>();
resourceAttributes.put("query", query);
resourceAttributes.put("queryType", queryObj.getQueryType());
resourceAttributes.put("createdOn", queryObj.getCreatedOn());
Resource resource = new Resource("tableExport", "0", resourceAttributes, null, null, null);
PersistentResource persistentResource = mock(PersistentResource.class);
when(persistentResource.getObject()).thenReturn(queryObj);
when(persistentResource.getRequestScope()).thenReturn(scope);
when(persistentResource.toResource(any(), any())).thenReturn(resource);
when(scope.getEntityProjection()).thenReturn(projection);
String output = formatter.format(persistentResource, 1);
assertTrue(output.contains(start));
}
use of com.yahoo.elide.async.models.TableExport in project elide by yahoo.
the class JSONExportFormatterTest method testResourceToJSON.
@Test
public void testResourceToJSON() {
JSONExportFormatter formatter = new JSONExportFormatter(elide);
TableExport queryObj = new TableExport();
String id = "edc4a871-dff2-4054-804e-d80075cf827d";
queryObj.setId(id);
String start = "{\"query\":\"{ tableExport { edges { node { query queryType} } } }\"," + "\"queryType\":\"GRAPHQL_V1_0\"}";
// Prepare EntityProjection
Set<Attribute> attributes = new LinkedHashSet<>();
attributes.add(Attribute.builder().type(TableExport.class).name("query").alias("query").build());
attributes.add(Attribute.builder().type(TableExport.class).name("queryType").build());
EntityProjection projection = EntityProjection.builder().type(TableExport.class).attributes(attributes).build();
Map<String, Object> resourceAttributes = new LinkedHashMap<>();
resourceAttributes.put("query", "{ tableExport { edges { node { query queryType} } } }");
resourceAttributes.put("queryType", QueryType.GRAPHQL_V1_0);
Resource resource = new Resource("tableExport", "0", resourceAttributes, null, null, null);
PersistentResource persistentResource = mock(PersistentResource.class);
when(persistentResource.getObject()).thenReturn(queryObj);
when(persistentResource.getRequestScope()).thenReturn(scope);
when(persistentResource.toResource(any(), any())).thenReturn(resource);
when(scope.getEntityProjection()).thenReturn(projection);
String output = formatter.resourceToJSON(elide.getMapper().getObjectMapper(), persistentResource);
assertTrue(output.contains(start));
}
use of com.yahoo.elide.async.models.TableExport in project elide by yahoo.
the class FileResultStorageEngine method storeResults.
@Override
public TableExportResult storeResults(TableExport tableExport, Observable<String> result) {
log.debug("store TableExportResults for Download");
String extension = this.isExtensionEnabled() ? tableExport.getResultType().getFileExtensionType().getExtension() : FileExtensionType.NONE.getExtension();
TableExportResult exportResult = new TableExportResult();
try (BufferedWriter writer = getWriter(tableExport.getId(), extension)) {
result.map(record -> record.concat(System.lineSeparator())).subscribe(recordCharArray -> {
writer.write(recordCharArray);
writer.flush();
}, throwable -> {
StringBuilder message = new StringBuilder();
message.append(throwable.getClass().getCanonicalName()).append(" : ");
message.append(throwable.getMessage());
exportResult.setMessage(message.toString());
throw new IllegalStateException(STORE_ERROR, throwable);
}, writer::flush);
} catch (IOException e) {
throw new IllegalStateException(STORE_ERROR, e);
}
return exportResult;
}
use of com.yahoo.elide.async.models.TableExport in project elide by yahoo.
the class RedisResultStorageEngine method storeResults.
@Override
public TableExportResult storeResults(TableExport tableExport, Observable<String> result) {
log.debug("store TableExportResults for Download");
String extension = this.isExtensionEnabled() ? tableExport.getResultType().getFileExtensionType().getExtension() : FileExtensionType.NONE.getExtension();
TableExportResult exportResult = new TableExportResult();
String key = tableExport.getId() + extension;
result.map(record -> record).subscribe(recordCharArray -> {
jedis.rpush(key, recordCharArray);
}, throwable -> {
StringBuilder message = new StringBuilder();
message.append(throwable.getClass().getCanonicalName()).append(" : ");
message.append(throwable.getMessage());
exportResult.setMessage(message.toString());
throw new IllegalStateException(STORE_ERROR, throwable);
});
jedis.expire(key, expirationSeconds);
return exportResult;
}
use of com.yahoo.elide.async.models.TableExport in project elide by yahoo.
the class GraphQLTableExportOperationTest method testProcessMultipleQuery.
@Test
public void testProcessMultipleQuery() {
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());
}
Aggregations