Search in sources :

Example 16 with PvmTransition

use of org.activiti.engine.impl.pvm.PvmTransition in project Activiti by Activiti.

the class ExecutionImpl method takeAll.

@SuppressWarnings("unchecked")
public void takeAll(List<PvmTransition> transitions, List<ActivityExecution> recyclableExecutions) {
    transitions = new ArrayList<PvmTransition>(transitions);
    recyclableExecutions = (recyclableExecutions != null ? new ArrayList<ActivityExecution>(recyclableExecutions) : new ArrayList<ActivityExecution>());
    if (recyclableExecutions.size() > 1) {
        for (ActivityExecution recyclableExecution : recyclableExecutions) {
            if (((ExecutionImpl) recyclableExecution).isScope()) {
                throw new PvmException("joining scope executions is not allowed");
            }
        }
    }
    ExecutionImpl concurrentRoot = ((isConcurrent && !isScope) ? getParent() : this);
    List<ExecutionImpl> concurrentActiveExecutions = new ArrayList<ExecutionImpl>();
    for (ExecutionImpl execution : concurrentRoot.getExecutions()) {
        if (execution.isActive()) {
            concurrentActiveExecutions.add(execution);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("transitions to take concurrent: {}", transitions);
        log.debug("active concurrent executions: {}", concurrentActiveExecutions);
    }
    if ((transitions.size() == 1) && (concurrentActiveExecutions.isEmpty())) {
        @SuppressWarnings("rawtypes") List<ExecutionImpl> recyclableExecutionImpls = (List) recyclableExecutions;
        for (ExecutionImpl prunedExecution : recyclableExecutionImpls) {
            // Others are already ended (end activities)
            if (!prunedExecution.isEnded()) {
                log.debug("pruning execution {}", prunedExecution);
                prunedExecution.remove();
            }
        }
        log.debug("activating the concurrent root {} as the single path of execution going forward", concurrentRoot);
        concurrentRoot.setActive(true);
        concurrentRoot.setActivity(activity);
        concurrentRoot.setConcurrent(false);
        concurrentRoot.take(transitions.get(0));
    } else {
        List<OutgoingExecution> outgoingExecutions = new ArrayList<OutgoingExecution>();
        recyclableExecutions.remove(concurrentRoot);
        log.debug("recyclable executions for reused: {}", recyclableExecutions);
        // first create the concurrent executions
        while (!transitions.isEmpty()) {
            PvmTransition outgoingTransition = transitions.remove(0);
            ExecutionImpl outgoingExecution = null;
            if (recyclableExecutions.isEmpty()) {
                outgoingExecution = concurrentRoot.createExecution();
                log.debug("new {} created to take transition {}", outgoingExecution, outgoingTransition);
            } else {
                outgoingExecution = (ExecutionImpl) recyclableExecutions.remove(0);
                log.debug("recycled {} to take transition {}", outgoingExecution, outgoingTransition);
            }
            outgoingExecution.setActive(true);
            outgoingExecution.setScope(false);
            outgoingExecution.setConcurrent(true);
            outgoingExecutions.add(new OutgoingExecution(outgoingExecution, outgoingTransition, true));
        }
        // prune the executions that are not recycled 
        for (ActivityExecution prunedExecution : recyclableExecutions) {
            log.debug("pruning execution {}", prunedExecution);
            prunedExecution.end();
        }
        // then launch all the concurrent executions
        for (OutgoingExecution outgoingExecution : outgoingExecutions) {
            outgoingExecution.take();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) PvmException(org.activiti.engine.impl.pvm.PvmException)

Example 17 with PvmTransition

use of org.activiti.engine.impl.pvm.PvmTransition in project Activiti by Activiti.

the class WaitState method signal.

public void signal(ActivityExecution execution, String signalName, Object event) {
    PvmTransition transition = findTransition(execution, signalName);
    execution.take(transition);
}
Also used : PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

Example 18 with PvmTransition

use of org.activiti.engine.impl.pvm.PvmTransition in project Activiti by Activiti.

the class Automatic method execute.

public void execute(ActivityExecution activityContext) throws Exception {
    PvmTransition defaultOutgoingTransition = activityContext.getActivity().getOutgoingTransitions().get(0);
    activityContext.take(defaultOutgoingTransition);
}
Also used : PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

Example 19 with PvmTransition

use of org.activiti.engine.impl.pvm.PvmTransition in project Activiti by Activiti.

the class Decision method execute.

public void execute(ActivityExecution execution) throws Exception {
    PvmTransition transition;
    String creditRating = (String) execution.getVariable("creditRating");
    if (creditRating.equals("AAA+")) {
        transition = execution.getActivity().findOutgoingTransition("wow");
    } else if (creditRating.equals("Aaa-")) {
        transition = execution.getActivity().findOutgoingTransition("nice");
    } else {
        transition = execution.getActivity().findOutgoingTransition("default");
    }
    execution.take(transition);
}
Also used : PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

Example 20 with PvmTransition

use of org.activiti.engine.impl.pvm.PvmTransition in project Activiti by Activiti.

the class BpmnParseTest method testParseNamespaceInConditionExpressionType.

@Deployment
public void testParseNamespaceInConditionExpressionType() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    ProcessDefinitionEntity processDefinitionEntity = commandExecutor.execute(new Command<ProcessDefinitionEntity>() {

        public ProcessDefinitionEntity execute(CommandContext commandContext) {
            return Context.getProcessEngineConfiguration().getDeploymentManager().findDeployedLatestProcessDefinitionByKey("resolvableNamespacesProcess");
        }
    });
    // Test that the process definition has been deployed
    assertNotNull(processDefinitionEntity);
    ActivityImpl activity = processDefinitionEntity.findActivity("ExclusiveGateway_1");
    assertNotNull(activity);
    // Test that the conditions has been resolved
    for (PvmTransition transition : activity.getOutgoingTransitions()) {
        if (transition.getDestination().getId().equals("Task_2")) {
            assertTrue(transition.getProperty("conditionText").equals("#{approved}"));
        } else if (transition.getDestination().getId().equals("Task_3")) {
            assertTrue(transition.getProperty("conditionText").equals("#{!approved}"));
        } else {
            fail("Something went wrong");
        }
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) Deployment(org.activiti.engine.test.Deployment)

Aggregations

PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)25 ArrayList (java.util.ArrayList)8 ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)7 PvmActivity (org.activiti.engine.impl.pvm.PvmActivity)6 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)6 ActivitiException (org.activiti.engine.ActivitiException)3 Expression (org.activiti.engine.delegate.Expression)3 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)3 Condition (org.activiti.engine.impl.Condition)3 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)3 List (java.util.List)2 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)2 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)2 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)2 PvmException (org.activiti.engine.impl.pvm.PvmException)2 TransitionImpl (org.activiti.engine.impl.pvm.process.TransitionImpl)2 InterpretableExecution (org.activiti.engine.impl.pvm.runtime.InterpretableExecution)2 Deployment (org.activiti.engine.test.Deployment)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1