Search in sources :

Example 6 with InvalidOperationException

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

the class GraphQLAsyncQueryOperation method execute.

@Override
public ElideResponse execute(AsyncAPI queryObj, RequestScope scope) throws URISyntaxException {
    User user = scope.getUser();
    String apiVersion = scope.getApiVersion();
    QueryRunner runner = getService().getRunners().get(apiVersion);
    if (runner == null) {
        throw new InvalidOperationException("Invalid API Version");
    }
    UUID requestUUID = UUID.fromString(queryObj.getRequestId());
    // TODO - we need to add the baseUrlEndpoint to the queryObject.
    ElideResponse response = runner.run("", queryObj.getQuery(), user, requestUUID, scope.getRequestHeaders());
    log.debug("GRAPHQL_V1_0 getResponseCode: {}, GRAPHQL_V1_0 getBody: {}", response.getResponseCode(), response.getBody());
    return response;
}
Also used : User(com.yahoo.elide.core.security.User) ElideResponse(com.yahoo.elide.ElideResponse) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) UUID(java.util.UUID) QueryRunner(com.yahoo.elide.graphql.QueryRunner)

Example 7 with InvalidOperationException

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

the class DefaultQueryValidator method validatePredicate.

protected void validatePredicate(Query query, FilterPredicate predicate) {
    SQLTable table = (SQLTable) query.getSource();
    Set<ColumnProjection> projections = extractFilterProjections(query, predicate);
    if (projections.isEmpty()) {
        return;
    }
    ColumnProjection projection = projections.iterator().next();
    validateColumn(query, projection);
    Column column = table.getColumn(Column.class, projection.getName());
    if (column.getValueType().equals(ValueType.ID)) {
        throw new InvalidOperationException("Filtering by ID is not supported on " + query.getSource().getName());
    }
    if (column.getValues() == null || column.getValues().isEmpty()) {
        return;
    }
    if (REGEX_OPERATORS.contains(predicate.getOperator())) {
        return;
    }
    predicate.getValues().forEach(value -> {
        if (!column.getValues().contains(value)) {
            throw new InvalidOperationException(String.format("Column '%s' values must match one of these values: %s", projection.getAlias(), column.getValues()));
        }
    });
}
Also used : Column(com.yahoo.elide.datastores.aggregation.metadata.models.Column) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) ColumnProjection(com.yahoo.elide.datastores.aggregation.query.ColumnProjection) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException)

Example 8 with InvalidOperationException

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

the class DefaultQueryValidatorTest method validateQuery.

private void validateQuery(Query query, String message) {
    DefaultQueryValidator validator = new DefaultQueryValidator(dictionary);
    InvalidOperationException exception = assertThrows(InvalidOperationException.class, () -> validator.validate(query));
    assertEquals(message, exception.getMessage());
}
Also used : InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException)

Example 9 with InvalidOperationException

use of com.yahoo.elide.core.exceptions.InvalidOperationException 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)

Example 10 with InvalidOperationException

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

the class GraphQLEndpoint method post.

/**
 * Create handler.
 * @param uriInfo URI info
 * @param headers the request headers
 * @param securityContext security context
 * @param graphQLDocument post data as jsonapi document
 * @return response
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response post(@Context UriInfo uriInfo, @Context HttpHeaders headers, @Context SecurityContext securityContext, String graphQLDocument) {
    String apiVersion = HeaderUtils.resolveApiVersion(headers.getRequestHeaders());
    Map<String, List<String>> requestHeaders = HeaderUtils.lowercaseAndRemoveAuthHeaders(headers.getRequestHeaders());
    User user = new SecurityContextUser(securityContext);
    QueryRunner runner = runners.getOrDefault(apiVersion, null);
    ElideResponse response;
    if (runner == null) {
        response = buildErrorResponse(elide.getMapper().getObjectMapper(), new InvalidOperationException("Invalid API Version"), false);
    } else {
        response = runner.run(getBaseUrlEndpoint(uriInfo), graphQLDocument, user, UUID.randomUUID(), requestHeaders);
    }
    return Response.status(response.getResponseCode()).entity(response.getBody()).build();
}
Also used : User(com.yahoo.elide.core.security.User) SecurityContextUser(com.yahoo.elide.jsonapi.resources.SecurityContextUser) ElideResponse(com.yahoo.elide.ElideResponse) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) SecurityContextUser(com.yahoo.elide.jsonapi.resources.SecurityContextUser) List(java.util.List) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

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