Search in sources :

Example 1 with HistoricDetailVariableInstanceUpdateEntity

use of org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity 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 2 with HistoricDetailVariableInstanceUpdateEntity

use of org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity in project Activiti by Activiti.

the class HistoricJPAVariableTest method testGetJPAUpdateEntityAsHistoricLog.

@Deployment(resources = { "org/activiti/standalone/jpa/HistoricJPAVariableTest.testGetJPAEntityAsHistoricLog.bpmn20.xml" })
public void testGetJPAUpdateEntityAsHistoricLog() {
    setupJPAEntities();
    // -----------------------------------------------------------------------------
    // Simple test, Start process with JPA entities as variables
    // -----------------------------------------------------------------------------
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("simpleEntityFieldAccess", simpleEntityFieldAccess);
    // Start the process with the JPA-entities as variables. They will be stored in the DB.
    this.processInstanceId = runtimeService.startProcessInstanceByKey("JPAVariableProcess", variables).getId();
    // Finish tasks
    for (Task task : taskService.createTaskQuery().includeProcessVariables().list()) {
        taskService.setVariable(task.getId(), "simpleEntityFieldAccess", simpleEntityFieldAccess);
        taskService.complete(task.getId());
    }
    // Get JPAEntity Variable by ProcessInstanceHistoryLogQuery
    ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId).includeVariableUpdates().singleResult();
    List<HistoricData> events = log.getHistoricData();
    for (HistoricData event : events) {
        Object value = ((HistoricDetailVariableInstanceUpdateEntity) event).getValue();
        assertThat(value).isInstanceOf(FieldAccessJPAEntity.class);
        assertThat(simpleEntityFieldAccess.getValue()).isEqualTo(((FieldAccessJPAEntity) value).getValue());
    }
}
Also used : Task(org.activiti.engine.task.Task) HistoricData(org.activiti.engine.history.HistoricData) HashMap(java.util.HashMap) ProcessInstanceHistoryLog(org.activiti.engine.history.ProcessInstanceHistoryLog) HistoricDetailVariableInstanceUpdateEntity(org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity) Deployment(org.activiti.engine.test.Deployment)

Example 3 with HistoricDetailVariableInstanceUpdateEntity

use of org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity 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) {
            assertThat(currentHistoricDetail).isInstanceOf(HistoricDetailVariableInstanceUpdateEntity.class);
            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;
                    }
                }
            }
        }
        assertThat(deletedVariableUpdateFound).isTrue();
    }
}
Also used : HistoricDetail(org.activiti.engine.history.HistoricDetail) HistoricDetailVariableInstanceUpdateEntity(org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity)

Example 4 with HistoricDetailVariableInstanceUpdateEntity

use of org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity 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) {
            assertThat(currentHistoricDetail).isInstanceOf(HistoricDetailVariableInstanceUpdateEntity.class);
            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;
                    }
                }
            }
        }
        assertThat(deletedVariableUpdateFound).isTrue();
    }
}
Also used : HistoricDetail(org.activiti.engine.history.HistoricDetail) HistoricDetailVariableInstanceUpdateEntity(org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity)

Aggregations

HistoricDetailVariableInstanceUpdateEntity (org.activiti.engine.impl.persistence.entity.HistoricDetailVariableInstanceUpdateEntity)4 HistoricDetail (org.activiti.engine.history.HistoricDetail)3 HashMap (java.util.HashMap)1 HistoricData (org.activiti.engine.history.HistoricData)1 ProcessInstanceHistoryLog (org.activiti.engine.history.ProcessInstanceHistoryLog)1 HistoricJPAEntityListVariableType (org.activiti.engine.impl.variable.HistoricJPAEntityListVariableType)1 HistoricJPAEntityVariableType (org.activiti.engine.impl.variable.HistoricJPAEntityVariableType)1 JPAEntityListVariableType (org.activiti.engine.impl.variable.JPAEntityListVariableType)1 JPAEntityVariableType (org.activiti.engine.impl.variable.JPAEntityVariableType)1 Task (org.activiti.engine.task.Task)1 Deployment (org.activiti.engine.test.Deployment)1