Java Code Examples for org.camunda.bpm.engine.variable.value.StringValue

The following examples show how to use org.camunda.bpm.engine.variable.value.StringValue. These examples are extracted from open source projects. 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 Project: camunda-bpm-platform   Source File: TimerExpressionBean.java    License: Apache License 2.0 6 votes vote down vote up
public String getTimerDuration() {
  if (timerExpression == null) {
    VariableInstance variable = runtimeService
        .createVariableInstanceQuery()
        .variableName("timerExpression")
        .singleResult();
    if (variable != null) {
      timerExpression = variable.getTypedValue();
    }
  }
  if (timerExpression == null) {
    throw new NullValueException("no variable 'timerExpression' found");
  }
  if (timerExpression instanceof StringValue) {
    return ((StringValue) timerExpression).getValue();
  }
  return String.valueOf(timerExpression.getValue());
}
 
Example 2
@Test
public void testSetVariableLocalTypedBehavior() {

  // given
  new RuntimeServiceFluentMock(runtimeService)
    .getVariableLocalTyped("Foo", true, Variables.stringValue("Bar"))
    .getVariableLocalTyped("Bar", true, Variables.stringValue("Zee"), Variables.stringValue("Tree"))
    .getVariablesLocalTyped(true, Variables.createVariables().putValue("Kermit", "TheFrog"))
    .getVariablesLocalTyped(Lists.newArrayList("Piggy"), true, Variables.createVariables().putValue("Piggy", "ThePig"));

  // given
  new RuntimeServiceFluentMock(runtimeService)
    .getVariableLocalTyped("Foo", Variables.stringValue("Bar"))
    .getVariableLocalTyped("Bar", Variables.stringValue("Zee"), Variables.stringValue("Tree"))
    .getVariablesLocalTyped(Variables.createVariables().putValue("Kermit", "TheFrog"));


  // when -> then
  // single
  assertThat(runtimeService.<StringValue>getVariableLocalTyped(task.getExecutionId(), "Foo", true)).isEqualTo(Variables.stringValue("Bar"));
  // multiple
  assertThat(runtimeService.<StringValue>getVariableLocalTyped(task.getExecutionId(), "Bar", true)).isEqualTo(Variables.stringValue("Zee"));
  assertThat(runtimeService.<StringValue>getVariableLocalTyped(task.getExecutionId(), "Bar", true)).isEqualTo(Variables.stringValue("Tree"));
  // all
  assertThat(runtimeService.getVariablesLocalTyped(task.getExecutionId(), true))
    .isEqualTo(Variables.createVariables().putValue("Kermit", "TheFrog"));
  // some
  assertThat(runtimeService.getVariablesLocalTyped(task.getExecutionId(), Lists.newArrayList("Piggy"), true))
    .isEqualTo(Variables.createVariables().putValue("Piggy", "ThePig"));

  assertThat(runtimeService.<StringValue>getVariableLocalTyped(task.getExecutionId(), "Foo")).isEqualTo(Variables.stringValue("Bar"));
  // multiple
  assertThat(runtimeService.<StringValue>getVariableLocalTyped(task.getExecutionId(), "Bar")).isEqualTo(Variables.stringValue("Zee"));
  assertThat(runtimeService.<StringValue>getVariableLocalTyped(task.getExecutionId(), "Bar")).isEqualTo(Variables.stringValue("Tree"));
  // all
  assertThat(runtimeService.getVariablesLocalTyped(task.getExecutionId()))
    .isEqualTo(Variables.createVariables().putValue("Kermit", "TheFrog"));

}
 
Example 3
@Test
public void testSetVariableTypedBehavior() {

  // given
  new RuntimeServiceFluentMock(runtimeService)
    .getVariableTyped("Foo", true, Variables.stringValue("Bar"))
    .getVariableTyped("Bar", true, Variables.stringValue("Zee"), Variables.stringValue("Tree"))
    .getVariablesTyped(true, Variables.createVariables().putValue("Kermit", "TheFrog"))
    .getVariablesTyped(Lists.newArrayList("Piggy"), true, Variables.createVariables().putValue("Piggy", "ThePig"));

  // given
  new RuntimeServiceFluentMock(runtimeService)
    .getVariableTyped("Foo", Variables.stringValue("Bar"))
    .getVariableTyped("Bar", Variables.stringValue("Zee"), Variables.stringValue("Tree"))
    .getVariablesTyped(Variables.createVariables().putValue("Kermit", "TheFrog"));


  // when -> then
  // single
  assertThat(runtimeService.<StringValue>getVariableTyped(task.getExecutionId(), "Foo", true)).isEqualTo(Variables.stringValue("Bar"));
  // multiple
  assertThat(runtimeService.<StringValue>getVariableTyped(task.getExecutionId(), "Bar", true)).isEqualTo(Variables.stringValue("Zee"));
  assertThat(runtimeService.<StringValue>getVariableTyped(task.getExecutionId(), "Bar", true)).isEqualTo(Variables.stringValue("Tree"));
  // all
  assertThat(runtimeService.getVariablesTyped(task.getExecutionId(), true))
    .isEqualTo(Variables.createVariables().putValue("Kermit", "TheFrog"));
  // some
  assertThat(runtimeService.getVariablesTyped(task.getExecutionId(), Lists.newArrayList("Piggy"), true))
    .isEqualTo(Variables.createVariables().putValue("Piggy", "ThePig"));

  assertThat(runtimeService.<StringValue>getVariableTyped(task.getExecutionId(), "Foo")).isEqualTo(Variables.stringValue("Bar"));
  // multiple
  assertThat(runtimeService.<StringValue>getVariableTyped(task.getExecutionId(), "Bar")).isEqualTo(Variables.stringValue("Zee"));
  assertThat(runtimeService.<StringValue>getVariableTyped(task.getExecutionId(), "Bar")).isEqualTo(Variables.stringValue("Tree"));
  // all
  assertThat(runtimeService.getVariablesTyped(task.getExecutionId()))
    .isEqualTo(Variables.createVariables().putValue("Kermit", "TheFrog"));

}
 
Example 4
@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/annotation/CompleteTaskTest.bpmn20.xml")
public void testProcessVariableTypeAnnotation() {
  BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);

  VariableMap variables = Variables.createVariables().putValue("injectedValue", "camunda");
  businessProcess.startProcessByKey("keyOfTheProcess", variables);

  TypedValue value = getBeanInstance(DeclarativeProcessController.class).getInjectedValue();
  assertNotNull(value);
  assertTrue(value instanceof StringValue);
  assertEquals(ValueType.STRING, value.getType());
  assertEquals("camunda", value.getValue());
}
 
Example 5
Source Project: camunda-bpm-platform   Source File: StartProcessTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/annotation/StartProcessTest.bpmn20.xml")
public void testStartProcessByKey() {

  assertNull(runtimeService.createProcessInstanceQuery().singleResult());

  getBeanInstance(DeclarativeProcessController.class).startProcessByKey();
  BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);

  assertNotNull(runtimeService.createProcessInstanceQuery().singleResult());

  assertEquals("camunda", businessProcess.getVariable("name"));

  TypedValue nameTypedValue = businessProcess.getVariableTyped("name");
  assertNotNull(nameTypedValue);
  assertTrue(nameTypedValue instanceof StringValue);
  assertEquals(ValueType.STRING, nameTypedValue.getType());
  assertEquals("camunda", nameTypedValue.getValue());

  assertEquals("untypedName", businessProcess.getVariable("untypedName"));

  TypedValue untypedNameTypedValue = businessProcess.getVariableTyped("untypedName");
  assertNotNull(untypedNameTypedValue);
  assertTrue(untypedNameTypedValue instanceof StringValue);
  assertEquals(ValueType.STRING, untypedNameTypedValue.getType());
  assertEquals("untypedName", untypedNameTypedValue.getValue());


  assertEquals("typedName", businessProcess.getVariable("typedName"));

  TypedValue typedNameTypedValue = businessProcess.getVariableTyped("typedName");
  assertNotNull(typedNameTypedValue);
  assertTrue(typedNameTypedValue instanceof StringValue);
  assertEquals(ValueType.STRING, typedNameTypedValue.getType());
  assertEquals("typedName", typedNameTypedValue.getValue());

  businessProcess.startTask(taskService.createTaskQuery().singleResult().getId());
  businessProcess.completeTask();
}
 
Example 6
@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/annotation/CompleteTaskTest.bpmn20.xml")
public void testProcessVariableLocalTypeAnnotation() {
  BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);

  VariableMap variables = Variables.createVariables().putValue("injectedLocalValue", "camunda");
  businessProcess.startProcessByKey("keyOfTheProcess", variables);

  TypedValue value = getBeanInstance(DeclarativeProcessController.class).getInjectedLocalValue();
  assertNotNull(value);
  assertTrue(value instanceof StringValue);
  assertEquals(ValueType.STRING, value.getType());
  assertEquals("camunda", value.getValue());
}
 
Example 7
Source Project: camunda-bpm-platform   Source File: StringFormType.java    License: 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 8
@Test
public void getVariableTypedWithAuthenticatedTenant() {
  identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));

  StringValue variable = caseService.getVariableTyped(caseExecutionId, VARIABLE_NAME);

  assertThat(variable.getValue(), is(VARIABLE_VALUE));
}
 
Example 9
@Test
public void getVariableTypedDisabledTenantCheck() {
  identityService.setAuthentication("user", null, null);
  processEngineConfiguration.setTenantCheckEnabled(false);

  StringValue variable = caseService.getVariableTyped(caseExecutionId, VARIABLE_NAME);

  assertThat(variable.getValue(), is(VARIABLE_VALUE));
}
 
Example 10
Source Project: camunda-bpm-platform   Source File: ExecutionEntityTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
  try {
    // then (see #testRemoveExecutionSequence)
    StringValue var = delegateTask.getExecution().getVariableLocalTyped("localVar");
    assertEquals("localVarVal", var.getValue());
  } catch (NullPointerException e) {
    fail("Local variable shouldn't be null.");
  }
}
 
Example 11
public StringValue convertToTypedValue(UntypedValueImpl untypedValue) {
  return Variables.stringValue((String) untypedValue.getValue());
}
 
Example 12
public StringValue readValue(TypedValueField typedValueField) {
  return Variables.stringValue((String) typedValueField.getValue());
}
 
Example 13
public void writeValue(StringValue stringValue, TypedValueField typedValueField) {
  typedValueField.setValue(stringValue.getValue());
}
 
Example 14
public StringValue convertToTypedValue(UntypedValueImpl untypedValue) {
  return Variables.stringValue((String) untypedValue.getValue(), untypedValue.isTransient());
}
 
Example 15
public StringValue readValue(ValueFields valueFields, boolean asTransientValue) {
  return Variables.stringValue(valueFields.getTextValue(), asTransientValue);
}
 
Example 16
public void writeValue(StringValue variableValue, ValueFields valueFields) {
  valueFields.setTextValue(variableValue.getValue());
}
 
Example 17
Source Project: camunda-bpm-platform   Source File: TaskVariablesTest.java    License: Apache License 2.0 4 votes vote down vote up
@Deployment
public void testTaskExecutionVariables() {
  String processInstanceId = runtimeService.startProcessInstanceByKey("oneTaskProcess").getId();
  String taskId = taskService.createTaskQuery().singleResult().getId();

  Map<String, Object> expectedVariables = new HashMap<String, Object>();
  assertEquals(expectedVariables, runtimeService.getVariables(processInstanceId));
  assertEquals(expectedVariables, taskService.getVariables(taskId));
  assertEquals(expectedVariables, runtimeService.getVariablesLocal(processInstanceId));
  assertEquals(expectedVariables, taskService.getVariablesLocal(taskId));

  runtimeService.setVariable(processInstanceId, "instrument", "trumpet");

  expectedVariables = new HashMap<String, Object>();
  assertEquals(expectedVariables, taskService.getVariablesLocal(taskId));
  expectedVariables.put("instrument", "trumpet");
  assertEquals(expectedVariables, runtimeService.getVariables(processInstanceId));
  assertEquals(expectedVariables, taskService.getVariables(taskId));
  assertEquals(expectedVariables, runtimeService.getVariablesLocal(processInstanceId));

  taskService.setVariable(taskId, "player", "gonzo");

  expectedVariables = new HashMap<String, Object>();
  assertEquals(expectedVariables, taskService.getVariablesLocal(taskId));
  expectedVariables.put("player", "gonzo");
  expectedVariables.put("instrument", "trumpet");
  assertEquals(expectedVariables, runtimeService.getVariables(processInstanceId));
  assertEquals(expectedVariables, taskService.getVariables(taskId));
  assertEquals(expectedVariables, runtimeService.getVariablesLocal(processInstanceId));
  assertEquals(expectedVariables, runtimeService.getVariablesLocal(processInstanceId, null));
  assertEquals(expectedVariables, runtimeService.getVariablesLocalTyped(processInstanceId, null, true));

  taskService.setVariableLocal(taskId, "budget", "unlimited");

  expectedVariables = new HashMap<String, Object>();
  expectedVariables.put("budget", "unlimited");
  assertEquals(expectedVariables, taskService.getVariablesLocal(taskId));
  assertEquals(expectedVariables, taskService.getVariablesLocalTyped(taskId, true));
  expectedVariables.put("player", "gonzo");
  expectedVariables.put("instrument", "trumpet");
  assertEquals(expectedVariables, taskService.getVariables(taskId));
  assertEquals(expectedVariables, taskService.getVariablesTyped(taskId, true));

  assertEquals(expectedVariables, taskService.getVariables(taskId, null));
  assertEquals(expectedVariables, taskService.getVariablesTyped(taskId, null, true));

  expectedVariables = new HashMap<String, Object>();
  expectedVariables.put("player", "gonzo");
  expectedVariables.put("instrument", "trumpet");
  assertEquals(expectedVariables, runtimeService.getVariables(processInstanceId));
  assertEquals(expectedVariables, runtimeService.getVariablesLocal(processInstanceId));


  // typed variable API

  ArrayList<String> serializableValue = new ArrayList<String>();
  serializableValue.add("1");
  serializableValue.add("2");
  taskService.setVariable(taskId, "objectVariable", objectValue(serializableValue).create());

  ArrayList<String> serializableValueLocal = new ArrayList<String>();
  serializableValueLocal.add("3");
  serializableValueLocal.add("4");
  taskService.setVariableLocal(taskId, "objectVariableLocal", objectValue(serializableValueLocal).create());

  Object value = taskService.getVariable(taskId, "objectVariable");
  assertEquals(serializableValue, value);

  Object valueLocal = taskService.getVariableLocal(taskId, "objectVariableLocal");
  assertEquals(serializableValueLocal, valueLocal);

  ObjectValue typedValue = taskService.getVariableTyped(taskId, "objectVariable");
  assertEquals(serializableValue, typedValue.getValue());

  ObjectValue serializedValue = taskService.getVariableTyped(taskId, "objectVariable", false);
  assertFalse(serializedValue.isDeserialized());

  ObjectValue typedValueLocal = taskService.getVariableLocalTyped(taskId, "objectVariableLocal");
  assertEquals(serializableValueLocal, typedValueLocal.getValue());

  ObjectValue serializedValueLocal = taskService.getVariableLocalTyped(taskId, "objectVariableLocal", false);
  assertFalse(serializedValueLocal.isDeserialized());

  try {
    StringValue val = taskService.getVariableTyped(taskId, "objectVariable");
    fail("expected exception");
  }
  catch(ClassCastException e) {
    //happy path
  }

}
 
Example 18
protected void verifyStringValue(Map<String, Object> stringValue) {
  StringValue exampleValue = MockProvider.EXAMPLE_HISTORIC_DECISION_STRING_VALUE;
  assertThat(stringValue, hasEntry("type", (Object) VariableValueDto.toRestApiTypeName(exampleValue.getType().getName())));
  assertThat(stringValue, hasEntry("value", (Object) exampleValue.getValue()));
  assertThat(stringValue, hasEntry("valueInfo", (Object) Collections.emptyMap()));
}
 
Example 19
public StringValue createValue(Object value, Map<String, Object> valueInfo) {
  return Variables.stringValue((String) value, isTransient(valueInfo));
}
 
Example 20
Source Project: camunda-bpm-mockito   Source File: VariableScopeFakeTest.java    License: Apache License 2.0 3 votes vote down vote up
@Test
public void variablesTyped() throws Exception {
  VariableMap variables = Variables.putValueTyped("foo", stringValue("bar"));

  variableScope.setVariablesLocal(variables);

  StringValue foo = variableScope.getVariableLocalTyped("foo");

  assertThat(foo.getValue()).isEqualTo("bar");
}