Search in sources :

Example 61 with HistoricVariableInstance

use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.

the class ExecutionListenerTest method testScriptListener.

@Test
@Deployment
public void testScriptListener() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
    assertTrue(processInstance.isEnded());
    if (processEngineRule.getProcessEngineConfiguration().getHistoryLevel().getId() >= HISTORYLEVEL_AUDIT) {
        HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
        long count = query.count();
        assertEquals(5, count);
        HistoricVariableInstance variableInstance = null;
        String[] variableNames = new String[] { "start-start", "start-end", "start-take", "end-start", "end-end" };
        for (String variableName : variableNames) {
            variableInstance = query.variableName(variableName).singleResult();
            assertNotNull("Unable ot find variable with name '" + variableName + "'", variableInstance);
            assertTrue("Variable '" + variableName + "' should be set to true", (Boolean) variableInstance.getValue());
        }
    }
}
Also used : HistoricVariableInstanceQuery(org.camunda.bpm.engine.history.HistoricVariableInstanceQuery) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 62 with HistoricVariableInstance

use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.

the class HistoricVariableInstanceManager method deleteHistoricVariableInstancesByTaskId.

public void deleteHistoricVariableInstancesByTaskId(String taskId) {
    if (isHistoryEnabled()) {
        HistoricVariableInstanceQuery historicProcessVariableQuery = new HistoricVariableInstanceQueryImpl().taskIdIn(taskId);
        List<HistoricVariableInstance> historicProcessVariables = historicProcessVariableQuery.list();
        for (HistoricVariableInstance historicProcessVariable : historicProcessVariables) {
            ((HistoricVariableInstanceEntity) historicProcessVariable).delete();
        }
    }
}
Also used : HistoricVariableInstanceQuery(org.camunda.bpm.engine.history.HistoricVariableInstanceQuery) HistoricVariableInstanceQueryImpl(org.camunda.bpm.engine.impl.HistoricVariableInstanceQueryImpl) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance)

Example 63 with HistoricVariableInstance

use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.

the class HistoricVariableInstanceManager method deleteHistoricVariableInstancesByProcessCaseInstanceId.

protected void deleteHistoricVariableInstancesByProcessCaseInstanceId(String historicProcessInstanceId, String historicCaseInstanceId) {
    ensureOnlyOneNotNull("Only the process instance or case instance id should be set", historicProcessInstanceId, historicCaseInstanceId);
    if (isHistoryEnabled()) {
        // delete entries in DB
        List<HistoricVariableInstance> historicVariableInstances;
        if (historicProcessInstanceId != null) {
            historicVariableInstances = findHistoricVariableInstancesByProcessInstanceId(historicProcessInstanceId);
        } else {
            historicVariableInstances = findHistoricVariableInstancesByCaseInstanceId(historicCaseInstanceId);
        }
        for (HistoricVariableInstance historicVariableInstance : historicVariableInstances) {
            ((HistoricVariableInstanceEntity) historicVariableInstance).delete();
        }
        // delete entries in Cache
        List<HistoricVariableInstanceEntity> cachedHistoricVariableInstances = getDbEntityManager().getCachedEntitiesByType(HistoricVariableInstanceEntity.class);
        for (HistoricVariableInstanceEntity historicVariableInstance : cachedHistoricVariableInstances) {
            // make sure we only delete the right ones (as we cannot make a proper query in the cache)
            if ((historicProcessInstanceId != null && historicProcessInstanceId.equals(historicVariableInstance.getProcessInstanceId())) || (historicCaseInstanceId != null && historicCaseInstanceId.equals(historicVariableInstance.getCaseInstanceId()))) {
                historicVariableInstance.delete();
            }
        }
    }
}
Also used : HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance)

Example 64 with HistoricVariableInstance

use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.

the class BulkHistoryDeleteTest method testCleanupHistoryCaseInstanceVariables.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceVariables() {
    // given
    // create case instances
    List<String> caseInstanceIds = new ArrayList<String>();
    int instanceCount = 10;
    for (int i = 0; i < instanceCount; i++) {
        VariableMap variables = Variables.createVariables();
        CaseInstance caseInstance = caseService.createCaseInstanceByKey("oneTaskCase", variables.putValue("name" + i, "theValue"));
        caseInstanceIds.add(caseInstance.getId());
        terminateAndCloseCaseInstance(caseInstance.getId(), variables);
    }
    // assume
    List<HistoricVariableInstance> variablesInstances = historyService.createHistoricVariableInstanceQuery().list();
    assertEquals(instanceCount, variablesInstances.size());
    // when
    historyService.deleteHistoricCaseInstancesBulk(caseInstanceIds);
    // then
    variablesInstances = historyService.createHistoricVariableInstanceQuery().list();
    assertEquals(0, variablesInstances.size());
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) VariableMap(org.camunda.bpm.engine.variable.VariableMap) ArrayList(java.util.ArrayList) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 65 with HistoricVariableInstance

use of org.camunda.bpm.engine.history.HistoricVariableInstance in project camunda-bpm-platform by camunda.

the class BulkHistoryDeleteTest method testCleanupHistoryCaseInstanceComplexVariable.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceComplexVariable() {
    // given
    // create case instances
    VariableMap variables = Variables.createVariables();
    CaseInstance caseInstance = caseService.createCaseInstanceByKey("oneTaskCase", variables.putValue("pojo", new TestPojo("okay", 13.37)));
    caseService.setVariable(caseInstance.getId(), "pojo", "theValue");
    // assume
    List<HistoricVariableInstance> variablesInstances = historyService.createHistoricVariableInstanceQuery().list();
    assertEquals(1, variablesInstances.size());
    List<HistoricDetail> detailsList = historyService.createHistoricDetailQuery().list();
    assertEquals(2, detailsList.size());
    terminateAndCloseCaseInstance(caseInstance.getId(), variables);
    // when
    historyService.deleteHistoricCaseInstancesBulk(Arrays.asList(caseInstance.getId()));
    // then
    variablesInstances = historyService.createHistoricVariableInstanceQuery().list();
    assertEquals(0, variablesInstances.size());
    detailsList = historyService.createHistoricDetailQuery().list();
    assertEquals(0, detailsList.size());
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) VariableMap(org.camunda.bpm.engine.variable.VariableMap) TestPojo(org.camunda.bpm.engine.test.dmn.businessruletask.TestPojo) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)88 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)44 Test (org.junit.Test)42 Deployment (org.camunda.bpm.engine.test.Deployment)39 HistoricVariableInstanceQuery (org.camunda.bpm.engine.history.HistoricVariableInstanceQuery)18 Task (org.camunda.bpm.engine.task.Task)17 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)14 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)13 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)12 RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)12 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)10 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)10 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)10 HashMap (java.util.HashMap)8 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)8 VariableMap (org.camunda.bpm.engine.variable.VariableMap)8 HistoricVariableUpdate (org.camunda.bpm.engine.history.HistoricVariableUpdate)7 Date (java.util.Date)6 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)6 MockHistoricVariableInstanceBuilder (org.camunda.bpm.engine.rest.helper.MockHistoricVariableInstanceBuilder)6