Search in sources :

Example 26 with TableExport

use of com.yahoo.elide.async.models.TableExport in project elide by yahoo.

the class CSVExportFormatterTest method testHeaderWithNonmatchingAlias.

@Test
public void testHeaderWithNonmatchingAlias() {
    CSVExportFormatter formatter = new CSVExportFormatter(elide, false);
    TableExport queryObj = new TableExport();
    String query = "{ tableExport { edges { node { query queryType } } } }";
    String id = "edc4a871-dff2-4054-804e-d80075cf827d";
    queryObj.setId(id);
    queryObj.setQuery(query);
    queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
    queryObj.setResultType(ResultType.CSV);
    // Prepare EntityProjection
    Set<Attribute> attributes = new LinkedHashSet<>();
    attributes.add(Attribute.builder().type(TableExport.class).name("query").alias("foo").build());
    attributes.add(Attribute.builder().type(TableExport.class).name("queryType").build());
    EntityProjection projection = EntityProjection.builder().type(TableExport.class).attributes(attributes).build();
    String output = formatter.preFormat(projection, queryObj);
    assertEquals("\"query\",\"queryType\"", output);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TableExport(com.yahoo.elide.async.models.TableExport) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Attribute(com.yahoo.elide.core.request.Attribute) Test(org.junit.jupiter.api.Test)

Example 27 with TableExport

use of com.yahoo.elide.async.models.TableExport in project elide by yahoo.

the class CSVExportFormatterTest method testHeaderSkip.

@Test
public void testHeaderSkip() {
    CSVExportFormatter formatter = new CSVExportFormatter(elide, true);
    TableExport queryObj = new TableExport();
    String query = "{ tableExport { edges { node { query queryType } } } }";
    String id = "edc4a871-dff2-4054-804e-d80075cf827d";
    queryObj.setId(id);
    queryObj.setQuery(query);
    queryObj.setQueryType(QueryType.GRAPHQL_V1_0);
    queryObj.setResultType(ResultType.CSV);
    // 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();
    String output = formatter.preFormat(projection, queryObj);
    assertNull(output);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TableExport(com.yahoo.elide.async.models.TableExport) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Attribute(com.yahoo.elide.core.request.Attribute) Test(org.junit.jupiter.api.Test)

Example 28 with TableExport

use of com.yahoo.elide.async.models.TableExport in project elide by yahoo.

the class TableExportHook method getOperation.

@Override
public Callable<AsyncAPIResult> getOperation(AsyncAPI export, RequestScope requestScope) {
    Callable<AsyncAPIResult> operation = null;
    TableExport exportObj = (TableExport) export;
    ResultType resultType = exportObj.getResultType();
    QueryType queryType = exportObj.getQueryType();
    com.yahoo.elide.core.RequestScope scope = (com.yahoo.elide.core.RequestScope) requestScope;
    TableExportFormatter formatter = supportedFormatters.get(resultType);
    if (formatter == null) {
        throw new InvalidOperationException("Formatter unavailable for " + resultType);
    }
    if (queryType.equals(QueryType.GRAPHQL_V1_0)) {
        operation = new GraphQLTableExportOperation(formatter, getAsyncExecutorService(), export, scope, engine);
    } else if (queryType.equals(QueryType.JSONAPI_V1_0)) {
        operation = new JSONAPITableExportOperation(formatter, getAsyncExecutorService(), export, scope, engine);
    } else {
        throw new InvalidOperationException(queryType + "is not supported");
    }
    return operation;
}
Also used : JSONAPITableExportOperation(com.yahoo.elide.async.operation.JSONAPITableExportOperation) ResultType(com.yahoo.elide.async.models.ResultType) RequestScope(com.yahoo.elide.core.security.RequestScope) TableExport(com.yahoo.elide.async.models.TableExport) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) GraphQLTableExportOperation(com.yahoo.elide.async.operation.GraphQLTableExportOperation) AsyncAPIResult(com.yahoo.elide.async.models.AsyncAPIResult) QueryType(com.yahoo.elide.async.models.QueryType) TableExportFormatter(com.yahoo.elide.async.export.formatter.TableExportFormatter)

Aggregations

TableExport (com.yahoo.elide.async.models.TableExport)28 Test (org.junit.jupiter.api.Test)20 TableExportResult (com.yahoo.elide.async.models.TableExportResult)13 EntityProjection (com.yahoo.elide.core.request.EntityProjection)11 JSONExportFormatter (com.yahoo.elide.async.export.formatter.JSONExportFormatter)10 Attribute (com.yahoo.elide.core.request.Attribute)9 LinkedHashSet (java.util.LinkedHashSet)8 PersistentResource (com.yahoo.elide.core.PersistentResource)4 FileExtensionType (com.yahoo.elide.async.models.FileExtensionType)3 RequestScope (com.yahoo.elide.core.RequestScope)3 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)3 Resource (com.yahoo.elide.jsonapi.models.Resource)3 Observable (io.reactivex.Observable)3 LinkedHashMap (java.util.LinkedHashMap)3 TableExportFormatter (com.yahoo.elide.async.export.formatter.TableExportFormatter)2 AsyncAPIResult (com.yahoo.elide.async.models.AsyncAPIResult)2 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 Singleton (javax.inject.Singleton)2 Getter (lombok.Getter)2