Search in sources :

Example 41 with Expression

use of org.activiti.engine.delegate.Expression in project herd by FINRAOS.

the class ActivitiHelperTest method testGetExpressionVariableAsBooleanInvalidValue.

@Test
public void testGetExpressionVariableAsBooleanInvalidValue() {
    // Mock dependencies.
    Expression expression = mock(Expression.class);
    DelegateExecution execution = mock(DelegateExecution.class);
    when(expression.getValue(execution)).thenReturn(INVALID_VALUE);
    // Try to call the method under test.
    try {
        activitiHelper.getExpressionVariableAsBoolean(expression, execution, VARIABLE_NAME, NO_VARIABLE_REQUIRED, NO_BOOLEAN_DEFAULT_VALUE);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("\"%s\" must be a valid boolean value of \"true\" or \"false\".", VARIABLE_NAME), e.getMessage());
    }
}
Also used : Expression(org.activiti.engine.delegate.Expression) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 42 with Expression

use of org.activiti.engine.delegate.Expression in project herd by FINRAOS.

the class ActivitiHelperTest method testGetRequiredExpressionVariableAsString.

@Test
public void testGetRequiredExpressionVariableAsString() {
    // Mock dependencies.
    Expression expression = mock(Expression.class);
    DelegateExecution execution = mock(DelegateExecution.class);
    when(expression.getValue(execution)).thenReturn(STRING_VALUE);
    // Call the method under test.
    String result = activitiHelper.getRequiredExpressionVariableAsString(expression, execution, VARIABLE_NAME);
    // Validate the result.
    assertEquals(STRING_VALUE, result);
}
Also used : Expression(org.activiti.engine.delegate.Expression) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 43 with Expression

use of org.activiti.engine.delegate.Expression in project herd by FINRAOS.

the class ActivitiHelperTest method testGetExpressionVariableAsIntegerBlankValue.

@Test
public void testGetExpressionVariableAsIntegerBlankValue() {
    // Mock dependencies.
    Expression expression = mock(Expression.class);
    DelegateExecution execution = mock(DelegateExecution.class);
    when(expression.getValue(execution)).thenReturn(BLANK_TEXT);
    // Call the method under test.
    Integer result = activitiHelper.getExpressionVariableAsInteger(expression, execution, VARIABLE_NAME, NO_VARIABLE_REQUIRED);
    // Validate the result.
    assertNull(result);
}
Also used : Expression(org.activiti.engine.delegate.Expression) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 44 with Expression

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

the class ExpressionResolver method resolveInStringPlaceHolder.

private String resolveInStringPlaceHolder(final ExpressionEvaluator expressionEvaluator, final String sourceString) {
    final Matcher matcher = EXPRESSION_PATTERN.matcher(sourceString);
    final StringBuffer sb = new StringBuffer();
    while (matcher.find()) {
        final String expressionKey = matcher.group(EXPRESSION_KEY_INDEX);
        final Expression expression = expressionManager.createExpression(expressionKey);
        try {
            final Object value = expressionEvaluator.evaluate(expression, expressionManager, delegateInterceptor);
            matcher.appendReplacement(sb, Objects.toString(value));
        } catch (final Exception e) {
            logger.warn("Unable to resolve expression in variables, keeping original value", e);
        }
    }
    matcher.appendTail(sb);
    return sb.toString();
}
Also used : Matcher(java.util.regex.Matcher) Expression(org.activiti.engine.delegate.Expression)

Example 45 with Expression

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

the class IntermediateThrowSignalEventActivityBehavior method execute.

public void execute(DelegateExecution execution) {
    CommandContext commandContext = Context.getCommandContext();
    String eventSubscriptionName = null;
    if (signalEventName != null) {
        eventSubscriptionName = signalEventName;
    } else {
        Expression expressionObject = commandContext.getProcessEngineConfiguration().getExpressionManager().createExpression(signalExpression);
        eventSubscriptionName = expressionObject.getValue(execution).toString();
    }
    EventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.getEventSubscriptionEntityManager();
    List<SignalEventSubscriptionEntity> subscriptionEntities = null;
    if (processInstanceScope) {
        subscriptionEntities = eventSubscriptionEntityManager.findSignalEventSubscriptionsByProcessInstanceAndEventName(execution.getProcessInstanceId(), eventSubscriptionName);
    } else {
        subscriptionEntities = eventSubscriptionEntityManager.findSignalEventSubscriptionsByEventName(eventSubscriptionName, execution.getTenantId());
    }
    for (SignalEventSubscriptionEntity signalEventSubscriptionEntity : subscriptionEntities) {
        Map<String, Object> signalVariables = Optional.ofNullable(execution.getVariables()).filter(it -> !it.isEmpty()).orElse(null);
        eventSubscriptionEntityManager.eventReceived(signalEventSubscriptionEntity, signalVariables, signalEventDefinition.isAsync());
    }
    Context.getAgenda().planTakeOutgoingSequenceFlowsOperation((ExecutionEntity) execution, true);
}
Also used : SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) Signal(org.activiti.bpmn.model.Signal) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) StringUtils(org.apache.commons.lang3.StringUtils) List(java.util.List) Context(org.activiti.engine.impl.context.Context) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) Map(java.util.Map) EventSubscriptionEntityManager(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntityManager) Optional(java.util.Optional) Expression(org.activiti.engine.delegate.Expression) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) Expression(org.activiti.engine.delegate.Expression) EventSubscriptionEntityManager(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntityManager) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)

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