Search in sources :

Example 1 with PvmProcessDefinition

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

the class ErrorPropagation method executeCatch.

private static void executeCatch(String errorHandlerId, ActivityExecution execution, String errorCode) {
    ProcessDefinitionImpl processDefinition = ((ExecutionEntity) execution).getProcessDefinition();
    ActivityImpl errorHandler = processDefinition.findActivity(errorHandlerId);
    if (errorHandler == null) {
        throw new ActivitiException(errorHandlerId + " not found in process definition");
    }
    boolean matchingParentFound = false;
    ActivityExecution leavingExecution = execution;
    ActivityImpl currentActivity = (ActivityImpl) execution.getActivity();
    ScopeImpl catchingScope = errorHandler.getParent();
    if (catchingScope instanceof ActivityImpl) {
        ActivityImpl catchingScopeActivity = (ActivityImpl) catchingScope;
        if (!catchingScopeActivity.isScope()) {
            // event subprocesses
            catchingScope = catchingScopeActivity.getParent();
        }
    }
    if (catchingScope instanceof PvmProcessDefinition) {
        executeEventHandler(errorHandler, ((ExecutionEntity) execution).getProcessInstance(), errorCode);
    } else {
        if (currentActivity.getId().equals(catchingScope.getId())) {
            matchingParentFound = true;
        } else {
            currentActivity = (ActivityImpl) currentActivity.getParent();
            // and matches the activity the boundary event is defined on
            while (!matchingParentFound && leavingExecution != null && currentActivity != null) {
                if (!leavingExecution.isConcurrent() && currentActivity.getId().equals(catchingScope.getId())) {
                    matchingParentFound = true;
                } else if (leavingExecution.isConcurrent()) {
                    leavingExecution = leavingExecution.getParent();
                } else {
                    currentActivity = currentActivity.getParentActivity();
                    leavingExecution = leavingExecution.getParent();
                }
            }
            // Follow parents up until matching scope can't be found anymore (needed to support for multi-instance)
            while (leavingExecution != null && leavingExecution.getParent() != null && leavingExecution.getParent().getActivity() != null && leavingExecution.getParent().getActivity().getId().equals(catchingScope.getId())) {
                leavingExecution = leavingExecution.getParent();
            }
        }
        if (matchingParentFound && leavingExecution != null) {
            executeEventHandler(errorHandler, leavingExecution, errorCode);
        } else {
            throw new ActivitiException("No matching parent execution for activity " + errorHandlerId + " found");
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinitionImpl(org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) PvmProcessDefinition(org.activiti.engine.impl.pvm.PvmProcessDefinition) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl)

Example 2 with PvmProcessDefinition

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

the class ScopeUtil method findScopeExecutionForScope.

/**
   * returns the top-most execution sitting in an activity part of the scope defined by 'scopeActivitiy'.
   */
public static ExecutionEntity findScopeExecutionForScope(ExecutionEntity execution, PvmScope scopeActivity) {
    if (scopeActivity instanceof PvmProcessDefinition) {
        return execution.getProcessInstance();
    } else {
        ActivityImpl currentActivity = execution.getActivity();
        ExecutionEntity candiadateExecution = null;
        ExecutionEntity originalExecution = execution;
        while (execution != null) {
            currentActivity = execution.getActivity();
            if (scopeActivity.getActivities().contains(currentActivity) || /* does not search rec*/
            scopeActivity.equals(currentActivity)) {
                // found a candidate execution; lets still check whether we find an
                // execution which is also sitting in an activity part of this scope
                // higher up the hierarchy
                candiadateExecution = execution;
            } else if (currentActivity != null && currentActivity.contains((ActivityImpl) scopeActivity)) /*searches rec*/
            {
                // now we're too "high", the candidate execution is the one.
                break;
            }
            execution = execution.getParent();
        }
        // if activity is scope, we need to get the parent at least:
        if (originalExecution == candiadateExecution && originalExecution.getActivity().isScope() && !originalExecution.getActivity().equals(scopeActivity)) {
            candiadateExecution = originalExecution.getParent();
        }
        return candiadateExecution;
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) PvmProcessDefinition(org.activiti.engine.impl.pvm.PvmProcessDefinition)

Example 3 with PvmProcessDefinition

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

the class PvmTest method testPvmAutomatic.

public void testPvmAutomatic() {
    PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().createActivity("a").initial().behavior(new Automatic()).transition("b").endActivity().createActivity("b").behavior(new Automatic()).transition("c").endActivity().createActivity("c").behavior(new WaitState()).endActivity().buildProcessDefinition();
    PvmProcessInstance processInstance = processDefinition.createProcessInstance();
    processInstance.start();
    assertNotNull(processInstance.findExecution("c"));
}
Also used : PvmProcessInstance(org.activiti.engine.impl.pvm.PvmProcessInstance) PvmProcessDefinition(org.activiti.engine.impl.pvm.PvmProcessDefinition) ProcessDefinitionBuilder(org.activiti.engine.impl.pvm.ProcessDefinitionBuilder)

Example 4 with PvmProcessDefinition

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

the class PvmTest method testPvmDecision.

public void testPvmDecision() {
    PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().createActivity("start").initial().behavior(new Automatic()).transition("checkCredit").endActivity().createActivity("checkCredit").behavior(new Decision()).transition("askDaughterOut", "wow").transition("takeToGolf", "nice").transition("ignore", "default").endActivity().createActivity("takeToGolf").behavior(new WaitState()).endActivity().createActivity("askDaughterOut").behavior(new WaitState()).endActivity().createActivity("ignore").behavior(new WaitState()).endActivity().buildProcessDefinition();
    PvmProcessInstance processInstance = processDefinition.createProcessInstance();
    processInstance.setVariable("creditRating", "Aaa-");
    processInstance.start();
    assertNotNull(processInstance.findExecution("takeToGolf"));
    processInstance = processDefinition.createProcessInstance();
    processInstance.setVariable("creditRating", "AAA+");
    processInstance.start();
    assertNotNull(processInstance.findExecution("askDaughterOut"));
    processInstance = processDefinition.createProcessInstance();
    processInstance.setVariable("creditRating", "bb-");
    processInstance.start();
    assertNotNull(processInstance.findExecution("ignore"));
}
Also used : PvmProcessInstance(org.activiti.engine.impl.pvm.PvmProcessInstance) PvmProcessDefinition(org.activiti.engine.impl.pvm.PvmProcessDefinition) ProcessDefinitionBuilder(org.activiti.engine.impl.pvm.ProcessDefinitionBuilder)

Example 5 with PvmProcessDefinition

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

the class PvmScopesAndConcurrencyTest method testConcurrentPathsComingOutOfScope.

/**
   *         +---------+ 
   *         |scope    |  +--+
   *         |      +---->|c1|
   *         |      |  |  +--+
   *         |      |  |
   * +-----+ |  +----+ |  +--+ 
   * |start|--->|fork|--->|c2|
   * +-----+ |  +----+ |  +--+
   *         |      |  |
   *         |      |  |  +--+
   *         |      +---->|c3|
   *         |         |  +--+
   *         +---------+
   */
public void testConcurrentPathsComingOutOfScope() {
    PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder().createActivity("start").initial().behavior(new Automatic()).transition("fork").endActivity().createActivity("scope").scope().createActivity("fork").behavior(new ParallelGateway()).transition("c1").transition("c2").transition("c3").endActivity().endActivity().createActivity("c1").behavior(new WaitState()).endActivity().createActivity("c2").behavior(new WaitState()).endActivity().createActivity("c3").behavior(new WaitState()).endActivity().buildProcessDefinition();
    PvmProcessInstance processInstance = processDefinition.createProcessInstance();
    processInstance.start();
    List<String> activeActivityIds = processInstance.findActiveActivityIds();
    List<String> expectedActiveActivityIds = new ArrayList<String>();
    expectedActiveActivityIds.add("c3");
    expectedActiveActivityIds.add("c1");
    expectedActiveActivityIds.add("c2");
    assertEquals(expectedActiveActivityIds, activeActivityIds);
}
Also used : WaitState(org.activiti.engine.test.pvm.activities.WaitState) PvmProcessInstance(org.activiti.engine.impl.pvm.PvmProcessInstance) ParallelGateway(org.activiti.engine.test.pvm.activities.ParallelGateway) ArrayList(java.util.ArrayList) PvmProcessDefinition(org.activiti.engine.impl.pvm.PvmProcessDefinition) ProcessDefinitionBuilder(org.activiti.engine.impl.pvm.ProcessDefinitionBuilder) Automatic(org.activiti.engine.test.pvm.activities.Automatic)

Aggregations

PvmProcessDefinition (org.activiti.engine.impl.pvm.PvmProcessDefinition)42 ProcessDefinitionBuilder (org.activiti.engine.impl.pvm.ProcessDefinitionBuilder)40 PvmProcessInstance (org.activiti.engine.impl.pvm.PvmProcessInstance)40 Automatic (org.activiti.engine.test.pvm.activities.Automatic)36 End (org.activiti.engine.test.pvm.activities.End)24 WaitState (org.activiti.engine.test.pvm.activities.WaitState)24 ArrayList (java.util.ArrayList)16 PvmExecution (org.activiti.engine.impl.pvm.PvmExecution)16 ParallelGateway (org.activiti.engine.test.pvm.activities.ParallelGateway)15 EmbeddedSubProcess (org.activiti.engine.test.pvm.activities.EmbeddedSubProcess)9 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)3 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)2 ProcessDefinitionImpl (org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl)2 EventScopeCreatingSubprocess (org.activiti.engine.test.pvm.activities.EventScopeCreatingSubprocess)2 HashMap (java.util.HashMap)1 ActivitiException (org.activiti.engine.ActivitiException)1 ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)1 ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)1 ExecutionImpl (org.activiti.engine.impl.pvm.runtime.ExecutionImpl)1 ReusableSubProcess (org.activiti.engine.test.pvm.activities.ReusableSubProcess)1