List of usage examples for javax.persistence.criteria CriteriaBuilder isTrue
Predicate isTrue(Expression<Boolean> x);
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/*from w w w. j av 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); }
From source file:com.dbs.sdwt.jpa.ByPropertySelectorUtil.java
private <E> void byBooleanSelector(Root<E> root, CriteriaBuilder builder, List<Predicate> predicates, SearchParameters sp, PropertySelector<? super E, Boolean> selector) { if (selector.isNotEmpty()) { List<Predicate> selectorPredicates = newArrayList(); for (Boolean selection : selector.getSelected()) { Path<Boolean> path = jpaUtil.getPath(root, selector.getAttributes()); if (selection == null) { selectorPredicates.add(builder.isNull(path)); } else { selectorPredicates.add(selection ? builder.isTrue(path) : builder.isFalse(path)); }/*from ww w. j a v a2 s . c o m*/ } if (selector.isOrMode()) { predicates.add(jpaUtil.orPredicate(builder, selectorPredicates)); } else { predicates.add(jpaUtil.andPredicate(builder, selectorPredicates)); } } }
From source file:com.deloitte.smt.service.SignalDetectionService.java
/** * @param searchDto//w w w. j a va 2 s . c o m * @param criteriaBuilder * @param rootIngredient * @param predicates */ private void addIngredients(SearchDto searchDto, CriteriaBuilder criteriaBuilder, Root<Ingredient> rootIngredient, List<Predicate> predicates) { if (!CollectionUtils.isEmpty(searchDto.getIngredients())) { Predicate ingredientNameEquals = criteriaBuilder .isTrue(rootIngredient.get("ingredientName").in(searchDto.getIngredients())); predicates.add(ingredientNameEquals); } }
From source file:com.deloitte.smt.service.SignalDetectionService.java
/** * @param searchDto/* w w w .j a v a 2 s. c om*/ * @param criteriaBuilder * @param rootSignalDetection * @param predicates */ private void addFrequency(SearchDto searchDto, CriteriaBuilder criteriaBuilder, Root<SignalDetection> rootSignalDetection, List<Predicate> predicates) { if (!CollectionUtils.isEmpty(searchDto.getFrequency())) { predicates.add( criteriaBuilder.isTrue(rootSignalDetection.get("runFrequency").in(searchDto.getFrequency()))); } }
From source file:com.deloitte.smt.service.SignalDetectionService.java
/** * @param searchDto// w ww.j a v a2s . co m * @param criteriaBuilder * @param rootSignalDetection * @param predicates */ private void addDescription(SearchDto searchDto, CriteriaBuilder criteriaBuilder, Root<SignalDetection> rootSignalDetection, List<Predicate> predicates) { if (StringUtils.isNotBlank(searchDto.getDescription())) { predicates.add( criteriaBuilder.isTrue(rootSignalDetection.get("description").in(searchDto.getDescription()))); } }
From source file:de.whs.poodle.repositories.StatisticsRepository.java
public List<Statistic> getStatistics(FeedbackSearchCriteria s, int instructorId, int limit) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Statistic> cq = cb.createQuery(Statistic.class); Root<Statistic> statistic = cq.from(Statistic.class); /* fetch the exercises immediately so they don't have to * be lazy-fetched one by one while rendering the table rows. */ statistic.fetch("exercise"); // join we need to match the course Join<Statistic, Course> course = statistic.join("courseTerm").join("course"); // create empty "and" predicate Predicate where = cb.conjunction(); // only non-empty Predicate notEmpty = cb.isFalse(statistic.get("empty")); where = cb.and(where, notEmpty);/*from ww w. ja va 2 s. co m*/ // only statistics for courses that the instructor has access to Predicate hasInstructorAccessToCourse = cb.isTrue(cb.function("has_instructor_access_to_course", Boolean.class, course.get("id"), cb.literal(instructorId))); where = cb.and(where, hasInstructorAccessToCourse); // filter by courseId if (s.getCourseId() != 0) { Predicate courseMatches = cb.equal(course.get("id"), s.getCourseId()); where = cb.and(where, courseMatches); } // filter by student if (s.getStudent() != null) { Predicate studentMatches = cb.equal(statistic.get("student").get("id"), s.getStudent().getId()); where = cb.and(where, studentMatches); } cq.where(where); // order by date cq.orderBy(cb.desc(statistic.get("completedAt"))); return em.createQuery(cq).setMaxResults(limit).getResultList(); }
From source file:com.deloitte.smt.service.SignalDetectionService.java
/** * @param searchDto//from w w w. ja v a2 s . c o m * @param criteriaBuilder * @param criteriaQuery * @param rootSignalDetection * @param predicates */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void addPts(SearchDto searchDto, CriteriaBuilder criteriaBuilder, CriteriaQuery criteriaQuery, Root<SignalDetection> rootSignalDetection, List<Predicate> predicates) { if (!CollectionUtils.isEmpty(searchDto.getPts())) { Root<Pt> rootPt = criteriaQuery.from(Pt.class); Predicate signalDetectionPtEquals = criteriaBuilder.equal(rootSignalDetection.get("id"), rootPt.get(SmtConstant.DETECTION_ID.getDescription())); Predicate hlgtNameIn = criteriaBuilder.isTrue(rootPt.get("ptName").in(searchDto.getPts())); predicates.add(signalDetectionPtEquals); predicates.add(hlgtNameIn); } }
From source file:com.deloitte.smt.service.SignalDetectionService.java
/** * @param searchDto// ww w . j a v a 2s. com * @param criteriaBuilder * @param criteriaQuery * @param rootIngredient * @param predicates */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void addProducts(SearchDto searchDto, CriteriaBuilder criteriaBuilder, CriteriaQuery criteriaQuery, Root<SignalDetection> rootSignalDetection, List<Predicate> predicates) { if (!CollectionUtils.isEmpty(searchDto.getProducts())) { Root<Product> rootProduct = criteriaQuery.from(Product.class); Predicate ingredientProductEquals = criteriaBuilder.equal(rootSignalDetection.get("id"), rootProduct.get("detectionId")); Predicate productNameIn = criteriaBuilder .isTrue(rootProduct.get("productName").in(searchDto.getProducts())); predicates.add(ingredientProductEquals); predicates.add(productNameIn); } }
From source file:com.deloitte.smt.service.SignalDetectionService.java
/** * @param searchDto//from ww w.j ava 2 s .c o m * @param criteriaBuilder * @param criteriaQuery * @param rootIngredient * @param predicates */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void addLicenses(SearchDto searchDto, CriteriaBuilder criteriaBuilder, CriteriaQuery criteriaQuery, Root<SignalDetection> rootSignalDetection, List<Predicate> predicates) { if (!CollectionUtils.isEmpty(searchDto.getLicenses())) { Root<License> rootLicense = criteriaQuery.from(License.class); Predicate ingredientLicenseEquals = criteriaBuilder.equal(rootSignalDetection.get("id"), rootLicense.get("ingredientId")); Predicate licenseNameIn = criteriaBuilder .isTrue(rootLicense.get("licenseName").in(searchDto.getLicenses())); predicates.add(ingredientLicenseEquals); predicates.add(licenseNameIn); } }
From source file:com.deloitte.smt.service.SignalDetectionService.java
/** * @param searchDto/*from w w w. j av a2s . co m*/ * @param criteriaBuilder * @param criteriaQuery * @param rootSignalDetection * @param predicates */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void addHlts(SearchDto searchDto, CriteriaBuilder criteriaBuilder, CriteriaQuery criteriaQuery, Root<SignalDetection> rootSignalDetection, List<Predicate> predicates) { if (!CollectionUtils.isEmpty(searchDto.getHlts())) { Root<Hlt> rootHlt = criteriaQuery.from(Hlt.class); Predicate signalDetectionHltEquals = criteriaBuilder.equal(rootSignalDetection.get("id"), rootHlt.get(SmtConstant.DETECTION_ID.getDescription())); Predicate hltNameIn = criteriaBuilder.isTrue(rootHlt.get("hltName").in(searchDto.getHlts())); predicates.add(signalDetectionHltEquals); predicates.add(hltNameIn); } }