Search in sources :

Example 46 with Expression

use of org.activiti.engine.delegate.Expression in project Activiti by Activiti.

the class TakeOutgoingSequenceFlowsOperation method handleAdhocSubProcess.

protected void handleAdhocSubProcess(FlowNode flowNode) {
    boolean completeAdhocSubProcess = false;
    AdhocSubProcess adhocSubProcess = (AdhocSubProcess) flowNode.getParentContainer();
    if (adhocSubProcess.getCompletionCondition() != null) {
        Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(adhocSubProcess.getCompletionCondition());
        Condition condition = new UelExpressionCondition(expression);
        if (condition.evaluate(adhocSubProcess.getId(), execution)) {
            completeAdhocSubProcess = true;
        }
    }
    if (flowNode.getOutgoingFlows().size() > 0) {
        leaveFlowNode(flowNode);
    } else {
        commandContext.getExecutionEntityManager().deleteExecutionAndRelatedData(execution, null);
    }
    if (completeAdhocSubProcess) {
        boolean endAdhocSubProcess = true;
        if (!adhocSubProcess.isCancelRemainingInstances()) {
            List<ExecutionEntity> childExecutions = commandContext.getExecutionEntityManager().findChildExecutionsByParentExecutionId(execution.getParentId());
            for (ExecutionEntity executionEntity : childExecutions) {
                if (!executionEntity.getId().equals(execution.getId())) {
                    endAdhocSubProcess = false;
                    break;
                }
            }
        }
        if (endAdhocSubProcess) {
            Context.getAgenda().planEndExecutionOperation(execution.getParent());
        }
    }
}
Also used : Condition(org.activiti.engine.impl.Condition) UelExpressionCondition(org.activiti.engine.impl.el.UelExpressionCondition) AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Expression(org.activiti.engine.delegate.Expression) UelExpressionCondition(org.activiti.engine.impl.el.UelExpressionCondition)

Example 47 with Expression

use of org.activiti.engine.delegate.Expression in project Activiti by Activiti.

the class ProcessInstanceHelper method getMessageName.

protected String getMessageName(CommandContext commandContext, MessageEventDefinition messageEventDefinition, DelegateExecution execution) {
    ExpressionManager expressionManager = commandContext.getProcessEngineConfiguration().getExpressionManager();
    String messageName = Optional.ofNullable(messageEventDefinition.getMessageRef()).orElse(messageEventDefinition.getMessageExpression());
    Expression expression = expressionManager.createExpression(messageName);
    return expression.getValue(execution).toString();
}
Also used : ExpressionManager(org.activiti.engine.impl.el.ExpressionManager) Expression(org.activiti.engine.delegate.Expression)

Example 48 with Expression

use of org.activiti.engine.delegate.Expression in project Activiti by Activiti.

the class ConditionUtil method hasTrueCondition.

public static boolean hasTrueCondition(SequenceFlow sequenceFlow, DelegateExecution execution) {
    String conditionExpression = null;
    if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
        ObjectNode elementProperties = Context.getBpmnOverrideElementProperties(sequenceFlow.getId(), execution.getProcessDefinitionId());
        conditionExpression = getActiveValue(sequenceFlow.getConditionExpression(), DynamicBpmnConstants.SEQUENCE_FLOW_CONDITION, elementProperties);
    } else {
        conditionExpression = sequenceFlow.getConditionExpression();
    }
    if (StringUtils.isNotEmpty(conditionExpression)) {
        Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(conditionExpression);
        Condition condition = new UelExpressionCondition(expression);
        if (condition.evaluate(sequenceFlow.getId(), execution)) {
            return true;
        }
        return false;
    } else {
        return true;
    }
}
Also used : UelExpressionCondition(org.activiti.engine.impl.el.UelExpressionCondition) Condition(org.activiti.engine.impl.Condition) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Expression(org.activiti.engine.delegate.Expression) UelExpressionCondition(org.activiti.engine.impl.el.UelExpressionCondition)

Example 49 with Expression

use of org.activiti.engine.delegate.Expression in project Activiti by Activiti.

the class TestExecutionListener method notify.

@Override
public void notify(DelegateExecution execution) {
    Expression inputExpression = DelegateHelper.getFieldExpression(execution, "input");
    Number input = (Number) inputExpression.getValue(execution);
    int result = input.intValue() * 100;
    Expression resultVarExpression = DelegateHelper.getFieldExpression(execution, "resultVar");
    execution.setVariable(resultVarExpression.getValue(execution).toString(), result);
}
Also used : Expression(org.activiti.engine.delegate.Expression)

Example 50 with Expression

use of org.activiti.engine.delegate.Expression in project Activiti by Activiti.

the class ExpressionResolverTest method resolveExpressionsMap_should_replaceExpressionByValue_when_MapContainsAnExpression.

@Test
public void resolveExpressionsMap_should_replaceExpressionByValue_when_MapContainsAnExpression() {
    // given
    Expression playerExpression = buildExpression("${player}");
    given(expressionEvaluator.evaluate(playerExpression, expressionManager, delegateInterceptor)).willReturn("Agatha");
    // when
    Map<String, Object> result = expressionResolver.resolveExpressionsMap(expressionEvaluator, singletonMap("players", map("Red", "John", "Green", "Peter", "Blue", "Mary", "Yellow", "${player}")));
    // then
    assertThat(result).containsEntry("players", map("Red", "John", "Green", "Peter", "Blue", "Mary", "Yellow", "Agatha"));
}
Also used : Expression(org.activiti.engine.delegate.Expression) Test(org.junit.jupiter.api.Test)

Aggregations

Expression (org.activiti.engine.delegate.Expression)61 ActivitiException (org.activiti.engine.ActivitiException)17 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)13 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)12 Test (org.junit.Test)12 Test (org.junit.jupiter.api.Test)12 ExpressionManager (org.activiti.engine.impl.el.ExpressionManager)11 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)8 Condition (org.activiti.engine.impl.Condition)6 Date (java.util.Date)5 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)5 BusinessCalendar (org.activiti.engine.impl.calendar.BusinessCalendar)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)4 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ArrayList (java.util.ArrayList)3 VariableScope (org.activiti.engine.delegate.VariableScope)3 CycleBusinessCalendar (org.activiti.engine.impl.calendar.CycleBusinessCalendar)3 DueDateBusinessCalendar (org.activiti.engine.impl.calendar.DueDateBusinessCalendar)3