use of org.springframework.data.jpa.domain.Specification in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotDraftSpecification method createdAtLessDays.
public static Specification<SnapshotDraftEntity> createdAtLessDays(long days) {
return new Specification<SnapshotDraftEntity>() {
@Override
public Predicate toPredicate(Root<SnapshotDraftEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
LocalDateTime limit = LocalDateTime.now();
limit = limit.minusDays(days);
return cb.and(cb.greaterThan(root.<LocalDateTime>get(SnapshotDraftEntity_.getCreatedAt()), limit));
}
};
}
use of org.springframework.data.jpa.domain.Specification in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotEconomicSpecification method createdAtLess2Months.
public static Specification<SnapshotEconomicEntity> createdAtLess2Months() {
return new Specification<SnapshotEconomicEntity>() {
@Override
public Predicate toPredicate(Root<SnapshotEconomicEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
LocalDateTime limit = LocalDateTime.now();
limit = limit.minusMonths(MONTH_AGO).withDayOfMonth(1);
return cb.and(cb.greaterThan(root.<LocalDateTime>get(SnapshotEconomicEntity_.getCreatedAt()), limit));
}
};
}
use of org.springframework.data.jpa.domain.Specification in project FP-PSP-SERVER by FundacionParaguaya.
the class FamilySpecification method byFilter.
public static Specification<FamilyEntity> byFilter(FamilyFilterDTO filter) {
return new Specification<FamilyEntity>() {
@Override
public Predicate toPredicate(Root<FamilyEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicates = new ArrayList<>();
if (filter.getApplicationId() != null) {
Join<FamilyEntity, ApplicationEntity> joinApplication = root.join(FamilyEntity_.getApplication());
Expression<Long> byApplicationId = joinApplication.<Long>get(ID_ATTRIBUTE);
predicates.add(cb.equal(byApplicationId, filter.getApplicationId()));
}
if (filter.getOrganizationId() != null) {
Expression<Long> byOrganizationId = root.join(FamilyEntity_.getOrganization()).<Long>get(ID_ATTRIBUTE);
predicates.add(cb.equal(byOrganizationId, filter.getOrganizationId()));
}
if (filter.getCountryId() != null) {
Join<FamilyEntity, CountryEntity> joinCountry = root.join(FamilyEntity_.getCountry());
Expression<Long> byCountryId = joinCountry.<Long>get(ID_ATTRIBUTE);
predicates.add(cb.equal(byCountryId, filter.getCountryId()));
}
if (filter.getCityId() != null) {
Join<FamilyEntity, CityEntity> joinCity = root.join(FamilyEntity_.getCity());
Expression<Long> byCityId = joinCity.<Long>get(ID_ATTRIBUTE);
predicates.add(cb.equal(byCityId, filter.getCityId()));
}
if (StringUtils.isNotEmpty(filter.getName())) {
String nameParamQuery = "%" + filter.getName().toLowerCase().replaceAll("\\s", "%") + "%";
Expression<String> likeName = cb.lower(root.get(FamilyEntity_.getName()));
predicates.add(cb.like(likeName, nameParamQuery));
}
if (filter.getLastModifiedGt() != null) {
LocalDateTime dateTimeParam = LocalDateTime.parse(filter.getLastModifiedGt());
Predicate predicate = cb.greaterThan(root.get(FamilyEntity_.getLastModifiedAt()), dateTimeParam);
predicates.add(predicate);
}
predicates.add(cb.isTrue(root.get(FamilyEntity_.getIsActive())));
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
}
};
}
use of org.springframework.data.jpa.domain.Specification in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotReportManagerImpl method listFamilyByOrganizationAndCreatedDate.
@Override
public List<OrganizationFamilyDTO> listFamilyByOrganizationAndCreatedDate(SnapshotFilterDTO filters) {
List<FamilyEntity> families = new ArrayList<>();
Sort sort = new Sort(new Sort.Order(Direction.ASC, "organization.name"), new Sort.Order(Direction.ASC, "name"));
Specification<FamilyEntity> dateRange = FamilySpecification.createdAtBetween2Dates(filters.getDateFrom(), filters.getDateTo());
families = familyRepository.findAll(where(byOrganization(filters.getOrganizationId())).and(dateRange).and(byApplication(filters.getApplicationId())).and(dateRange), sort);
Map<OrganizationEntity, List<FamilyEntity>> groupByOrganization = families.stream().collect(Collectors.groupingBy(f -> f.getOrganization()));
List<OrganizationFamilyDTO> toRet = new ArrayList<>();
groupByOrganization.forEach((k, v) -> {
OrganizationFamilyDTO fa = new OrganizationFamilyDTO(k.getName(), k.getCode(), k.getDescription(), k.isActive());
fa.setFamilies(familyReportMapper.entityListToDtoList(v));
toRet.add(fa);
});
return toRet;
}
use of org.springframework.data.jpa.domain.Specification in project summer by foxsugar.
the class HomeServiceImpl method findChargeByOrderId.
@Override
public Charge findChargeByOrderId(long oId) {
Specification<Charge> specification = new Specification<Charge>() {
@Override
public Predicate toPredicate(Root<Charge> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Path path = root.get("orderId");
Predicate predicate = path.as(Long.class).in(Arrays.asList(oId));
return predicate;
}
};
Charge charge = chargeDao.findOne(specification);
return charge;
}
Aggregations