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());
}
}
}
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();
}
}
}
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();
}
}
}
}
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());
}
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());
}
Aggregations