Search in sources :

Example 1 with HistoricProcessInstance

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;
}
Also used : HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) HistoricProcessInstanceDto(org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceDto)

Example 2 with HistoricProcessInstance

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;
}
Also used : HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance)

Example 3 with HistoricProcessInstance

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());
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with HistoricProcessInstance

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());
}
Also used : HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 5 with HistoricProcessInstance

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());
    }
}
Also used : Task(org.camunda.bpm.engine.task.Task) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)113 Deployment (org.camunda.bpm.engine.test.Deployment)46 Test (org.junit.Test)37 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)36 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)25 Task (org.camunda.bpm.engine.task.Task)19 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)18 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 ArrayList (java.util.ArrayList)15 Calendar (java.util.Calendar)12 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)12 GregorianCalendar (java.util.GregorianCalendar)11 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)9 RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)9 HistoricProcessInstanceQueryDto (org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto)7 List (java.util.List)5 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)5 Response (com.jayway.restassured.response.Response)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4