Search in sources :

Example 1 with ProcessDefinitionImpl

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

the class AtomicOperationProcessStart method eventNotificationsCompleted.

@Override
protected void eventNotificationsCompleted(InterpretableExecution execution) {
    if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        Map<String, Object> variablesMap = null;
        try {
            variablesMap = execution.getVariables();
        } catch (Throwable t) {
        // In some rare cases getting the execution variables can fail (JPA entity load failure for example)
        // We ignore the exception here, because it's only meant to include variables in the initialized event.
        }
        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityWithVariablesEvent(ActivitiEventType.ENTITY_INITIALIZED, execution, variablesMap, false));
        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createProcessStartedEvent(execution, variablesMap, false));
    }
    ProcessDefinitionImpl processDefinition = execution.getProcessDefinition();
    StartingExecution startingExecution = execution.getStartingExecution();
    List<ActivityImpl> initialActivityStack = processDefinition.getInitialActivityStack(startingExecution.getInitial());
    execution.setActivity(initialActivityStack.get(0));
    execution.performOperation(PROCESS_START_INITIAL);
}
Also used : ProcessDefinitionImpl(org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl)

Example 2 with ProcessDefinitionImpl

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

the class PvmScopeAndEventsTest method testStartEndWithScopesAndNestedActivitiesNotAtInitial.

/**
   * +--------------------------------------------------------------------------------+
   * | mostOuterNestedActivity                                                        |                  
   * | +----------------------------------------------------------------------------+ |
   * | | outerScope (scope)                                                         | |
   * | | +----------------------------------+ +-----------------------------------+ | |
   * | | | firstInnerScope (scope)          | | secondInnerScope (scope)          | | |
   * | | | +------------------------------+ | | +-------------------------------+ | | |
   * | | | | firstMostInnerNestedActivity | | | | secondMostInnerNestedActivity | | | |
   * | | | | +-------+   +-------------+  | | | | +--------------+    +-----+   | | | |
   * | | | | | start |-->| waitInFirst |--------->| waitInSecond |--> | end |   | | | |
   * | | | | +-------+   +-------------+  | | | | +--------------+    +-----+   | | | |
   * | | | +------------------------------+ | | +-------------------------------+ | | |
   * | | +----------------------------------+ +-----------------------------------+ | |
   * | +----------------------------------------------------------------------------+ |
   * +--------------------------------------------------------------------------------+
   * 
   */
// this test does not start the process at the initial (the activity with id 'start'), but at 
// 'waitInFirst'
public void testStartEndWithScopesAndNestedActivitiesNotAtInitial() {
    EventCollector eventCollector = new EventCollector();
    PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("scopes and events").executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).createActivity("mostOuterNestedActivity").executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).createActivity("outerScope").executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).createActivity("firstInnerScope").executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).createActivity("firstMostInnerNestedActivity").executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).createActivity("start").initial().behavior(new Automatic()).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).transition("waitInFirst").endActivity().createActivity("waitInFirst").behavior(new WaitState()).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).transition("waitInSecond").endActivity().endActivity().endActivity().createActivity("secondInnerScope").executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).createActivity("secondMostInnerNestedActivity").executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).createActivity("waitInSecond").behavior(new WaitState()).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).transition("end").endActivity().createActivity("end").behavior(new End()).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).endActivity().endActivity().endActivity().endActivity().endActivity().buildProcessDefinition();
    ActivityImpl alternativeInitial = (ActivityImpl) processDefinition.findActivity("waitInFirst");
    PvmProcessInstance processInstance = ((ProcessDefinitionImpl) processDefinition).createProcessInstanceForInitial(alternativeInitial);
    processInstance.start();
    List<String> expectedEvents = new ArrayList<String>();
    expectedEvents.add("start on ProcessDefinition(scopes and events)");
    expectedEvents.add("start on Activity(mostOuterNestedActivity)");
    expectedEvents.add("start on Activity(outerScope)");
    expectedEvents.add("start on Activity(firstInnerScope)");
    expectedEvents.add("start on Activity(firstMostInnerNestedActivity)");
    expectedEvents.add("start on Activity(waitInFirst)");
    assertEquals("expected " + expectedEvents + ", but was \n" + eventCollector + "\n", expectedEvents, eventCollector.events);
    eventCollector.events.clear();
    PvmExecution execution = processInstance.findExecution("waitInFirst");
    execution.signal(null, null);
    expectedEvents = new ArrayList<String>();
    expectedEvents.add("end on Activity(waitInFirst)");
    expectedEvents.add("end on Activity(firstMostInnerNestedActivity)");
    expectedEvents.add("end on Activity(firstInnerScope)");
    expectedEvents.add("start on Activity(secondInnerScope)");
    expectedEvents.add("start on Activity(secondMostInnerNestedActivity)");
    expectedEvents.add("start on Activity(waitInSecond)");
    assertEquals("expected " + expectedEvents + ", but was \n" + eventCollector + "\n", expectedEvents, eventCollector.events);
    eventCollector.events.clear();
    execution = processInstance.findExecution("waitInSecond");
    execution.signal(null, null);
    expectedEvents = new ArrayList<String>();
    expectedEvents.add("end on Activity(waitInSecond)");
    expectedEvents.add("start on Activity(end)");
    expectedEvents.add("end on Activity(end)");
    expectedEvents.add("end on Activity(secondMostInnerNestedActivity)");
    expectedEvents.add("end on Activity(secondInnerScope)");
    expectedEvents.add("end on Activity(outerScope)");
    expectedEvents.add("end on Activity(mostOuterNestedActivity)");
    expectedEvents.add("end on ProcessDefinition(scopes and events)");
    assertEquals("expected " + expectedEvents + ", but was \n" + eventCollector + "\n", expectedEvents, eventCollector.events);
    eventCollector.events.clear();
}
Also used : WaitState(org.activiti.engine.test.pvm.activities.WaitState) PvmProcessInstance(org.activiti.engine.impl.pvm.PvmProcessInstance) ProcessDefinitionImpl(org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl) ArrayList(java.util.ArrayList) PvmExecution(org.activiti.engine.impl.pvm.PvmExecution) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) PvmProcessDefinition(org.activiti.engine.impl.pvm.PvmProcessDefinition) End(org.activiti.engine.test.pvm.activities.End) ProcessDefinitionBuilder(org.activiti.engine.impl.pvm.ProcessDefinitionBuilder) Automatic(org.activiti.engine.test.pvm.activities.Automatic)

Example 3 with ProcessDefinitionImpl

use of org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl 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 4 with ProcessDefinitionImpl

use of org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl in project bamboobsc by billchen198318.

the class TestBPMN001 method queryProcessDefinition.

@Test
public void queryProcessDefinition() throws Exception {
    RepositoryService repositoryService = (RepositoryService) AppContext.getBean("repositoryService");
    ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
    List<ProcessDefinition> processDefs = processDefinitionQuery.processDefinitionKey("Employee360DegreeFeedbackProjectPublishProcess").orderByProcessDefinitionVersion().desc().list();
    for (ProcessDefinition pd : processDefs) {
        System.out.println(pd.getId() + " , " + pd.getName() + " , " + pd.getKey() + " , " + pd.getVersion());
        ProcessDefinitionImpl pdObj = (ProcessDefinitionImpl) repositoryService.getProcessDefinition(pd.getId());
        System.out.println(pdObj.getActivities());
    }
}
Also used : ProcessDefinitionImpl(org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) RepositoryService(org.activiti.engine.RepositoryService) Test(org.junit.Test)

Example 5 with ProcessDefinitionImpl

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

the class AtomicOperationProcessStartInitial method eventNotificationsCompleted.

@Override
protected void eventNotificationsCompleted(InterpretableExecution execution) {
    ActivityImpl activity = (ActivityImpl) execution.getActivity();
    ProcessDefinitionImpl processDefinition = execution.getProcessDefinition();
    StartingExecution startingExecution = execution.getStartingExecution();
    if (activity == startingExecution.getInitial()) {
        execution.disposeStartingExecution();
        execution.performOperation(ACTIVITY_EXECUTE);
    } else {
        List<ActivityImpl> initialActivityStack = processDefinition.getInitialActivityStack(startingExecution.getInitial());
        int index = initialActivityStack.indexOf(activity);
        activity = initialActivityStack.get(index + 1);
        InterpretableExecution executionToUse = null;
        if (activity.isScope()) {
            executionToUse = (InterpretableExecution) execution.getExecutions().get(0);
        } else {
            executionToUse = execution;
        }
        executionToUse.setActivity(activity);
        executionToUse.performOperation(PROCESS_START_INITIAL);
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ProcessDefinitionImpl(org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl)

Aggregations

ProcessDefinitionImpl (org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl)8 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)6 ActivitiException (org.activiti.engine.ActivitiException)2 PvmProcessDefinition (org.activiti.engine.impl.pvm.PvmProcessDefinition)2 ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)2 ArrayList (java.util.ArrayList)1 AbstractSimulationActivityBehavior (org.activiti.crystalball.simulator.delegate.AbstractSimulationActivityBehavior)1 RepositoryService (org.activiti.engine.RepositoryService)1 UserTaskActivityBehavior (org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior)1 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)1 ProcessDefinitionBuilder (org.activiti.engine.impl.pvm.ProcessDefinitionBuilder)1 PvmExecution (org.activiti.engine.impl.pvm.PvmExecution)1 PvmProcessInstance (org.activiti.engine.impl.pvm.PvmProcessInstance)1 ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 ProcessDefinitionQuery (org.activiti.engine.repository.ProcessDefinitionQuery)1 Automatic (org.activiti.engine.test.pvm.activities.Automatic)1 End (org.activiti.engine.test.pvm.activities.End)1 WaitState (org.activiti.engine.test.pvm.activities.WaitState)1 Test (org.junit.Test)1