Search in sources :

Example 6 with WorkflowHistoricProcessInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowHistoricProcessInstanceService method find.

@Override
public Page<WorkflowHistoricProcessInstanceDto> find(WorkflowFilterDto filter, Pageable pageable, BasePermission... permission) {
    String processDefinitionId = filter.getProcessDefinitionId();
    String processInstanceId = filter.getProcessInstanceId();
    Map<String, Object> equalsVariables = filter.getEqualsVariables();
    HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery();
    boolean trimmed = true;
    if (processInstanceId != null) {
        // Process variables will be included only for get by instance ID
        trimmed = false;
        query.includeProcessVariables();
        query.processInstanceId(processInstanceId);
    }
    if (processDefinitionId != null) {
        query.processDefinitionId(processDefinitionId);
    }
    if (filter.getSuperProcessInstanceId() != null) {
        query.superProcessInstanceId(filter.getSuperProcessInstanceId());
    }
    if (filter.getProcessDefinitionKey() != null) {
        // For case when we have only process id, we will convert him to key
        query.processDefinitionKey(convertProcessIdToKey(filter.getProcessDefinitionKey()));
    }
    if (filter.getName() != null) {
        // with case sensitive
        query.variableValueLike(WorkflowHistoricProcessInstanceService.PROCESS_INSTANCE_NAME, "%" + filter.getName() + "%");
    }
    if (equalsVariables != null) {
        for (Entry<String, Object> entry : equalsVariables.entrySet()) {
            query.variableValueEquals(entry.getKey(), entry.getValue());
        }
    }
    // TODO: refactor and use username/id from filter
    if (!securityService.isAdmin()) {
        // Applicant and Implementer is added to involved user after process
        // (subprocess) started. This modification allow not use OR clause.
        query.involvedUser(securityService.getCurrentId().toString());
    }
    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 (WorkflowHistoricProcessInstanceService.SORT_BY_START_TIME.equals(fieldForSort)) {
        query.orderByProcessInstanceStartTime();
    } else if (WorkflowHistoricProcessInstanceService.SORT_BY_END_TIME.equals(fieldForSort)) {
        query.orderByProcessInstanceEndTime();
    } else {
        query.orderByProcessDefinitionId();
        // there must be default order
        query.asc();
    }
    if (ascSort) {
        query.asc();
    }
    if (descSort) {
        query.desc();
    }
    long count = query.count();
    // it's possible that pageable is null
    List<HistoricProcessInstance> processInstances = null;
    if (pageable == null) {
        processInstances = query.list();
    } else {
        processInstances = query.listPage((pageable.getPageNumber()) * pageable.getPageSize(), pageable.getPageSize());
    }
    List<WorkflowHistoricProcessInstanceDto> dtos = new ArrayList<>();
    if (processInstances != null) {
        for (HistoricProcessInstance instance : processInstances) {
            dtos.add(toResource(instance, trimmed));
        }
    }
    return new PageImpl<WorkflowHistoricProcessInstanceDto>(dtos, pageable, count);
}
Also used : Order(org.springframework.data.domain.Sort.Order) PageImpl(org.springframework.data.domain.PageImpl) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto)

Example 7 with WorkflowHistoricProcessInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowHistoricProcessInstanceService method search.

/**
 * Search process history. Process variables will be included only for get
 * specific process history. It means filter.processInstanceId is filled.
 *
 * @param filter
 * @return
 */
@Override
public ResourcesWrapper<WorkflowHistoricProcessInstanceDto> search(WorkflowFilterDto filter) {
    Pageable pageable = null;
    // get pageable setting from filter - backward compatibility
    if (StringUtils.isNotEmpty(filter.getSortByFields())) {
        Sort sort = null;
        if (filter.isSortAsc()) {
            sort = new Sort(Direction.ASC, filter.getSortByFields());
        } else {
            sort = new Sort(Direction.DESC, filter.getSortByFields());
        }
        pageable = new PageRequest(filter.getPageNumber(), filter.getPageSize(), sort);
    } else {
        pageable = new PageRequest(filter.getPageNumber(), filter.getPageSize());
    }
    Page<WorkflowHistoricProcessInstanceDto> page = this.find(filter, pageable);
    return new ResourcesWrapper<>(page.getContent(), page.getTotalElements(), page.getTotalPages(), filter.getPageNumber(), filter.getPageSize());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) ResourcesWrapper(eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto)

Aggregations

WorkflowHistoricProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto)7 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)3 List (java.util.List)2 Sort (org.springframework.data.domain.Sort)2 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 ResourcesWrapper (eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper)1 WorkflowProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)1 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)1 ApiOperation (io.swagger.annotations.ApiOperation)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)1 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)1 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 Test (org.junit.Test)1 InputStreamResource (org.springframework.core.io.InputStreamResource)1 PageImpl (org.springframework.data.domain.PageImpl)1