use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowHistoricTaskInstanceService method find.
@Override
public Page<WorkflowHistoricTaskInstanceDto> find(WorkflowFilterDto filter, Pageable pageable, BasePermission... permission) {
String processDefinitionId = filter.getProcessDefinitionId();
String processInstanceId = filter.getProcessInstanceId();
HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery();
query.includeProcessVariables();
if (filter.getId() != null) {
query.taskId(filter.getId().toString());
}
if (processInstanceId != null) {
query.processInstanceId(processInstanceId);
}
if (processDefinitionId != null) {
query.processDefinitionId(processDefinitionId);
}
if (filter.getProcessDefinitionKey() != null) {
query.processDefinitionKey(filter.getProcessDefinitionKey());
}
// historic task instance ... admin can see all historic tasks every time
if (!securityService.isAdmin()) {
// TODO Now we don't have detail for historic task. When we need detail, then we will need create different projection (detail can't be read by applicant)
String loggedUserId = securityService.getCurrentId().toString();
query.taskInvolvedUser(loggedUserId);
}
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;
}
}
}
}
if (WorkflowHistoricTaskInstanceService.SORT_BY_CREATE_TIME.equals(fieldForSort)) {
query.orderByTaskCreateTime();
} else if (WorkflowHistoricTaskInstanceService.SORT_BY_END_TIME.equals(fieldForSort)) {
query.orderByHistoricTaskInstanceEndTime();
} else {
query.orderByProcessDefinitionId();
// there must be default order
query.asc();
}
if (ascSort) {
query.asc();
}
if (descSort) {
query.desc();
}
long count = query.count();
List<HistoricTaskInstance> processInstances = null;
if (pageable == null) {
processInstances = query.list();
} else {
processInstances = query.listPage((pageable.getPageNumber()) * pageable.getPageSize(), pageable.getPageSize());
}
List<WorkflowHistoricTaskInstanceDto> dtos = new ArrayList<>();
if (processInstances != null) {
for (HistoricTaskInstance instance : processInstances) {
dtos.add(toResource(instance));
}
}
return new PageImpl<WorkflowHistoricTaskInstanceDto>(dtos, pageable, count);
}
Aggregations