Search in sources :

Example 1 with HistoricVariableUpdate

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

the class ProcessInstanceLogQueryAndByteArrayTypeVariableTest method testIncludeVariableUpdates.

public void testIncludeVariableUpdates() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
        HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).variableName("var").singleResult();
        assertEquals(historicVariableInstance.getValue(), LARGE_STRING_VALUE);
        ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId).includeVariableUpdates().singleResult();
        List<HistoricData> events = log.getHistoricData();
        assertEquals(1, events.size());
        for (HistoricData event : events) {
            assertTrue(event instanceof HistoricVariableUpdate);
            assertEquals(((HistoricDetailVariableInstanceUpdateEntity) event).getValue(), LARGE_STRING_VALUE);
        }
    }
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricData(org.activiti.engine.history.HistoricData) ProcessInstanceHistoryLog(org.activiti.engine.history.ProcessInstanceHistoryLog) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance)

Example 2 with HistoricVariableUpdate

use of org.activiti.engine.history.HistoricVariableUpdate 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 3 with HistoricVariableUpdate

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

the class AdminCompletedInstancesPanel method addVariables.

protected void addVariables(HistoricProcessInstance processInstance) {
    if (variablesHeader != null) {
        mainPanel.removeComponent(variablesHeader);
        mainPanel.removeComponent(variablesEmptyHeader);
    }
    if (noVariablesLabel != null) {
        mainPanel.removeComponent(noVariablesLabel);
    }
    variablesHeader = new Label(i18nManager.getMessage(Messages.PROCESS_INSTANCE_HEADER_VARIABLES));
    variablesHeader.addStyleName(ExplorerLayout.STYLE_H3);
    variablesHeader.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
    variablesHeader.addStyleName(ExplorerLayout.STYLE_NO_LINE);
    addDetailComponent(variablesHeader);
    variablesEmptyHeader = new Label("&nbsp;", Label.CONTENT_XHTML);
    addDetailComponent(variablesEmptyHeader);
    if (variablesTable != null) {
        mainPanel.removeComponent(variablesTable);
    }
    // variable sorting is done in-memory (which is ok, since normally there aren't that many vars)
    List<HistoricDetail> variables = historyService.createHistoricDetailQuery().processInstanceId(processInstance.getId()).orderByTime().desc().list();
    if (!variables.isEmpty()) {
        variablesTable = new Table();
        variablesTable.setWidth(60, UNITS_PERCENTAGE);
        variablesTable.setHeight(250, UNITS_PIXELS);
        variablesTable.addStyleName(ExplorerLayout.STYLE_PROCESS_INSTANCE_TASK_LIST);
        variablesTable.addContainerProperty("name", String.class, null, i18nManager.getMessage(Messages.PROCESS_INSTANCE_VARIABLE_NAME), null, Table.ALIGN_LEFT);
        variablesTable.addContainerProperty("value", String.class, null, i18nManager.getMessage(Messages.PROCESS_INSTANCE_VARIABLE_VALUE), null, Table.ALIGN_LEFT);
        variablesTable.addContainerProperty("type", String.class, null, i18nManager.getMessage(Messages.GROUP_TYPE), null, Table.ALIGN_LEFT);
        List<String> variableNames = new ArrayList<String>();
        for (HistoricDetail detail : variables) {
            if (detail instanceof HistoricVariableUpdate) {
                HistoricVariableUpdate variable = (HistoricVariableUpdate) detail;
                if (variableNames.contains(variable.getVariableName()) == false) {
                    variableNames.add(variable.getVariableName());
                    Item variableItem = variablesTable.addItem(variable.getVariableName());
                    variableItem.getItemProperty("name").setValue(variable.getVariableName());
                    // Get string value to show
                    String theValue = variableRendererManager.getStringRepresentation(variable.getValue());
                    variableItem.getItemProperty("value").setValue(theValue);
                    variableItem.getItemProperty("type").setValue("variable");
                }
            } else {
                HistoricFormProperty form = (HistoricFormProperty) detail;
                if (variableNames.contains(form.getPropertyId()) == false) {
                    variableNames.add(form.getPropertyId());
                    Item variableItem = variablesTable.addItem(form.getPropertyId());
                    variableItem.getItemProperty("name").setValue(form.getPropertyId());
                    variableItem.getItemProperty("value").setValue(form.getPropertyValue());
                    variableItem.getItemProperty("type").setValue("form property");
                }
            }
        }
        variablesTable.setPageLength(variables.size());
        addDetailComponent(variablesTable);
    } else {
        noVariablesLabel = new Label(i18nManager.getMessage(Messages.PROCESS_INSTANCE_NO_VARIABLES));
        addDetailComponent(noVariablesLabel);
    }
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) Item(com.vaadin.data.Item) Table(com.vaadin.ui.Table) HistoricFormProperty(org.activiti.engine.history.HistoricFormProperty) Label(com.vaadin.ui.Label) PrettyTimeLabel(org.activiti.explorer.ui.custom.PrettyTimeLabel) ArrayList(java.util.ArrayList)

Example 4 with HistoricVariableUpdate

use of org.activiti.engine.history.HistoricVariableUpdate in project midpoint by Evolveum.

the class ActivitiInterface method queryActivitiProcessInstance.

public void queryActivitiProcessInstance(QueryProcessCommand qpc, Task task, OperationResult result) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
    String pid = qpc.getPid();
    LOGGER.trace("Querying process instance id {}", pid);
    HistoryService hs = activitiEngine.getHistoryService();
    HistoricDetailQuery hdq = hs.createHistoricDetailQuery().variableUpdates().processInstanceId(pid).orderByTime().desc();
    Map<String, Object> variables = new HashMap<>();
    for (HistoricDetail hd : hdq.list()) {
        HistoricVariableUpdate hvu = (HistoricVariableUpdate) hd;
        String varname = hvu.getVariableName();
        Object value = hvu.getValue();
        LOGGER.trace(" - found historic variable update: {} <- {}", varname, value);
        if (!variables.containsKey(varname)) {
            variables.put(varname, value);
        }
    }
    HistoricDetailQuery hdq2 = hs.createHistoricDetailQuery().formProperties().processInstanceId(pid).orderByVariableRevision().desc();
    for (HistoricDetail hd : hdq2.list()) {
        HistoricFormProperty hfp = (HistoricFormProperty) hd;
        String varname = hfp.getPropertyId();
        Object value = hfp.getPropertyValue();
        LOGGER.trace(" - found historic form property: {} <- {}", varname, value);
        variables.put(varname, value);
    }
    QueryProcessResponse qpr = new QueryProcessResponse(pid, variables, processInterfaceFinder);
    ProcessInstance pi = activitiEngine.getProcessEngine().getRuntimeService().createProcessInstanceQuery().processInstanceId(pid).singleResult();
    qpr.setRunning(pi != null && !pi.isEnded());
    LOGGER.trace("Running process instance = {}, isRunning: {}", pi, qpr.isRunning());
    LOGGER.trace("Response to be sent to midPoint: {}", qpr);
    wfTaskController.onProcessEvent(qpr, task, result);
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) HistoricFormProperty(org.activiti.engine.history.HistoricFormProperty) HashMap(java.util.HashMap) HistoryService(org.activiti.engine.HistoryService) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricDetailQuery(org.activiti.engine.history.HistoricDetailQuery)

Example 5 with HistoricVariableUpdate

use of org.activiti.engine.history.HistoricVariableUpdate 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();
        assertThat(updates).hasSize(2);
        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");
        assertThat(update1.getActivityInstanceId()).isNotNull();
        assertThat(update1.getExecutionId()).isNotNull();
        HistoricActivityInstance historicActivityInstance1 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update1.getActivityInstanceId()).singleResult();
        assertThat(historicActivityInstance1.getActivityId()).isEqualTo("usertask1");
        // TODO https://activiti.atlassian.net/browse/ACT-1083
        assertThat(update2.getActivityInstanceId()).isNotNull();
        HistoricActivityInstance historicActivityInstance2 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update2.getActivityInstanceId()).singleResult();
        assertThat(historicActivityInstance2.getActivityId()).isEqualTo("usertask2");
        /*
       * 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
       */
        assertThat(historicActivityInstance2.getExecutionId().equals(update2.getExecutionId())).isFalse();
    }
}
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)

Aggregations

HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)17 HistoricDetail (org.activiti.engine.history.HistoricDetail)14 HashMap (java.util.HashMap)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)8 Deployment (org.activiti.engine.test.Deployment)8 Task (org.activiti.engine.task.Task)6 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)5 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)5 HistoricFormProperty (org.activiti.engine.history.HistoricFormProperty)4 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)4 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 HistoryService (org.activiti.engine.HistoryService)2 HistoricData (org.activiti.engine.history.HistoricData)2 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)2 HistoricVariableInstanceQuery (org.activiti.engine.history.HistoricVariableInstanceQuery)2 Item (com.vaadin.data.Item)1 Label (com.vaadin.ui.Label)1 Table (com.vaadin.ui.Table)1