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;
}
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);
}
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;
}
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;
}
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);
}
Aggregations