Search in sources :

Example 1 with ResourcesWrapper

use of eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowProcessInstanceService method searchInternal.

@Override
public ResourcesWrapper<WorkflowProcessInstanceDto> searchInternal(WorkflowFilterDto filter, boolean checkRight) {
    String processDefinitionId = filter.getProcessDefinitionId();
    Map<String, Object> equalsVariables = filter.getEqualsVariables();
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
    query.active();
    query.includeProcessVariables();
    if (processDefinitionId != null) {
        query.processDefinitionId(processDefinitionId);
    }
    if (filter.getProcessDefinitionKey() != null) {
        query.processDefinitionKey(filter.getProcessDefinitionKey());
    }
    if (filter.getProcessInstanceId() != null) {
        query.processInstanceId(filter.getProcessInstanceId());
    }
    if (filter.getCategory() != null) {
        // Find definitions with this category (use double sided like)
        // We have to find definitions first, because process instance can't
        // be find by category.
        ProcessDefinitionQuery queryDefinition = repositoryService.createProcessDefinitionQuery();
        queryDefinition.active();
        queryDefinition.latestVersion();
        queryDefinition.processDefinitionCategoryLike(filter.getCategory() + "%");
        List<ProcessDefinition> processDefinitions = queryDefinition.list();
        Set<String> processDefinitionKeys = new HashSet<>();
        processDefinitions.forEach(p -> processDefinitionKeys.add(p.getKey()));
        if (processDefinitionKeys.isEmpty()) {
            // We don`t have any definitions ... nothing must be returned
            processDefinitionKeys.add("-1");
        }
        query.processDefinitionKeys(processDefinitionKeys);
    }
    if (equalsVariables != null) {
        for (Entry<String, Object> entry : equalsVariables.entrySet()) {
            query.variableValueEquals(entry.getKey(), entry.getValue());
        }
    }
    // (subprocess) started. This modification allow not use OR clause.
    if (checkRight && !securityService.isAdmin()) {
        query.involvedUser(securityService.getCurrentId().toString());
    }
    query.orderByProcessDefinitionId();
    query.desc();
    long count = query.count();
    List<ProcessInstance> processInstances = query.listPage((filter.getPageNumber()) * filter.getPageSize(), filter.getPageSize());
    List<WorkflowProcessInstanceDto> dtos = new ArrayList<>();
    if (processInstances != null) {
        for (ProcessInstance instance : processInstances) {
            dtos.add(toResource(instance));
        }
    }
    double totalPageDouble = ((double) count / filter.getPageSize());
    double totlaPageFlorred = Math.floor(totalPageDouble);
    long totalPage = 0;
    if (totalPageDouble > totlaPageFlorred) {
        totalPage = (long) (totlaPageFlorred + 1);
    }
    return new ResourcesWrapper<>(dtos, count, totalPage, filter.getPageNumber(), filter.getPageSize());
}
Also used : ArrayList(java.util.ArrayList) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ResourcesWrapper(eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper) ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) HashSet(java.util.HashSet)

Example 2 with ResourcesWrapper

use of eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowTaskInstanceService method search.

@Override
public ResourcesWrapper<WorkflowTaskInstanceDto> 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());
    }
    filter.setCandidateOrAssigned(securityService.getCurrentId().toString());
    Page<WorkflowTaskInstanceDto> 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) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) Sort(org.springframework.data.domain.Sort) ResourcesWrapper(eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper)

Example 3 with ResourcesWrapper

use of eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper 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)

Example 4 with ResourcesWrapper

use of eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowHistoricTaskInstanceService method search.

@Override
public ResourcesWrapper<WorkflowHistoricTaskInstanceDto> 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<WorkflowHistoricTaskInstanceDto> 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) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto) ResourcesWrapper(eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper)

Aggregations

ResourcesWrapper (eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper)4 PageRequest (org.springframework.data.domain.PageRequest)3 Pageable (org.springframework.data.domain.Pageable)3 Sort (org.springframework.data.domain.Sort)3 WorkflowHistoricProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto)1 WorkflowHistoricTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)1 WorkflowProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)1 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 ProcessDefinitionQuery (org.activiti.engine.repository.ProcessDefinitionQuery)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 ProcessInstanceQuery (org.activiti.engine.runtime.ProcessInstanceQuery)1