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());
}
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;
}
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);
}
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);
}
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;
}
Aggregations