Search in sources :

Example 1 with IfPart

use of org.camunda.bpm.model.cmmn.instance.IfPart in project camunda-cmmn-model by camunda.

the class Cmmn10Test method shouldGetMultipleIfPartConditions.

@Test
public void shouldGetMultipleIfPartConditions() {
    CmmnModelInstance modelInstance = getCmmnModelInstance();
    Sentry sentry = modelInstance.getModelElementsByType(Sentry.class).iterator().next();
    IfPart ifPart = sentry.getIfPart();
    assertThat(ifPart).isNotNull();
    Collection<ConditionExpression> conditions = ifPart.getConditions();
    assertThat(conditions).hasSize(2);
    ConditionExpression condition = ifPart.getCondition();
    assertThat(condition).isNotNull();
}
Also used : IfPart(org.camunda.bpm.model.cmmn.instance.IfPart) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression) Sentry(org.camunda.bpm.model.cmmn.instance.Sentry) CmmnModelInstance(org.camunda.bpm.model.cmmn.CmmnModelInstance) Test(org.junit.Test)

Example 2 with IfPart

use of org.camunda.bpm.model.cmmn.instance.IfPart in project camunda-bpm-platform by camunda.

the class SentryHandler method handleElement.

public CmmnSentryDeclaration handleElement(Sentry element, CmmnHandlerContext context) {
    String id = element.getId();
    Collection<OnPart> onParts = element.getOnParts();
    IfPart ifPart = element.getIfPart();
    List<CamundaVariableOnPart> variableOnParts = queryExtensionElementsByClass(element, CamundaVariableOnPart.class);
    if ((ifPart == null || ifPart.getConditions().isEmpty()) && variableOnParts.isEmpty()) {
        if (onParts == null || onParts.isEmpty()) {
            LOG.ignoredSentryWithMissingCondition(id);
            return null;
        } else {
            boolean atLeastOneOnPartsValid = false;
            for (OnPart onPart : onParts) {
                if (onPart instanceof PlanItemOnPart) {
                    PlanItemOnPart planItemOnPart = (PlanItemOnPart) onPart;
                    if (planItemOnPart.getSource() != null && planItemOnPart.getStandardEvent() != null) {
                        atLeastOneOnPartsValid = true;
                        break;
                    }
                }
            }
            if (!atLeastOneOnPartsValid) {
                LOG.ignoredSentryWithInvalidParts(id);
                return null;
            }
        }
    }
    CmmnSentryDeclaration sentryDeclaration = new CmmnSentryDeclaration(id);
    // the ifPart will be initialized immediately
    initializeIfPart(ifPart, sentryDeclaration, context);
    // the variableOnParts will be initialized immediately as it does not have any dependency
    initializeVariableOnParts(element, sentryDeclaration, context, variableOnParts);
    // ...whereas the onParts will be initialized later because the
    // the reference to the plan items (sourceRef) and the reference
    // to the sentry (sentryRef) cannot be set in this step. To set
    // the corresponding reference (sourceRef or sentryRef) on the
    // transformed sentry all planned items and all sentries inside
    // the current stage should be already transformed.
    CmmnActivity parent = context.getParent();
    if (parent != null) {
        parent.addSentry(sentryDeclaration);
    }
    return sentryDeclaration;
}
Also used : CamundaVariableOnPart(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart) PlanItemOnPart(org.camunda.bpm.model.cmmn.instance.PlanItemOnPart) OnPart(org.camunda.bpm.model.cmmn.instance.OnPart) CaseFileItemOnPart(org.camunda.bpm.model.cmmn.instance.CaseFileItemOnPart) PlanItemOnPart(org.camunda.bpm.model.cmmn.instance.PlanItemOnPart) CmmnSentryDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration) IfPart(org.camunda.bpm.model.cmmn.instance.IfPart) CamundaVariableOnPart(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)

Example 3 with IfPart

use of org.camunda.bpm.model.cmmn.instance.IfPart in project camunda-bpm-platform by camunda.

the class SentryHandlerTest method testSentryWithIfPart.

@Test
public void testSentryWithIfPart() {
    // given
    IfPart ifPart = createElement(sentry, "abc", IfPart.class);
    ConditionExpression conditionExpression = createElement(ifPart, "def", ConditionExpression.class);
    Body body = createElement(conditionExpression, null, Body.class);
    String expression = "${test}";
    body.setTextContent(expression);
    // when
    CmmnSentryDeclaration sentryDeclaration = sentryHandler.handleElement(sentry, context);
    // then
    assertNotNull(sentryDeclaration);
    CmmnIfPartDeclaration ifPartDeclaration = sentryDeclaration.getIfPart();
    assertNotNull(ifPartDeclaration);
    Expression condition = ifPartDeclaration.getCondition();
    assertNotNull(condition);
    assertEquals(expression, condition.getExpressionText());
    assertTrue(sentryDeclaration.getOnParts().isEmpty());
}
Also used : CmmnIfPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration) CmmnSentryDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration) IfPart(org.camunda.bpm.model.cmmn.instance.IfPart) Expression(org.camunda.bpm.engine.delegate.Expression) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression) Body(org.camunda.bpm.model.cmmn.instance.Body) Test(org.junit.Test)

Example 4 with IfPart

use of org.camunda.bpm.model.cmmn.instance.IfPart 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());
}
Also used : CmmnSentryDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration) IfPart(org.camunda.bpm.model.cmmn.instance.IfPart) CasePlanModelHandler(org.camunda.bpm.engine.impl.cmmn.handler.CasePlanModelHandler) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression) Sentry(org.camunda.bpm.model.cmmn.instance.Sentry) CmmnOnPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnOnPartDeclaration) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) Body(org.camunda.bpm.model.cmmn.instance.Body) Test(org.junit.Test)

Example 5 with IfPart

use of org.camunda.bpm.model.cmmn.instance.IfPart in project camunda-bpm-platform by camunda.

the class HumanTaskPlanItemHandlerTest method testMultipleExitCriteria.

@Test
public void testMultipleExitCriteria() {
    // given
    // create first sentry containing ifPart
    Sentry sentry1 = createElement(casePlanModel, "Sentry_1", Sentry.class);
    IfPart ifPart1 = createElement(sentry1, "abc", IfPart.class);
    ConditionExpression conditionExpression1 = createElement(ifPart1, "def", ConditionExpression.class);
    Body body1 = createElement(conditionExpression1, null, Body.class);
    body1.setTextContent("${test}");
    // set first exitCriteria
    ExitCriterion criterion1 = createElement(planItem, ExitCriterion.class);
    criterion1.setSentry(sentry1);
    // create first sentry containing ifPart
    Sentry sentry2 = createElement(casePlanModel, "Sentry_2", Sentry.class);
    IfPart ifPart2 = createElement(sentry2, "ghi", IfPart.class);
    ConditionExpression conditionExpression2 = createElement(ifPart2, "jkl", ConditionExpression.class);
    Body body2 = createElement(conditionExpression2, null, Body.class);
    body2.setTextContent("${test}");
    // set second exitCriteria
    ExitCriterion criterion2 = createElement(planItem, ExitCriterion.class);
    criterion2.setSentry(sentry2);
    // transform casePlanModel as parent
    CmmnActivity parent = new CasePlanModelHandler().handleElement(casePlanModel, context);
    context.setParent(parent);
    // transform Sentry
    CmmnSentryDeclaration firstSentryDeclaration = new SentryHandler().handleElement(sentry1, context);
    CmmnSentryDeclaration secondSentryDeclaration = new SentryHandler().handleElement(sentry2, context);
    // when
    CmmnActivity newActivity = handler.handleElement(planItem, context);
    // then
    assertTrue(newActivity.getEntryCriteria().isEmpty());
    assertFalse(newActivity.getExitCriteria().isEmpty());
    assertEquals(2, newActivity.getExitCriteria().size());
    assertTrue(newActivity.getExitCriteria().contains(firstSentryDeclaration));
    assertTrue(newActivity.getExitCriteria().contains(secondSentryDeclaration));
}
Also used : CmmnSentryDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration) SentryHandler(org.camunda.bpm.engine.impl.cmmn.handler.SentryHandler) IfPart(org.camunda.bpm.model.cmmn.instance.IfPart) CasePlanModelHandler(org.camunda.bpm.engine.impl.cmmn.handler.CasePlanModelHandler) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression) Sentry(org.camunda.bpm.model.cmmn.instance.Sentry) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) ExitCriterion(org.camunda.bpm.model.cmmn.instance.ExitCriterion) Body(org.camunda.bpm.model.cmmn.instance.Body) Test(org.junit.Test)

Aggregations

IfPart (org.camunda.bpm.model.cmmn.instance.IfPart)41 CmmnSentryDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration)39 ConditionExpression (org.camunda.bpm.model.cmmn.instance.ConditionExpression)39 Test (org.junit.Test)39 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)37 Sentry (org.camunda.bpm.model.cmmn.instance.Sentry)37 SentryHandler (org.camunda.bpm.engine.impl.cmmn.handler.SentryHandler)35 CasePlanModelHandler (org.camunda.bpm.engine.impl.cmmn.handler.CasePlanModelHandler)34 Body (org.camunda.bpm.model.cmmn.instance.Body)25 EntryCriterion (org.camunda.bpm.model.cmmn.instance.EntryCriterion)21 ExitCriterion (org.camunda.bpm.model.cmmn.instance.ExitCriterion)21 Expression (org.camunda.bpm.engine.delegate.Expression)2 CmmnIfPartDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration)2 CmmnOnPartDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnOnPartDeclaration)1 CmmnModelInstance (org.camunda.bpm.model.cmmn.CmmnModelInstance)1 CaseFileItemOnPart (org.camunda.bpm.model.cmmn.instance.CaseFileItemOnPart)1 CmmnElement (org.camunda.bpm.model.cmmn.instance.CmmnElement)1 OnPart (org.camunda.bpm.model.cmmn.instance.OnPart)1 PlanItemOnPart (org.camunda.bpm.model.cmmn.instance.PlanItemOnPart)1 CamundaVariableOnPart (org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableOnPart)1