Java Code Examples for org.activiti.engine.delegate.Expression#getValue()

The following examples show how to use org.activiti.engine.delegate.Expression#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SingletonDelegateExpressionBean.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
  
  // just a quick check to avoid creating a specific test for it
  int nrOfFieldExtensions = DelegateHelper.getFields(execution).size();
  if (nrOfFieldExtensions != 3) {
    throw new RuntimeException("Error: 3 field extensions expected, but was " + nrOfFieldExtensions);
  }
  
  Expression fieldAExpression = DelegateHelper.getFieldExpression(execution, "fieldA");
  Number fieldA = (Number) fieldAExpression.getValue(execution);
  
  Expression fieldBExpression = DelegateHelper.getFieldExpression(execution, "fieldB");
  Number fieldB = (Number) fieldBExpression.getValue(execution);
  
  int result = fieldA.intValue() + fieldB.intValue();
  
  String resultVariableName = DelegateHelper.getFieldExpression(execution, "resultVariableName").getValue(execution).toString();
  execution.setVariable(resultVariableName, result);
}
 
Example 2
Source File: CallActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void completing(DelegateExecution execution, DelegateExecution subProcessInstance) throws Exception {
  // only data. no control flow available on this execution.

  ExpressionManager expressionManager = Context.getProcessEngineConfiguration().getExpressionManager();

  // copy process variables
  ExecutionEntity executionEntity = (ExecutionEntity) execution;
  CallActivity callActivity = (CallActivity) executionEntity.getCurrentFlowElement();
  for (IOParameter ioParameter : callActivity.getOutParameters()) {
    Object value = null;
    if (StringUtils.isNotEmpty(ioParameter.getSourceExpression())) {
      Expression expression = expressionManager.createExpression(ioParameter.getSourceExpression().trim());
      value = expression.getValue(subProcessInstance);

    } else {
      value = subProcessInstance.getVariable(ioParameter.getSource());
    }
    execution.setVariable(ioParameter.getTarget(), value);
  }
}
 
Example 3
Source File: UelExpressionCondition.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public boolean evaluate(String sequenceFlowId, DelegateExecution execution) {
  String conditionExpression = null;
  if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
    ObjectNode elementProperties = Context.getBpmnOverrideElementProperties(sequenceFlowId, execution.getProcessDefinitionId());
    conditionExpression = getActiveValue(initialConditionExpression, DynamicBpmnConstants.SEQUENCE_FLOW_CONDITION, elementProperties);
  } else {
    conditionExpression = initialConditionExpression;
  }
  
  Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(conditionExpression);
  Object result = expression.getValue(execution);
  
  if (result==null) {
    throw new ActivitiException("condition expression returns null");
  }
  if (! (result instanceof Boolean)) {
    throw new ActivitiException("condition expression returns non-Boolean: "+result+" ("+result.getClass().getName()+")");
  }
  return (Boolean) result;
}
 
Example 4
Source File: DelegateExpressionUtil.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static Object resolveDelegateExpression(Expression expression, 
    VariableScope variableScope, List<FieldDeclaration> fieldDeclarations) {
  
  // Note: we can't cache the result of the expression, because the
  // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
  Object delegate = expression.getValue(variableScope);
  
  if (fieldDeclarations != null && fieldDeclarations.size() > 0) {
    
    DelegateExpressionFieldInjectionMode injectionMode = Context.getProcessEngineConfiguration().getDelegateExpressionFieldInjectionMode();
    if (injectionMode.equals(DelegateExpressionFieldInjectionMode.COMPATIBILITY)) {
      ClassDelegate.applyFieldDeclaration(fieldDeclarations, delegate, true);
    } else if (injectionMode.equals(DelegateExpressionFieldInjectionMode.MIXED)) {
      ClassDelegate.applyFieldDeclaration(fieldDeclarations, delegate, false);
    }
    
  }
  
  return delegate;
}
 
Example 5
Source File: DelegateExpressionUtil.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static Object resolveDelegateExpression(Expression expression, 
    VariableScope variableScope, List<FieldDeclaration> fieldDeclarations) {
  
  // Note: we can't cache the result of the expression, because the
  // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
  Object delegate = expression.getValue(variableScope);
  
  if (fieldDeclarations != null && fieldDeclarations.size() > 0) {
    
    DelegateExpressionFieldInjectionMode injectionMode = Context.getProcessEngineConfiguration().getDelegateExpressionFieldInjectionMode();
    if (injectionMode.equals(DelegateExpressionFieldInjectionMode.COMPATIBILITY)) {
      ClassDelegate.applyFieldDeclaration(fieldDeclarations, delegate, true);
    } else if (injectionMode.equals(DelegateExpressionFieldInjectionMode.MIXED)) {
      ClassDelegate.applyFieldDeclaration(fieldDeclarations, delegate, false);
    }
    
  }
  
  return delegate;
}
 
Example 6
Source File: MailActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected String getStringFromField(Expression expression, DelegateExecution execution) {
  if (expression != null) {
    Object value = expression.getValue(execution);
    if (value != null) {
      return value.toString();
    }
  }
  return null;
}
 
Example 7
Source File: TestExecutionListener.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 8
Source File: MailActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private Object checkAllowedTypes(Expression expression, DelegateExecution execution) {
  if (expression == null) {
    return null;
  }
  Object value = expression.getValue(execution);
  if (value == null) {
    return null;
  }
  for (Class<?> allowedType : ALLOWED_ATT_TYPES) {
    if (allowedType.isInstance(value)) {
      return value;
    }
  }
  throw new ActivitiException("Invalid attachment type: " + value.getClass());
}
 
Example 9
Source File: SkipExpressionUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static boolean shouldSkipFlowElement(DelegateExecution execution, Expression skipExpression) {
  Object value = skipExpression.getValue(execution);

  if (value instanceof Boolean) {
    return ((Boolean) value).booleanValue();

  } else {
    throw new ActivitiIllegalArgumentException("Skip expression does not resolve to a boolean: " + skipExpression.getExpressionText());
  }
}
 
Example 10
Source File: SkipExpressionUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static boolean shouldSkipFlowElement(CommandContext commandContext, DelegateExecution execution, String skipExpressionString) {
  Expression skipExpression = commandContext.getProcessEngineConfiguration().getExpressionManager().createExpression(skipExpressionString);
  Object value = skipExpression.getValue(execution);

  if (value instanceof Boolean) {
    return ((Boolean) value).booleanValue();

  } else {
    throw new ActivitiIllegalArgumentException("Skip expression does not resolve to a boolean: " + skipExpression.getExpressionText());
  }
}
 
Example 11
Source File: MuleSendActivitiBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected String getStringFromField(Expression expression, DelegateExecution execution) {
  if (expression != null) {
    Object value = expression.getValue(execution);
    if (value != null) {
      return value.toString();
    }
  }
  return null;
}
 
Example 12
Source File: ConvertDateToISO8601.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected String getExpressionString(Expression expression, VariableScope variableScope) 
{
    if (expression != null) 
    {
        return (String) expression.getValue(variableScope);
    }
    return null;
}
 
Example 13
Source File: MailActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private Object checkAllowedTypes(Expression expression, DelegateExecution execution) {
  if (expression == null) {
    return null;
  }
  Object value = expression.getValue(execution);
  if (value == null) {
    return null;
  }
  for (Class<?> allowedType : ALLOWED_ATT_TYPES) {
    if (allowedType.isInstance(value)) {
      return value;
    }
  }
  throw new ActivitiException("Invalid attachment type: " + value.getClass());
}
 
Example 14
Source File: ShellActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected String getStringFromField(Expression expression, DelegateExecution execution) {
  if (expression != null) {
    Object value = expression.getValue(execution);
    if (value != null) {
      return value.toString();
    }
  }
  return null;
}
 
Example 15
Source File: SkipExpressionUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static boolean shouldSkipFlowElement(ActivityExecution execution, Expression skipExpression) {
  Object value = skipExpression.getValue(execution);
  
  if (value instanceof Boolean) {
    return ((Boolean)value).booleanValue();
    
  } else {
    throw new ActivitiIllegalArgumentException("Skip expression does not resolve to a boolean: " + skipExpression.getExpressionText());
  }
}
 
Example 16
Source File: CamelBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected String getStringFromField(Expression expression, DelegateExecution execution) {
  if (expression != null) {
    Object value = expression.getValue(execution);
    if (value != null) {
      return value.toString();
    }
  }
  return null;
}
 
Example 17
Source File: TestTaskListener.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
  Expression inputExpression = DelegateHelper.getFieldExpression(delegateTask, "input");
  Number input = (Number) inputExpression.getValue(delegateTask);
  
  int result = input.intValue() / 2;
  
  Expression resultVarExpression = DelegateHelper.getFieldExpression(delegateTask, "resultVar");
  delegateTask.setVariable(resultVarExpression.getValue(delegateTask).toString(), result);
}
 
Example 18
Source File: DefaultJobManager.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected void restoreExtraData(JobEntity timerEntity, VariableScope variableScope) {
  String activityId = timerEntity.getJobHandlerConfiguration();

  if (timerEntity.getJobHandlerType().equalsIgnoreCase(TimerStartEventJobHandler.TYPE) ||
      timerEntity.getJobHandlerType().equalsIgnoreCase(TriggerTimerEventJobHandler.TYPE)) {

    activityId = TimerEventHandler.getActivityIdFromConfiguration(timerEntity.getJobHandlerConfiguration());
    String endDateExpressionString = TimerEventHandler.getEndDateFromConfiguration(timerEntity.getJobHandlerConfiguration());

    if (endDateExpressionString != null) {
      Expression endDateExpression = processEngineConfiguration.getExpressionManager().createExpression(endDateExpressionString);

      String endDateString = null;

      BusinessCalendar businessCalendar = processEngineConfiguration.getBusinessCalendarManager().getBusinessCalendar(
          getBusinessCalendarName(TimerEventHandler.geCalendarNameFromConfiguration(timerEntity.getJobHandlerConfiguration()), variableScope));

      if (endDateExpression != null) {
        Object endDateValue = endDateExpression.getValue(variableScope);
        if (endDateValue instanceof String) {
          endDateString = (String) endDateValue;
        } else if (endDateValue instanceof Date) {
          timerEntity.setEndDate((Date) endDateValue);
        } else {
          throw new ActivitiException("Timer '" + ((ExecutionEntity) variableScope).getActivityId()
              + "' was not configured with a valid duration/time, either hand in a java.util.Date or a String in format 'yyyy-MM-dd'T'hh:mm:ss'");
        }

        if (timerEntity.getEndDate() == null) {
          timerEntity.setEndDate(businessCalendar.resolveEndDate(endDateString));
        }
      }
    }
  }

  int maxIterations = 1;
  if (timerEntity.getProcessDefinitionId() != null) {
    org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(timerEntity.getProcessDefinitionId());
    maxIterations = getMaxIterations(process, activityId);
    if (maxIterations <= 1) {
      maxIterations = getMaxIterations(process, activityId);
    }
  }
  timerEntity.setMaxIterations(maxIterations);
}
 
Example 19
Source File: TimerJobEntity.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected void restoreExtraData(CommandContext commandContext, String jobHandlerConfiguration) {
  String embededActivityId = jobHandlerConfiguration;

  if (jobHandlerType.equalsIgnoreCase(TimerExecuteNestedActivityJobHandler.TYPE) ||
          jobHandlerType.equalsIgnoreCase(TimerCatchIntermediateEventJobHandler.TYPE) ||
          jobHandlerType.equalsIgnoreCase(TimerStartEventJobHandler.TYPE)) {

    embededActivityId = TimerEventHandler.getActivityIdFromConfiguration(jobHandlerConfiguration);

    String endDateExpressionString = TimerEventHandler.getEndDateFromConfiguration(jobHandlerConfiguration);

    if (endDateExpressionString!=null) {
       Expression endDateExpression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(endDateExpressionString);

      String endDateString = null;

      BusinessCalendar businessCalendar = Context.getProcessEngineConfiguration().getBusinessCalendarManager()
          .getBusinessCalendar(getBusinessCalendarName(TimerEventHandler.geCalendarNameFromConfiguration(jobHandlerConfiguration)));

      VariableScope executionEntity = null;
      if (executionId != null) {
        executionEntity = commandContext.getExecutionEntityManager().findExecutionById(executionId);
      }
      
      if (executionEntity == null) {
        executionEntity = NoExecutionVariableScope.getSharedInstance();
      }

      if (endDateExpression != null) {
        Object endDateValue = endDateExpression.getValue(executionEntity);
        if (endDateValue instanceof String) {
          endDateString = (String) endDateValue;
        } else if (endDateValue instanceof Date) {
          endDate = (Date) endDateValue;
        } else {
          throw new ActivitiException("Timer '" + ((ExecutionEntity) executionEntity).getActivityId()
                  + "' was not configured with a valid duration/time, either hand in a java.util.Date or a String in format 'yyyy-MM-dd'T'hh:mm:ss'");
        }

        if (endDate == null) {
          endDate = businessCalendar.resolveEndDate(endDateString);
        }
      }
    }
  }

   if (processDefinitionId != null) {
    ProcessDefinition def = Context.getProcessEngineConfiguration().getRepositoryService().getProcessDefinition(processDefinitionId);
    maxIterations = checkStartEventDefinitions(def, embededActivityId);
    if (maxIterations <= 1) {
      maxIterations = checkBoundaryEventsDefinitions(def, embededActivityId);
    }
  } else {
    maxIterations = 1;
  }
}
 
Example 20
Source File: ActivitiHelper.java    From herd with Apache License 2.0 2 votes vote down vote up
/**
 * Gets an expression variable from the execution. This method will return null if the expression is null (i.e. when a workflow doesn't define the
 * expression).
 *
 * @param expression the expression variable to get.
 * @param execution the execution that contains the variable value.
 *
 * @return the variable value or null if the expression is null.
 */
public Object getExpressionVariable(Expression expression, DelegateExecution execution)
{
    return (expression == null ? null : expression.getValue(execution));
}