Search in sources :

Example 21 with ProcessDefinitionQuery

use of org.activiti.engine.repository.ProcessDefinitionQuery in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowProcessDefinitionService method findAllProcessDefinitions.

/**
 * Find all last version and active process definitions
 */
@Override
public List<WorkflowProcessDefinitionDto> findAllProcessDefinitions() {
    ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();
    query.active();
    query.latestVersion();
    List<ProcessDefinition> processDefinitions = query.list();
    List<WorkflowProcessDefinitionDto> processDefinitionDtos = new ArrayList<>();
    if (processDefinitions == null) {
        return processDefinitionDtos;
    }
    for (ProcessDefinition p : processDefinitions) {
        processDefinitionDtos.add(toDto(p));
    }
    return processDefinitionDtos;
}
Also used : ArrayList(java.util.ArrayList) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) WorkflowProcessDefinitionDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto)

Example 22 with ProcessDefinitionQuery

use of org.activiti.engine.repository.ProcessDefinitionQuery 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 23 with ProcessDefinitionQuery

use of org.activiti.engine.repository.ProcessDefinitionQuery in project Activiti by Activiti.

the class SpringAutoDeployTest method testNoRedeploymentForSpringContainerRestart.

public void testNoRedeploymentForSpringContainerRestart() throws Exception {
    createAppContext(CTX_PATH);
    DeploymentQuery deploymentQuery = repositoryService.createDeploymentQuery();
    assertEquals(1, deploymentQuery.count());
    ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
    assertEquals(3, processDefinitionQuery.count());
    // Creating a new app context with same resources doesn't lead to more
    // deployments
    new ClassPathXmlApplicationContext(CTX_NO_DROP_PATH);
    assertEquals(1, deploymentQuery.count());
    assertEquals(3, processDefinitionQuery.count());
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery)

Example 24 with ProcessDefinitionQuery

use of org.activiti.engine.repository.ProcessDefinitionQuery in project Activiti by Activiti.

the class ProcessDefinitionQueryTest method testQueryByInvalidKey.

public void testQueryByInvalidKey() {
    ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().processDefinitionKey("invalid");
    verifyQueryResults(query, 0);
    try {
        repositoryService.createProcessDefinitionQuery().processDefinitionKey(null);
        fail();
    } catch (ActivitiIllegalArgumentException e) {
    }
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery)

Example 25 with ProcessDefinitionQuery

use of org.activiti.engine.repository.ProcessDefinitionQuery in project Activiti by Activiti.

the class ProcessDefinitionQueryTest method testQueryByInvalidNameLike.

public void testQueryByInvalidNameLike() {
    ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery().processDefinitionNameLike("%invalid%");
    verifyQueryResults(query, 0);
}
Also used : ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery)

Aggregations

ProcessDefinitionQuery (org.activiti.engine.repository.ProcessDefinitionQuery)34 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)12 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)5 ArrayList (java.util.ArrayList)4 WorkflowProcessDefinitionDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 SysBpmnResourceVO (com.netsteadfast.greenstep.vo.SysBpmnResourceVO)1 ResourcesWrapper (eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper)1 WorkflowProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)1 HashSet (java.util.HashSet)1 RepositoryService (org.activiti.engine.RepositoryService)1 ProcessDefinitionImpl (org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl)1 DeploymentQuery (org.activiti.engine.repository.DeploymentQuery)1 ProcessInstanceQuery (org.activiti.engine.runtime.ProcessInstanceQuery)1 Task (org.activiti.engine.task.Task)1 Test (org.junit.Test)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1