in genie-web/src/main/java/com/netflix/genie/web/data/services/impl/jpa/queries/predicates/ClusterPredicates.java [66:107]
public static Predicate find(
final Root<ClusterEntity> root,
final AbstractQuery<?> cq,
final CriteriaBuilder cb,
@Nullable final String name,
@Nullable final Set<String> statuses,
@Nullable final Set<TagEntity> tags,
@Nullable final Instant minUpdateTime,
@Nullable final Instant maxUpdateTime
) {
final List<Predicate> predicates = new ArrayList<>();
if (StringUtils.isNotBlank(name)) {
predicates.add(
PredicateUtils.getStringLikeOrEqualPredicate(cb, root.get(ClusterEntity_.name), name)
);
}
if (minUpdateTime != null) {
predicates.add(cb.greaterThanOrEqualTo(root.get(ClusterEntity_.updated), minUpdateTime));
}
if (maxUpdateTime != null) {
predicates.add(cb.lessThan(root.get(ClusterEntity_.updated), maxUpdateTime));
}
if (tags != null && !tags.isEmpty()) {
final Join<ClusterEntity, TagEntity> tagEntityJoin = root.join(ClusterEntity_.tags);
predicates.add(tagEntityJoin.in(tags));
cq.groupBy(root.get(ClusterEntity_.id));
cq.having(cb.equal(cb.count(root.get(ClusterEntity_.id)), tags.size()));
}
if (statuses != null && !statuses.isEmpty()) {
//Could optimize this as we know size could use native array
predicates.add(
cb.or(
statuses
.stream()
.map(status -> cb.equal(root.get(ClusterEntity_.status), status))
.toArray(Predicate[]::new)
)
);
}
return cb.and(predicates.toArray(new Predicate[0]));
}