use of org.camunda.bpm.engine.impl.cmmn.model.CmmnOnPartDeclaration in project camunda-bpm-platform by camunda.
the class SentryHandler method initializeOnPart.
protected void initializeOnPart(PlanItemOnPart onPart, Sentry sentry, CmmnHandlerContext context) {
CmmnActivity parent = context.getParent();
String sentryId = sentry.getId();
CmmnSentryDeclaration sentryDeclaration = parent.getSentry(sentryId);
PlanItem source = onPart.getSource();
PlanItemTransition standardEvent = onPart.getStandardEvent();
if (source != null && standardEvent != null) {
CmmnOnPartDeclaration onPartDeclaration = new CmmnOnPartDeclaration();
// initialize standardEvent
String standardEventName = standardEvent.name();
onPartDeclaration.setStandardEvent(standardEventName);
// initialize sourceRef
String sourceId = source.getId();
CmmnActivity sourceActivity = parent.findActivity(sourceId);
if (sourceActivity != null) {
onPartDeclaration.setSource(sourceActivity);
}
// initialize sentryRef
Sentry sentryRef = onPart.getSentry();
if (sentryRef != null) {
String sentryRefId = sentryRef.getId();
CmmnSentryDeclaration sentryRefDeclaration = parent.getSentry(sentryRefId);
onPartDeclaration.setSentry(sentryRefDeclaration);
}
// add onPartDeclaration to sentryDeclaration
sentryDeclaration.addOnPart(onPartDeclaration);
}
}
use of org.camunda.bpm.engine.impl.cmmn.model.CmmnOnPartDeclaration in project camunda-bpm-platform by camunda.
the class SentryHandlerTest method testSentryWithOnPart.
@Test
public void testSentryWithOnPart() {
// given
CmmnActivity casePlanModelActivity = new CasePlanModelHandler().handleElement(casePlanModel, context);
context.setParent(casePlanModelActivity);
CmmnSentryDeclaration sentryDeclaration = sentryHandler.handleElement(sentry, context);
CmmnActivity source = taskItemHandler.handleElement(planItem, context);
// when
sentryHandler.initializeOnParts(sentry, context);
// then
assertNotNull(sentryDeclaration);
List<CmmnOnPartDeclaration> onParts = sentryDeclaration.getOnParts();
assertNotNull(onParts);
assertFalse(onParts.isEmpty());
assertEquals(1, onParts.size());
List<CmmnOnPartDeclaration> onPartsAssociatedWithSource = sentryDeclaration.getOnParts(source.getId());
assertNotNull(onPartsAssociatedWithSource);
assertFalse(onPartsAssociatedWithSource.isEmpty());
assertEquals(1, onParts.size());
CmmnOnPartDeclaration onPartDeclaration = onPartsAssociatedWithSource.get(0);
assertNotNull(onPartDeclaration);
// source
assertEquals(source, onPartDeclaration.getSource());
assertEquals(onPart.getSource().getId(), onPartDeclaration.getSource().getId());
// standardEvent
assertEquals(onPart.getStandardEvent().name(), onPartDeclaration.getStandardEvent());
// sentry
assertNull(onPartDeclaration.getSentry());
assertNull(sentryDeclaration.getIfPart());
}
use of org.camunda.bpm.engine.impl.cmmn.model.CmmnOnPartDeclaration in project camunda-bpm-platform by camunda.
the class SentryHandlerTest method testSentryWithOnPartReferencesSentry.
@Test
public void testSentryWithOnPartReferencesSentry() {
// given
Sentry exitSentry = createElement(casePlanModel, "anotherSentry", Sentry.class);
IfPart ifPart = createElement(exitSentry, "IfPart_1", IfPart.class);
ConditionExpression conditionExpression = createElement(ifPart, "con_1", ConditionExpression.class);
Body body = createElement(conditionExpression, null, Body.class);
body.setTextContent("${test}");
onPart.setSentry(exitSentry);
CmmnActivity casePlanModelActivity = new CasePlanModelHandler().handleElement(casePlanModel, context);
context.setParent(casePlanModelActivity);
CmmnSentryDeclaration sentryDeclaration = sentryHandler.handleElement(sentry, context);
CmmnSentryDeclaration exitSentryDeclaration = sentryHandler.handleElement(exitSentry, context);
CmmnActivity source = taskItemHandler.handleElement(planItem, context);
// when
sentryHandler.initializeOnParts(sentry, context);
// then
assertNotNull(sentryDeclaration);
List<CmmnOnPartDeclaration> onParts = sentryDeclaration.getOnParts();
assertNotNull(onParts);
assertFalse(onParts.isEmpty());
assertEquals(1, onParts.size());
List<CmmnOnPartDeclaration> onPartsAssociatedWithSource = sentryDeclaration.getOnParts(source.getId());
assertNotNull(onPartsAssociatedWithSource);
assertFalse(onPartsAssociatedWithSource.isEmpty());
assertEquals(1, onParts.size());
CmmnOnPartDeclaration onPartDeclaration = onPartsAssociatedWithSource.get(0);
assertNotNull(onPartDeclaration);
// source
assertEquals(source, onPartDeclaration.getSource());
assertEquals(onPart.getSource().getId(), onPartDeclaration.getSource().getId());
// standardEvent
assertEquals(onPart.getStandardEvent().name(), onPartDeclaration.getStandardEvent());
// sentry
assertNotNull(onPartDeclaration.getSentry());
assertEquals(exitSentryDeclaration, onPartDeclaration.getSentry());
assertNull(sentryDeclaration.getIfPart());
}
use of org.camunda.bpm.engine.impl.cmmn.model.CmmnOnPartDeclaration in project camunda-bpm-platform by camunda.
the class CaseExecutionOccurTest method testOccurMilestone.
@Test
public void testOccurMilestone() {
// given
// a case definition
CmmnCaseDefinition caseDefinition = new CaseDefinitionBuilder("Case1").createActivity("A").behavior(new MilestoneActivityBehavior()).endActivity().buildCaseDefinition();
CmmnActivity activity = caseDefinition.findActivity("A");
// a pseudo sentry
CmmnSentryDeclaration sentryDeclaration = new CmmnSentryDeclaration("X");
caseDefinition.findActivity("Case1").addSentry(sentryDeclaration);
activity.addEntryCriteria(sentryDeclaration);
CmmnOnPartDeclaration onPartDeclaration = new CmmnOnPartDeclaration();
onPartDeclaration.setSource(new CmmnActivity("B", caseDefinition));
onPartDeclaration.setStandardEvent("complete");
sentryDeclaration.addOnPart(onPartDeclaration);
// an active case instance
CmmnCaseInstance caseInstance = caseDefinition.createCaseInstance();
caseInstance.create();
// task A as a child of the case instance
CmmnActivityExecution milestoneA = caseInstance.findCaseExecution("A");
// when
// completing
milestoneA.occur();
// then
// task A is completed ...
assertTrue(milestoneA.isCompleted());
// ... and the case instance is also completed
assertTrue(caseInstance.isCompleted());
// task A is not part of the case instance anymore
assertNull(caseInstance.findCaseExecution("A"));
// the case instance has no children
assertTrue(((CaseExecutionImpl) caseInstance).getCaseExecutions().isEmpty());
}
use of org.camunda.bpm.engine.impl.cmmn.model.CmmnOnPartDeclaration in project camunda-bpm-platform by camunda.
the class CmmnExecution method createSentryParts.
public void createSentryParts() {
CmmnActivity activity = getActivity();
ensureNotNull("Case execution '" + id + "': has no current activity", "activity", activity);
List<CmmnSentryDeclaration> sentries = activity.getSentries();
if (sentries != null && !sentries.isEmpty()) {
for (CmmnSentryDeclaration sentryDeclaration : sentries) {
CmmnIfPartDeclaration ifPartDeclaration = sentryDeclaration.getIfPart();
if (ifPartDeclaration != null) {
CmmnSentryPart ifPart = createIfPart(sentryDeclaration, ifPartDeclaration);
addSentryPart(ifPart);
}
List<CmmnOnPartDeclaration> onPartDeclarations = sentryDeclaration.getOnParts();
for (CmmnOnPartDeclaration onPartDeclaration : onPartDeclarations) {
CmmnSentryPart onPart = createOnPart(sentryDeclaration, onPartDeclaration);
addSentryPart(onPart);
}
List<CmmnVariableOnPartDeclaration> variableOnPartDeclarations = sentryDeclaration.getVariableOnParts();
for (CmmnVariableOnPartDeclaration variableOnPartDeclaration : variableOnPartDeclarations) {
CmmnSentryPart variableOnPart = createVariableOnPart(sentryDeclaration, variableOnPartDeclaration);
addSentryPart(variableOnPart);
}
}
}
}
Aggregations