Search in sources :

Example 31 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class BoundaryEventActivityBehavior method execute.

@SuppressWarnings("unchecked")
public void execute(ActivityExecution execution) throws Exception {
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    ActivityImpl boundaryActivity = executionEntity.getProcessDefinition().findActivity(activityId);
    ActivityImpl interruptedActivity = executionEntity.getActivity();
    List<PvmTransition> outgoingTransitions = boundaryActivity.getOutgoingTransitions();
    List<ExecutionEntity> interruptedExecutions = null;
    if (interrupting) {
        // Call activity
        if (executionEntity.getSubProcessInstance() != null) {
            executionEntity.getSubProcessInstance().deleteCascade(executionEntity.getDeleteReason());
        } else {
            Context.getCommandContext().getHistoryManager().recordActivityEnd(executionEntity);
        }
        executionEntity.setActivity(boundaryActivity);
        interruptedExecutions = new ArrayList<ExecutionEntity>(executionEntity.getExecutions());
        for (ExecutionEntity interruptedExecution : interruptedExecutions) {
            interruptedExecution.deleteCascade("interrupting boundary event '" + execution.getActivity().getId() + "' fired");
        }
        execution.takeAll(outgoingTransitions, (List) interruptedExecutions);
    } else {
        // non interrupting event, introduced with BPMN 2.0, we need to create a new execution in this case
        // create a new execution and move it out from the timer activity
        ExecutionEntity concurrentRoot = executionEntity.getParent().isConcurrent() ? executionEntity.getParent() : executionEntity;
        ExecutionEntity outgoingExecution = concurrentRoot.createExecution();
        outgoingExecution.setActive(true);
        outgoingExecution.setScope(false);
        outgoingExecution.setConcurrent(true);
        outgoingExecution.takeAll(outgoingTransitions, Collections.EMPTY_LIST);
        outgoingExecution.remove();
        // now we have to move the execution back to the real activity
        // since the execution stays there (non interrupting) and it was
        // set to the boundary event before
        executionEntity.setActivity(interruptedActivity);
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

Example 32 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class ExecutionQueryImpl method executeList.

@SuppressWarnings({ "unchecked" })
public List<Execution> executeList(CommandContext commandContext, Page page) {
    checkQueryOk();
    ensureVariablesInitialized();
    List<?> executions = commandContext.getExecutionEntityManager().findExecutionsByQueryCriteria(this, page);
    for (ExecutionEntity execution : (List<ExecutionEntity>) executions) {
        String activityId = null;
        if (execution.getId().equals(execution.getProcessInstanceId())) {
            if (execution.getProcessDefinitionId() != null) {
                ProcessDefinitionEntity processDefinition = commandContext.getProcessEngineConfiguration().getDeploymentManager().findDeployedProcessDefinitionById(execution.getProcessDefinitionId());
                activityId = processDefinition.getKey();
            }
        } else {
            activityId = execution.getActivityId();
        }
        if (activityId != null) {
            localize(execution, activityId);
        }
    }
    return (List<Execution>) executions;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ArrayList(java.util.ArrayList) List(java.util.List) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 33 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class StartToEndTest method testStartProcessInstanceWithServiceTask.

@Deployment(resources = { "org/activiti/engine/test/bpmn/StartToEndTest.testStartWithServiceTask.bpmn20.xml" })
public void testStartProcessInstanceWithServiceTask() {
    Map<String, Object> varMap = new HashMap<String, Object>();
    varMap.put("test", "hello");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("startToEnd", varMap);
    assertProcessEnded(processInstance.getId());
    Map<String, Object> returnVarMap = ((ExecutionEntity) processInstance).getVariableValues();
    assertEquals("hello", returnVarMap.get("test"));
    assertEquals("string", returnVarMap.get("string"));
    assertEquals(true, returnVarMap.get("boolean"));
    assertEquals(25.5, returnVarMap.get("double"));
    assertEquals(10L, returnVarMap.get("long"));
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 34 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class StartToEndTest method testStartProcessInstanceWithVariables.

@Deployment(resources = { "org/activiti/engine/test/bpmn/StartToEndTest.testStartToEnd.bpmn20.xml" })
public void testStartProcessInstanceWithVariables() {
    Map<String, Object> varMap = new HashMap<String, Object>();
    varMap.put("test", "hello");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("startToEnd", varMap);
    assertProcessEnded(processInstance.getId());
    Map<String, Object> returnVarMap = ((ExecutionEntity) processInstance).getVariableValues();
    assertEquals("hello", returnVarMap.get("test"));
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 35 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project midpoint by Evolveum.

the class DumpVariables method dumpExecutionVariables.

private void dumpExecutionVariables(String executionId, DelegateExecution delegateExecution, Execution execution, Set<String> variablesSeen, RuntimeService runtimeService) {
    Map<String, Object> variablesLocal = runtimeService.getVariablesLocal(executionId);
    LOGGER.trace("Execution id={} ({} variables); class={}/{}", executionId, variablesLocal.size(), delegateExecution != null ? delegateExecution.getClass().getName() : null, execution != null ? execution.getClass().getName() : null);
    TreeSet<String> names = new TreeSet<>(variablesLocal.keySet());
    names.forEach(n -> LOGGER.trace(" - {} = {} {}", n, variablesLocal.get(n), variablesSeen.contains(n) ? "(dup)" : ""));
    variablesSeen.addAll(variablesLocal.keySet());
    if (delegateExecution instanceof ExecutionEntity) {
        ExecutionEntity executionEntity = (ExecutionEntity) delegateExecution;
        if (executionEntity.getParent() != null) {
            dumpExecutionVariables(executionEntity.getParentId(), executionEntity.getParent(), null, variablesSeen, runtimeService);
        }
    } else if (delegateExecution instanceof ExecutionImpl) {
        ExecutionImpl executionImpl = (ExecutionImpl) delegateExecution;
        if (executionImpl.getParent() != null) {
            dumpExecutionVariables(executionImpl.getParentId(), executionImpl.getParent(), null, variablesSeen, runtimeService);
        }
    } else {
        Execution execution1 = runtimeService.createExecutionQuery().executionId(executionId).singleResult();
        if (execution1 == null) {
            LOGGER.trace("Execution with id {} was not found.", executionId);
        } else if (execution1.getParentId() != null) {
            Execution execution2 = runtimeService.createExecutionQuery().executionId(execution1.getParentId()).singleResult();
            dumpExecutionVariables(execution.getParentId(), null, execution2, variablesSeen, runtimeService);
        }
    }
}
Also used : DelegateExecution(org.activiti.engine.delegate.DelegateExecution) Execution(org.activiti.engine.runtime.Execution) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ExecutionImpl(org.activiti.engine.impl.pvm.runtime.ExecutionImpl)

Aggregations

ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)58 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)15 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)15 ActivitiException (org.activiti.engine.ActivitiException)12 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)11 ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)8 HashMap (java.util.HashMap)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 CompensateEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity)5 Deployment (org.activiti.engine.test.Deployment)5 ArrayList (java.util.ArrayList)4 DeploymentManager (org.activiti.engine.impl.persistence.deploy.DeploymentManager)4 AttachmentEntity (org.activiti.engine.impl.persistence.entity.AttachmentEntity)3 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)3 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)3 List (java.util.List)2 ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)2