Java Code Examples for org.camunda.bpm.engine.variable.Variables#stringValue()

The following examples show how to use org.camunda.bpm.engine.variable.Variables#stringValue() . 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: CaseCallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
    "org/camunda/bpm/engine/test/bpmn/callactivity/CaseCallActivityTest.testOutputAll.bpmn20.xml",
    "org/camunda/bpm/engine/test/api/cmmn/oneTaskCaseWithManualActivation.cmmn"
  })
public void testCallCaseOutputAllVariablesTypedToProcess(){
  startProcessInstanceByKey("process");
  CaseInstance caseInstance = queryOneTaskCaseInstance();
  String variableName = "foo";
  String variableName2 = "null";
  TypedValue variableValue = Variables.stringValue("bar");
  TypedValue variableValue2 = Variables.integerValue(null);
  caseService.withCaseExecution(caseInstance.getId())
    .setVariable(variableName, variableValue)
    .setVariable(variableName2, variableValue2)
    .execute();
  complete(caseInstance.getId());

  Task task = taskService.createTaskQuery().singleResult();
  TypedValue value = runtimeService.getVariableTyped(task.getProcessInstanceId(), variableName);
  assertThat(value, is(variableValue));
  value = runtimeService.getVariableTyped(task.getProcessInstanceId(), variableName2);
  assertThat(value, is(variableValue2));
}
 
Example 2
Source File: CallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Test case for handing over process variables to a sub process via the typed
 * api and passing all variables
 */
@Deployment(resources = {
  "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testSubProcessAllDataInputOutputTypedApi.bpmn20.xml",
  "org/camunda/bpm/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml"})
public void testSubProcessWithAllDataInputOutputTypedApi() {

  TypedValue superVariable = Variables.stringValue(null);
  VariableMap vars = Variables.createVariables();
  vars.putValueTyped("superVariable", superVariable);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("subProcessDataInputOutput", vars);

  // one task in the subprocess should be active after starting the process instance
  TaskQuery taskQuery = taskService.createTaskQuery();
  Task taskInSubProcess = taskQuery.singleResult();
  assertThat(taskInSubProcess.getName(), is("Task in subprocess"));
  assertThat(runtimeService.getVariableTyped(taskInSubProcess.getProcessInstanceId(), "superVariable"), is(superVariable));
  assertThat(taskService.getVariableTyped(taskInSubProcess.getId(), "superVariable"), is(superVariable));

  TypedValue subVariable = Variables.stringValue(null);
  runtimeService.setVariable(taskInSubProcess.getProcessInstanceId(), "subVariable", subVariable);

  // Completing this task ends the subprocess which leads to a task in the super process
  taskService.complete(taskInSubProcess.getId());

  Task taskAfterSubProcess = taskQuery.singleResult();
  assertThat(taskAfterSubProcess.getName(), is("Task in super process"));
  assertThat(runtimeService.getVariableTyped(processInstance.getId(), "subVariable"), is(subVariable));
  assertThat(taskService.getVariableTyped(taskAfterSubProcess.getId(), "superVariable"), is(superVariable));

  // Completing this task ends the super process which leads to a task in the super process
  taskService.complete(taskAfterSubProcess.getId());

  assertProcessEnded(processInstance.getId());
  assertEquals(0, runtimeService.createExecutionQuery().list().size());
}
 
Example 3
Source File: CallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Test case for handing over process variables to a sub process via the typed
 * api and passing only certain variables
 */
@Deployment(resources = {
  "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testSubProcessLimitedDataInputOutputTypedApi.bpmn20.xml",
  "org/camunda/bpm/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml"})
public void testSubProcessWithLimitedDataInputOutputTypedApi() {

  TypedValue superVariable = Variables.stringValue(null);
  VariableMap vars = Variables.createVariables();
  vars.putValueTyped("superVariable", superVariable);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("subProcessDataInputOutput", vars);

  // one task in the subprocess should be active after starting the process instance
  TaskQuery taskQuery = taskService.createTaskQuery();
  Task taskInSubProcess = taskQuery.singleResult();
  assertThat(taskInSubProcess.getName(), is("Task in subprocess"));
  assertThat(runtimeService.getVariableTyped(taskInSubProcess.getProcessInstanceId(), "subVariable"), is(superVariable));
  assertThat(taskService.getVariableTyped(taskInSubProcess.getId(), "subVariable"), is(superVariable));

  TypedValue subVariable = Variables.stringValue(null);
  runtimeService.setVariable(taskInSubProcess.getProcessInstanceId(), "subVariable", subVariable);

  // super variable is unchanged
  assertThat(runtimeService.getVariableTyped(processInstance.getId(), "superVariable"), is(superVariable));

  // Completing this task ends the subprocess which leads to a task in the super process
  taskService.complete(taskInSubProcess.getId());

  Task taskAfterSubProcess = taskQuery.singleResult();
  assertThat(taskAfterSubProcess.getName(), is("Task in super process"));
  assertThat(runtimeService.getVariableTyped(processInstance.getId(), "superVariable"), is(subVariable));
  assertThat(taskService.getVariableTyped(taskAfterSubProcess.getId(), "superVariable"), is(subVariable));

  // Completing this task ends the super process which leads to a task in the super process
  taskService.complete(taskAfterSubProcess.getId());

  assertProcessEnded(processInstance.getId());
  assertEquals(0, runtimeService.createExecutionQuery().list().size());
}
 
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: EnumFormType.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public TypedValue convertValue(TypedValue propertyValue) {
  Object value = propertyValue.getValue();
  if(value == null || String.class.isInstance(value)) {
    validateValue(value);
    return Variables.stringValue((String) value, propertyValue.isTransient());
  }
  else {
    throw new ProcessEngineException("Value '"+value+"' is not of type String.");
  }
}
 
Example 6
Source File: StringFormType.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public TypedValue convertValue(TypedValue propertyValue) {
  if(propertyValue instanceof StringValue) {
    return propertyValue;
  }
  else {
    Object value = propertyValue.getValue();
    if(value == null) {
      return Variables.stringValue(null, propertyValue.isTransient());
    }
    else {
      return Variables.stringValue(value.toString(), propertyValue.isTransient());
    }
  }
}
 
Example 7
Source File: DateFormType.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public TypedValue convertToFormValue(TypedValue modelValue) {
  if(modelValue.getValue() == null) {
    return Variables.stringValue(null, modelValue.isTransient());
  } else if(modelValue.getType() == ValueType.DATE) {
    return Variables.stringValue(dateFormat.format(modelValue.getValue()), modelValue.isTransient());
  }
  else {
    throw new ProcessEngineException("Expected value to be of type '"+ValueType.DATE+"' but got '"+modelValue.getType()+"'.");
  }
}
 
Example 8
Source File: PrimitiveValueTypeImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public StringValue createValue(Object value, Map<String, Object> valueInfo) {
  return Variables.stringValue((String) value, isTransient(valueInfo));
}
 
Example 9
Source File: StringValueMapper.java    From camunda-external-task-client-java with Apache License 2.0 4 votes vote down vote up
public StringValue convertToTypedValue(UntypedValueImpl untypedValue) {
  return Variables.stringValue((String) untypedValue.getValue());
}
 
Example 10
Source File: ProcessTaskTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = {
    "org/camunda/bpm/engine/test/cmmn/processtask/ProcessTaskTest.testVariablesRoundtrip.cmmn",
    "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"
  })
public void testInputOutputLimitedTypedVariables() {
  String variableName = "aVariable";
  String variableName2 = "anotherVariable";
  TypedValue caseVariableValue = Variables.stringValue("abc");
  TypedValue caseVariableValue2 = Variables.integerValue(null);

  String caseInstanceId = createCaseInstanceByKey(ONE_PROCESS_TASK_CASE,
      Variables.createVariables().putValue(variableName, caseVariableValue)
      .putValue(variableName2, caseVariableValue2)).getId();

  String processInstanceId = queryProcessInstance().getId();
  TypedValue value = runtimeService.getVariableTyped(processInstanceId, variableName);
  assertThat(value, is(caseVariableValue));
  value = runtimeService.getVariableTyped(processInstanceId, variableName2);
  assertThat(value, is(caseVariableValue2));


  TypedValue processVariableValue = Variables.stringValue("cba");
  TypedValue processVariableValue2 = Variables.booleanValue(null);
  runtimeService.setVariable(processInstanceId, variableName, processVariableValue);
  runtimeService.setVariable(processInstanceId, variableName2, processVariableValue2);

  // should also complete process instance
  taskService.complete(queryTask().getId());

  value = caseService.getVariableTyped(caseInstanceId, variableName);
  assertThat(value, is(processVariableValue));
  value = caseService.getVariableTyped(caseInstanceId, variableName2);
  assertThat(value, is(processVariableValue2));
  // complete ////////////////////////////////////////////////////////

  assertProcessEnded(processInstanceId);

  close(caseInstanceId);
  assertCaseEnded(caseInstanceId);

}
 
Example 11
Source File: ProcessTaskTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = {
    "org/camunda/bpm/engine/test/cmmn/processtask/ProcessTaskTest.testInputOutputAll.cmmn",
    "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"
  })
public void testInputOutputAllTypedVariables() {
  String variableName = "aVariable";
  String variableName2 = "anotherVariable";
  String variableName3 = "theThirdVariable";
  TypedValue variableValue = Variables.stringValue("abc");
  TypedValue variableValue2 = Variables.longValue(null);

  String caseInstanceId = createCaseInstanceByKey(ONE_PROCESS_TASK_CASE,
      Variables.createVariables()
      .putValue(variableName, variableValue)
      .putValue(variableName2, variableValue2))
      .getId();
  String processTaskId = queryCaseExecutionByActivityId(PROCESS_TASK).getId();

  String processInstanceId = queryProcessInstance().getId();

  TypedValue value = runtimeService.getVariableTyped(processInstanceId, variableName);
  assertThat(value, is(variableValue));
  value = runtimeService.getVariableTyped(processInstanceId, variableName2);
  assertThat(value, is(variableValue2));

  String taskId = queryTask().getId();

  TypedValue variableValue3 = Variables.integerValue(1);
  runtimeService.setVariable(processInstanceId, variableName3, variableValue3);

  // should also complete process instance
  taskService.complete(taskId);

  value = caseService.getVariableTyped(caseInstanceId, variableName3);

  assertThat(value, is(variableValue3));

  // complete ////////////////////////////////////////////////////////

  assertProcessEnded(processInstanceId);

  close(caseInstanceId);
  assertCaseEnded(caseInstanceId);
}
 
Example 12
Source File: StringValueSerializer.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public StringValue readValue(ValueFields valueFields, boolean asTransientValue) {
  return Variables.stringValue(valueFields.getTextValue(), asTransientValue);
}
 
Example 13
Source File: StringValueSerializer.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public StringValue convertToTypedValue(UntypedValueImpl untypedValue) {
  return Variables.stringValue((String) untypedValue.getValue(), untypedValue.isTransient());
}
 
Example 14
Source File: FormPropertyAdapter.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public TypedValue getValue() {
  return Variables.stringValue(formProperty.getValue());
}
 
Example 15
Source File: StringDataTypeTransformer.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public TypedValue transform(Object value) throws IllegalArgumentException {
  String stringValue = String.valueOf(value);
  return Variables.stringValue(stringValue);
}
 
Example 16
Source File: DeclarativeProcessController.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@StartProcess("keyOfTheProcess")
public void startProcessByKey() {
  name = "camunda";
  untypedName = "untypedName";
  typedName = Variables.stringValue("typedName");
}
 
Example 17
Source File: StringDataTypeTransformer.java    From camunda-engine-dmn with Apache License 2.0 4 votes vote down vote up
@Override
public TypedValue transform(Object value) throws IllegalArgumentException {
  String stringValue = String.valueOf(value);
  return Variables.stringValue(stringValue);
}
 
Example 18
Source File: StringValueMapper.java    From camunda-external-task-client-java with Apache License 2.0 4 votes vote down vote up
public StringValue readValue(TypedValueField typedValueField) {
  return Variables.stringValue((String) typedValueField.getValue());
}