Example usage for javax.persistence.criteria Root joinList

List of usage examples for javax.persistence.criteria Root joinList

Introduction

In this page you can find the example usage for javax.persistence.criteria Root joinList.

Prototype

<X, Y> ListJoin<X, Y> joinList(String attributeName);

Source Link

Document

Create an inner join to the specified List-valued attribute.

Usage

From source file:com.orange.clara.tool.controllers.AbstractDefaultController.java

protected List<WatchedResource> getFilteredWatchedResources(User user, boolean isAdmin, String isPublic,
        String tags, String types, Date afterDate) {
    Specification<WatchedResource> specification = new Specification<WatchedResource>() {
        @Override// w w  w .  ja  v  a  2 s  .  c  o  m
        public Predicate toPredicate(Root<WatchedResource> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
            List<Predicate> predicates = new ArrayList<>();
            if (tags != null) {
                ListJoin<WatchedResource, Tag> tagJoin = root.joinList("tags");
                predicates.add(cb.isTrue(tagJoin.get("name").in(Tag.namesFromStringList(tags))));
            }
            if (types != null) {
                predicates.add(cb.isTrue(root.get("type").in(ResourceType.fromStringList(types))));
            }
            if (isPublic != null) {
                predicates.add(cb.isTrue(root.get("isPublic")));
            }
            if (afterDate != null) {
                predicates.add(cb.greaterThan(root.get("updatedResourceAt"), afterDate));
            }
            if (!isAdmin) {
                ListJoin<WatchedResource, User> usersJoin = root.joinList("users");
                predicates.add(cb.equal(usersJoin.get("uuid"), user.getUuid()));
            }
            Predicate finalPredicate = cb.and(predicates.toArray(new Predicate[] {}));
            if (isPublic != null) {
                finalPredicate = cb.or(finalPredicate, cb.isTrue(root.get("isPublic")));
            }
            return finalPredicate;
        }
    };
    return this.watchedResourceRepo.findAll(specification);
}