Search in sources :

Example 66 with HistoricVariableInstance

use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.

the class ExternalTaskServiceTest method testCompleteWithLocalVariables.

public void testCompleteWithLocalVariables() {
    // given
    BpmnModelInstance instance = Bpmn.createExecutableProcess("Process").startEvent().serviceTask("externalTask").camundaType("external").camundaTopic("foo").camundaTaskPriority("100").camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ReadLocalVariableListenerImpl.class).userTask("user").endEvent().done();
    deployment(instance);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");
    List<LockedExternalTask> lockedTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic("foo", 1L).execute();
    // when
    externalTaskService.complete(lockedTasks.get(0).getId(), WORKER_ID, null, Variables.createVariables().putValue("abc", "bar"));
    // then
    VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstance.getId()).singleResult();
    assertNull(variableInstance);
    if (processEngineConfiguration.getHistoryLevel() == HistoryLevel.HISTORY_LEVEL_AUDIT || processEngineConfiguration.getHistoryLevel() == HistoryLevel.HISTORY_LEVEL_FULL) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().activityInstanceIdIn(lockedTasks.get(0).getActivityInstanceId()).singleResult();
        assertNotNull(historicVariableInstance);
        assertEquals("abc", historicVariableInstance.getName());
        assertEquals("bar", historicVariableInstance.getValue());
    }
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance)

Example 67 with HistoricVariableInstance

use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.

the class ModifyVariableInSameTransactionTest method testDeleteAndInsertTheSameVariableByteArray.

@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
public void testDeleteAndInsertTheSameVariableByteArray() {
    BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("serviceTaskProcess").startEvent().userTask("userTask").serviceTask("service").camundaClass(DeleteAndInsertVariableDelegate.class).userTask("userTask1").endEvent().done();
    ProcessDefinition processDefinition = testHelper.deployAndGetDefinition(bpmnModel);
    VariableMap variables = Variables.createVariables().putValue("listVar", Arrays.asList(new int[] { 1, 2, 3 }));
    ProcessInstance instance = engineRule.getRuntimeService().startProcessInstanceById(processDefinition.getId(), variables);
    Task task = engineRule.getTaskService().createTaskQuery().singleResult();
    engineRule.getTaskService().complete(task.getId());
    VariableInstance variable = engineRule.getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(instance.getId()).variableName("listVar").singleResult();
    assertNotNull(variable);
    assertEquals("stringValue", variable.getValue());
    HistoricVariableInstance historicVariable = engineRule.getHistoryService().createHistoricVariableInstanceQuery().singleResult();
    assertEquals(variable.getName(), historicVariable.getName());
    assertEquals(HistoricVariableInstance.STATE_CREATED, historicVariable.getState());
}
Also used : Task(org.camunda.bpm.engine.task.Task) VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Example 68 with HistoricVariableInstance

use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.

the class ModifyVariableInSameTransactionTest method testDeleteAndInsertTheSameVariable.

@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
public void testDeleteAndInsertTheSameVariable() {
    BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("serviceTaskProcess").startEvent().userTask("userTask").serviceTask("service").camundaClass(DeleteAndInsertVariableDelegate.class).userTask("userTask1").endEvent().done();
    ProcessDefinition processDefinition = testHelper.deployAndGetDefinition(bpmnModel);
    VariableMap variables = Variables.createVariables().putValue("foo", "firstValue");
    ProcessInstance instance = engineRule.getRuntimeService().startProcessInstanceById(processDefinition.getId(), variables);
    Task task = engineRule.getTaskService().createTaskQuery().singleResult();
    engineRule.getTaskService().complete(task.getId());
    VariableInstance variable = engineRule.getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(instance.getId()).variableName("foo").singleResult();
    assertNotNull(variable);
    assertEquals("secondValue", variable.getValue());
    HistoricVariableInstance historicVariable = engineRule.getHistoryService().createHistoricVariableInstanceQuery().singleResult();
    assertEquals(variable.getName(), historicVariable.getName());
    assertEquals(HistoricVariableInstance.STATE_CREATED, historicVariable.getState());
}
Also used : Task(org.camunda.bpm.engine.task.Task) VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Example 69 with HistoricVariableInstance

use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.

the class PaDataFormatConfiguratorTest method testTaskVariableImplicitObjectValueUpdate.

@Test
public void testTaskVariableImplicitObjectValueUpdate() throws JsonProcessingException, IOException {
    // given a process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("implicitTaskVariableUpdate");
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    // when setting a variable such that the process-application-local dataformat applies
    // 10th of January 1970
    Date date = new Date(JsonSerializable.ONE_DAY_IN_MILLIS * 10);
    JsonSerializable jsonSerializable = new JsonSerializable(date);
    try {
        ProcessApplicationContext.setCurrentProcessApplication(ReferenceStoringProcessApplication.INSTANCE);
        taskService.setVariableLocal(task.getId(), ImplicitObjectValueUpdateHandler.VARIABLE_NAME, Variables.objectValue(jsonSerializable).serializationDataFormat(SerializationDataFormats.JSON).create());
    } finally {
        ProcessApplicationContext.clear();
    }
    // and triggering an implicit update of the object value variable
    taskService.setAssignee(task.getId(), "foo");
    // then the process-application-local format was used for making the update
    ObjectValue objectValue = taskService.getVariableTyped(task.getId(), ImplicitObjectValueUpdateHandler.VARIABLE_NAME, false);
    ImplicitObjectValueUpdateHandler.addADay(jsonSerializable);
    String serializedValue = objectValue.getValueSerialized();
    String expectedSerializedValue = jsonSerializable.toExpectedJsonString(JsonDataFormatConfigurator.DATE_FORMAT);
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode actualJsonTree = objectMapper.readTree(serializedValue);
    JsonNode expectedJsonTree = objectMapper.readTree(expectedSerializedValue);
    // JsonNode#equals makes a deep comparison
    Assert.assertEquals(expectedJsonTree, actualJsonTree);
    // and it is also correct in the history
    HistoricVariableInstance historicObjectValue = historyService.createHistoricVariableInstanceQuery().processInstanceId(pi.getId()).variableName(ImplicitObjectValueUpdateHandler.VARIABLE_NAME).disableCustomObjectDeserialization().singleResult();
    serializedValue = ((ObjectValue) historicObjectValue.getTypedValue()).getValueSerialized();
    actualJsonTree = objectMapper.readTree(serializedValue);
    Assert.assertEquals(expectedJsonTree, actualJsonTree);
}
Also used : Task(org.camunda.bpm.engine.task.Task) ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) JsonSerializable(org.camunda.bpm.integrationtest.functional.spin.dataformat.JsonSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest) Test(org.junit.Test)

Example 70 with HistoricVariableInstance

use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.

the class TaskAuthorizationTest method testStandaloneTaskUpdateVariablesLocalWithReadPermissionOnTask.

@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
public void testStandaloneTaskUpdateVariablesLocalWithReadPermissionOnTask() {
    // given
    String taskId = "myTask";
    createTask(taskId);
    createGrantAuthorization(TASK, taskId, userId, UPDATE);
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery();
    // when (1)
    ((TaskServiceImpl) taskService).updateVariablesLocal(taskId, getVariables(), null);
    // then (1)
    disableAuthorization();
    verifyQueryResults(query, 1);
    enableAuthorization();
    // when (2)
    ((TaskServiceImpl) taskService).updateVariablesLocal(taskId, null, Arrays.asList(VARIABLE_NAME));
    // then (2)
    disableAuthorization();
    verifyQueryResults(query, 0);
    enableAuthorization();
    // when (3)
    ((TaskServiceImpl) taskService).updateVariablesLocal(taskId, getVariables(), Arrays.asList(VARIABLE_NAME));
    // then (3)
    disableAuthorization();
    verifyQueryResults(query, 0);
    enableAuthorization();
    deleteTask(taskId, true);
    List<HistoricVariableInstance> deletedVariables = historyService.createHistoricVariableInstanceQuery().includeDeleted().list();
    Assert.assertEquals("DELETED", deletedVariables.get(0).getState());
    Assert.assertEquals("DELETED", deletedVariables.get(1).getState());
}
Also used : VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) TaskServiceImpl(org.camunda.bpm.engine.impl.TaskServiceImpl) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Aggregations

HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)88 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)44 Test (org.junit.Test)42 Deployment (org.camunda.bpm.engine.test.Deployment)39 HistoricVariableInstanceQuery (org.camunda.bpm.engine.history.HistoricVariableInstanceQuery)18 Task (org.camunda.bpm.engine.task.Task)17 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)14 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)13 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)12 RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)12 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)10 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)10 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)10 HashMap (java.util.HashMap)8 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)8 VariableMap (org.camunda.bpm.engine.variable.VariableMap)8 HistoricVariableUpdate (org.camunda.bpm.engine.history.HistoricVariableUpdate)7 Date (java.util.Date)6 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)6 MockHistoricVariableInstanceBuilder (org.camunda.bpm.engine.rest.helper.MockHistoricVariableInstanceBuilder)6