Search in sources :

Example 6 with WorkflowHistoricTaskInstanceDto

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);
}
Also used : Order(org.springframework.data.domain.Sort.Order) PageImpl(org.springframework.data.domain.PageImpl) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)

Aggregations

WorkflowHistoricTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)6 ArrayList (java.util.ArrayList)3 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)2 Sort (org.springframework.data.domain.Sort)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 ResourcesWrapper (eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper)1 WorkflowProcessDefinitionDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto)1 List (java.util.List)1 HistoricIdentityLink (org.activiti.engine.history.HistoricIdentityLink)1 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)1 HistoricTaskInstanceQuery (org.activiti.engine.history.HistoricTaskInstanceQuery)1 PageImpl (org.springframework.data.domain.PageImpl)1 PageRequest (org.springframework.data.domain.PageRequest)1 Pageable (org.springframework.data.domain.Pageable)1 Order (org.springframework.data.domain.Sort.Order)1