Java Code Examples for org.camunda.bpm.engine.variable.VariableMap#putValueTyped()

The following examples show how to use org.camunda.bpm.engine.variable.VariableMap#putValueTyped() . 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: RestartProcessInstancesCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected VariableMap collectLastVariables(CommandContext commandContext,
                                           HistoricProcessInstance processInstance) {
  HistoryService historyService = commandContext.getProcessEngineConfiguration()
      .getHistoryService();

  List<HistoricVariableInstance> historicVariables =
      historyService.createHistoricVariableInstanceQuery()
          .executionIdIn(processInstance.getId())
          .list();

  VariableMap variables = new VariableMapImpl();
  for (HistoricVariableInstance variable : historicVariables) {
    variables.putValueTyped(variable.getName(), variable.getTypedValue());
  }

  return variables;
}
 
Example 2
Source File: RestartProcessInstancesCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected VariableMap collectInitialVariables(CommandContext commandContext,
                                              HistoricProcessInstance processInstance) {
  HistoryService historyService = commandContext.getProcessEngineConfiguration()
      .getHistoryService();

  List<HistoricDetail> historicDetails =
      historyService.createHistoricDetailQuery()
      .variableUpdates()
      .executionId(processInstance.getId())
      .initial()
      .list();

  // legacy behavior < 7.13: the initial flag is never set for instances started
  // in these versions. We must perform the old logic of finding initial variables
  if (historicDetails.size() == 0) {
    HistoricActivityInstance startActivityInstance = resolveStartActivityInstance(processInstance);

    if (startActivityInstance != null) {
      HistoricDetailQueryImpl queryWithStartActivities = (HistoricDetailQueryImpl) historyService.createHistoricDetailQuery()
              .variableUpdates()
              .activityInstanceId(startActivityInstance.getId())
              .executionId(processInstance.getId());
      historicDetails = queryWithStartActivities
             .sequenceCounter(1)
             .list();
    }
  }

  VariableMap variables = new VariableMapImpl();
  for (HistoricDetail detail : historicDetails) {
    HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) detail;
    variables.putValueTyped(variableUpdate.getVariableName(), variableUpdate.getTypedValue());
  }

  return variables;
}
 
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: 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 5
Source File: DecisionDefinitionResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected Map<String, VariableValueDto> createResultEntriesDto(DmnDecisionResultEntries entries) {
  VariableMap variableMap = Variables.createVariables();

  for(String key : entries.keySet()) {
    TypedValue typedValue = entries.getEntryTyped(key);
    variableMap.putValueTyped(key, typedValue);
  }

  return VariableValueDto.fromMap(variableMap);
}
 
Example 6
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static VariableMap createMockSerializedVariables() {
  VariableMap variables = Variables.createVariables();
  ObjectValue serializedVar = Variables.serializedObjectValue(EXAMPLE_VARIABLE_INSTANCE_SERIALIZED_VALUE)
          .serializationDataFormat(FORMAT_APPLICATION_JSON)
          .objectTypeName(ArrayList.class.getName())
          .create();

  ObjectValue deserializedVar = new ObjectValueImpl(EXAMPLE_VARIABLE_INSTANCE_DESERIALIZED_VALUE,
                                                    EXAMPLE_VARIABLE_INSTANCE_SERIALIZED_VALUE,
                                                    FORMAT_APPLICATION_JSON, Object.class.getName(), true);
  variables.putValueTyped(EXAMPLE_VARIABLE_INSTANCE_NAME, serializedVar);
  variables.putValueTyped(EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME, deserializedVar);
  return variables;
}
 
Example 7
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public static VariableMap createMockFormVariables() {
  VariableMap mock = Variables.createVariables();
  mock.putValueTyped(EXAMPLE_VARIABLE_INSTANCE_NAME, EXAMPLE_PRIMITIVE_VARIABLE_VALUE);
  return mock;
}