Java Code Examples for org.camunda.bpm.engine.variable.type.ValueType

The following examples show how to use org.camunda.bpm.engine.variable.type.ValueType. 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
@Override
public boolean canConvertFromTypedValue(TypedValue typedValue) {
  if (typedValue.getType() != ValueType.NUMBER) {
    return false;
  }

  if (typedValue.getValue() != null) {
    NumberValue numberValue = (NumberValue) typedValue;
    double doubleValue = numberValue.getValue().doubleValue();

    // returns false if the value changes due to conversion (e.g. by overflows
    // or by loss in precision)
    if (numberValue.getValue().shortValue() != doubleValue) {
      return false;
    }
  }

  return true;
}
 
Example 2
@Override
public IntegerValue convertFromTypedValue(TypedValue typedValue) {
  if (typedValue.getType() != ValueType.NUMBER) {
    throw unsupportedConversion(typedValue.getType());
  }

  IntegerValueImpl integerValue = null;
  NumberValue numberValue = (NumberValue) typedValue;
  if (numberValue.getValue() != null) {
    integerValue = (IntegerValueImpl) Variables.integerValue(numberValue.getValue().intValue());
  } else {
    integerValue = (IntegerValueImpl) Variables.integerValue(null);
  }
  integerValue.setTransient(numberValue.isTransient());
  return integerValue;
}
 
Example 3
@Test
public void testPutSingleLocalVariableFromSerializedWithNoValue() {
  String variableKey = "aVariableKey";

  Map<String, Object> requestJson = VariablesBuilder
      .getObjectValueMap(null, ValueType.OBJECT.getName(), null, null);

  given().pathParam("id", MockProvider.EXAMPLE_EXECUTION_ID).pathParam("varId", variableKey)
    .contentType(ContentType.JSON).body(requestJson)
    .then().expect().statusCode(Status.NO_CONTENT.getStatusCode())
    .when().put(SINGLE_EXECUTION_LOCAL_VARIABLE_URL);

  verify(runtimeServiceMock).setVariableLocal(eq(MockProvider.EXAMPLE_EXECUTION_ID), eq(variableKey),
      argThat(EqualsObjectValue
        .objectValueMatcher()
        .serializationFormat(null)
        .objectTypeName(null)
        .serializedValue(null)));
}
 
Example 4
@Test
public void testJavaObjectVariableSerialization() {
  when(caseServiceMock.getVariablesTyped(MockProvider.EXAMPLE_CASE_INSTANCE_ID, true)).thenReturn(EXAMPLE_OBJECT_VARIABLES);

  Response response = given().pathParam("id", MockProvider.EXAMPLE_CASE_INSTANCE_ID)
    .then().expect().statusCode(Status.OK.getStatusCode())
    .body(EXAMPLE_VARIABLE_KEY, notNullValue())
    .body(EXAMPLE_VARIABLE_KEY + ".value.property1", equalTo("aPropertyValue"))
    .body(EXAMPLE_VARIABLE_KEY + ".value.property2", equalTo(true))
    .body(EXAMPLE_VARIABLE_KEY + ".type", equalTo(VariableTypeHelper.toExpectedValueTypeName(ValueType.OBJECT)))
    .body(EXAMPLE_VARIABLE_KEY + ".valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME, equalTo(ExampleVariableObject.class.getName()))
    .body(EXAMPLE_VARIABLE_KEY + ".valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT, equalTo("application/json"))
    .when().get(CASE_INSTANCE_VARIABLES_URL);

  Assert.assertEquals("Should return exactly one variable", 1, response.jsonPath().getMap("").size());

  verify(caseServiceMock).getVariablesTyped(MockProvider.EXAMPLE_CASE_INSTANCE_ID, true);
}
 
Example 5
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSelectHistoricVariableInstances() throws JSONException {
  if (processEngineConfiguration.getHistoryLevel().getId() >=
      HistoryLevel.HISTORY_LEVEL_AUDIT.getId()) {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    JsonSerializable bean = new JsonSerializable("a String", 42, false);
    runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME).create());

    HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult();
    assertNotNull(historicVariable.getValue());
    assertNull(historicVariable.getErrorMessage());

    assertEquals(ValueType.OBJECT.getName(), historicVariable.getTypeName());
    assertEquals(ValueType.OBJECT.getName(), historicVariable.getVariableTypeName());

    JsonSerializable historyValue = (JsonSerializable) historicVariable.getValue();
    assertEquals(bean.getStringProperty(), historyValue.getStringProperty());
    assertEquals(bean.getIntProperty(), historyValue.getIntProperty());
    assertEquals(bean.getBooleanProperty(), historyValue.getBooleanProperty());
  }
}
 
Example 6
protected void initJpa() {
  if (jpaPersistenceUnitName != null) {
    jpaEntityManagerFactory = JpaHelper.createEntityManagerFactory(jpaPersistenceUnitName);
  }
  if (jpaEntityManagerFactory != null) {
    sessionFactories.put(EntityManagerSession.class, new EntityManagerSessionFactory(jpaEntityManagerFactory, jpaHandleTransaction, jpaCloseEntityManager));
    JPAVariableSerializer jpaType = (JPAVariableSerializer) variableSerializers.getSerializerByName(JPAVariableSerializer.NAME);
    // Add JPA-type
    if (jpaType == null) {
      // We try adding the variable right after byte serializer, if available
      int serializableIndex = variableSerializers.getSerializerIndexByName(ValueType.BYTES.getName());
      if (serializableIndex > -1) {
        variableSerializers.addSerializer(new JPAVariableSerializer(), serializableIndex);
      } else {
        variableSerializers.addSerializer(new JPAVariableSerializer());
      }
    }
  }
}
 
Example 7
protected TypedValueSerializer determineSerializer(VariableSerializers serializers, TypedValue value) {
  TypedValueSerializer serializer = serializers.findSerializerForValue(value);

  if(serializer.getType() == ValueType.BYTES){
    throw new ProcessEngineException("Variables of type ByteArray cannot be used to query");
  }
  else if(serializer.getType() == ValueType.FILE){
    throw new ProcessEngineException("Variables of type File cannot be used to query");
  }
  else if(serializer instanceof JPAVariableSerializer) {
    if(wrappedQueryValue.getOperator() != QueryOperator.EQUALS) {
      throw new ProcessEngineException("JPA entity variables can only be used in 'variableValueEquals'");
    }

  }
  else {
    if(!serializer.getType().isPrimitiveValueType()) {
      throw new ProcessEngineException("Object values cannot be used to query");
    }

  }

  return serializer;
}
 
Example 8
Source Project: camunda-bpm-platform   Source File: TaskQueryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn")
public void testQueryResultOrderingByCaseInstanceVariables() {
  // given three tasks with String case instance variables
  CaseInstance instance1 = caseService.createCaseInstanceByKey("oneTaskCase",
      Collections.<String, Object>singletonMap("var", "cValue"));
  CaseInstance instance2 = caseService.createCaseInstanceByKey("oneTaskCase",
      Collections.<String, Object>singletonMap("var", "aValue"));
  CaseInstance instance3 = caseService.createCaseInstanceByKey("oneTaskCase",
      Collections.<String, Object>singletonMap("var", "bValue"));

  // when I make a task query with ascending variable ordering by tasks variables
  List<Task> tasks = taskService.createTaskQuery()
    .caseDefinitionKey("oneTaskCase")
    .orderByCaseInstanceVariable("var", ValueType.STRING)
    .asc()
    .list();

  // then the tasks are ordered correctly by their local variables
  assertEquals(3, tasks.size());
  assertEquals(instance2.getId(), tasks.get(0).getCaseInstanceId());
  assertEquals(instance3.getId(), tasks.get(1).getCaseInstanceId());
  assertEquals(instance1.getId(), tasks.get(2).getCaseInstanceId());
}
 
Example 9
@Override
public LongValue convertFromTypedValue(TypedValue typedValue) {
  if (typedValue.getType() != ValueType.NUMBER) {
    throw unsupportedConversion(typedValue.getType());
  }

  LongValueImpl longvalue = null;
  NumberValue numberValue = (NumberValue) typedValue;

  if (numberValue.getValue() != null) {
    longvalue = (LongValueImpl) Variables.longValue(numberValue.getValue().longValue());
  } else {
    longvalue =  (LongValueImpl) Variables.longValue(null);
  }
  longvalue.setTransient(numberValue.isTransient());
  return longvalue;
}
 
Example 10
Source Project: camunda-bpm-platform   Source File: TaskQueryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml")
public void testQueryResultOrderingByStringVariableWithMixedCase() {
  // given three tasks with String and Integer process instance variables
  ProcessInstance instance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Collections.<String, Object>singletonMap("var", "a"));
  ProcessInstance instance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Collections.<String, Object>singletonMap("var", "B"));
  ProcessInstance instance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Collections.<String, Object>singletonMap("var", "c"));

  // when I make a task query with variable ordering by String values
  List<Task> tasks = taskService.createTaskQuery()
    .processDefinitionKey("oneTaskProcess")
    .orderByProcessVariable("var", ValueType.STRING)
    .asc()
    .list();

  // then the tasks are ordered correctly
  assertEquals(3, tasks.size());
  // first the numeric valued task (since it is treated like null-valued)
  assertEquals(instance1.getId(), tasks.get(0).getProcessInstanceId());
  // then the others in alphabetical order
  assertEquals(instance2.getId(), tasks.get(1).getProcessInstanceId());
  assertEquals(instance3.getId(), tasks.get(2).getProcessInstanceId());
}
 
Example 11
@Test
public void testPutSingleVariableFromSerialized() throws Exception {
  String serializedValue = "{\"prop\" : \"value\"}";
  Map<String, Object> requestJson = VariablesBuilder
      .getObjectValueMap(serializedValue, ValueType.OBJECT.getName(), "aDataFormat", "aRootType");

  String variableKey = "aVariableKey";

  given()
    .pathParam("id", MockProvider.EXAMPLE_TASK_ID).pathParam("varId", variableKey)
    .contentType(ContentType.JSON)
    .body(requestJson)
  .expect()
    .statusCode(Status.NO_CONTENT.getStatusCode())
  .when()
    .put(SINGLE_TASK_PUT_SINGLE_VARIABLE_URL);

  verify(taskServiceMock).setVariable(
      eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey),
      argThat(EqualsObjectValue.objectValueMatcher()
        .serializedValue(serializedValue)
        .serializationFormat("aDataFormat")
        .objectTypeName("aRootType")));
}
 
Example 12
@Test
public void testPutSingleVariableFromSerializedWithNoValue() {
  String variableKey = "aVariableKey";

  Map<String, Object> requestJson = VariablesBuilder
      .getObjectValueMap(null, ValueType.OBJECT.getName(), null, null);

  given().pathParam("id", MockProvider.EXAMPLE_TASK_ID).pathParam("varId", variableKey)
    .contentType(ContentType.JSON).body(requestJson)
    .then().expect().statusCode(Status.NO_CONTENT.getStatusCode())
    .when().put(SINGLE_TASK_PUT_SINGLE_VARIABLE_URL);

  verify(taskServiceMock).setVariable(
      eq(MockProvider.EXAMPLE_TASK_ID), eq(variableKey),
      argThat(EqualsObjectValue.objectValueMatcher()));
}
 
Example 13
@Override
public boolean canConvertFromTypedValue(TypedValue typedValue) {
  if (typedValue.getType() != ValueType.NUMBER) {
    return false;
  }

  if (typedValue.getValue() != null) {
    NumberValue numberValue = (NumberValue) typedValue;
    double doubleValue = numberValue.getValue().doubleValue();

    // returns false if the value changes due to conversion (e.g. by overflows
    // or by loss in precision)
    if (numberValue.getValue().intValue() != doubleValue) {
      return false;
    }
  }

  return true;
}
 
Example 14
@Test
public void testSpinVariableInstanceRetrieval() {
  MockHistoricVariableInstanceBuilder builder = MockProvider.mockHistoricVariableInstance()
      .typedValue(Variables
          .serializedObjectValue("aSpinSerializedValue")
          .serializationDataFormat("aDataFormat")
          .objectTypeName("aRootType")
          .create());

  List<HistoricVariableInstance> mockInstances = new ArrayList<HistoricVariableInstance>();
  mockInstances.add(builder.build());

  mockedQuery = setUpMockHistoricVariableInstanceQuery(mockInstances);

  given()
      .then().expect().statusCode(Status.OK.getStatusCode())
      .and()
        .body("size()", is(1))
        .body("[0].type", equalTo(VariableTypeHelper.toExpectedValueTypeName(ValueType.OBJECT)))
        .body("[0].value", equalTo("aSpinSerializedValue"))
        .body("[0].valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME,
            equalTo("aRootType"))
        .body("[0].valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT,
            equalTo("aDataFormat"))
      .when().get(HISTORIC_VARIABLE_INSTANCE_RESOURCE_URL);
}
 
Example 15
@Override
public ShortValue convertFromTypedValue(TypedValue typedValue) {
  if (typedValue.getType() != ValueType.NUMBER) {
    throw unsupportedConversion(typedValue.getType());
  }

  ShortValueImpl shortValue = null;
  NumberValue numberValue = (NumberValue) typedValue;
  if (numberValue.getValue() != null) {
    shortValue = (ShortValueImpl) Variables.shortValue(numberValue.getValue().shortValue());
  } else {
    shortValue =  (ShortValueImpl) Variables.shortValue(null);
  }
  shortValue.setTransient(numberValue.isTransient());
  return shortValue;
}
 
Example 16
@SuppressWarnings("unchecked")
public ValueMapper<T> findMapperForTypedValue(T typedValue) {
  ValueType type = typedValue.getType();

  if (type != null && type.isAbstract()) {
    throw LOG.valueMapperExceptionWhileSerializingAbstractValue(type.getName());
  }

  List<ValueMapper<T>> matchedSerializers = new ArrayList<>();

  for (ValueMapper<?> serializer : serializerList) {
    if(serializer.canHandleTypedValue(typedValue)) {
      matchedSerializers.add((ValueMapper<T>) serializer);
      if(serializer.getType().isPrimitiveValueType()) {
        break;
      }
    }
  }

  if(matchedSerializers.size() == 1) {
    return matchedSerializers.get(0);
  }
  else if (matchedSerializers.size() > 1) {
    // ambiguous match, use default serializer
    return matchedSerializers.stream()
      .filter(serializer -> defaultSerializationFormat.equals(serializer.getSerializationDataformat()))
      .findFirst()
      .orElse(matchedSerializers.get(0));
  }
  else {
    throw LOG.valueMapperExceptionDueToSerializerNotFoundForTypedValue(typedValue);
  }
}
 
Example 17
Source Project: camunda-bpm-platform   Source File: TaskQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml")
public void testQueryOrderByTaskVariableInteger() {
  ProcessInstance instance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  ProcessInstance instance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  ProcessInstance instance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess");

  Task task500 = taskService.createTaskQuery().processInstanceId(instance1.getId()).singleResult();
  taskService.setVariableLocal(task500.getId(), "var", 500);

  Task task250 = taskService.createTaskQuery().processInstanceId(instance2.getId()).singleResult();
  taskService.setVariableLocal(task250.getId(), "var", 250);

  Task task1000 = taskService.createTaskQuery().processInstanceId(instance3.getId()).singleResult();
  taskService.setVariableLocal(task1000.getId(), "var", 1000);

  // asc
  List<Task> tasks = taskService.createTaskQuery()
    .processDefinitionKey("oneTaskProcess")
    .orderByTaskVariable("var", ValueType.INTEGER)
    .asc()
    .list();

  assertEquals(3, tasks.size());
  assertEquals(task250.getId(), tasks.get(0).getId());
  assertEquals(task500.getId(), tasks.get(1).getId());
  assertEquals(task1000.getId(), tasks.get(2).getId());

  // desc
  tasks = taskService.createTaskQuery()
    .processDefinitionKey("oneTaskProcess")
    .orderByProcessVariable("var", ValueType.INTEGER)
    .desc()
    .list();

  assertEquals(3, tasks.size());
  assertEquals(task1000.getId(), tasks.get(0).getId());
  assertEquals(task500.getId(), tasks.get(1).getId());
  assertEquals(task250.getId(), tasks.get(2).getId());
}
 
Example 18
@Test
public void testJavaObjectVariableSerialization() {
  Response response = given().pathParam("id", MockProvider.ANOTHER_EXAMPLE_PROCESS_INSTANCE_ID)
    .then().expect().statusCode(Status.OK.getStatusCode())
    .body(EXAMPLE_VARIABLE_KEY, notNullValue())
    .body(EXAMPLE_VARIABLE_KEY + ".value.property1", equalTo("aPropertyValue"))
    .body(EXAMPLE_VARIABLE_KEY + ".value.property2", equalTo(true))
    .body(EXAMPLE_VARIABLE_KEY + ".type", equalTo(VariableTypeHelper.toExpectedValueTypeName(ValueType.OBJECT)))
    .body(EXAMPLE_VARIABLE_KEY + ".valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME, equalTo(ExampleVariableObject.class.getName()))
    .body(EXAMPLE_VARIABLE_KEY + ".valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT, equalTo("application/json"))
    .when().get(PROCESS_INSTANCE_VARIABLES_URL);

  Assert.assertEquals("Should return exactly one variable", 1, response.jsonPath().getMap("").size());
}
 
Example 19
Source Project: camunda-bpm-platform   Source File: TaskQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml")
public void testQueryResultOrderingByVariablesWithSecondaryOrderingByProcessInstanceId() {
  // given three tasks with String process instance variables
  ProcessInstance bInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Variables.createVariables().putValue("var", "b"));
  ProcessInstance bInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Variables.createVariables().putValue("var", "b"));
  ProcessInstance cInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Variables.createVariables().putValue("var", "c"));
  ProcessInstance cInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Variables.createVariables().putValue("var", "c"));
  ProcessInstance aInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Variables.createVariables().putValue("var", "a"));
  ProcessInstance aInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Variables.createVariables().putValue("var", "a"));

  // when I make a task query with variable ordering by String values
  List<Task> tasks = taskService.createTaskQuery()
      .processDefinitionKey("oneTaskProcess")
      .orderByProcessVariable("var", ValueType.STRING)
      .asc()
      .orderByProcessInstanceId()
      .asc()
      .list();

  // then the tasks are ordered correctly
  assertEquals(6, tasks.size());

  // var = a
  verifyTasksSortedByProcessInstanceId(Arrays.asList(aInstance1, aInstance2),
      tasks.subList(0, 2));

  // var = b
  verifyTasksSortedByProcessInstanceId(Arrays.asList(bInstance1, bInstance2),
      tasks.subList(2, 4));

  // var = c
  verifyTasksSortedByProcessInstanceId(Arrays.asList(cInstance1, cInstance2),
      tasks.subList(4, 6));
}
 
Example 20
Source Project: camunda-bpm-platform   Source File: TaskQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml")
public void testQueryResultOrderingByTaskVariables() {
  // given three tasks with String process instance variables
  ProcessInstance instance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
    Collections.<String, Object>singletonMap("var", "aValue"));
  ProcessInstance instance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
    Collections.<String, Object>singletonMap("var", "bValue"));
  ProcessInstance instance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
    Collections.<String, Object>singletonMap("var", "cValue"));

  // and some local variables on the tasks
  Task task1 = taskService.createTaskQuery().processInstanceId(instance1.getId()).singleResult();
  taskService.setVariableLocal(task1.getId(), "var", "cValue");

  Task task2 = taskService.createTaskQuery().processInstanceId(instance2.getId()).singleResult();
  taskService.setVariableLocal(task2.getId(), "var", "bValue");

  Task task3 = taskService.createTaskQuery().processInstanceId(instance3.getId()).singleResult();
  taskService.setVariableLocal(task3.getId(), "var", "aValue");

  // when I make a task query with ascending variable ordering by tasks variables
  List<Task> tasks = taskService.createTaskQuery()
    .processDefinitionKey("oneTaskProcess")
    .orderByTaskVariable("var", ValueType.STRING)
    .asc()
    .list();

  // then the tasks are ordered correctly by their local variables
  assertEquals(3, tasks.size());
  assertEquals(instance3.getId(), tasks.get(0).getProcessInstanceId());
  assertEquals(instance2.getId(), tasks.get(1).getProcessInstanceId());
  assertEquals(instance1.getId(), tasks.get(2).getProcessInstanceId());
}
 
Example 21
@Test
public void withTypedValue() {
  fake.withValue(new AbstractTypedValue<>("foo", ValueType.STRING));

  assertThat(fake.getTypedValue().getType()).isEqualTo(ValueType.STRING);
  assertThat(fake.getTypedValue().getValue()).isEqualTo("foo");
}
 
Example 22
Source Project: camunda-bpm-platform   Source File: TaskQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/task/TaskQueryTest.testLocalExecutionVariable.bpmn20.xml")
public void testQueryResultOrderingByExecutionVariables() {
  // given three tasks with String process instance variables
  ProcessInstance instance1 = runtimeService.startProcessInstanceByKey("parallelGateway",
    Collections.<String, Object>singletonMap("var", "aValue"));
  ProcessInstance instance2 = runtimeService.startProcessInstanceByKey("parallelGateway",
    Collections.<String, Object>singletonMap("var", "bValue"));
  ProcessInstance instance3 = runtimeService.startProcessInstanceByKey("parallelGateway",
    Collections.<String, Object>singletonMap("var", "cValue"));

  // and some local variables on the tasks
  Task task1 = taskService.createTaskQuery().processInstanceId(instance1.getId()).singleResult();
  runtimeService.setVariableLocal(task1.getExecutionId(), "var", "cValue");

  Task task2 = taskService.createTaskQuery().processInstanceId(instance2.getId()).singleResult();
  runtimeService.setVariableLocal(task2.getExecutionId(), "var", "bValue");

  Task task3 = taskService.createTaskQuery().processInstanceId(instance3.getId()).singleResult();
  runtimeService.setVariableLocal(task3.getExecutionId(), "var", "aValue");

  // when I make a task query with ascending variable ordering by tasks variables
  List<Task> tasks = taskService.createTaskQuery()
    .processDefinitionKey("parallelGateway")
    .orderByExecutionVariable("var", ValueType.STRING)
    .asc()
    .list();

  // then the tasks are ordered correctly by their local variables
  assertEquals(3, tasks.size());
  assertEquals(instance3.getId(), tasks.get(0).getProcessInstanceId());
  assertEquals(instance2.getId(), tasks.get(1).getProcessInstanceId());
  assertEquals(instance1.getId(), tasks.get(2).getProcessInstanceId());
}
 
Example 23
@Test
public void variable_update() {
  fake.update("foo", stringValue("bar"));

  assertThat(fake.getName()).isEqualTo("foo");
  assertThat(fake.getTypedValue().getValue()).isEqualTo("bar");
  assertThat(fake.getTypeName()).isEqualTo("string");
  assertThat(fake.getTypedValue().getType()).isEqualTo(ValueType.STRING);
  assertThat(fake.getEventName()).isEqualTo(CaseVariableListener.UPDATE);
}
 
Example 24
@Test
public void variable_delete() {
  fake.delete("foo", stringValue("bar"));

  assertThat(fake.getName()).isEqualTo("foo");
  assertThat(fake.getTypedValue().getValue()).isEqualTo("bar");
  assertThat(fake.getTypeName()).isEqualTo("string");
  assertThat(fake.getTypedValue().getType()).isEqualTo(ValueType.STRING);
  assertThat(fake.getEventName()).isEqualTo(CaseVariableListener.DELETE);
}
 
Example 25
Source Project: camunda-bpm-platform   Source File: TaskQueryImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TaskQuery orderByCaseInstanceVariable(String variableName, ValueType valueType) {
  if (isOrQueryActive) {
    throw new ProcessEngineException("Invalid query usage: cannot set orderByCaseInstanceVariable() within 'or' query");
  }

  ensureNotNull("variableName", variableName);
  ensureNotNull("valueType", valueType);

  orderBy(VariableOrderProperty.forCaseInstanceVariable(variableName, valueType));
  return this;
}
 
Example 26
@Test
public void testHandleBpmnErrorWithVariables() {
  Map<String, Object> parameters = new HashMap<String, Object>();
  parameters.put("errorCode", "anErrorCode");
  Map<String, Object> variables = VariablesBuilder
      .create()
      .variable("var1", "val1")
      .variable("var2", "val2", "String")
      .variable("var3", ValueType.OBJECT.getName(), "val3", "aFormat", "aRootType")
      .getVariables();
  parameters.put("variables", variables);

  given()
    .contentType(POST_JSON_CONTENT_TYPE)
    .body(parameters)
    .pathParam("id", "aTaskId")
  .then()
    .expect()
    .statusCode(Status.NO_CONTENT.getStatusCode())
  .when()
    .post(HANDLE_BPMN_ERROR_URL);

  verify(taskServiceMock).handleBpmnError(
      eq("aTaskId"),
      eq("anErrorCode"),
      isNull(String.class),
      argThat(EqualsVariableMap.matches()
        .matcher("var1", EqualsUntypedValue.matcher().value("val1"))
        .matcher("var2", EqualsPrimitiveValue.stringValue("val2"))
        .matcher("var3",
          EqualsObjectValue.objectValueMatcher()
            .type(ValueType.OBJECT)
            .serializedValue("val3")
            .serializationFormat("aFormat")
            .objectTypeName("aRootType"))));
  verifyNoMoreInteractions(taskServiceMock);
}
 
Example 27
Source Project: camunda-bpm-platform   Source File: TaskQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml")
public void testQueryResultOrderingByVariablesWithNullValues() {
  // given three tasks with String process instance variables
  ProcessInstance instance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Collections.<String, Object>singletonMap("var", "bValue"));
  ProcessInstance instance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Collections.<String, Object>singletonMap("var", "cValue"));
  ProcessInstance instance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Collections.<String, Object>singletonMap("var", "aValue"));
  ProcessInstance instance4 = runtimeService.startProcessInstanceByKey("oneTaskProcess");

  // when I make a task query with variable ordering by String values
  List<Task> tasks = taskService.createTaskQuery()
      .processDefinitionKey("oneTaskProcess")
      .orderByProcessVariable("var", ValueType.STRING)
      .asc()
      .list();

  Task firstTask = tasks.get(0);

  // the null-valued task should be either first or last
  if (firstTask.getProcessInstanceId().equals(instance4.getId())) {
    // then the others in ascending order
    assertEquals(instance3.getId(), tasks.get(1).getProcessInstanceId());
    assertEquals(instance1.getId(), tasks.get(2).getProcessInstanceId());
    assertEquals(instance2.getId(), tasks.get(3).getProcessInstanceId());
  } else {
    assertEquals(instance3.getId(), tasks.get(0).getProcessInstanceId());
    assertEquals(instance1.getId(), tasks.get(1).getProcessInstanceId());
    assertEquals(instance2.getId(), tasks.get(2).getProcessInstanceId());
    assertEquals(instance4.getId(), tasks.get(3).getProcessInstanceId());
  }
}
 
Example 28
public void execute(DelegateExecution execution) throws Exception {

    // validate integer variable
    Integer expectedIntValue = 1234;
    assertEquals(expectedIntValue, execution.getVariable("anIntegerVariable"));
    assertEquals(expectedIntValue, execution.getVariableTyped("anIntegerVariable").getValue());
    assertEquals(ValueType.INTEGER, execution.getVariableTyped("anIntegerVariable").getType());
    assertNull(execution.getVariableLocal("anIntegerVariable"));
    assertNull(execution.getVariableLocalTyped("anIntegerVariable"));

    // set an additional local variable
    execution.setVariableLocal("aStringVariable", "aStringValue");

    String expectedStringValue = "aStringValue";
    assertEquals(expectedStringValue, execution.getVariable("aStringVariable"));
    assertEquals(expectedStringValue, execution.getVariableTyped("aStringVariable").getValue());
    assertEquals(ValueType.STRING, execution.getVariableTyped("aStringVariable").getType());
    assertEquals(expectedStringValue, execution.getVariableLocal("aStringVariable"));
    assertEquals(expectedStringValue, execution.getVariableLocalTyped("aStringVariable").getValue());
    assertEquals(ValueType.STRING, execution.getVariableLocalTyped("aStringVariable").getType());

    SimpleSerializableBean objectValue = (SimpleSerializableBean) execution.getVariable("anObjectValue");
    assertNotNull(objectValue);
    assertEquals(10, objectValue.getIntProperty());
    ObjectValue variableTyped = execution.getVariableTyped("anObjectValue");
    assertEquals(10, variableTyped.getValue(SimpleSerializableBean.class).getIntProperty());
    assertEquals(Variables.SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());

    objectValue = (SimpleSerializableBean) execution.getVariable("anUntypedObjectValue");
    assertNotNull(objectValue);
    assertEquals(30, objectValue.getIntProperty());
    variableTyped = execution.getVariableTyped("anUntypedObjectValue");
    assertEquals(30, variableTyped.getValue(SimpleSerializableBean.class).getIntProperty());
    assertEquals(Context.getProcessEngineConfiguration().getDefaultSerializationFormat(), variableTyped.getSerializationDataFormat());

  }
 
Example 29
Source Project: camunda-bpm-platform   Source File: SpinValueImpl.java    License: Apache License 2.0 5 votes vote down vote up
public SpinValueImpl(
    Spin<?> value,
    String serializedValue,
    String dataFormatName,
    boolean isDeserialized,
    ValueType type,
    boolean isTransient) {

  super(value, type);

  this.serializedValue = serializedValue;
  this.dataFormatName = dataFormatName;
  this.isDeserialized = isDeserialized;
  this.isTransient = isTransient;
}
 
Example 30
Source Project: camunda-bpm-platform   Source File: TaskQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml")
public void testQueryResultOrderingByVariablesWithMixedTypes() {
  // given three tasks with String and Integer process instance variables
  ProcessInstance instance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Collections.<String, Object>singletonMap("var", 42));
  ProcessInstance instance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Collections.<String, Object>singletonMap("var", "cValue"));
  ProcessInstance instance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess",
      Collections.<String, Object>singletonMap("var", "aValue"));

  // when I make a task query with variable ordering by String values
  List<Task> tasks = taskService.createTaskQuery()
    .processDefinitionKey("oneTaskProcess")
    .orderByProcessVariable("var", ValueType.STRING)
    .asc()
    .list();

  Task firstTask = tasks.get(0);

  // the numeric-valued task should be either first or last
  if (firstTask.getProcessInstanceId().equals(instance1.getId())) {
    // then the others in ascending order
    assertEquals(instance3.getId(), tasks.get(1).getProcessInstanceId());
    assertEquals(instance2.getId(), tasks.get(2).getProcessInstanceId());
  } else {
    assertEquals(instance3.getId(), tasks.get(0).getProcessInstanceId());
    assertEquals(instance2.getId(), tasks.get(1).getProcessInstanceId());
    assertEquals(instance1.getId(), tasks.get(2).getProcessInstanceId());
  }
}