use of com.yahoo.elide.core.filter.expression.AndFilterExpression in project elide by yahoo.
the class PersistentResource method getRelationUnchecked.
/**
* Retrieve an unchecked set of relations.
*/
private Observable<PersistentResource> getRelationUnchecked(com.yahoo.elide.core.request.Relationship relationship) {
String relationName = relationship.getName();
FilterExpression filterExpression = relationship.getProjection().getFilterExpression();
Pagination pagination = relationship.getProjection().getPagination();
Sorting sorting = relationship.getProjection().getSorting();
RelationshipType type = getRelationshipType(relationName);
final Type<?> relationClass = dictionary.getParameterizedType(obj, relationName);
if (relationClass == null) {
throw new InvalidAttributeException(relationName, this.getTypeName());
}
// Invoke filterExpressionCheck and then merge with filterExpression.
Optional<FilterExpression> permissionFilter = getPermissionFilterExpression(relationClass, requestScope, relationship.getProjection().getRequestedFields());
Optional<FilterExpression> computedFilters = Optional.ofNullable(filterExpression);
if (permissionFilter.isPresent() && filterExpression != null) {
FilterExpression mergedExpression = new AndFilterExpression(filterExpression, permissionFilter.get());
computedFilters = Optional.of(mergedExpression);
} else if (permissionFilter.isPresent()) {
computedFilters = permissionFilter;
}
com.yahoo.elide.core.request.Relationship modifiedRelationship = relationship.copyOf().projection(relationship.getProjection().copyOf().filterExpression(computedFilters.orElse(null)).sorting(sorting).pagination(pagination).build()).build();
Observable<PersistentResource> resources;
if (type.isToMany()) {
DataStoreIterable val = transaction.getToManyRelation(transaction, obj, modifiedRelationship, requestScope);
if (val == null) {
return Observable.empty();
}
resources = Observable.fromIterable(new PersistentResourceSet(this, relationName, val, requestScope));
} else {
Object val = transaction.getToOneRelation(transaction, obj, modifiedRelationship, requestScope);
if (val == null) {
return Observable.empty();
}
resources = Observable.fromArray(new PersistentResource(val, this, relationName, requestScope.getUUIDFor(val), requestScope));
}
return resources;
}
use of com.yahoo.elide.core.filter.expression.AndFilterExpression in project elide by yahoo.
the class AsyncAPICleanerRunnable method timeoutAsyncAPI.
/**
* This method updates the status of long running async query which
* were interrupted due to host crash/app shutdown to TIMEDOUT.
* @param type AsyncAPI Type Implementation.
*/
protected <T extends AsyncAPI> void timeoutAsyncAPI(Class<T> type) {
try {
Date filterDate = dateUtil.calculateFilterDate(Calendar.MINUTE, maxRunTimeMinutes);
PathElement createdOnPathElement = new PathElement(type, Long.class, "createdOn");
PathElement statusPathElement = new PathElement(type, String.class, "status");
FilterPredicate inPredicate = new InPredicate(statusPathElement, QueryStatus.PROCESSING, QueryStatus.QUEUED);
FilterPredicate lePredicate = new LEPredicate(createdOnPathElement, filterDate);
AndFilterExpression fltTimeoutExp = new AndFilterExpression(inPredicate, lePredicate);
asyncAPIDao.updateStatusAsyncAPIByFilter(fltTimeoutExp, QueryStatus.TIMEDOUT, type);
} catch (Exception e) {
log.error("Exception in scheduled cleanup: {}", e.toString());
}
}
use of com.yahoo.elide.core.filter.expression.AndFilterExpression in project elide by yahoo.
the class FilterTranslatorTest method testBetweenOperator.
@Test
public void testBetweenOperator() throws Exception {
List<Path.PathElement> authorId = Arrays.asList(new Path.PathElement(Book.class, Author.class, "authors"), new Path.PathElement(Author.class, Long.class, "id"));
List<Path.PathElement> publishDate = Arrays.asList(new Path.PathElement(Book.class, Long.class, "publishDate"));
FilterPredicate authorPred = new FilterPredicate(new Path(authorId), Operator.BETWEEN, Arrays.asList(1, 15));
FilterPredicate publishPred = new FilterPredicate(new Path(publishDate), Operator.NOTBETWEEN, Arrays.asList(1, 15));
AndFilterExpression andFilter = new AndFilterExpression(authorPred, publishPred);
FilterTranslator filterOp = new FilterTranslator(dictionary);
String query = filterOp.apply(andFilter, false);
String authorP1 = authorPred.getParameters().get(0).getPlaceholder();
String authorP2 = authorPred.getParameters().get(1).getPlaceholder();
String publishP1 = publishPred.getParameters().get(0).getPlaceholder();
String publishP2 = publishPred.getParameters().get(1).getPlaceholder();
String expected = "(authors.id BETWEEN " + authorP1 + " AND " + authorP2 + " AND " + "publishDate NOT BETWEEN " + publishP1 + " AND " + publishP2 + ")";
assertEquals(expected, query);
// Assert excepetion if parameter length is not 2
assertThrows(IllegalArgumentException.class, () -> filterOp.apply(new FilterPredicate(new Path(authorId), Operator.BETWEEN, Arrays.asList(3))));
}
use of com.yahoo.elide.core.filter.expression.AndFilterExpression in project elide by yahoo.
the class FilterTranslatorTest method testMemberOfOperator.
@Test
public void testMemberOfOperator() throws Exception {
List<Path.PathElement> path = Arrays.asList(new Path.PathElement(Book.class, String.class, "awards"));
FilterPredicate p1 = new FilterPredicate(new Path(path), Operator.HASMEMBER, Arrays.asList("awards1"));
FilterPredicate p2 = new FilterPredicate(new Path(path), Operator.HASNOMEMBER, Arrays.asList("awards2"));
AndFilterExpression and = new AndFilterExpression(p1, p2);
FilterTranslator filterOp = new FilterTranslator(dictionary);
String query = filterOp.apply(and, false);
String p1Params = p1.getParameters().stream().map(FilterPredicate.FilterParameter::getPlaceholder).collect(Collectors.joining(", "));
String p2Params = p2.getParameters().stream().map(FilterPredicate.FilterParameter::getPlaceholder).collect(Collectors.joining(", "));
String expected = "(" + p1Params + " MEMBER OF awards " + "AND " + p2Params + " NOT MEMBER OF awards)";
assertEquals(expected, query);
}
Aggregations