Search in sources :

Example 6 with ApplicationEntity

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());
}
Also used : ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) PageRequest(org.springframework.data.domain.PageRequest) PaginableList(py.org.fundacionparaguaya.pspserver.common.pagination.PaginableList) PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) ApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity)

Example 7 with ApplicationEntity

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()]));
        }
    };
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) LocalDateTime(java.time.LocalDateTime) FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ArrayList(java.util.ArrayList) CityEntity(py.org.fundacionparaguaya.pspserver.system.entities.CityEntity) Specification(org.springframework.data.jpa.domain.Specification) Predicate(javax.persistence.criteria.Predicate) ApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity) CountryEntity(py.org.fundacionparaguaya.pspserver.system.entities.CountryEntity)

Aggregations

ApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity)7 ArrayList (java.util.ArrayList)2 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)2 ApplicationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO)2 OrganizationEntity (py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity)2 UserApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)2 ImageDTO (py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO)2 LocalDateTime (java.time.LocalDateTime)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 Predicate (javax.persistence.criteria.Predicate)1 Root (javax.persistence.criteria.Root)1 PageRequest (org.springframework.data.domain.PageRequest)1 Specification (org.springframework.data.jpa.domain.Specification)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 PaginableList (py.org.fundacionparaguaya.pspserver.common.pagination.PaginableList)1 PspPageRequest (py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest)1 FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)1 OrganizationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)1 SurveyOrganizationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.SurveyOrganizationDTO)1