use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class HistoricProcessInstanceRestServiceImpl method queryHistoricProcessInstances.
@Override
public List<HistoricProcessInstanceDto> queryHistoricProcessInstances(HistoricProcessInstanceQueryDto queryDto, Integer firstResult, Integer maxResults) {
queryDto.setObjectMapper(objectMapper);
HistoricProcessInstanceQuery query = queryDto.toQuery(processEngine);
List<HistoricProcessInstance> matchingHistoricProcessInstances;
if (firstResult != null || maxResults != null) {
matchingHistoricProcessInstances = executePaginatedQuery(query, firstResult, maxResults);
} else {
matchingHistoricProcessInstances = query.list();
}
List<HistoricProcessInstanceDto> historicProcessInstanceDtoResults = new ArrayList<HistoricProcessInstanceDto>();
for (HistoricProcessInstance historicProcessInstance : matchingHistoricProcessInstances) {
HistoricProcessInstanceDto resultHistoricProcessInstanceDto = HistoricProcessInstanceDto.fromHistoricProcessInstance(historicProcessInstance);
historicProcessInstanceDtoResults.add(resultHistoricProcessInstanceDto);
}
return historicProcessInstanceDtoResults;
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class MockProvider method createMockHistoricProcessInstanceUnfinished.
public static HistoricProcessInstance createMockHistoricProcessInstanceUnfinished() {
HistoricProcessInstance mock = mock(HistoricProcessInstance.class);
when(mock.getId()).thenReturn(EXAMPLE_PROCESS_INSTANCE_ID);
when(mock.getBusinessKey()).thenReturn(EXAMPLE_PROCESS_INSTANCE_BUSINESS_KEY);
when(mock.getProcessDefinitionId()).thenReturn(EXAMPLE_PROCESS_DEFINITION_ID);
when(mock.getDeleteReason()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_DELETE_REASON);
when(mock.getEndTime()).thenReturn(null);
when(mock.getStartTime()).thenReturn(DateTimeUtil.parseDate(EXAMPLE_HISTORIC_PROCESS_INSTANCE_START_TIME));
when(mock.getDurationInMillis()).thenReturn(EXAMPLE_HISTORIC_PROCESS_INSTANCE_DURATION_MILLIS);
return mock;
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class ProcessInstantiationAtActivitiesHistoryTest method testHistoricProcessInstanceAsyncStartEvent.
@Deployment(resources = ASYNC_PROCESS)
public void testHistoricProcessInstanceAsyncStartEvent() {
// when
ProcessInstance instance = runtimeService.createProcessInstanceByKey("exclusiveGateway").startBeforeActivity("task2").setVariable("aVar", "aValue").execute();
// then
HistoricProcessInstance historicInstance = historyService.createHistoricProcessInstanceQuery().singleResult();
assertNotNull(historicInstance);
assertEquals(instance.getId(), historicInstance.getId());
assertNotNull(historicInstance.getStartTime());
assertNull(historicInstance.getEndTime());
// should be the first activity started
assertEquals("task2", historicInstance.getStartActivityId());
// task2 wasn't entered yet
assertEquals(0, historyService.createHistoricActivityInstanceQuery().count());
// history events for variables exist already
ActivityInstance activityInstance = runtimeService.getActivityInstance(instance.getId());
HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().variableName("aVar").singleResult();
assertNotNull(historicVariable);
assertEquals(instance.getId(), historicVariable.getProcessInstanceId());
assertEquals(activityInstance.getId(), historicVariable.getActivityInstanceId());
assertEquals("aVar", historicVariable.getName());
assertEquals("aValue", historicVariable.getValue());
HistoricDetail historicDetail = historyService.createHistoricDetailQuery().variableInstanceId(historicVariable.getId()).singleResult();
assertEquals(instance.getId(), historicDetail.getProcessInstanceId());
assertNotNull(historicDetail);
// TODO: fix if this is not ok due to CAM-3886
assertNull(historicDetail.getActivityInstanceId());
assertTrue(historicDetail instanceof HistoricVariableUpdate);
assertEquals("aVar", ((HistoricVariableUpdate) historicDetail).getVariableName());
assertEquals("aValue", ((HistoricVariableUpdate) historicDetail).getValue());
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class ProcessInstantiationAtActivitiesHistoryTest method testHistoricProcessInstanceForSingleActivityInstantiation.
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS)
public void testHistoricProcessInstanceForSingleActivityInstantiation() {
// when
ProcessInstance instance = runtimeService.createProcessInstanceByKey("exclusiveGateway").startBeforeActivity("task1").execute();
// then
HistoricProcessInstance historicInstance = historyService.createHistoricProcessInstanceQuery().singleResult();
assertNotNull(historicInstance);
assertEquals(instance.getId(), historicInstance.getId());
assertNotNull(historicInstance.getStartTime());
assertNull(historicInstance.getEndTime());
// should be the first activity started
assertEquals("task1", historicInstance.getStartActivityId());
HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().singleResult();
assertNotNull(historicActivityInstance);
assertEquals("task1", historicActivityInstance.getActivityId());
assertNotNull(historicActivityInstance.getId());
assertFalse(instance.getId().equals(historicActivityInstance.getId()));
assertNotNull(historicActivityInstance.getStartTime());
assertNull(historicActivityInstance.getEndTime());
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class CallActivityTest method testSubProcessBusinessKeyInput.
/**
* Test case for handing businessKey to a sub process
*/
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testSubProcessBusinessKeyInput.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml" })
public void testSubProcessBusinessKeyInput() {
String businessKey = "myBusinessKey";
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("subProcessBusinessKeyInput", businessKey);
// one task in the super process should be active after starting the process instance
TaskQuery taskQuery = taskService.createTaskQuery();
Task taskBeforeSubProcess = taskQuery.singleResult();
assertEquals("Task before subprocess", taskBeforeSubProcess.getName());
assertEquals("myBusinessKey", processInstance.getBusinessKey());
taskService.complete(taskBeforeSubProcess.getId());
if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
// called process started so businesskey should be written in history
HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery().superProcessInstanceId(processInstance.getId()).singleResult();
assertEquals(businessKey, hpi.getBusinessKey());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().processInstanceBusinessKey(businessKey).list().size());
}
// one task in sub process should be active after starting sub process instance
taskQuery = taskService.createTaskQuery();
Task taskInSubProcess = taskQuery.singleResult();
assertEquals("Task in subprocess", taskInSubProcess.getName());
ProcessInstance subProcessInstance = runtimeService.createProcessInstanceQuery().processInstanceId(taskInSubProcess.getProcessInstanceId()).singleResult();
assertEquals("myBusinessKey", subProcessInstance.getBusinessKey());
taskService.complete(taskInSubProcess.getId());
// task after sub process in super process
taskQuery = taskService.createTaskQuery();
Task taskAfterSubProcess = taskQuery.singleResult();
assertEquals("Task after subprocess", taskAfterSubProcess.getName());
taskService.complete(taskAfterSubProcess.getId());
assertProcessEnded(processInstance.getId());
assertEquals(0, runtimeService.createExecutionQuery().list().size());
if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery().superProcessInstanceId(processInstance.getId()).finished().singleResult();
assertEquals(businessKey, hpi.getBusinessKey());
assertEquals(2, historyService.createHistoricProcessInstanceQuery().processInstanceBusinessKey(businessKey).finished().list().size());
}
}
Aggregations