Search in sources :

Example 1 with HistoricDetail

use of org.activiti.engine.history.HistoricDetail in project Activiti by Activiti.

the class HistoricDetailEntityManager method deleteHistoricDetailsByTaskId.

public void deleteHistoricDetailsByTaskId(String taskId) {
    if (getHistoryManager().isHistoryLevelAtLeast(HistoryLevel.FULL)) {
        HistoricDetailQueryImpl detailsQuery = (HistoricDetailQueryImpl) new HistoricDetailQueryImpl().taskId(taskId);
        List<HistoricDetail> details = detailsQuery.list();
        for (HistoricDetail detail : details) {
            ((HistoricDetailEntity) detail).delete();
        }
    }
}
Also used : HistoricDetail(org.activiti.engine.history.HistoricDetail) HistoricDetailQueryImpl(org.activiti.engine.impl.HistoricDetailQueryImpl)

Example 2 with HistoricDetail

use of org.activiti.engine.history.HistoricDetail in project Activiti by Activiti.

the class HistoricVariableInstanceTest method testVariableUpdatesLinkedToActivity.

@Deployment(resources = { "org/activiti/standalone/history/FullHistoryTest.testVariableUpdatesAreLinkedToActivity.bpmn20.xml" })
public void testVariableUpdatesLinkedToActivity() throws Exception {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("ProcessWithSubProcess");
        Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("test", "1");
        taskService.complete(task.getId(), variables);
        // now we are in the subprocess
        task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
        variables.clear();
        variables.put("test", "2");
        taskService.complete(task.getId(), variables);
        // now we are ended
        assertProcessEnded(pi.getId());
        // check history
        List<HistoricDetail> updates = historyService.createHistoricDetailQuery().variableUpdates().list();
        assertEquals(2, updates.size());
        Map<String, HistoricVariableUpdate> updatesMap = new HashMap<String, HistoricVariableUpdate>();
        HistoricVariableUpdate update = (HistoricVariableUpdate) updates.get(0);
        updatesMap.put((String) update.getValue(), update);
        update = (HistoricVariableUpdate) updates.get(1);
        updatesMap.put((String) update.getValue(), update);
        HistoricVariableUpdate update1 = updatesMap.get("1");
        HistoricVariableUpdate update2 = updatesMap.get("2");
        assertNotNull(update1.getActivityInstanceId());
        assertNotNull(update1.getExecutionId());
        HistoricActivityInstance historicActivityInstance1 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update1.getActivityInstanceId()).singleResult();
        assertEquals(historicActivityInstance1.getExecutionId(), update1.getExecutionId());
        assertEquals("usertask1", historicActivityInstance1.getActivityId());
        // TODO https://activiti.atlassian.net/browse/ACT-1083
        assertNotNull(update2.getActivityInstanceId());
        HistoricActivityInstance historicActivityInstance2 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update2.getActivityInstanceId()).singleResult();
        assertEquals("usertask2", historicActivityInstance2.getActivityId());
        /*
	     * This is OK! The variable is set on the root execution, on a execution never run through the activity, where the process instances
	     * stands when calling the set Variable. But the ActivityId of this flow node is used. So the execution id's doesn't have to be equal.
	     * 
	     * execution id: On which execution it was set
	     * activity id: in which activity was the process instance when setting the variable
	     */
        assertFalse(historicActivityInstance2.getExecutionId().equals(update2.getExecutionId()));
    }
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 3 with HistoricDetail

use of org.activiti.engine.history.HistoricDetail in project Activiti by Activiti.

the class FullHistoryTest method testHistoricDetailQueryMixed.

@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.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) HistoricFormProperty(org.activiti.engine.history.HistoricFormProperty) HashMap(java.util.HashMap) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 4 with HistoricDetail

use of org.activiti.engine.history.HistoricDetail in project Activiti by Activiti.

the class FullHistoryTest method testHistoricVariableUpdatesAllTypes.

@Deployment
public void testHistoricVariableUpdatesAllTypes() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss SSS");
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("aVariable", "initial value");
    Date startedDate = sdf.parse("01/01/2001 01:23:45 000");
    // In the javaDelegate, the current time is manipulated
    Date updatedDate = sdf.parse("01/01/2001 01:23:46 000");
    processEngineConfiguration.getClock().setCurrentTime(startedDate);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("HistoricVariableUpdateProcess", variables);
    List<HistoricDetail> details = historyService.createHistoricDetailQuery().variableUpdates().processInstanceId(processInstance.getId()).orderByVariableName().asc().orderByTime().asc().list();
    // 8 variable updates should be present, one performed when starting process
    // the other 7 are set in VariableSetter serviceTask
    assertEquals(9, details.size());
    // Since we order by varName, first entry should be aVariable update from startTask
    HistoricVariableUpdate startVarUpdate = (HistoricVariableUpdate) details.get(0);
    assertEquals("aVariable", startVarUpdate.getVariableName());
    assertEquals("initial value", startVarUpdate.getValue());
    assertEquals(0, startVarUpdate.getRevision());
    assertEquals(processInstance.getId(), startVarUpdate.getProcessInstanceId());
    // Date should the the one set when starting
    assertEquals(startedDate, startVarUpdate.getTime());
    HistoricVariableUpdate updatedStringVariable = (HistoricVariableUpdate) details.get(1);
    assertEquals("aVariable", updatedStringVariable.getVariableName());
    assertEquals("updated value", updatedStringVariable.getValue());
    assertEquals(processInstance.getId(), updatedStringVariable.getProcessInstanceId());
    // Date should be the updated date
    assertEquals(updatedDate, updatedStringVariable.getTime());
    HistoricVariableUpdate intVariable = (HistoricVariableUpdate) details.get(2);
    assertEquals("bVariable", intVariable.getVariableName());
    assertEquals(123, intVariable.getValue());
    assertEquals(processInstance.getId(), intVariable.getProcessInstanceId());
    assertEquals(updatedDate, intVariable.getTime());
    HistoricVariableUpdate longVariable = (HistoricVariableUpdate) details.get(3);
    assertEquals("cVariable", longVariable.getVariableName());
    assertEquals(12345L, longVariable.getValue());
    assertEquals(processInstance.getId(), longVariable.getProcessInstanceId());
    assertEquals(updatedDate, longVariable.getTime());
    HistoricVariableUpdate doubleVariable = (HistoricVariableUpdate) details.get(4);
    assertEquals("dVariable", doubleVariable.getVariableName());
    assertEquals(1234.567, doubleVariable.getValue());
    assertEquals(processInstance.getId(), doubleVariable.getProcessInstanceId());
    assertEquals(updatedDate, doubleVariable.getTime());
    HistoricVariableUpdate shortVariable = (HistoricVariableUpdate) details.get(5);
    assertEquals("eVariable", shortVariable.getVariableName());
    assertEquals((short) 12, shortVariable.getValue());
    assertEquals(processInstance.getId(), shortVariable.getProcessInstanceId());
    assertEquals(updatedDate, shortVariable.getTime());
    HistoricVariableUpdate dateVariable = (HistoricVariableUpdate) details.get(6);
    assertEquals("fVariable", dateVariable.getVariableName());
    assertEquals(sdf.parse("01/01/2001 01:23:45 678"), dateVariable.getValue());
    assertEquals(processInstance.getId(), dateVariable.getProcessInstanceId());
    assertEquals(updatedDate, dateVariable.getTime());
    HistoricVariableUpdate serializableVariable = (HistoricVariableUpdate) details.get(7);
    assertEquals("gVariable", serializableVariable.getVariableName());
    assertEquals(new SerializableVariable("hello hello"), serializableVariable.getValue());
    assertEquals(processInstance.getId(), serializableVariable.getProcessInstanceId());
    assertEquals(updatedDate, serializableVariable.getTime());
    HistoricVariableUpdate byteArrayVariable = (HistoricVariableUpdate) details.get(8);
    assertEquals("hVariable", byteArrayVariable.getVariableName());
    assertEquals(";-)", new String((byte[]) byteArrayVariable.getValue()));
    assertEquals(processInstance.getId(), byteArrayVariable.getProcessInstanceId());
    assertEquals(updatedDate, byteArrayVariable.getTime());
    // end process instance
    List<Task> tasks = taskService.createTaskQuery().list();
    assertEquals(1, tasks.size());
    taskService.complete(tasks.get(0).getId());
    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("aVariable", historicVariable.getVariableName());
    assertEquals("updated value", historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(1);
    assertEquals("bVariable", historicVariable.getVariableName());
    assertEquals(123, historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(2);
    assertEquals("cVariable", historicVariable.getVariableName());
    assertEquals(12345L, historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(3);
    assertEquals("dVariable", historicVariable.getVariableName());
    assertEquals(1234.567, historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(4);
    assertEquals("eVariable", historicVariable.getVariableName());
    assertEquals((short) 12, historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(5);
    assertEquals("fVariable", historicVariable.getVariableName());
    assertEquals(sdf.parse("01/01/2001 01:23:45 678"), historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(6);
    assertEquals("gVariable", historicVariable.getVariableName());
    assertEquals(new SerializableVariable("hello hello"), historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(7);
    assertEquals("hVariable", historicVariable.getVariableName());
    assertEquals(";-)", ";-)", new String((byte[]) historicVariable.getValue()));
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) Date(java.util.Date) SerializableVariable(org.activiti.engine.test.history.SerializableVariable) HistoricVariableInstanceQuery(org.activiti.engine.history.HistoricVariableInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) SimpleDateFormat(java.text.SimpleDateFormat) Deployment(org.activiti.engine.test.Deployment)

Example 5 with HistoricDetail

use of org.activiti.engine.history.HistoricDetail in project Activiti by Activiti.

the class FullHistoryTest method testHistoricVariableRemovedWhenRuntimeVariableIsRemoved.

// Test for https://activiti.atlassian.net/browse/ACT-2186
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testHistoricVariableRemovedWhenRuntimeVariableIsRemoved() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("var1", "Hello");
    vars.put("var2", "World");
    vars.put("var3", "!");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    // Verify runtime
    assertEquals(3, runtimeService.getVariables(processInstance.getId()).size());
    assertEquals(3, runtimeService.getVariables(processInstance.getId(), Arrays.asList("var1", "var2", "var3")).size());
    assertNotNull(runtimeService.getVariable(processInstance.getId(), "var2"));
    // Verify history
    assertEquals(3, historyService.createHistoricVariableInstanceQuery().list().size());
    assertNotNull(historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("var2").singleResult());
    // Verify historic details
    List<HistoricDetail> details = historyService.createHistoricDetailQuery().processInstanceId(processInstance.getId()).variableUpdates().orderByTime().asc().list();
    // 3 vars
    assertEquals(3, details.size());
    for (HistoricDetail historicDetail : details) {
        assertNotNull(((HistoricVariableUpdate) historicDetail).getValue());
    }
    // Remove one variable
    runtimeService.removeVariable(processInstance.getId(), "var2");
    // Verify runtime
    assertEquals(2, runtimeService.getVariables(processInstance.getId()).size());
    assertEquals(2, runtimeService.getVariables(processInstance.getId(), Arrays.asList("var1", "var2", "var3")).size());
    assertNull(runtimeService.getVariable(processInstance.getId(), "var2"));
    // Verify history
    assertEquals(2, historyService.createHistoricVariableInstanceQuery().list().size());
    assertNull(historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("var2").singleResult());
    // Verify historic details
    details = historyService.createHistoricDetailQuery().processInstanceId(processInstance.getId()).variableUpdates().orderByTime().asc().list();
    // 3 vars + 1 delete
    assertEquals(4, details.size());
    // The last entry should be the delete
    for (int i = 0; i < details.size(); i++) {
        if (i != 3) {
            assertNotNull(((HistoricVariableUpdate) details.get(i)).getValue());
        } else if (i == 3) {
            assertNull(((HistoricVariableUpdate) details.get(i)).getValue());
        }
    }
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

HistoricDetail (org.activiti.engine.history.HistoricDetail)19 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)11 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)10 Deployment (org.activiti.engine.test.Deployment)10 HashMap (java.util.HashMap)9 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)7 Task (org.activiti.engine.task.Task)7 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)6 HistoricFormProperty (org.activiti.engine.history.HistoricFormProperty)4 HistoricDetailVariableInstanceUpdateEntity (org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity)3 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2 HistoryService (org.activiti.engine.HistoryService)2 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)2 HistoricVariableInstanceQuery (org.activiti.engine.history.HistoricVariableInstanceQuery)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 Item (com.vaadin.data.Item)1 Label (com.vaadin.ui.Label)1