Search in sources :

Example 31 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class AbstractSetProcessInstanceStateCmd method execute.

public Void execute(CommandContext commandContext) {
    if (executionId == null) {
        throw new ActivitiIllegalArgumentException("ProcessInstanceId cannot be null.");
    }
    ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findExecutionById(executionId);
    if (executionEntity == null) {
        throw new ActivitiObjectNotFoundException("Cannot find processInstance for id '" + executionId + "'.", Execution.class);
    }
    if (!executionEntity.isProcessInstanceType()) {
        throw new ActivitiException("Cannot set suspension state for execution '" + executionId + "': not a process instance.");
    }
    SuspensionStateUtil.setSuspensionState(executionEntity, getNewState());
    // All child executions are suspended
    List<ExecutionEntity> childExecutions = commandContext.getExecutionEntityManager().findChildExecutionsByProcessInstanceId(executionId);
    for (ExecutionEntity childExecution : childExecutions) {
        if (!childExecution.getId().equals(executionId)) {
            SuspensionStateUtil.setSuspensionState(childExecution, getNewState());
        }
    }
    // All tasks are suspended
    List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByProcessInstanceId(executionId);
    for (TaskEntity taskEntity : tasks) {
        SuspensionStateUtil.setSuspensionState(taskEntity, getNewState());
    }
    return null;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 32 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class SetProcessInstanceNameCmd method execute.

@Override
public Void execute(CommandContext commandContext) {
    if (processInstanceId == null) {
        throw new ActivitiIllegalArgumentException("processInstanceId is null");
    }
    ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
    if (execution == null) {
        throw new ActivitiObjectNotFoundException("process instance " + processInstanceId + " doesn't exist", ProcessInstance.class);
    }
    if (!execution.isProcessInstanceType()) {
        throw new ActivitiObjectNotFoundException("process instance " + processInstanceId + " doesn't exist, the given ID references an execution, though", ProcessInstance.class);
    }
    if (execution.isSuspended()) {
        throw new ActivitiException("process instance " + processInstanceId + " is suspended, cannot set name");
    }
    // Actually set the name
    execution.setName(name);
    // Record the change in history
    commandContext.getHistoryManager().recordProcessInstanceNameChange(processInstanceId, name);
    return null;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 33 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class NeedsActiveProcessDefinitionCmd method execute.

public T execute(CommandContext commandContext) {
    DeploymentManager deploymentManager = commandContext.getProcessEngineConfiguration().getDeploymentManager();
    ProcessDefinitionEntity processDefinition = deploymentManager.findDeployedProcessDefinitionById(processDefinitionId);
    if (deploymentManager.isProcessDefinitionSuspended(processDefinitionId)) {
        throw new ActivitiException("Cannot execute operation because process definition '" + processDefinition.getName() + "' (id=" + processDefinition.getId() + ") is supended");
    }
    return execute(commandContext, processDefinition);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) DeploymentManager(org.activiti.engine.impl.persistence.deploy.DeploymentManager) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 34 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class ProcessInstanceSuspensionTest method testTaskOperationsFailAfterProcessInstanceSuspend.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testTaskOperationsFailAfterProcessInstanceSuspend() {
    // Start a new process instance with one task
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    final Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(task);
    // Suspend the process instance
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    // Completing the task should fail
    try {
        taskService.complete(task.getId());
        fail("It is not allowed to complete a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Claiming the task should fail
    try {
        taskService.claim(task.getId(), "jos");
        fail("It is not allowed to claim a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Setting variable on the task should fail
    try {
        taskService.setVariable(task.getId(), "someVar", "someValue");
        fail("It is not allowed to set a variable on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Setting variable on the task should fail
    try {
        taskService.setVariableLocal(task.getId(), "someVar", "someValue");
        fail("It is not allowed to set a variable on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Setting variables on the task should fail
    try {
        HashMap<String, String> variables = new HashMap<String, String>();
        variables.put("varOne", "one");
        variables.put("varTwo", "two");
        taskService.setVariables(task.getId(), variables);
        fail("It is not allowed to set variables on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Setting variables on the task should fail
    try {
        HashMap<String, String> variables = new HashMap<String, String>();
        variables.put("varOne", "one");
        variables.put("varTwo", "two");
        taskService.setVariablesLocal(task.getId(), variables);
        fail("It is not allowed to set variables on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Removing variable on the task should fail
    try {
        taskService.removeVariable(task.getId(), "someVar");
        fail("It is not allowed to remove a variable on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Removing variable on the task should fail
    try {
        taskService.removeVariableLocal(task.getId(), "someVar");
        fail("It is not allowed to remove a variable on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Removing variables on the task should fail
    try {
        taskService.removeVariables(task.getId(), Arrays.asList("one", "two"));
        fail("It is not allowed to remove variables on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Removing variables on the task should fail
    try {
        taskService.removeVariablesLocal(task.getId(), Arrays.asList("one", "two"));
        fail("It is not allowed to remove variables on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Adding candidate groups on the task should fail
    try {
        taskService.addCandidateGroup(task.getId(), "blahGroup");
        fail("It is not allowed to add a candidate group on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Adding candidate users on the task should fail
    try {
        taskService.addCandidateUser(task.getId(), "blahUser");
        fail("It is not allowed to add a candidate user on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Adding candidate users on the task should fail
    try {
        taskService.addGroupIdentityLink(task.getId(), "blahGroup", IdentityLinkType.CANDIDATE);
        fail("It is not allowed to add a candidate user on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Adding an identity link on the task should fail
    try {
        taskService.addUserIdentityLink(task.getId(), "blahUser", IdentityLinkType.OWNER);
        fail("It is not allowed to add an identityLink on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Adding a comment on the task should fail
    try {
        taskService.addComment(task.getId(), processInstance.getId(), "test comment");
        fail("It is not allowed to add a comment on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Adding an attachment on the task should fail
    try {
        taskService.createAttachment("text", task.getId(), processInstance.getId(), "testName", "testDescription", "http://test.com");
        fail("It is not allowed to add an attachment on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Set an assignee on the task should fail
    try {
        taskService.setAssignee(task.getId(), "mispiggy");
        fail("It is not allowed to set an assignee on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Set an owner on the task should fail
    try {
        taskService.setOwner(task.getId(), "kermit");
        fail("It is not allowed to set an owner on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
    // Set priority on the task should fail
    try {
        taskService.setPriority(task.getId(), 99);
        fail("It is not allowed to set a priority on a task of a suspended process instance");
    } catch (ActivitiException e) {
    // This is good
    }
}
Also used : Task(org.activiti.engine.task.Task) ActivitiException(org.activiti.engine.ActivitiException) HashMap(java.util.HashMap) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 35 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class ProcessInstanceSuspensionTest method testSubmitTaskFormAfterProcessInstanceSuspend.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testSubmitTaskFormAfterProcessInstanceSuspend() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    try {
        formService.submitTaskFormData(taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult().getId(), new HashMap<String, String>());
        fail();
    } catch (ActivitiException e) {
    // This is expected
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)247 Deployment (org.activiti.engine.test.Deployment)38 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)36 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)35 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)31 IOException (java.io.IOException)28 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 ArrayList (java.util.ArrayList)20 TaskQuery (org.activiti.engine.task.TaskQuery)16 HashMap (java.util.HashMap)14 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)14 Task (org.activiti.engine.task.Task)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 ObjectOutputStream (java.io.ObjectOutputStream)10 Date (java.util.Date)10 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)10 JobExecutor (org.activiti.engine.impl.jobexecutor.JobExecutor)9