Search in sources :

Example 11 with PageImpl

use of org.springframework.data.domain.PageImpl 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)

Example 12 with PageImpl

use of org.springframework.data.domain.PageImpl in project CzechIdMng by bcvsolutions.

the class AbstractReadDtoService method toDtoPage.

/**
 * Converts list of entities wrapped to Page object to list of DTOs wrapped
 * to Page object.
 *
 * @param entityPage
 * @return
 */
protected Page<DTO> toDtoPage(Page<E> entityPage) {
    List<DTO> dtos = this.toDtos(entityPage.getContent(), true);
    PageRequest pageRequest = null;
    if (entityPage.getSize() > 0) {
        pageRequest = new PageRequest(entityPage.getNumber(), entityPage.getSize(), entityPage.getSort());
    }
    Page<DTO> dtoPage = new PageImpl<>(dtos, pageRequest, entityPage.getTotalElements());
    return dtoPage;
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest)

Example 13 with PageImpl

use of org.springframework.data.domain.PageImpl in project CzechIdMng by bcvsolutions.

the class DefaultAuditIdentityService method findRevisionBy.

@Override
public Page<IdmAudit> findRevisionBy(AuditEntityFilter filter, Pageable pageable) {
    AuditIdentityFilter identityFilter = (AuditIdentityFilter) filter;
    // 
    List<String> identitiesIds = Collections.emptyList();
    if (identityFilter.getUsername() != null) {
        // in identities can be more UUID, we search for all
        identitiesIds = getAuditRepository().findDistinctOwnerIdByOwnerTypeAndOwnerCode(IdmIdentity.class.getName(), identityFilter.getUsername());
        // remove null values
        identitiesIds.removeAll(Collections.singleton(null));
        // no entity found for this username return empty list
        if (identitiesIds.isEmpty()) {
            return new PageImpl<>(Collections.emptyList());
        }
    }
    // 
    IdmAuditFilter auditFilter = new IdmAuditFilter();
    auditFilter.setFrom(identityFilter.getFrom());
    auditFilter.setTill(identityFilter.getTill());
    auditFilter.setOwnerType(IdmIdentity.class.getName());
    auditFilter.setChangedAttributes(identityFilter.getChangedAttributes());
    // set id as owner id
    if (identityFilter.getId() != null) {
        auditFilter.setOwnerId(identityFilter.getId().toString());
    }
    // 
    if (!identitiesIds.isEmpty()) {
        auditFilter.setOwnerIds(identitiesIds);
    }
    // 
    return this.getAuditRepository().find(auditFilter, pageable);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) AuditIdentityFilter(eu.bcvsolutions.idm.core.audit.dto.filter.AuditIdentityFilter) IdmAuditFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity)

Example 14 with PageImpl

use of org.springframework.data.domain.PageImpl in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerUnitTest method createEvents.

private Page<IdmEntityEventDto> createEvents(PriorityType priority, int count) {
    List<IdmEntityEventDto> events = new ArrayList<>();
    DateTime created = new DateTime().minusMillis(count);
    for (int i = 0; i < count; i++) {
        IdmEntityEventDto event = new IdmEntityEventDto();
        event.setCreated(created.plusMillis(count));
        event.setPriority(priority);
        event.setOwnerId(UUID.randomUUID());
        event.setEventType("custom");
        events.add(event);
    }
    // 
    return new PageImpl<>(events);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)

Example 15 with PageImpl

use of org.springframework.data.domain.PageImpl in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningBreakConfigService method find.

@Override
public Page<SysProvisioningBreakConfigDto> find(SysProvisioningBreakConfigFilter filter, Pageable pageable, BasePermission... permission) {
    Page<SysProvisioningBreakConfigDto> configs = super.find(filter, pageable, permission);
    // if include global config and set systemId add global configurations
    if (filter != null && filter.isIncludeGlobalConfig() && filter.getSystemId() != null && configs.getTotalElements() != MAX_CONFIGS_FOR_SYSTEM) {
        List<SysProvisioningBreakConfigDto> configsList = addGlobalConfigs(configs.getContent(), filter.getSystemId());
        // 
        if (!configsList.isEmpty()) {
            PageRequest pageRequest = new PageRequest(pageable.getPageNumber(), configsList.size(), pageable.getSort());
            Page<SysProvisioningBreakConfigDto> dtoPage = new PageImpl<>(configsList, pageRequest, configsList.size());
            return dtoPage;
        }
    }
    // 
    return configs;
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) SysProvisioningBreakConfigDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakConfigDto)

Aggregations

PageImpl (org.springframework.data.domain.PageImpl)18 ArrayList (java.util.ArrayList)9 PageRequest (org.springframework.data.domain.PageRequest)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 List (java.util.List)4 Test (org.junit.Test)4 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)3 IdmProcessedTaskItemFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter)3 UUID (java.util.UUID)3 Page (org.springframework.data.domain.Page)3 Pageable (org.springframework.data.domain.Pageable)3 Sort (org.springframework.data.domain.Sort)3 Order (org.springframework.data.domain.Sort.Order)3 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)2 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)2 LookupService (eu.bcvsolutions.idm.core.api.service.LookupService)2 Collectors (java.util.stream.Collectors)2 Resources (org.springframework.hateoas.Resources)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Lists (com.google.common.collect.Lists)1