Search in sources :

Example 1 with InvalidOperationException

use of com.yahoo.elide.core.exceptions.InvalidOperationException in project elide by yahoo.

the class AggregationDataStoreTransaction method throwReadOnlyException.

private <T> void throwReadOnlyException(T entity) {
    EntityDictionary dictionary = metaDataStore.getMetadataDictionary();
    Type<?> type = dictionary.getType(entity);
    throw new InvalidOperationException(dictionary.getJsonAliasFor(type) + " is read only.");
}
Also used : InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 2 with InvalidOperationException

use of com.yahoo.elide.core.exceptions.InvalidOperationException in project elide by yahoo.

the class DefaultQueryValidator method validateHavingClause.

@Override
public void validateHavingClause(Query query) {
    FilterExpression havingClause = query.getHavingFilter();
    if (havingClause == null) {
        return;
    }
    havingClause.accept(new PredicateExtractionVisitor()).forEach(predicate -> {
        Path path = predicate.getPath();
        if (path.getPathElements().size() > 1) {
            throw new InvalidOperationException("Relationship traversal not supported for analytic queries.");
        }
        validatePredicate(query, predicate);
        extractFilterProjections(query, havingClause).stream().forEach(projection -> {
            Predicate<ColumnProjection> filterByNameAndArgs = (column) -> (column.getAlias().equals(projection.getAlias()) || column.getName().equals(projection.getName())) && column.getArguments().equals(projection.getArguments());
            // Query by (alias or name) and arguments.   The filter may or may not be using the alias.
            if (query.getColumnProjection(filterByNameAndArgs) == null) {
                Predicate<ColumnProjection> filterByName = (column) -> (column.getAlias().equals(projection.getAlias()) || column.getName().equals(projection.getName()));
                // The column wasn't projected at all.
                if (query.getColumnProjection(filterByName) == null) {
                    throw new InvalidOperationException(String.format("Post aggregation filtering on '%s' requires the field to be projected in the response", projection.getAlias()));
                // The column was projected but arguments didn't match.
                } else {
                    throw new InvalidOperationException(String.format("Post aggregation filtering on '%s' requires the field to be projected " + "in the response with matching arguments", projection.getAlias()));
                }
            }
        });
    });
}
Also used : Path(com.yahoo.elide.core.Path) PredicateExtractionVisitor(com.yahoo.elide.core.filter.expression.PredicateExtractionVisitor) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Path(com.yahoo.elide.core.Path) Queryable.extractFilterProjections(com.yahoo.elide.datastores.aggregation.query.Queryable.extractFilterProjections) Argument(com.yahoo.elide.core.request.Argument) HashSet(java.util.HashSet) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) Map(java.util.Map) Column(com.yahoo.elide.datastores.aggregation.metadata.models.Column) ColumnProjection(com.yahoo.elide.datastores.aggregation.query.ColumnProjection) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) LinkedHashSet(java.util.LinkedHashSet) Sorting(com.yahoo.elide.core.request.Sorting) Predicate(java.util.function.Predicate) ValueType(com.yahoo.elide.datastores.aggregation.metadata.enums.ValueType) ArgumentDefinition(com.yahoo.elide.datastores.aggregation.metadata.models.ArgumentDefinition) Set(java.util.Set) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Query(com.yahoo.elide.datastores.aggregation.query.Query) List(java.util.List) Stream(java.util.stream.Stream) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) Type(com.yahoo.elide.core.type.Type) Operator(com.yahoo.elide.core.filter.Operator) Optional(java.util.Optional) ColumnProjection(com.yahoo.elide.datastores.aggregation.query.ColumnProjection) PredicateExtractionVisitor(com.yahoo.elide.core.filter.expression.PredicateExtractionVisitor) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression)

Example 3 with InvalidOperationException

use of com.yahoo.elide.core.exceptions.InvalidOperationException in project elide by yahoo.

the class DefaultQueryValidator method validateWhereClause.

@Override
public void validateWhereClause(Query query) {
    FilterExpression whereClause = query.getWhereFilter();
    if (whereClause == null) {
        return;
    }
    whereClause.accept(new PredicateExtractionVisitor()).forEach(predicate -> {
        Path path = predicate.getPath();
        if (path.getPathElements().size() > 1) {
            throw new InvalidOperationException("Relationship traversal not supported for analytic queries.");
        }
        validatePredicate(query, predicate);
    });
}
Also used : Path(com.yahoo.elide.core.Path) PredicateExtractionVisitor(com.yahoo.elide.core.filter.expression.PredicateExtractionVisitor) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression)

Example 4 with InvalidOperationException

use of com.yahoo.elide.core.exceptions.InvalidOperationException in project elide by yahoo.

the class ElideAsyncConfiguration method getTableExportHook.

// TODO Remove this method when ElideSettings has all the settings.
// Then the check can be done in TableExportHook.
// Trying to avoid adding too many individual properties to ElideSettings for now.
// https://github.com/yahoo/elide/issues/1803
private TableExportHook getTableExportHook(AsyncExecutorService asyncExecutorService, ElideConfigProperties settings, Map<ResultType, TableExportFormatter> supportedFormatters, ResultStorageEngine resultStorageEngine) {
    boolean exportEnabled = ElideAutoConfiguration.isExportEnabled(settings.getAsync());
    TableExportHook tableExportHook = null;
    if (exportEnabled) {
        tableExportHook = new TableExportHook(asyncExecutorService, settings.getAsync().getMaxAsyncAfterSeconds(), supportedFormatters, resultStorageEngine);
    } else {
        tableExportHook = new TableExportHook(asyncExecutorService, settings.getAsync().getMaxAsyncAfterSeconds(), supportedFormatters, resultStorageEngine) {

            @Override
            public void validateOptions(AsyncAPI export, RequestScope requestScope) {
                throw new InvalidOperationException("TableExport is not supported.");
            }
        };
    }
    return tableExportHook;
}
Also used : AsyncAPI(com.yahoo.elide.async.models.AsyncAPI) TableExportHook(com.yahoo.elide.async.hooks.TableExportHook) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) RequestScope(com.yahoo.elide.core.security.RequestScope)

Example 5 with InvalidOperationException

use of com.yahoo.elide.core.exceptions.InvalidOperationException in project elide by yahoo.

the class GraphqlController method post.

/**
 * Single entry point for GraphQL requests.
 *
 * @param requestHeaders request headers
 * @param graphQLDocument post data as json document
 * @param principal The user principal
 * @return response
 */
@PostMapping(value = { "/**", "" }, consumes = JSON_CONTENT_TYPE, produces = JSON_CONTENT_TYPE)
public Callable<ResponseEntity<String>> post(@RequestHeader HttpHeaders requestHeaders, @RequestBody String graphQLDocument, Authentication principal) {
    final User user = new AuthenticationUser(principal);
    final String apiVersion = HeaderUtils.resolveApiVersion(requestHeaders);
    final Map<String, List<String>> requestHeadersCleaned = HeaderUtils.lowercaseAndRemoveAuthHeaders(requestHeaders);
    final QueryRunner runner = runners.getRunner(apiVersion);
    final String baseUrl = getBaseUrlEndpoint();
    return new Callable<ResponseEntity<String>>() {

        @Override
        public ResponseEntity<String> call() throws Exception {
            ElideResponse response;
            if (runner == null) {
                response = buildErrorResponse(mapper, new InvalidOperationException("Invalid API Version"), false);
            } else {
                Elide elide = runner.getElide();
                response = runner.run(baseUrl, graphQLDocument, user, UUID.randomUUID(), requestHeadersCleaned);
            }
            return ResponseEntity.status(response.getResponseCode()).body(response.getBody());
        }
    };
}
Also used : User(com.yahoo.elide.core.security.User) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) ElideResponse(com.yahoo.elide.ElideResponse) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) List(java.util.List) Elide(com.yahoo.elide.Elide) AuthenticationUser(com.yahoo.elide.spring.security.AuthenticationUser) QueryRunner(com.yahoo.elide.graphql.QueryRunner) Callable(java.util.concurrent.Callable) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

InvalidOperationException (com.yahoo.elide.core.exceptions.InvalidOperationException)10 ElideResponse (com.yahoo.elide.ElideResponse)3 User (com.yahoo.elide.core.security.User)3 List (java.util.List)3 Path (com.yahoo.elide.core.Path)2 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)2 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)2 PredicateExtractionVisitor (com.yahoo.elide.core.filter.expression.PredicateExtractionVisitor)2 RequestScope (com.yahoo.elide.core.security.RequestScope)2 Column (com.yahoo.elide.datastores.aggregation.metadata.models.Column)2 ColumnProjection (com.yahoo.elide.datastores.aggregation.query.ColumnProjection)2 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)2 QueryRunner (com.yahoo.elide.graphql.QueryRunner)2 Elide (com.yahoo.elide.Elide)1 TableExportFormatter (com.yahoo.elide.async.export.formatter.TableExportFormatter)1 TableExportHook (com.yahoo.elide.async.hooks.TableExportHook)1 AsyncAPI (com.yahoo.elide.async.models.AsyncAPI)1 AsyncAPIResult (com.yahoo.elide.async.models.AsyncAPIResult)1 QueryType (com.yahoo.elide.async.models.QueryType)1 ResultType (com.yahoo.elide.async.models.ResultType)1