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;
}
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()));
}
});
}
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());
}
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;
}
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();
}
Aggregations