Search in sources :

Example 26 with HistoricDetail

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

the class FullHistoryTest method testHistoricDetailQueryById.

@Test
public void testHistoricDetailQueryById() {
    Task newTask = taskService.newTask();
    taskService.saveTask(newTask);
    String variableName = "someName";
    String variableValue = "someValue";
    taskService.setVariable(newTask.getId(), variableName, variableValue);
    HistoricDetail result = historyService.createHistoricDetailQuery().singleResult();
    HistoricDetail resultById = historyService.createHistoricDetailQuery().detailId(result.getId()).singleResult();
    assertNotNull(resultById);
    assertEquals(result.getId(), resultById.getId());
    assertEquals(variableName, ((HistoricVariableUpdate) resultById).getVariableName());
    assertEquals(variableValue, ((HistoricVariableUpdate) resultById).getValue());
    assertEquals(ValueType.STRING.getName(), ((HistoricVariableUpdate) resultById).getVariableTypeName());
    assertEquals(ValueType.STRING.getName(), ((HistoricVariableUpdate) resultById).getTypeName());
    taskService.deleteTask(newTask.getId(), true);
}
Also used : HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) Task(org.camunda.bpm.engine.task.Task) Test(org.junit.Test)

Example 27 with HistoricDetail

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

the class FullHistoryTest method testVariableUpdates.

@Test
@Deployment
public void testVariableUpdates() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("number", "one");
    variables.put("character", "a");
    variables.put("bytes", ":-(".getBytes());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveTask", variables);
    runtimeService.setVariable(processInstance.getId(), "number", "two");
    runtimeService.setVariable(processInstance.getId(), "bytes", ":-)".getBytes());
    // Start-task should be added to history
    HistoricActivityInstance historicStartEvent = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("theStart").singleResult();
    assertNotNull(historicStartEvent);
    HistoricActivityInstance waitStateActivity = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("waitState").singleResult();
    assertNotNull(waitStateActivity);
    HistoricActivityInstance serviceTaskActivity = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("serviceTask").singleResult();
    assertNotNull(serviceTaskActivity);
    List<HistoricDetail> historicDetails = historyService.createHistoricDetailQuery().orderByVariableName().asc().orderByVariableRevision().asc().list();
    assertEquals(10, historicDetails.size());
    HistoricVariableUpdate historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(0);
    assertEquals("bytes", historicVariableUpdate.getVariableName());
    assertEquals(":-(", new String((byte[]) historicVariableUpdate.getValue()));
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
    // Variable is updated when process was in waitstate
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(1);
    assertEquals("bytes", historicVariableUpdate.getVariableName());
    assertEquals(":-)", new String((byte[]) historicVariableUpdate.getValue()));
    assertEquals(1, historicVariableUpdate.getRevision());
    assertEquals(waitStateActivity.getId(), historicVariableUpdate.getActivityInstanceId());
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(2);
    assertEquals("character", historicVariableUpdate.getVariableName());
    assertEquals("a", historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(3);
    assertEquals("number", historicVariableUpdate.getVariableName());
    assertEquals("one", historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
    // Variable is updated when process was in waitstate
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(4);
    assertEquals("number", historicVariableUpdate.getVariableName());
    assertEquals("two", historicVariableUpdate.getValue());
    assertEquals(1, historicVariableUpdate.getRevision());
    assertEquals(waitStateActivity.getId(), historicVariableUpdate.getActivityInstanceId());
    // Variable set from process-start execution listener
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(5);
    assertEquals("zVar1", historicVariableUpdate.getVariableName());
    assertEquals("Event: start", historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
    // Variable set from transition take execution listener
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(6);
    assertEquals("zVar2", historicVariableUpdate.getVariableName());
    assertEquals("Event: take", historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertNull(historicVariableUpdate.getActivityInstanceId());
    // Variable set from activity start execution listener on the servicetask
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(7);
    assertEquals("zVar3", historicVariableUpdate.getVariableName());
    assertEquals("Event: start", historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(serviceTaskActivity.getId(), historicVariableUpdate.getActivityInstanceId());
    // Variable set from activity end execution listener on the servicetask
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(8);
    assertEquals("zVar4", historicVariableUpdate.getVariableName());
    assertEquals("Event: end", historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(serviceTaskActivity.getId(), historicVariableUpdate.getActivityInstanceId());
    // Variable set from service-task
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(9);
    assertEquals("zzz", historicVariableUpdate.getVariableName());
    assertEquals(123456789L, historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(serviceTaskActivity.getId(), historicVariableUpdate.getActivityInstanceId());
    // trigger receive task
    runtimeService.signal(processInstance.getId());
    testHelper.assertProcessEnded(processInstance.getId());
    // check for historic process variables set
    HistoricVariableInstanceQuery historicProcessVariableQuery = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc();
    assertEquals(8, historicProcessVariableQuery.count());
    List<HistoricVariableInstance> historicVariables = historicProcessVariableQuery.list();
    // Variable status when process is finished
    HistoricVariableInstance historicVariable = historicVariables.get(0);
    assertEquals("bytes", historicVariable.getVariableName());
    assertEquals(":-)", new String((byte[]) historicVariable.getValue()));
    historicVariable = historicVariables.get(1);
    assertEquals("character", historicVariable.getVariableName());
    assertEquals("a", historicVariable.getValue());
    historicVariable = historicVariables.get(2);
    assertEquals("number", historicVariable.getVariableName());
    assertEquals("two", historicVariable.getValue());
    historicVariable = historicVariables.get(3);
    assertEquals("zVar1", historicVariable.getVariableName());
    assertEquals("Event: start", historicVariable.getValue());
    historicVariable = historicVariables.get(4);
    assertEquals("zVar2", historicVariable.getVariableName());
    assertEquals("Event: take", historicVariable.getValue());
    historicVariable = historicVariables.get(5);
    assertEquals("zVar3", historicVariable.getVariableName());
    assertEquals("Event: start", historicVariable.getValue());
    historicVariable = historicVariables.get(6);
    assertEquals("zVar4", historicVariable.getVariableName());
    assertEquals("Event: end", historicVariable.getValue());
    historicVariable = historicVariables.get(7);
    assertEquals("zzz", historicVariable.getVariableName());
    assertEquals(123456789L, historicVariable.getValue());
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) HashMap(java.util.HashMap) HistoricVariableInstanceQuery(org.camunda.bpm.engine.history.HistoricVariableInstanceQuery) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 28 with HistoricDetail

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

the class FullHistoryTest method testHistoricDetailQueryMixed.

@Test
@Deployment
public void testHistoricDetailQueryMixed() throws Exception {
    Map<String, String> formProperties = new HashMap<String, String>();
    formProperties.put("formProp1", "activiti rocks!");
    formProperties.put("formProp2", "12345");
    ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("historicDetailMixed").singleResult();
    ProcessInstance processInstance = formService.submitStartFormData(procDef.getId(), formProperties);
    List<HistoricDetail> details = historyService.createHistoricDetailQuery().processInstanceId(processInstance.getId()).orderByVariableName().asc().list();
    assertEquals(4, details.size());
    assertTrue(details.get(0) instanceof HistoricFormProperty);
    HistoricFormProperty formProp1 = (HistoricFormProperty) details.get(0);
    assertEquals("formProp1", formProp1.getPropertyId());
    assertEquals("activiti rocks!", formProp1.getPropertyValue());
    assertTrue(details.get(1) instanceof HistoricFormProperty);
    HistoricFormProperty formProp2 = (HistoricFormProperty) details.get(1);
    assertEquals("formProp2", formProp2.getPropertyId());
    assertEquals("12345", formProp2.getPropertyValue());
    assertTrue(details.get(2) instanceof HistoricVariableUpdate);
    HistoricVariableUpdate varUpdate1 = (HistoricVariableUpdate) details.get(2);
    assertEquals("variable1", varUpdate1.getVariableName());
    assertEquals("activiti rocks!", varUpdate1.getValue());
    // This variable should be of type LONG since this is defined in the process-definition
    assertTrue(details.get(3) instanceof HistoricVariableUpdate);
    HistoricVariableUpdate varUpdate2 = (HistoricVariableUpdate) details.get(3);
    assertEquals("variable2", varUpdate2.getVariableName());
    assertEquals(12345L, varUpdate2.getValue());
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) HistoricFormProperty(org.camunda.bpm.engine.history.HistoricFormProperty) HashMap(java.util.HashMap) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 29 with HistoricDetail

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

the class UserOperationIdTest method testSetTaskVariablesInServiceTask.

@Test
public void testSetTaskVariablesInServiceTask() {
    // given
    BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess(PROCESS_KEY).startEvent().userTask().serviceTask().camundaExpression("${execution.setVariable('foo', 'bar')}").endEvent().done();
    testRule.deploy(bpmnModelInstance);
    identityService.setAuthenticatedUserId("demo");
    runtimeService.startProcessInstanceByKey(PROCESS_KEY);
    Task task = taskService.createTaskQuery().singleResult();
    // when
    taskService.complete(task.getId());
    // then
    HistoricDetail historicDetail = historyService.createHistoricDetailQuery().singleResult();
    // no user operation log id is set for this update, as it is not written as part of the user operation
    assertNull(historicDetail.getUserOperationId());
}
Also used : HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) Task(org.camunda.bpm.engine.task.Task) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 30 with HistoricDetail

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

the class HistoricDetailManager method deleteHistoricDetailsByTaskId.

public void deleteHistoricDetailsByTaskId(String taskId) {
    if (isHistoryEnabled()) {
        // delete entries in DB
        List<HistoricDetail> historicDetails = findHistoricDetailsByTaskId(taskId);
        for (HistoricDetail historicDetail : historicDetails) {
            ((HistoricDetailEventEntity) historicDetail).delete();
        }
        // delete entries in Cache
        List<HistoricDetailEventEntity> cachedHistoricDetails = getDbEntityManager().getCachedEntitiesByType(HistoricDetailEventEntity.class);
        for (HistoricDetailEventEntity historicDetail : cachedHistoricDetails) {
            // make sure we only delete the right ones (as we cannot make a proper query in the cache)
            if (taskId.equals(historicDetail.getTaskId())) {
                historicDetail.delete();
            }
        }
    }
}
Also used : HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) HistoricDetailEventEntity(org.camunda.bpm.engine.impl.history.event.HistoricDetailEventEntity)

Aggregations

HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)40 Deployment (org.camunda.bpm.engine.test.Deployment)23 Test (org.junit.Test)20 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)14 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)14 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)14 Task (org.camunda.bpm.engine.task.Task)13 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)12 HistoricVariableUpdate (org.camunda.bpm.engine.history.HistoricVariableUpdate)10 HashMap (java.util.HashMap)7 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)7 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)6 ArrayList (java.util.ArrayList)3 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)3 HistoricDetailVariableInstanceUpdateEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 HistoricDetailQuery (org.camunda.bpm.engine.history.HistoricDetailQuery)2 HistoricFormProperty (org.camunda.bpm.engine.history.HistoricFormProperty)2 HistoricVariableInstanceQuery (org.camunda.bpm.engine.history.HistoricVariableInstanceQuery)2