Open darrachequesne opened 2 years ago
Hi @darrachequesne , I have read the documentation for the SearchBuilder
, but I'm still not completely sure how it should be applied on the server-side. Could you give some hints?
I have an idea of creating multiple enum
s which are mapped to specific CriteriaBuilder
methods. Do you think it will be a good design decision?
For example:
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class Criteria {
private Condition condition;
private String data;
private String origData;
private String type;
private List<String> value;
private String logic;
private List<Criteria> criteria;
public <T> Predicate notEmpty(Root<T> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
return criteriaBuilder.equal(criteriaBuilder.length(root.get(origData)), 0);
}
}
And condition enum
will look like that:
public enum Condition {
NOT_EMPTY("!null", (builder) -> builder::notEmpty);
private String key;
private Function<Criteria, Specification> predicate;
Condition(String key, Function<Criteria, Specification> predicate) {
this.key = key;
this.predicate = predicate;
}
}
I would be willing to throw in $100 to get this working
Reference: https://datatables.net/extensions/searchbuilder/
We will need to handle the additional query parameters (which can be nested):
Contribution is welcome!