use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testVariableUpdatesLinkedToActivity.
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/standalone/history/FullHistoryTest.testVariableUpdatesAreLinkedToActivity.bpmn20.xml" })
public void testVariableUpdatesLinkedToActivity() throws Exception {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("ProcessWithSubProcess");
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("test", "1");
taskService.complete(task.getId(), variables);
// now we are in the subprocess
task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
variables.clear();
variables.put("test", "2");
taskService.complete(task.getId(), variables);
// now we are ended
testHelper.assertProcessEnded(pi.getId());
// check history
List<HistoricDetail> updates = historyService.createHistoricDetailQuery().variableUpdates().list();
assertEquals(2, updates.size());
Map<String, HistoricVariableUpdate> updatesMap = new HashMap<String, HistoricVariableUpdate>();
HistoricVariableUpdate update = (HistoricVariableUpdate) updates.get(0);
updatesMap.put((String) update.getValue(), update);
update = (HistoricVariableUpdate) updates.get(1);
updatesMap.put((String) update.getValue(), update);
HistoricVariableUpdate update1 = updatesMap.get("1");
HistoricVariableUpdate update2 = updatesMap.get("2");
assertNotNull(update1.getActivityInstanceId());
assertNotNull(update1.getExecutionId());
HistoricActivityInstance historicActivityInstance1 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update1.getActivityInstanceId()).singleResult();
assertEquals(historicActivityInstance1.getExecutionId(), update1.getExecutionId());
assertEquals("usertask1", historicActivityInstance1.getActivityId());
assertNotNull(update2.getActivityInstanceId());
HistoricActivityInstance historicActivityInstance2 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update2.getActivityInstanceId()).singleResult();
assertEquals("usertask2", historicActivityInstance2.getActivityId());
/*
* This is OK! The variable is set on the root execution, on a execution never run through the activity, where the process instances
* stands when calling the set Variable. But the ActivityId of this flow node is used. So the execution id's doesn't have to be equal.
*
* execution id: On which execution it was set
* activity id: in which activity was the process instance when setting the variable
*/
assertFalse(historicActivityInstance2.getExecutionId().equals(update2.getExecutionId()));
}
use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class HistoricActivityInstanceRestServiceImpl method queryHistoricActivityInstances.
@Override
public List<HistoricActivityInstanceDto> queryHistoricActivityInstances(HistoricActivityInstanceQueryDto queryDto, Integer firstResult, Integer maxResults) {
queryDto.setObjectMapper(objectMapper);
HistoricActivityInstanceQuery query = queryDto.toQuery(processEngine);
List<HistoricActivityInstance> matchingHistoricActivityInstances;
if (firstResult != null || maxResults != null) {
matchingHistoricActivityInstances = executePaginatedQuery(query, firstResult, maxResults);
} else {
matchingHistoricActivityInstances = query.list();
}
List<HistoricActivityInstanceDto> historicActivityInstanceResults = new ArrayList<HistoricActivityInstanceDto>();
for (HistoricActivityInstance historicActivityInstance : matchingHistoricActivityInstances) {
HistoricActivityInstanceDto resultHistoricActivityInstance = HistoricActivityInstanceDto.fromHistoricActivityInstance(historicActivityInstance);
historicActivityInstanceResults.add(resultHistoricActivityInstance);
}
return historicActivityInstanceResults;
}
use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class HistoricActivityInstanceResourceImpl method getHistoricActivityInstance.
public HistoricActivityInstanceDto getHistoricActivityInstance() {
HistoryService historyService = engine.getHistoryService();
HistoricActivityInstance instance = historyService.createHistoricActivityInstanceQuery().activityInstanceId(activityInstanceId).singleResult();
if (instance == null) {
throw new InvalidRequestException(Status.NOT_FOUND, "Historic activity instance with id '" + activityInstanceId + "' does not exist");
}
return HistoricActivityInstanceDto.fromHistoricActivityInstance(instance);
}
use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class RestartProcessInstancesCmd method resolveStartActivityInstance.
protected HistoricActivityInstance resolveStartActivityInstance(HistoricProcessInstance processInstance) {
HistoryService historyService = Context.getProcessEngineConfiguration().getHistoryService();
String processInstanceId = processInstance.getId();
String startActivityId = processInstance.getStartActivityId();
ensureNotNull("startActivityId", startActivityId);
List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).activityId(startActivityId).orderPartiallyByOccurrence().asc().list();
ensureNotEmpty("historicActivityInstances", historicActivityInstances);
HistoricActivityInstance startActivityInstance = historicActivityInstances.get(0);
return startActivityInstance;
}
use of org.camunda.bpm.engine.history.HistoricActivityInstance in project camunda-bpm-platform by camunda.
the class RestartProcessInstancesCmd method collectInitialVariables.
protected VariableMap collectInitialVariables(CommandContext commandContext, HistoricProcessInstance processInstance) {
HistoryService historyService = commandContext.getProcessEngineConfiguration().getHistoryService();
HistoricActivityInstance startActivityInstance = resolveStartActivityInstance(processInstance);
HistoricDetailQueryImpl query = (HistoricDetailQueryImpl) historyService.createHistoricDetailQuery().variableUpdates().executionId(processInstance.getId()).activityInstanceId(startActivityInstance.getId());
List<HistoricDetail> historicDetails = query.sequenceCounter(1).list();
VariableMap variables = new VariableMapImpl();
for (HistoricDetail detail : historicDetails) {
HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) detail;
variables.putValueTyped(variableUpdate.getVariableName(), variableUpdate.getTypedValue());
}
return variables;
}
Aggregations