use of py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class ApplicationServiceImpl method listApplicationsHubs.
@Override
public PaginableList<ApplicationDTO> listApplicationsHubs(int page, int perPage, String orderBy, String sortBy) {
PageRequest pageRequest = new PspPageRequest(page, perPage, orderBy, sortBy);
Page<ApplicationEntity> pageResponse = applicationRepository.findAllByIsHub(true, pageRequest);
if (pageResponse == null) {
return new PaginableList<ApplicationDTO>(Collections.emptyList());
}
Page<ApplicationDTO> applicationPage = pageResponse.map(new Converter<ApplicationEntity, ApplicationDTO>() {
public ApplicationDTO convert(ApplicationEntity source) {
return applicationMapper.entityToDto(source);
}
});
return new PaginableList<ApplicationDTO>(applicationPage, applicationPage.getContent());
}
use of py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity 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()]));
}
};
}
Aggregations