
com.yahoo.elide.async.hooks.TableExportHook Maven / Gradle / Ivy
/*
* Copyright 2020, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.async.hooks;
import com.yahoo.elide.annotation.LifeCycleHookBinding.Operation;
import com.yahoo.elide.annotation.LifeCycleHookBinding.TransactionPhase;
import com.yahoo.elide.async.export.formatter.TableExportFormatter;
import com.yahoo.elide.async.models.AsyncAPI;
import com.yahoo.elide.async.models.AsyncAPIResult;
import com.yahoo.elide.async.models.QueryType;
import com.yahoo.elide.async.models.ResultType;
import com.yahoo.elide.async.models.TableExport;
import com.yahoo.elide.async.operation.GraphQLTableExportOperation;
import com.yahoo.elide.async.operation.JSONAPITableExportOperation;
import com.yahoo.elide.async.service.AsyncExecutorService;
import com.yahoo.elide.async.service.storageengine.ResultStorageEngine;
import com.yahoo.elide.core.exceptions.InvalidOperationException;
import com.yahoo.elide.core.security.ChangeSpec;
import com.yahoo.elide.core.security.RequestScope;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
/**
* LifeCycle Hook for execution of TableExpoer.
*/
public class TableExportHook extends AsyncAPIHook {
Map supportedFormatters;
ResultStorageEngine engine;
public TableExportHook (AsyncExecutorService asyncExecutorService, Integer maxAsyncAfterSeconds,
Map supportedFormatters, ResultStorageEngine engine) {
super(asyncExecutorService, maxAsyncAfterSeconds);
this.supportedFormatters = supportedFormatters;
this.engine = engine;
}
@Override
public void execute(Operation operation, TransactionPhase phase, TableExport export, RequestScope requestScope,
Optional changes) {
Callable callable = getOperation(export, requestScope);
executeHook(operation, phase, export, requestScope, callable);
}
@Override
public void validateOptions(AsyncAPI export, RequestScope requestScope) {
super.validateOptions(export, requestScope);
}
@Override
public Callable getOperation(AsyncAPI export, RequestScope requestScope) {
Callable 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;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy