Search in sources :

Example 6 with PvmProcessInstance

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

the class ReusableSubProcess method execute.

public void execute(ActivityExecution execution) throws Exception {
    PvmProcessInstance subProcessInstance = execution.createSubProcessInstance(processDefinition);
    // TODO set variables
    subProcessInstance.start();
}
Also used : PvmProcessInstance(org.activiti.engine.impl.pvm.PvmProcessInstance)

Example 7 with PvmProcessInstance

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

the class CallActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    String processDefinitonKey = this.processDefinitonKey;
    if (processDefinitionExpression != null) {
        processDefinitonKey = (String) processDefinitionExpression.getValue(execution);
    }
    DeploymentManager deploymentManager = Context.getProcessEngineConfiguration().getDeploymentManager();
    ProcessDefinitionEntity processDefinition = null;
    if (execution.getTenantId() == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(execution.getTenantId())) {
        processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKey(processDefinitonKey);
    } else {
        processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKeyAndTenantId(processDefinitonKey, execution.getTenantId());
    }
    // Do not start a process instance if the process definition is suspended
    if (deploymentManager.isProcessDefinitionSuspended(processDefinition.getId())) {
        throw new ActivitiException("Cannot start process instance. Process definition " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") is suspended");
    }
    PvmProcessInstance subProcessInstance = execution.createSubProcessInstance(processDefinition);
    if (inheritVariables) {
        Map<String, Object> variables = execution.getVariables();
        for (Map.Entry<String, Object> entry : variables.entrySet()) {
            subProcessInstance.setVariable(entry.getKey(), entry.getValue());
        }
    }
    // copy process variables
    for (AbstractDataAssociation dataInputAssociation : dataInputAssociations) {
        Object value = null;
        if (dataInputAssociation.getSourceExpression() != null) {
            value = dataInputAssociation.getSourceExpression().getValue(execution);
        } else {
            value = execution.getVariable(dataInputAssociation.getSource());
        }
        subProcessInstance.setVariable(dataInputAssociation.getTarget(), value);
    }
    try {
        subProcessInstance.start();
    } catch (Exception e) {
        if (!ErrorPropagation.mapException(e, execution, mapExceptions, true))
            throw e;
    }
}
Also used : PvmProcessInstance(org.activiti.engine.impl.pvm.PvmProcessInstance) ActivitiException(org.activiti.engine.ActivitiException) AbstractDataAssociation(org.activiti.engine.impl.bpmn.data.AbstractDataAssociation) DeploymentManager(org.activiti.engine.impl.persistence.deploy.DeploymentManager) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) Map(java.util.Map) ActivitiException(org.activiti.engine.ActivitiException)

Example 8 with PvmProcessInstance

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

the class PvmEventTest method testSimpleAutmaticConcurrencyEvents.

/**
   *                   +--+
   *              +--->|c1|---+
   *              |    +--+   |
   *              |           v
   * +-----+   +----+       +----+   +---+
   * |start|-->|fork|       |join|-->|end|
   * +-----+   +----+       +----+   +---+
   *              |           ^
   *              |    +--+   |
   *              +--->|c2|---+
   *                   +--+
   */
public void testSimpleAutmaticConcurrencyEvents() {
    EventCollector eventCollector = new EventCollector();
    PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("events").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("fork").endActivity().createActivity("fork").behavior(new ParallelGateway()).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).transition("c1").transition("c2").endActivity().createActivity("c1").behavior(new Automatic()).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).transition("join").endActivity().createActivity("c2").behavior(new Automatic()).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).transition("join").endActivity().createActivity("join").behavior(new ParallelGateway()).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().buildProcessDefinition();
    PvmProcessInstance processInstance = processDefinition.createProcessInstance();
    processInstance.start();
    List<String> expectedEvents = new ArrayList<String>();
    expectedEvents.add("start on ProcessDefinition(events)");
    expectedEvents.add("start on Activity(start)");
    expectedEvents.add("end on Activity(start)");
    expectedEvents.add("start on Activity(fork)");
    expectedEvents.add("end on Activity(fork)");
    expectedEvents.add("start on Activity(c1)");
    expectedEvents.add("end on Activity(c1)");
    expectedEvents.add("start on Activity(join)");
    expectedEvents.add("end on Activity(fork)");
    expectedEvents.add("start on Activity(c2)");
    expectedEvents.add("end on Activity(c2)");
    expectedEvents.add("start on Activity(join)");
    expectedEvents.add("end on Activity(join)");
    expectedEvents.add("start on Activity(end)");
    expectedEvents.add("end on Activity(end)");
    expectedEvents.add("end on ProcessDefinition(events)");
    assertEquals("expected " + expectedEvents + ", but was \n" + eventCollector + "\n", expectedEvents, eventCollector.events);
}
Also used : 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) End(org.activiti.engine.test.pvm.activities.End) ProcessDefinitionBuilder(org.activiti.engine.impl.pvm.ProcessDefinitionBuilder) Automatic(org.activiti.engine.test.pvm.activities.Automatic)

Example 9 with PvmProcessInstance

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

the class PvmEventTest method testNestedActivitiesEventsOnTransitionEvents.

/**
   *         +--------------+
   *         |outerscope    |
   *         | +----------+ |
   *         | |innerscope| |
   * +-----+ | | +----+   | | +---+
   * |start|---->|wait|------>|end|
   * +-----+ | | +----+   | | +---+
   *         | +----------+ |
   *         +--------------+
   */
public void testNestedActivitiesEventsOnTransitionEvents() {
    EventCollector eventCollector = new EventCollector();
    PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("events").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).startTransition("wait").executionListener(eventCollector).endTransition().endActivity().createActivity("outerscope").executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).createActivity("innerscope").scope().executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).createActivity("wait").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().endActivity().endActivity().createActivity("end").behavior(new WaitState()).endActivity().buildProcessDefinition();
    PvmProcessInstance processInstance = processDefinition.createProcessInstance();
    processInstance.start();
    List<String> expectedEvents = new ArrayList<String>();
    expectedEvents.add("start on ProcessDefinition(events)");
    expectedEvents.add("start on Activity(start)");
    expectedEvents.add("end on Activity(start)");
    expectedEvents.add("take on (start)-->(wait)");
    expectedEvents.add("start on Activity(outerscope)");
    expectedEvents.add("start on Activity(innerscope)");
    expectedEvents.add("start on Activity(wait)");
    assertEquals("expected " + expectedEvents + ", but was \n" + eventCollector + "\n", expectedEvents, eventCollector.events);
    PvmExecution execution = processInstance.findExecution("wait");
    execution.signal(null, null);
    expectedEvents.add("end on Activity(wait)");
    expectedEvents.add("end on Activity(innerscope)");
    expectedEvents.add("end on Activity(outerscope)");
    assertEquals("expected " + expectedEvents + ", but was \n" + eventCollector + "\n", expectedEvents, eventCollector.events);
}
Also used : WaitState(org.activiti.engine.test.pvm.activities.WaitState) PvmProcessInstance(org.activiti.engine.impl.pvm.PvmProcessInstance) 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) PvmExecution(org.activiti.engine.impl.pvm.PvmExecution)

Example 10 with PvmProcessInstance

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

the class PvmEventTest method testEmbeddedSubProcessEvents.

/**
   *           +------------------------------+
   * +-----+   | +-----------+   +----------+ |   +---+
   * |start|-->| |startInside|-->|endInsdide| |-->|end|
   * +-----+   | +-----------+   +----------+ |   +---+
   *           +------------------------------+
   */
public void testEmbeddedSubProcessEvents() {
    EventCollector eventCollector = new EventCollector();
    PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("events").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("embeddedsubprocess").endActivity().createActivity("embeddedsubprocess").scope().behavior(new EmbeddedSubProcess()).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).createActivity("startInside").behavior(new Automatic()).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).transition("endInside").endActivity().createActivity("endInside").behavior(new End()).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START, eventCollector).executionListener(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_END, eventCollector).endActivity().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().buildProcessDefinition();
    PvmProcessInstance processInstance = processDefinition.createProcessInstance();
    processInstance.start();
    List<String> expectedEvents = new ArrayList<String>();
    expectedEvents.add("start on ProcessDefinition(events)");
    expectedEvents.add("start on Activity(start)");
    expectedEvents.add("end on Activity(start)");
    expectedEvents.add("start on Activity(embeddedsubprocess)");
    expectedEvents.add("start on Activity(startInside)");
    expectedEvents.add("end on Activity(startInside)");
    expectedEvents.add("start on Activity(endInside)");
    expectedEvents.add("end on Activity(endInside)");
    expectedEvents.add("end on Activity(embeddedsubprocess)");
    expectedEvents.add("start on Activity(end)");
    expectedEvents.add("end on Activity(end)");
    expectedEvents.add("end on ProcessDefinition(events)");
    assertEquals("expected " + expectedEvents + ", but was \n" + eventCollector + "\n", expectedEvents, eventCollector.events);
}
Also used : EmbeddedSubProcess(org.activiti.engine.test.pvm.activities.EmbeddedSubProcess) PvmProcessInstance(org.activiti.engine.impl.pvm.PvmProcessInstance) ArrayList(java.util.ArrayList) 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)

Aggregations

PvmProcessInstance (org.activiti.engine.impl.pvm.PvmProcessInstance)42 ProcessDefinitionBuilder (org.activiti.engine.impl.pvm.ProcessDefinitionBuilder)40 PvmProcessDefinition (org.activiti.engine.impl.pvm.PvmProcessDefinition)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 EventScopeCreatingSubprocess (org.activiti.engine.test.pvm.activities.EventScopeCreatingSubprocess)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ActivitiException (org.activiti.engine.ActivitiException)1 AbstractDataAssociation (org.activiti.engine.impl.bpmn.data.AbstractDataAssociation)1 DeploymentManager (org.activiti.engine.impl.persistence.deploy.DeploymentManager)1 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)1 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)1 ProcessDefinitionImpl (org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl)1 ExecutionImpl (org.activiti.engine.impl.pvm.runtime.ExecutionImpl)1