Search in sources :

Example 1 with ResourcePage

use of eu.bcvsolutions.idm.core.api.rest.domain.ResourcePage in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowProcessInstanceService method find.

@Override
public Page<WorkflowProcessInstanceDto> find(WorkflowFilterDto filter, Pageable pageable, BasePermission... permission) {
    // we must call original method search because is there check flag checkRight
    if (pageable != null) {
        filter.setPageNumber(pageable.getPageNumber());
        filter.setPageSize(pageable.getPageSize());
        // 
        String fieldForSort = null;
        boolean ascSort = false;
        boolean descSort = false;
        if (pageable != null) {
            Sort sort = pageable.getSort();
            if (sort != null) {
                for (Order order : sort) {
                    if (!StringUtils.isEmpty(order.getProperty())) {
                        // TODO: now is implemented only one property sort
                        fieldForSort = order.getProperty();
                        if (order.getDirection() == Direction.ASC) {
                            ascSort = true;
                        } else if (order.getDirection() == Direction.DESC) {
                            descSort = true;
                        }
                        break;
                    }
                }
            }
        }
        filter.setSortAsc(ascSort);
        filter.setSortDesc(descSort);
        filter.setSortByFields(fieldForSort);
    }
    ResourcesWrapper<WorkflowProcessInstanceDto> search = this.search(filter);
    // 
    ResourcePage pages = search.getPage();
    List<WorkflowProcessInstanceDto> processes = (List<WorkflowProcessInstanceDto>) search.getResources();
    // 
    return new PageImpl<WorkflowProcessInstanceDto>(processes, pageable, pages.getTotalElements());
}
Also used : Order(org.springframework.data.domain.Sort.Order) PageImpl(org.springframework.data.domain.PageImpl) Sort(org.springframework.data.domain.Sort) ArrayList(java.util.ArrayList) List(java.util.List) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) ResourcePage(eu.bcvsolutions.idm.core.api.rest.domain.ResourcePage)

Aggregations

ResourcePage (eu.bcvsolutions.idm.core.api.rest.domain.ResourcePage)1 WorkflowProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PageImpl (org.springframework.data.domain.PageImpl)1 Sort (org.springframework.data.domain.Sort)1 Order (org.springframework.data.domain.Sort.Order)1