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());
}
use of org.activiti.engine.history.HistoricVariableUpdate in project Activiti by Activiti.
the class FullHistoryTest method testHistoricVariableUpdatesAllTypes.
@Deployment
public void testHistoricVariableUpdatesAllTypes() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss SSS");
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("aVariable", "initial value");
Date startedDate = sdf.parse("01/01/2001 01:23:45 000");
// In the javaDelegate, the current time is manipulated
Date updatedDate = sdf.parse("01/01/2001 01:23:46 000");
processEngineConfiguration.getClock().setCurrentTime(startedDate);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("HistoricVariableUpdateProcess", variables);
List<HistoricDetail> details = historyService.createHistoricDetailQuery().variableUpdates().processInstanceId(processInstance.getId()).orderByVariableName().asc().orderByTime().asc().list();
// 8 variable updates should be present, one performed when starting process
// the other 7 are set in VariableSetter serviceTask
assertEquals(9, details.size());
// Since we order by varName, first entry should be aVariable update from startTask
HistoricVariableUpdate startVarUpdate = (HistoricVariableUpdate) details.get(0);
assertEquals("aVariable", startVarUpdate.getVariableName());
assertEquals("initial value", startVarUpdate.getValue());
assertEquals(0, startVarUpdate.getRevision());
assertEquals(processInstance.getId(), startVarUpdate.getProcessInstanceId());
// Date should the the one set when starting
assertEquals(startedDate, startVarUpdate.getTime());
HistoricVariableUpdate updatedStringVariable = (HistoricVariableUpdate) details.get(1);
assertEquals("aVariable", updatedStringVariable.getVariableName());
assertEquals("updated value", updatedStringVariable.getValue());
assertEquals(processInstance.getId(), updatedStringVariable.getProcessInstanceId());
// Date should be the updated date
assertEquals(updatedDate, updatedStringVariable.getTime());
HistoricVariableUpdate intVariable = (HistoricVariableUpdate) details.get(2);
assertEquals("bVariable", intVariable.getVariableName());
assertEquals(123, intVariable.getValue());
assertEquals(processInstance.getId(), intVariable.getProcessInstanceId());
assertEquals(updatedDate, intVariable.getTime());
HistoricVariableUpdate longVariable = (HistoricVariableUpdate) details.get(3);
assertEquals("cVariable", longVariable.getVariableName());
assertEquals(12345L, longVariable.getValue());
assertEquals(processInstance.getId(), longVariable.getProcessInstanceId());
assertEquals(updatedDate, longVariable.getTime());
HistoricVariableUpdate doubleVariable = (HistoricVariableUpdate) details.get(4);
assertEquals("dVariable", doubleVariable.getVariableName());
assertEquals(1234.567, doubleVariable.getValue());
assertEquals(processInstance.getId(), doubleVariable.getProcessInstanceId());
assertEquals(updatedDate, doubleVariable.getTime());
HistoricVariableUpdate shortVariable = (HistoricVariableUpdate) details.get(5);
assertEquals("eVariable", shortVariable.getVariableName());
assertEquals((short) 12, shortVariable.getValue());
assertEquals(processInstance.getId(), shortVariable.getProcessInstanceId());
assertEquals(updatedDate, shortVariable.getTime());
HistoricVariableUpdate dateVariable = (HistoricVariableUpdate) details.get(6);
assertEquals("fVariable", dateVariable.getVariableName());
assertEquals(sdf.parse("01/01/2001 01:23:45 678"), dateVariable.getValue());
assertEquals(processInstance.getId(), dateVariable.getProcessInstanceId());
assertEquals(updatedDate, dateVariable.getTime());
HistoricVariableUpdate serializableVariable = (HistoricVariableUpdate) details.get(7);
assertEquals("gVariable", serializableVariable.getVariableName());
assertEquals(new SerializableVariable("hello hello"), serializableVariable.getValue());
assertEquals(processInstance.getId(), serializableVariable.getProcessInstanceId());
assertEquals(updatedDate, serializableVariable.getTime());
HistoricVariableUpdate byteArrayVariable = (HistoricVariableUpdate) details.get(8);
assertEquals("hVariable", byteArrayVariable.getVariableName());
assertEquals(";-)", new String((byte[]) byteArrayVariable.getValue()));
assertEquals(processInstance.getId(), byteArrayVariable.getProcessInstanceId());
assertEquals(updatedDate, byteArrayVariable.getTime());
// end process instance
List<Task> tasks = taskService.createTaskQuery().list();
assertEquals(1, tasks.size());
taskService.complete(tasks.get(0).getId());
assertProcessEnded(processInstance.getId());
// check for historic process variables set
HistoricVariableInstanceQuery historicProcessVariableQuery = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc();
assertEquals(8, historicProcessVariableQuery.count());
List<HistoricVariableInstance> historicVariables = historicProcessVariableQuery.list();
// Variable status when process is finished
HistoricVariableInstance historicVariable = historicVariables.get(0);
assertEquals("aVariable", historicVariable.getVariableName());
assertEquals("updated value", historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(1);
assertEquals("bVariable", historicVariable.getVariableName());
assertEquals(123, historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(2);
assertEquals("cVariable", historicVariable.getVariableName());
assertEquals(12345L, historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(3);
assertEquals("dVariable", historicVariable.getVariableName());
assertEquals(1234.567, historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(4);
assertEquals("eVariable", historicVariable.getVariableName());
assertEquals((short) 12, historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(5);
assertEquals("fVariable", historicVariable.getVariableName());
assertEquals(sdf.parse("01/01/2001 01:23:45 678"), historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(6);
assertEquals("gVariable", historicVariable.getVariableName());
assertEquals(new SerializableVariable("hello hello"), historicVariable.getValue());
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
historicVariable = historicVariables.get(7);
assertEquals("hVariable", historicVariable.getVariableName());
assertEquals(";-)", ";-)", new String((byte[]) historicVariable.getValue()));
assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
}
use of org.activiti.engine.history.HistoricVariableUpdate in project Activiti by Activiti.
the class FullHistoryTest method testHistoricVariableRemovedWhenRuntimeVariableIsRemoved.
// Test for https://activiti.atlassian.net/browse/ACT-2186
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testHistoricVariableRemovedWhenRuntimeVariableIsRemoved() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("var1", "Hello");
vars.put("var2", "World");
vars.put("var3", "!");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
// Verify runtime
assertEquals(3, runtimeService.getVariables(processInstance.getId()).size());
assertEquals(3, runtimeService.getVariables(processInstance.getId(), Arrays.asList("var1", "var2", "var3")).size());
assertNotNull(runtimeService.getVariable(processInstance.getId(), "var2"));
// Verify history
assertEquals(3, historyService.createHistoricVariableInstanceQuery().list().size());
assertNotNull(historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("var2").singleResult());
// Verify historic details
List<HistoricDetail> details = historyService.createHistoricDetailQuery().processInstanceId(processInstance.getId()).variableUpdates().orderByTime().asc().list();
// 3 vars
assertEquals(3, details.size());
for (HistoricDetail historicDetail : details) {
assertNotNull(((HistoricVariableUpdate) historicDetail).getValue());
}
// Remove one variable
runtimeService.removeVariable(processInstance.getId(), "var2");
// Verify runtime
assertEquals(2, runtimeService.getVariables(processInstance.getId()).size());
assertEquals(2, runtimeService.getVariables(processInstance.getId(), Arrays.asList("var1", "var2", "var3")).size());
assertNull(runtimeService.getVariable(processInstance.getId(), "var2"));
// Verify history
assertEquals(2, historyService.createHistoricVariableInstanceQuery().list().size());
assertNull(historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).variableName("var2").singleResult());
// Verify historic details
details = historyService.createHistoricDetailQuery().processInstanceId(processInstance.getId()).variableUpdates().orderByTime().asc().list();
// 3 vars + 1 delete
assertEquals(4, details.size());
// The last entry should be the delete
for (int i = 0; i < details.size(); i++) {
if (i != 3) {
assertNotNull(((HistoricVariableUpdate) details.get(i)).getValue());
} else if (i == 3) {
assertNull(((HistoricVariableUpdate) details.get(i)).getValue());
}
}
}
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);
}
use of org.activiti.engine.history.HistoricVariableUpdate in project Activiti by Activiti.
the class HistoricDetailDataResource method getVariableFromRequest.
public RestVariable getVariableFromRequest(boolean includeBinary, String detailId, HttpServletRequest request) {
Object value = null;
HistoricVariableUpdate variableUpdate = null;
HistoricDetail detailObject = historyService.createHistoricDetailQuery().id(detailId).singleResult();
if (detailObject instanceof HistoricVariableUpdate) {
variableUpdate = (HistoricVariableUpdate) detailObject;
value = variableUpdate.getValue();
}
if (value == null) {
throw new ActivitiObjectNotFoundException("Historic detail '" + detailId + "' doesn't have a variable value.", VariableInstanceEntity.class);
} else {
return restResponseFactory.createRestVariable(variableUpdate.getVariableName(), value, null, detailId, RestResponseFactory.VARIABLE_HISTORY_DETAIL, includeBinary);
}
}
Aggregations