Search in sources :

Example 6 with JSONExportFormatter

use of com.yahoo.elide.async.export.formatter.JSONExportFormatter in project elide by yahoo.

the class ElideAsyncConfiguration method buildAsyncExecutorService.

/**
 * Configure the AsyncExecutorService used for submitting async query requests.
 * @param elide elideObject.
 * @param settings Elide settings.
 * @param asyncQueryDao AsyncDao object.
 * @return a AsyncExecutorService.
 */
@Bean
@ConditionalOnMissingBean
public AsyncExecutorService buildAsyncExecutorService(RefreshableElide elide, ElideConfigProperties settings, AsyncAPIDAO asyncQueryDao, @Autowired(required = false) ResultStorageEngine resultStorageEngine) {
    AsyncProperties asyncProperties = settings.getAsync();
    ExecutorService executor = Executors.newFixedThreadPool(asyncProperties.getThreadPoolSize());
    ExecutorService updater = Executors.newFixedThreadPool(asyncProperties.getThreadPoolSize());
    AsyncExecutorService asyncExecutorService = new AsyncExecutorService(elide.getElide(), executor, updater, asyncQueryDao);
    // Binding AsyncQuery LifeCycleHook
    AsyncQueryHook asyncQueryHook = new AsyncQueryHook(asyncExecutorService, asyncProperties.getMaxAsyncAfterSeconds());
    EntityDictionary dictionary = elide.getElide().getElideSettings().getDictionary();
    dictionary.bindTrigger(AsyncQuery.class, CREATE, PREFLUSH, asyncQueryHook, false);
    dictionary.bindTrigger(AsyncQuery.class, CREATE, POSTCOMMIT, asyncQueryHook, false);
    dictionary.bindTrigger(AsyncQuery.class, CREATE, PRESECURITY, asyncQueryHook, false);
    boolean exportEnabled = ElideAutoConfiguration.isExportEnabled(asyncProperties);
    if (exportEnabled) {
        // Initialize the Formatters.
        boolean skipCSVHeader = asyncProperties.getExport() != null && asyncProperties.getExport().isSkipCSVHeader();
        Map<ResultType, TableExportFormatter> supportedFormatters = new HashMap<>();
        supportedFormatters.put(ResultType.CSV, new CSVExportFormatter(elide.getElide(), skipCSVHeader));
        supportedFormatters.put(ResultType.JSON, new JSONExportFormatter(elide.getElide()));
        // Binding TableExport LifeCycleHook
        TableExportHook tableExportHook = getTableExportHook(asyncExecutorService, settings, supportedFormatters, resultStorageEngine);
        dictionary.bindTrigger(TableExport.class, CREATE, PREFLUSH, tableExportHook, false);
        dictionary.bindTrigger(TableExport.class, CREATE, POSTCOMMIT, tableExportHook, false);
        dictionary.bindTrigger(TableExport.class, CREATE, PRESECURITY, tableExportHook, false);
    }
    return asyncExecutorService;
}
Also used : TableExportHook(com.yahoo.elide.async.hooks.TableExportHook) HashMap(java.util.HashMap) AsyncQueryHook(com.yahoo.elide.async.hooks.AsyncQueryHook) JSONExportFormatter(com.yahoo.elide.async.export.formatter.JSONExportFormatter) ResultType(com.yahoo.elide.async.models.ResultType) CSVExportFormatter(com.yahoo.elide.async.export.formatter.CSVExportFormatter) AsyncExecutorService(com.yahoo.elide.async.service.AsyncExecutorService) ExecutorService(java.util.concurrent.ExecutorService) AsyncExecutorService(com.yahoo.elide.async.service.AsyncExecutorService) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) TableExportFormatter(com.yahoo.elide.async.export.formatter.TableExportFormatter) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 7 with JSONExportFormatter

use of com.yahoo.elide.async.export.formatter.JSONExportFormatter 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());
}
Also used : TableExport(com.yahoo.elide.async.models.TableExport) JSONExportFormatter(com.yahoo.elide.async.export.formatter.JSONExportFormatter) TableExportResult(com.yahoo.elide.async.models.TableExportResult) Test(org.junit.jupiter.api.Test)

Example 8 with JSONExportFormatter

use of com.yahoo.elide.async.export.formatter.JSONExportFormatter 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());
}
Also used : TableExport(com.yahoo.elide.async.models.TableExport) JSONExportFormatter(com.yahoo.elide.async.export.formatter.JSONExportFormatter) TableExportResult(com.yahoo.elide.async.models.TableExportResult) Test(org.junit.jupiter.api.Test)

Example 9 with JSONExportFormatter

use of com.yahoo.elide.async.export.formatter.JSONExportFormatter 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());
}
Also used : TableExport(com.yahoo.elide.async.models.TableExport) JSONExportFormatter(com.yahoo.elide.async.export.formatter.JSONExportFormatter) TableExportResult(com.yahoo.elide.async.models.TableExportResult) Test(org.junit.jupiter.api.Test)

Example 10 with JSONExportFormatter

use of com.yahoo.elide.async.export.formatter.JSONExportFormatter in project elide by yahoo.

the class JsonAPITableExportOperationTest method testProcessQueryWithRelationship.

@Test
public void testProcessQueryWithRelationship() {
    TableExport queryObj = new TableExport();
    String query = "/group?fields[group]=products";
    String id = "edc4a871-dff2-4194-804e-d80075cf827d";
    queryObj.setId(id);
    queryObj.setQuery(query);
    queryObj.setQueryType(QueryType.JSONAPI_V1_0);
    queryObj.setResultType(ResultType.CSV);
    JSONAPITableExportOperation jsonAPIOperation = new JSONAPITableExportOperation(new JSONExportFormatter(elide), asyncExecutorService, queryObj, requestScope, engine);
    TableExportResult queryResultObj = (TableExportResult) jsonAPIOperation.call();
    assertEquals(200, queryResultObj.getHttpStatus());
    assertEquals("Export is not supported for Query that requires traversing Relationships.", queryResultObj.getMessage());
    assertNull(queryResultObj.getRecordCount());
    assertNull(queryResultObj.getUrl());
}
Also used : TableExport(com.yahoo.elide.async.models.TableExport) JSONExportFormatter(com.yahoo.elide.async.export.formatter.JSONExportFormatter) TableExportResult(com.yahoo.elide.async.models.TableExportResult) Test(org.junit.jupiter.api.Test)

Aggregations

JSONExportFormatter (com.yahoo.elide.async.export.formatter.JSONExportFormatter)11 TableExport (com.yahoo.elide.async.models.TableExport)10 TableExportResult (com.yahoo.elide.async.models.TableExportResult)10 Test (org.junit.jupiter.api.Test)10 CSVExportFormatter (com.yahoo.elide.async.export.formatter.CSVExportFormatter)1 TableExportFormatter (com.yahoo.elide.async.export.formatter.TableExportFormatter)1 AsyncQueryHook (com.yahoo.elide.async.hooks.AsyncQueryHook)1 TableExportHook (com.yahoo.elide.async.hooks.TableExportHook)1 ResultType (com.yahoo.elide.async.models.ResultType)1 AsyncExecutorService (com.yahoo.elide.async.service.AsyncExecutorService)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1