Search in sources :

Example 16 with HistoricDetail

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

the class FullHistoryTest method testVariableUpdates.

@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());
    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()));
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(1);
    assertEquals("character", historicVariable.getVariableName());
    assertEquals("a", historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(2);
    assertEquals("number", historicVariable.getVariableName());
    assertEquals("two", historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    assertNotSame(historicVariable.getCreateTime(), historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(3);
    assertEquals("zVar1", historicVariable.getVariableName());
    assertEquals("Event: start", historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(4);
    assertEquals("zVar2", historicVariable.getVariableName());
    assertEquals("Event: take", historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(5);
    assertEquals("zVar3", historicVariable.getVariableName());
    assertEquals("Event: start", historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(6);
    assertEquals("zVar4", historicVariable.getVariableName());
    assertEquals("Event: end", historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(7);
    assertEquals("zzz", historicVariable.getVariableName());
    assertEquals(123456789L, historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLike("number", "tw%").singleResult();
    assertNotNull(historicVariable);
    assertEquals("number", historicVariable.getVariableName());
    assertEquals("two", historicVariable.getValue());
    historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLikeIgnoreCase("number", "TW%").singleResult();
    assertNotNull(historicVariable);
    assertEquals("number", historicVariable.getVariableName());
    assertEquals("two", historicVariable.getValue());
    historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLikeIgnoreCase("number", "TW2%").singleResult();
    assertNull(historicVariable);
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) HashMap(java.util.HashMap) HistoricVariableInstanceQuery(org.activiti.engine.history.HistoricVariableInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 17 with HistoricDetail

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

the class TaskServiceTest method testGetVariableByHistoricActivityInstance.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testGetVariableByHistoricActivityInstance() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    assertNotNull(processInstance);
    Task task = taskService.createTaskQuery().singleResult();
    taskService.setVariable(task.getId(), "variable1", "value1");
    taskService.setVariable(task.getId(), "variable1", "value2");
    HistoricActivityInstance historicActivitiInstance = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("theTask").singleResult();
    assertNotNull(historicActivitiInstance);
    List<HistoricDetail> resultSet = historyService.createHistoricDetailQuery().variableUpdates().activityInstanceId(historicActivitiInstance.getId()).orderByTime().asc().list();
    assertEquals(2, resultSet.size());
    assertEquals("variable1", ((HistoricVariableUpdate) resultSet.get(0)).getVariableName());
    assertEquals("value1", ((HistoricVariableUpdate) resultSet.get(0)).getValue());
    assertEquals("variable1", ((HistoricVariableUpdate) resultSet.get(1)).getVariableName());
    assertEquals("value2", ((HistoricVariableUpdate) resultSet.get(1)).getValue());
}
Also used : HistoricDetail(org.activiti.engine.history.HistoricDetail) Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 18 with HistoricDetail

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

the class TaskServiceTest method checkHistoricVariableUpdateEntity.

private void checkHistoricVariableUpdateEntity(String variableName, String processInstanceId) {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        boolean deletedVariableUpdateFound = false;
        List<HistoricDetail> resultSet = historyService.createHistoricDetailQuery().processInstanceId(processInstanceId).list();
        for (HistoricDetail currentHistoricDetail : resultSet) {
            assertTrue(currentHistoricDetail instanceof HistoricDetailVariableInstanceUpdateEntity);
            HistoricDetailVariableInstanceUpdateEntity historicVariableUpdate = (HistoricDetailVariableInstanceUpdateEntity) currentHistoricDetail;
            if (historicVariableUpdate.getName().equals(variableName)) {
                if (historicVariableUpdate.getValue() == null) {
                    if (deletedVariableUpdateFound) {
                        fail("Mismatch: A HistoricVariableUpdateEntity with a null value already found");
                    } else {
                        deletedVariableUpdateFound = true;
                    }
                }
            }
        }
        assertTrue(deletedVariableUpdateFound);
    }
}
Also used : HistoricDetail(org.activiti.engine.history.HistoricDetail) HistoricDetailVariableInstanceUpdateEntity(org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity)

Example 19 with HistoricDetail

use of org.activiti.engine.history.HistoricDetail in project carbon-business-process by wso2.

the class HistoricDetailService method getVariableFromRequest.

public RestVariable getVariableFromRequest(boolean includeBinary, String detailId) {
    Object value = null;
    HistoricVariableUpdate variableUpdate = null;
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    HistoricDetail detailObject = historyService.createHistoricDetailQuery().id(detailId).singleResult();
    if (detailObject instanceof HistoricVariableUpdate) {
        variableUpdate = (HistoricVariableUpdate) detailObject;
        value = variableUpdate.getValue();
    }
    if (value == null) {
        throw new ActivitiObjectNotFoundException("Historic detail '" + detailId + "' doesn't have a variable value.", VariableInstanceEntity.class);
    } else {
        return new RestResponseFactory().createRestVariable(variableUpdate.getVariableName(), value, null, detailId, RestResponseFactory.VARIABLE_HISTORY_DETAIL, includeBinary, uriInfo.getBaseUri().toString());
    }
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoryService(org.activiti.engine.HistoryService) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

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