Search in sources :

Example 46 with HistoricActivityInstance

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()));
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) Task(org.camunda.bpm.engine.task.Task) HashMap(java.util.HashMap) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 47 with HistoricActivityInstance

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

Example 48 with HistoricActivityInstance

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);
}
Also used : HistoryService(org.camunda.bpm.engine.HistoryService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance)

Example 49 with HistoricActivityInstance

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

Example 50 with HistoricActivityInstance

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;
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) VariableMapImpl(org.camunda.bpm.engine.variable.impl.VariableMapImpl) VariableMap(org.camunda.bpm.engine.variable.VariableMap) HistoricDetailQueryImpl(org.camunda.bpm.engine.impl.HistoricDetailQueryImpl) HistoryService(org.camunda.bpm.engine.HistoryService) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance)

Aggregations

HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)80 Deployment (org.camunda.bpm.engine.test.Deployment)56 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)45 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)24 Task (org.camunda.bpm.engine.task.Task)19 Test (org.junit.Test)17 HistoricActivityInstanceQuery (org.camunda.bpm.engine.history.HistoricActivityInstanceQuery)13 HashMap (java.util.HashMap)12 RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)8 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)6 Date (java.util.Date)5 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)5 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)5 HistoricTaskInstance (org.camunda.bpm.engine.history.HistoricTaskInstance)4 ArrayList (java.util.ArrayList)3 HistoryService (org.camunda.bpm.engine.HistoryService)3 HistoricVariableUpdate (org.camunda.bpm.engine.history.HistoricVariableUpdate)3 Response (com.jayway.restassured.response.Response)2 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)2 HistoricVariableInstanceQuery (org.camunda.bpm.engine.history.HistoricVariableInstanceQuery)2