Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the SearchBuilder extension #134

Open
darrachequesne opened this issue Oct 3, 2021 · 4 comments
Open

Add support for the SearchBuilder extension #134

darrachequesne opened this issue Oct 3, 2021 · 4 comments

Comments

@darrachequesne
Copy link
Owner

Reference: https://datatables.net/extensions/searchbuilder/

We will need to handle the additional query parameters (which can be nested):

searchBuilder.criteria[0].condition  			=
searchBuilder.criteria[0].data  			Firstname
searchBuilder.criteria[0].origData  			firstName
searchBuilder.criteria[0].type  			string
searchBuilder.criteria[0].value[]  			john
searchBuilder.criteria[0].value1  			john
searchBuilder.criteria[1].criteria[0].condition		starts
searchBuilder.criteria[1].criteria[0].data  		Lastname
searchBuilder.criteria[1].criteria[0].origData		lastName
searchBuilder.criteria[1].criteria[0].type  		string
searchBuilder.criteria[1].criteria[0].value[]  		do
searchBuilder.criteria[1].criteria[0].value1  		do
searchBuilder.criteria[1].criteria[1].condition  	null
searchBuilder.criteria[1].criteria[1].data  		Lastname
searchBuilder.criteria[1].criteria[1].origData  	lastName
searchBuilder.criteria[1].criteria[1].type  		string
searchBuilder.criteria[1].logic  			OR
searchBuilder.logic					AND

Contribution is welcome!

@Praytic
Copy link

Praytic commented Oct 7, 2021

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?

@Praytic
Copy link

Praytic commented Oct 7, 2021

I have an idea of creating multiple enums which are mapped to specific CriteriaBuilder methods. Do you think it will be a good design decision?

@Praytic
Copy link

Praytic commented Oct 7, 2021

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;
  }
}

@KrunchMuffin
Copy link

I would be willing to throw in $100 to get this working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants