Search in sources :

Example 11 with CmmnExecution

use of org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution in project camunda-bpm-platform by camunda.

the class DefaultCmmnHistoryEventProducer method createCaseInstanceCreateEvt.

public HistoryEvent createCaseInstanceCreateEvt(DelegateCaseExecution caseExecution) {
    final CaseExecutionEntity caseExecutionEntity = (CaseExecutionEntity) caseExecution;
    // create event instance
    HistoricCaseInstanceEventEntity evt = newCaseInstanceEventEntity(caseExecutionEntity);
    // initialize event
    initCaseInstanceEvent(evt, caseExecutionEntity, HistoryEventTypes.CASE_INSTANCE_CREATE);
    // set create time
    evt.setCreateTime(ClockUtil.getCurrentTime());
    // set create user id
    evt.setCreateUserId(Context.getCommandContext().getAuthenticatedUserId());
    // set super case instance id
    CmmnExecution superCaseExecution = caseExecutionEntity.getSuperCaseExecution();
    if (superCaseExecution != null) {
        evt.setSuperCaseInstanceId(superCaseExecution.getCaseInstanceId());
    }
    // set super process instance id
    ExecutionEntity superExecution = caseExecutionEntity.getSuperExecution();
    if (superExecution != null) {
        evt.setSuperProcessInstanceId(superExecution.getProcessInstanceId());
    }
    return evt;
}
Also used : CaseExecutionEntity(org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity) CaseExecutionEntity(org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) CmmnExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution) HistoricCaseInstanceEventEntity(org.camunda.bpm.engine.impl.history.event.HistoricCaseInstanceEventEntity)

Example 12 with CmmnExecution

use of org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution in project camunda-bpm-platform by camunda.

the class CaseTaskTest method testSuspendSubCaseInstance.

/**
 * default behaviour of manual activation changed - remove manual activation
 * change definition of oneTaskCase in order to allow suspension state
 */
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneCaseTaskCase.cmmn", "org/camunda/bpm/engine/test/api/cmmn/oneTaskCaseWithManualActivation.cmmn" })
public void testSuspendSubCaseInstance() {
    // given
    String superCaseInstanceId = createCaseInstanceByKey(ONE_CASE_TASK_CASE).getId();
    String caseTaskId = queryCaseExecutionByActivityId(CASE_TASK).getId();
    String subCaseInstanceId = queryOneTaskCaseInstance().getId();
    // when
    suspend(subCaseInstanceId);
    // then
    CmmnExecution subCaseInstance = (CmmnExecution) queryOneTaskCaseInstance();
    assertNotNull(subCaseInstance);
    assertTrue(subCaseInstance.isSuspended());
    CaseExecution caseTask = queryCaseExecutionByActivityId(CASE_TASK);
    assertNotNull(caseTask);
    assertTrue(caseTask.isActive());
    // complete ////////////////////////////////////////////////////////
    close(subCaseInstanceId);
    assertCaseEnded(subCaseInstanceId);
    terminate(caseTaskId);
    close(superCaseInstanceId);
    assertCaseEnded(superCaseInstanceId);
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) CmmnExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 13 with CmmnExecution

use of org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution in project camunda-bpm-platform by camunda.

the class CmmnCaseDefinition method createCaseInstance.

public CmmnCaseInstance createCaseInstance(String businessKey) {
    // create a new case instance
    CmmnExecution caseInstance = newCaseInstance();
    // set the definition...
    caseInstance.setCaseDefinition(this);
    // ... and the case instance (identity)
    caseInstance.setCaseInstance(caseInstance);
    // set the business key
    caseInstance.setBusinessKey(businessKey);
    // get the case plan model as "initial" activity
    CmmnActivity casePlanModel = getActivities().get(0);
    // set the case plan model activity
    caseInstance.setActivity(casePlanModel);
    return caseInstance;
}
Also used : CmmnExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution)

Example 14 with CmmnExecution

use of org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution in project camunda-bpm-platform by camunda.

the class StageActivityBehavior method canComplete.

protected boolean canComplete(CmmnActivityExecution execution, boolean throwException, boolean autoComplete) {
    String id = execution.getId();
    List<? extends CmmnExecution> children = execution.getCaseExecutions();
    if (children == null || children.isEmpty()) {
        // then the stage can complete.
        return true;
    }
    // verify there are no STATE_ACTIVE children
    for (CmmnExecution child : children) {
        if (child.isActive()) {
            if (throwException) {
                throw LOG.remainingChildException("complete", id, child.getId(), CaseExecutionState.ACTIVE);
            }
            return false;
        }
    }
    if (autoComplete) {
        for (CmmnExecution child : children) {
            if (child.isRequired() && !child.isDisabled() && !child.isCompleted() && !child.isTerminated()) {
                if (throwException) {
                    throw LOG.remainingChildException("complete", id, child.getId(), child.getCurrentState());
                }
                return false;
            }
        }
    } else {
        for (CmmnExecution child : children) {
            if (!child.isDisabled() && !child.isCompleted() && !child.isTerminated()) {
                if (throwException) {
                    throw LOG.wrongChildStateException("complete", id, child.getId(), "[available|enabled|suspended]");
                }
                return false;
            }
        }
    // TODO: are there any DiscretionaryItems?
    // if yes, then it is not possible to complete
    // this stage (NOTE: manualCompletion == false)!
    }
    return true;
}
Also used : CmmnExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution)

Example 15 with CmmnExecution

use of org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution in project camunda-bpm-platform by camunda.

the class CaseInstanceTest method testCaseInstanceWithOneState.

/**
 *   +-----------------+
 *   | Case1            \
 *   +-------------------+-----------------+
 *   |                                     |
 *   |     +------------------------+      |
 *   |    / X                        \     |
 *   |   +    +-------+  +-------+    +    |
 *   |   |    |   A   |  |   B   |    |    |
 *   |   +    +-------+  +-------+    +    |
 *   |    \                          /     |
 *   |     +------------------------+      |
 *   |                                     |
 *   +-------------------------------------+
 */
@Test
public void testCaseInstanceWithOneState() {
    CaseExecutionStateTransitionCollector stateTransitionCollector = new CaseExecutionStateTransitionCollector();
    CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").listener("create", stateTransitionCollector).createActivity("X").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new StageActivityBehavior()).createActivity("A").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new TaskWaitState()).endActivity().createActivity("B").listener("create", stateTransitionCollector).listener("enable", stateTransitionCollector).listener("manualStart", stateTransitionCollector).property(ItemHandler.PROPERTY_MANUAL_ACTIVATION_RULE, defaultManualActivation()).behavior(new TaskWaitState()).endActivity().endActivity().buildCaseDefinition();
    CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
    caseInstance.create();
    // expected state transitions after the creation of a case instance:
    // ()        --create(Case1)--> active
    // ()        --create(X)-->     available
    // available --enable(X)-->     enabled
    List<String> expectedStateTransitions = initAndAssertExpectedTransitions(stateTransitionCollector);
    // clear lists
    emptyCollector(stateTransitionCollector, expectedStateTransitions);
    CaseExecutionImpl planItemX = assertCaseXState(caseInstance);
    List<CaseExecutionImpl> childPlanItems;
    // manual start of x
    planItemX.manualStart();
    // X should be active
    assertTrue(planItemX.isActive());
    // expected state transitions after a manual start of X:
    // enabled   --manualStart(X)--> active
    // ()        --create(A)-->      available
    // available --enable(A)-->      enabled
    // ()        --create(B)-->      available
    // available --enable(B)-->      enabled
    expectedStateTransitions.add("enabled --manualStart(X)--> active");
    expectedStateTransitions.add("() --create(A)--> available");
    expectedStateTransitions.add("available --enable(A)--> enabled");
    expectedStateTransitions.add("() --create(B)--> available");
    expectedStateTransitions.add("available --enable(B)--> enabled");
    assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
    // clear lists
    emptyCollector(stateTransitionCollector, expectedStateTransitions);
    // X should have two chil plan items
    childPlanItems = planItemX.getCaseExecutions();
    assertEquals(2, childPlanItems.size());
    for (CmmnExecution childPlanItem : childPlanItems) {
        // both children should be enabled
        assertTrue(childPlanItem.isEnabled());
        // manual start of a child
        childPlanItem.manualStart();
        // the child should be active
        assertTrue(childPlanItem.isActive());
        // X should be the parent of both children
        assertEquals(planItemX, childPlanItem.getParent());
    }
    // expected state transitions after the manual starts of A and B:
    // enabled   --manualStart(A)--> active
    // enabled   --manualStart(B)--> active
    expectedStateTransitions.add("enabled --manualStart(A)--> active");
    expectedStateTransitions.add("enabled --manualStart(B)--> active");
    assertEquals(expectedStateTransitions, stateTransitionCollector.stateTransitions);
}
Also used : CaseExecutionImpl(org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl) StageActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior) CmmnCaseDefinition(org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition) CmmnCaseInstance(org.camunda.bpm.engine.impl.cmmn.execution.CmmnCaseInstance) CmmnExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution) CaseDefinitionBuilder(org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder) Test(org.junit.Test)

Aggregations

CmmnExecution (org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution)16 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)4 Deployment (org.camunda.bpm.engine.test.Deployment)4 CmmnActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.CmmnActivityBehavior)2 CmmnCompositeActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.CmmnCompositeActivityBehavior)2 StageActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.StageActivityBehavior)2 CaseExecutionImpl (org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl)2 CmmnCaseInstance (org.camunda.bpm.engine.impl.cmmn.execution.CmmnCaseInstance)2 CaseDefinitionBuilder (org.camunda.bpm.engine.impl.cmmn.model.CaseDefinitionBuilder)2 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)2 CmmnCaseDefinition (org.camunda.bpm.engine.impl.cmmn.model.CmmnCaseDefinition)2 Execution (org.camunda.bpm.engine.runtime.Execution)2 Test (org.junit.Test)2 TransferVariablesActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.TransferVariablesActivityBehavior)1 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)1 CaseExecutionState (org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionState)1 CmmnActivityExecution (org.camunda.bpm.engine.impl.cmmn.execution.CmmnActivityExecution)1 HistoricCaseInstanceEventEntity (org.camunda.bpm.engine.impl.history.event.HistoricCaseInstanceEventEntity)1 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)1 SubProcessActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.SubProcessActivityBehavior)1