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