QueryDSL MultiValueBinding possible with multiple types?

Viewed 355

I am working with a SpringBoot Rest API in Java and I have an IssueRepository for Issue entities that extends QuerydslPredicateExecutor and QuerydslBinderCustomizer. Each issue entity is linked to a latestActivity entity that contains the boolean field isClosed. I want to search for all issues that are not closed - so either the issue has no latestActivity, or it has a latestActivity where isClosed=false. My frontend constructs a URL to represent this: /api/issues&latestActivity.isClosed=0&latestActivity=-1.

I want to use QueryDsl bindings to OR these two conditions together using MultiValueBinding as described in QueryDSL predicate bindings "or" between multiple path. This is the proposed solution:

@Override
default void customize(QuerydslBindings bindings, QDocument root) {

StringPath[] multiPropertySearchPaths = new StringPath[] {root.prop1, root.prop2, root.prop3};

/**
 * Binds prop1, prop2 and prop3 in OR clause
 * This binding will activate when one of the given properties are searched in query params
 */
bindings.bind(multiPropertySearchPaths).all(new MultiValueBinding<StringPath, String>() {
    @Override
    public Predicate bind(StringPath path, Collection<? extends String> values) {
        BooleanBuilder predicate = new BooleanBuilder();
        // Bind paths present in array multiPropertySearchPaths with incoming values
        for (StringPath propertyPath : multiPropertySearchPaths) {
            values.forEach(value -> predicate.or(propertyPath.containsIgnoreCase(value)));
        }
        return predicate;
    }
});
}

My problem is that I can't define multiPropertySearchPaths or MultiValueBinding because my paths are of two different types (issue.latestActivity is an entity path, but issue.latestActivity.isClosed is a boolean path).

Is there a way to use MultiValueBinding or some other QueryDsl feature to OR two fields of different types?

0 Answers
Related