Search in sources :

Example 1 with CmmnIfPartDeclaration

use of org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration in project camunda-bpm-platform by camunda.

the class SentryHandler method initializeIfPart.

protected void initializeIfPart(IfPart ifPart, CmmnSentryDeclaration sentryDeclaration, CmmnHandlerContext context) {
    if (ifPart == null) {
        return;
    }
    Collection<ConditionExpression> conditions = ifPart.getConditions();
    if (conditions.size() > 1) {
        String id = sentryDeclaration.getId();
        LOG.multipleIgnoredConditions(id);
    }
    ExpressionManager expressionManager = context.getExpressionManager();
    ConditionExpression condition = conditions.iterator().next();
    Expression conditionExpression = expressionManager.createExpression(condition.getText());
    CmmnIfPartDeclaration ifPartDeclaration = new CmmnIfPartDeclaration();
    ifPartDeclaration.setCondition(conditionExpression);
    sentryDeclaration.setIfPart(ifPartDeclaration);
}
Also used : ExpressionManager(org.camunda.bpm.engine.impl.el.ExpressionManager) CmmnIfPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration) Expression(org.camunda.bpm.engine.delegate.Expression) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression)

Example 2 with CmmnIfPartDeclaration

use of org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration in project camunda-bpm-platform by camunda.

the class CmmnExecution method isSentryPartsSatisfied.

protected boolean isSentryPartsSatisfied(String sentryId, List<? extends CmmnSentryPart> sentryParts) {
    // if part will be evaluated in the end
    CmmnSentryPart ifPart = null;
    if (sentryParts != null && !sentryParts.isEmpty()) {
        for (CmmnSentryPart sentryPart : sentryParts) {
            if (PLAN_ITEM_ON_PART.equals(sentryPart.getType())) {
                if (!sentryPart.isSatisfied()) {
                    return false;
                }
            } else if (VARIABLE_ON_PART.equals(sentryPart.getType())) {
                if (!sentryPart.isSatisfied()) {
                    return false;
                }
            } else {
                /* IF_PART.equals(sentryPart.getType) == true */
                ifPart = sentryPart;
                // once the ifPart has been satisfied the whole sentry is satisfied
                if (ifPart.isSatisfied()) {
                    return true;
                }
            }
        }
    }
    if (ifPart != null) {
        CmmnExecution execution = ifPart.getCaseExecution();
        ensureNotNull("Case execution of sentry '" + ifPart.getSentryId() + "': is null", execution);
        CmmnActivity activity = ifPart.getCaseExecution().getActivity();
        ensureNotNull("Case execution '" + id + "': has no current activity", "activity", activity);
        CmmnSentryDeclaration sentryDeclaration = activity.getSentry(sentryId);
        ensureNotNull("Case execution '" + id + "': has no declaration for sentry '" + sentryId + "'", "sentryDeclaration", sentryDeclaration);
        CmmnIfPartDeclaration ifPartDeclaration = sentryDeclaration.getIfPart();
        ensureNotNull("Sentry declaration '" + sentryId + "' has no definied ifPart, but there should be one defined for case execution '" + id + "'.", "ifPartDeclaration", ifPartDeclaration);
        Expression condition = ifPartDeclaration.getCondition();
        ensureNotNull("A condition was expected for ifPart of Sentry declaration '" + sentryId + "' for case execution '" + id + "'.", "condition", condition);
        Object result = condition.getValue(this);
        ensureInstanceOf("condition expression returns non-Boolean", "result", result, Boolean.class);
        Boolean booleanResult = (Boolean) result;
        ifPart.setSatisfied(booleanResult);
        return booleanResult;
    }
    // ifPart then the whole sentry is satisfied.
    return true;
}
Also used : CmmnIfPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration) CmmnSentryDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration) Expression(org.camunda.bpm.engine.delegate.Expression) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)

Example 3 with CmmnIfPartDeclaration

use of org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration 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 CmmnIfPartDeclaration

use of org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration in project camunda-bpm-platform by camunda.

the class SentryHandlerTest method testSentryWithIfPartWithMultipleCondition.

@Test
public void testSentryWithIfPartWithMultipleCondition() {
    // given
    IfPart ifPart = createElement(sentry, "abc", IfPart.class);
    ConditionExpression firstConditionExpression = createElement(ifPart, "con_1", ConditionExpression.class);
    Body firstBody = createElement(firstConditionExpression, null, Body.class);
    String firstExpression = "${firstExpression}";
    firstBody.setTextContent(firstExpression);
    ConditionExpression secondConditionExpression = createElement(ifPart, "con_2", ConditionExpression.class);
    Body secondBody = createElement(secondConditionExpression, null, Body.class);
    String secondExpression = "${secondExpression}";
    secondBody.setTextContent(secondExpression);
    // when
    CmmnSentryDeclaration sentryDeclaration = sentryHandler.handleElement(sentry, context);
    // then
    assertNotNull(sentryDeclaration);
    CmmnIfPartDeclaration ifPartDeclaration = sentryDeclaration.getIfPart();
    assertNotNull(ifPartDeclaration);
    Expression condition = ifPartDeclaration.getCondition();
    assertNotNull(condition);
    assertEquals(firstExpression, condition.getExpressionText());
    // the second condition will be ignored!
    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 5 with CmmnIfPartDeclaration

use of org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration 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);
            }
        }
    }
}
Also used : CmmnIfPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration) CmmnSentryDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration) CmmnVariableOnPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnVariableOnPartDeclaration) CmmnOnPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnOnPartDeclaration) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)

Aggregations

CmmnIfPartDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration)5 Expression (org.camunda.bpm.engine.delegate.Expression)4 CmmnSentryDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration)4 ConditionExpression (org.camunda.bpm.model.cmmn.instance.ConditionExpression)3 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)2 Body (org.camunda.bpm.model.cmmn.instance.Body)2 IfPart (org.camunda.bpm.model.cmmn.instance.IfPart)2 Test (org.junit.Test)2 CmmnOnPartDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnOnPartDeclaration)1 CmmnVariableOnPartDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnVariableOnPartDeclaration)1 ExpressionManager (org.camunda.bpm.engine.impl.el.ExpressionManager)1