Java Code Examples for org.camunda.bpm.engine.delegate.VariableScope#setVariable()

The following examples show how to use org.camunda.bpm.engine.delegate.VariableScope#setVariable() . 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: FluentMock.java    From camunda-bpm-mockito with Apache License 2.0 5 votes vote down vote up
protected void setVariables(final VariableScope variableScope, final Map<String, Object> variables) {
  if (variables == null || variables.isEmpty()) {
    return;
  }
  for (final Entry<String, Object> variable : variables.entrySet()) {
    variableScope.setVariable(variable.getKey(), variable.getValue());
  }
}
 
Example 2
Source File: DefaultFormHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void submitFormVariables(VariableMap properties, VariableScope variableScope) {
  boolean userOperationLogEnabled = Context.getCommandContext().isUserOperationLogEnabled();
  Context.getCommandContext().enableUserOperationLog();

  VariableMap propertiesCopy = new VariableMapImpl(properties);

  // support legacy form properties
  for (FormPropertyHandler formPropertyHandler: formPropertyHandlers) {
    // submitFormProperty will remove all the keys which it takes care of
    formPropertyHandler.submitFormProperty(variableScope, propertiesCopy);
  }

  // support form data:
  for (FormFieldHandler formFieldHandler : formFieldHandlers) {
    if (!formFieldHandler.isBusinessKey()) {
      formFieldHandler.handleSubmit(variableScope, propertiesCopy, properties);
    }
  }

  // any variables passed in which are not handled by form-fields or form
  // properties are added to the process as variables
  for (String propertyId: propertiesCopy.keySet()) {
    variableScope.setVariable(propertyId, propertiesCopy.getValueTyped(propertyId));
  }

  fireFormPropertyHistoryEvents(properties, variableScope);

  Context.getCommandContext().setLogUserOperationEnabled(userOperationLogEnabled);
}
 
Example 3
Source File: FormPropertyHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void submitFormProperty(VariableScope variableScope, VariableMap variables) {
  if (!isWritable && variables.containsKey(id)) {
    throw new ProcessEngineException("form property '"+id+"' is not writable");
  }

  if (isRequired && !variables.containsKey(id) && defaultExpression == null) {
    throw new ProcessEngineException("form property '"+id+"' is required");
  }

  Object modelValue = null;
  if (variables.containsKey(id)) {
    final Object propertyValue = variables.remove(id);
    if (type != null) {
      modelValue = type.convertFormValueToModelValue(propertyValue);
    } else {
      modelValue = propertyValue;
    }
  } else if (defaultExpression != null) {
    final Object expressionValue = defaultExpression.getValue(variableScope);
    if (type != null && expressionValue != null) {
      modelValue = type.convertFormValueToModelValue(expressionValue.toString());
    } else if (expressionValue != null) {
      modelValue = expressionValue.toString();
    } else if (isRequired) {
      throw new ProcessEngineException("form property '"+id+"' is required");
    }
  }

  if (modelValue != null) {
    if (variableName != null) {
      variableScope.setVariable(variableName, modelValue);
    } else if (variableExpression != null) {
      variableExpression.setValue(modelValue, variableScope);
    } else {
      variableScope.setVariable(id, modelValue);
    }
  }
}
 
Example 4
Source File: FormFieldHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void handleSubmit(VariableScope variableScope, VariableMap values, VariableMap allValues) {
  TypedValue submittedValue = (TypedValue) values.getValueTyped(id);
  values.remove(id);

  // perform validation
  for (FormFieldValidationConstraintHandler validationHandler : validationHandlers) {
    Object value = null;
    if(submittedValue != null) {
      value = submittedValue.getValue();
    }
    validationHandler.validate(value, allValues, this, variableScope);
  }

  // update variable(s)
  TypedValue modelValue = null;
  if (submittedValue != null) {
    if (type != null) {
      modelValue = type.convertToModelValue(submittedValue);
    }
    else {
      modelValue = submittedValue;
    }
  }
  else if (defaultValueExpression != null) {
    final TypedValue expressionValue = Variables.untypedValue(defaultValueExpression.getValue(variableScope));
    if (type != null) {
      // first, need to convert to model value since the default value may be a String Constant specified in the model xml.
      modelValue = type.convertToModelValue(Variables.untypedValue(expressionValue));
    }
    else if (expressionValue != null) {
      modelValue = Variables.stringValue(expressionValue.getValue().toString());
    }
  }

  if (modelValue != null) {
    if (id != null) {
      variableScope.setVariable(id, modelValue);
    }
  }
}
 
Example 5
Source File: VariableScopeElResolver.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void setValue(ELContext context, Object base, Object property, Object value) {
  if (base == null) {
    String variable = (String) property;
    Object object = context.getContext(VariableScope.class);
    if (object != null) {
      VariableScope variableScope = (VariableScope) object;
      if (variableScope.hasVariable(variable)) {
        variableScope.setVariable(variable, value);
        context.setPropertyResolved(true);
      }
    }
  }
}