Combine provided queryDSL predicates with predefined queries

Viewed 588

In context of Spring Data REST I would like to expose search/filter functionality on the result of the single query. If my query was findAll that would be out of the box (it would be enough to extend QueryDslPredicateExecutor). But how can I combine my custom query (findMyNotes) with additional filtering provided by the user (that are marked as done). I mean something like:

@Entity
class Note {
    @Id
    private UUID id;
    private UUID personId;
    private String status;
    private String text;
}

@RepositoryRestResource(path = "notes", itemResourceRel = "notes", collectionResourceRel = "notes")
interface NoteRepository extends JpaRepository<Note, UUID>, QueryDslPredicateExecutor<Note> {

    @RestResource(path="notes/my")
    @Query("select n from Note n where n.personId=:creatorId")
    Page<Note> findDone(@Param("creatorId") UUID creatorId, Predicate predicate, Pageable pageable);
}

I didn't find anything out of the box. Therefore I was thinking to use AOP and:

  1. have multiple paths (multiple @RestResource ?) that map to org.springframework.data.querydsl.QueryDslPredicateExecutor#findAll(Predicate, org.springframework.data.domain.Pageable)
  2. have my own annotation that would point me to the method that returns the original queryDSL Predicate (contents of @Query in my example)
  3. by AOP calculate AND of those two predicates and pass it as a parameter to findAll method

The problem is that I don't know how to do the first point (apart from hacking it in servlet filters) - map multiple paths to the same findAll method.

Or alternatively is there maybe something working out of the box that I missed?

0 Answers
Related