AnsweredAssumed Answered

Bug in HistoricDetail with version 5.17.0??

Question asked by aitor on May 29, 2015
Latest reply on Jun 3, 2015 by aitor
Hello,

I'm migrating my application from Activiti 5.14 to 5.17.0.2
I found a difference in the treatment of HistoricDetail (VariableUpdate type). The difference is when I store variables with "processEngine.getTaskService(). SetVariable()".
I want to know if it's a bug.

If I store variables with:

processEngine.getTaskService().setVariable(taskId, "var_save", "this is a save var");


With activiti 5.17.0.2. In the database. ACT_HI_DETAIL table: the "ACT_INST_ID_" field is null.
With activiti 5.14 the field has the correct value (the ID of the activity).

I run the following test:

process:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="simple_process" name="Simple Process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="User Task"></userTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_simple_process">
    <bpmndi:BPMNPlane bpmnElement="simple_process" id="BPMNPlane_simple_process">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="90.0" y="90.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="170.0" y="80.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="320.0" y="90.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="125.0" y="107.0"></omgdi:waypoint>
        <omgdi:waypoint x="170.0" y="107.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="275.0" y="107.0"></omgdi:waypoint>
        <omgdi:waypoint x="320.0" y="107.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>


Test code:


// Deploy and start process



// #####################
TaskService taskService = processEngine.getTaskService();

Task task = taskService.createTaskQuery().singleResult();

// Unassigned task list
List<Task> taskList = taskService.createTaskQuery().taskUnassigned().list();
String taskId = taskList.get(0).getId(); // only one task

// Assignee: 'kermit'
taskService.setAssignee(taskId, "kermit");

// Save var without complete
taskService.setVariable(taskId, "var_save", "this is a save var");

// Complete task with other var
Map<String, Object> variableMapComplete = new HashMap<String, Object>();
variableMapComplete.put("var_complete", "this is a complete var");
taskService.complete(taskList.get(0).getId(), variableMapComplete);

// print historic vars from all activities
HistoryService historyService =  processEngine.getHistoryService();

List<HistoricActivityInstance> processInstanceTaskList = historyService.createHistoricActivityInstanceQuery()
      .processInstanceId(processInstance.getId())
      .orderByHistoricActivityInstanceStartTime().desc()
      .orderByHistoricActivityInstanceEndTime().desc().list();

for (HistoricActivityInstance hcoActivityInstance : processInstanceTaskList) {
   System.out.println("Activity: " + hcoActivityInstance.getActivityName());
   
   List<HistoricDetail> historicVariableUpdateList = historyService.createHistoricDetailQuery()
         .variableUpdates()
         .activityInstanceId(hcoActivityInstance.getId())
         .orderByTime().desc().list();
   
   for (HistoricDetail historicDetail : historicVariableUpdateList) {
      HistoricVariableUpdate hcoVar = (HistoricVariableUpdate) historicDetail;
      System.out.println("\tVariable –> " + hcoVar.getVariableName() + ": " + hcoVar.getValue());
   }
}


Results with Activiti 5.14:


Activity: End
Activity: User Task
   Variable –> var_complete: this is a complete var
   Variable –> var_save: this is a save var
Activity: Start


Results with Activiti 5.17.0.2:


Activity: End
Activity: User Task
   Variable –> var_complete: this is a complete var
Activity: Start


With "Activiti 5.17.0.2" variable stored using "taskService.setVariable" is not linked to the task "User Task". However the variable stored with "taskService.complete" if it is linked to the "User Task" task.

Is this a bug?

Thanks.

Outcomes