Search in sources :

Example 1 with PspPageRequest

use of py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest in project FP-PSP-SERVER by FundacionParaguaya.

the class UserServiceImpl method listUsers.

@Override
public Page<UserDTO> listUsers(int page, int perPage, String orderBy, String sortBy, UserDetailsDTO userDetails) {
    PageRequest pageRequest = new PspPageRequest(page, perPage, orderBy, "user." + sortBy);
    Page<UserApplicationEntity> userApplicationPage = userApplicationRepository.findAll(Specifications.where(hasApplication(userDetails.getApplication())).and(hasOrganization(userDetails.getOrganization())).and(userIsActive()), pageRequest);
    return userApplicationPage.map(userApplicationMapper::entityToUserDto);
}
Also used : PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) PageRequest(org.springframework.data.domain.PageRequest) PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) UserApplicationEntity(py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)

Example 2 with PspPageRequest

use of py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest in project FP-PSP-SERVER by FundacionParaguaya.

the class ApplicationController method getPaginatedApplications.

@GetMapping()
public ResponseEntity<PaginableList<ApplicationDTO>> getPaginatedApplications(@RequestParam(value = "page", required = false, defaultValue = "1") int page, @RequestParam(value = "per_page", required = false, defaultValue = "12") int perPage, @RequestParam(value = "sort_by", required = false, defaultValue = "name") String sortBy, @RequestParam(value = "order", required = false, defaultValue = "asc") String orderBy, @RequestParam(value = "filter", required = false, defaultValue = "") String filter, @AuthenticationPrincipal UserDetailsDTO userDetails) {
    PageRequest pageRequest = new PspPageRequest(page, perPage, orderBy, sortBy);
    Page<ApplicationDTO> pageProperties = applicationService.getPaginatedApplications(userDetails, filter, pageRequest);
    PaginableList<ApplicationDTO> response = new PaginableList<>(pageProperties, pageProperties.getContent());
    return ResponseEntity.ok(response);
}
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) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with PspPageRequest

use of py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest in project FP-PSP-SERVER by FundacionParaguaya.

the class OrganizationServiceImpl method listOrganizations.

@Override
public PaginableList<OrganizationDTO> listOrganizations(Long applicationId, Long organizationId, int page, int perPage, String orderBy, String sortBy) {
    PaginableList<OrganizationDTO> response;
    PageRequest pageRequest = new PspPageRequest(page, perPage, orderBy, sortBy);
    Page<OrganizationEntity> pageResponse = organizationRepository.findAll(where(byFilter(applicationId, organizationId)), pageRequest);
    if (pageResponse == null) {
        return new PaginableList<>(Collections.emptyList());
    } else {
        Page<OrganizationDTO> organizationPage = pageResponse.map(new Converter<OrganizationEntity, OrganizationDTO>() {

            @Override
            public OrganizationDTO convert(OrganizationEntity source) {
                return organizationMapper.entityToDto(source);
            }
        });
        response = new PaginableList<OrganizationDTO>(organizationPage, organizationPage.getContent());
    }
    return response;
}
Also used : PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) PageRequest(org.springframework.data.domain.PageRequest) PaginableList(py.org.fundacionparaguaya.pspserver.common.pagination.PaginableList) OrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity) PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)

Example 4 with PspPageRequest

use of py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest in project FP-PSP-SERVER by FundacionParaguaya.

the class OrganizationController method getAllOrganizations.

@GetMapping()
public ResponseEntity<PaginableList<OrganizationDTO>> getAllOrganizations(@RequestParam(value = "page", required = false, defaultValue = "1") int page, @RequestParam(value = "per_page", required = false, defaultValue = "12") int perPage, @RequestParam(value = "sort_by", required = false, defaultValue = "name") String sortBy, @RequestParam(value = "order", required = false, defaultValue = "asc") String orderBy, @RequestParam(value = "filter", required = false, defaultValue = "") String filter, @AuthenticationPrincipal UserDetailsDTO userDetails) {
    PageRequest pageRequest = new PspPageRequest(page, perPage, orderBy, sortBy);
    Page<OrganizationDTO> pageProperties = organizationService.listOrganizations(userDetails, filter, pageRequest);
    PaginableList<OrganizationDTO> response = new PaginableList<>(pageProperties, pageProperties.getContent());
    return ResponseEntity.ok(response);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) PaginableList(py.org.fundacionparaguaya.pspserver.common.pagination.PaginableList) PspPageRequest(py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with PspPageRequest

use of py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest 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)

Aggregations

PageRequest (org.springframework.data.domain.PageRequest)5 PspPageRequest (py.org.fundacionparaguaya.pspserver.common.pagination.PspPageRequest)5 PaginableList (py.org.fundacionparaguaya.pspserver.common.pagination.PaginableList)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ApplicationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO)2 OrganizationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)2 ApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.ApplicationEntity)1 OrganizationEntity (py.org.fundacionparaguaya.pspserver.network.entities.OrganizationEntity)1 UserApplicationEntity (py.org.fundacionparaguaya.pspserver.network.entities.UserApplicationEntity)1