Search in sources :

Example 6 with HistoricDetail

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

the class FullHistoryTest method testHistoricFormPropertiesOnReEnteringActivity.

/**
   * Test created to validate ACT-621 fix.
   */
@Deployment
public void testHistoricFormPropertiesOnReEnteringActivity() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("comeBack", Boolean.TRUE);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("HistoricFormPropertiesProcess", variables);
    assertNotNull(processInstance);
    // Submit form on task
    Map<String, String> data = new HashMap<String, String>();
    data.put("formProp1", "Property value");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    formService.submitTaskFormData(task.getId(), data);
    // Historic property should be available
    List<HistoricDetail> details = historyService.createHistoricDetailQuery().formProperties().processInstanceId(processInstance.getId()).list();
    assertNotNull(details);
    assertEquals(1, details.size());
    // Task should be active in the same activity as the previous one
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    formService.submitTaskFormData(task.getId(), data);
    details = historyService.createHistoricDetailQuery().formProperties().processInstanceId(processInstance.getId()).list();
    assertNotNull(details);
    assertEquals(2, details.size());
    // Should have 2 different historic activity instance ID's, with the same activityId
    assertNotSame(details.get(0).getActivityInstanceId(), details.get(1).getActivityInstanceId());
    HistoricActivityInstance historicActInst1 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(details.get(0).getActivityInstanceId()).singleResult();
    HistoricActivityInstance historicActInst2 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(details.get(1).getActivityInstanceId()).singleResult();
    assertEquals(historicActInst1.getActivityId(), historicActInst2.getActivityId());
}
Also used : HistoricDetail(org.activiti.engine.history.HistoricDetail) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 7 with HistoricDetail

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

the class HistoricDetailQueryImpl method executeList.

public List<HistoricDetail> executeList(CommandContext commandContext, Page page) {
    checkQueryOk();
    List<HistoricDetail> historicDetails = commandContext.getHistoricDetailEntityManager().findHistoricDetailsByQueryCriteria(this, page);
    HistoricDetailVariableInstanceUpdateEntity varUpdate = null;
    if (historicDetails != null) {
        for (HistoricDetail historicDetail : historicDetails) {
            if (historicDetail instanceof HistoricDetailVariableInstanceUpdateEntity) {
                varUpdate = (HistoricDetailVariableInstanceUpdateEntity) historicDetail;
                // Touch byte-array to ensure initialized inside context
                // TODO there should be a generic way to initialize variable values
                varUpdate.getBytes();
                // cached value
                if (varUpdate.getVariableType() instanceof JPAEntityVariableType) {
                    // Use HistoricJPAEntityVariableType to force caching of value to return from query
                    varUpdate.setVariableType(HistoricJPAEntityVariableType.getSharedInstance());
                    varUpdate.getValue();
                } else if (varUpdate.getVariableType() instanceof JPAEntityListVariableType) {
                    // Use HistoricJPAEntityListVariableType to force caching of list to return from query
                    varUpdate.setVariableType(HistoricJPAEntityListVariableType.getSharedInstance());
                    varUpdate.getValue();
                }
            }
        }
    }
    return historicDetails;
}
Also used : HistoricDetail(org.activiti.engine.history.HistoricDetail) HistoricJPAEntityVariableType(org.activiti.engine.impl.variable.HistoricJPAEntityVariableType) JPAEntityVariableType(org.activiti.engine.impl.variable.JPAEntityVariableType) HistoricJPAEntityListVariableType(org.activiti.engine.impl.variable.HistoricJPAEntityListVariableType) JPAEntityListVariableType(org.activiti.engine.impl.variable.JPAEntityListVariableType) HistoricDetailVariableInstanceUpdateEntity(org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity)

Example 8 with HistoricDetail

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

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

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

the class RuntimeServiceTest 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)

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