Search in sources :

Example 1 with CaseExecution

use of org.camunda.bpm.engine.runtime.CaseExecution in project camunda-bpm-platform by camunda.

the class CaseExecutionRestServiceImpl method queryCaseExecutions.

public List<CaseExecutionDto> queryCaseExecutions(CaseExecutionQueryDto queryDto, Integer firstResult, Integer maxResults) {
    ProcessEngine engine = getProcessEngine();
    queryDto.setObjectMapper(getObjectMapper());
    CaseExecutionQuery query = queryDto.toQuery(engine);
    List<CaseExecution> matchingExecutions;
    if (firstResult != null || maxResults != null) {
        matchingExecutions = executePaginatedQuery(query, firstResult, maxResults);
    } else {
        matchingExecutions = query.list();
    }
    List<CaseExecutionDto> executionResults = new ArrayList<CaseExecutionDto>();
    for (CaseExecution execution : matchingExecutions) {
        CaseExecutionDto resultExecution = CaseExecutionDto.fromCaseExecution(execution);
        executionResults.add(resultExecution);
    }
    return executionResults;
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) CaseExecutionDto(org.camunda.bpm.engine.rest.dto.runtime.CaseExecutionDto) ArrayList(java.util.ArrayList) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) CaseExecutionQuery(org.camunda.bpm.engine.runtime.CaseExecutionQuery)

Example 2 with CaseExecution

use of org.camunda.bpm.engine.runtime.CaseExecution in project camunda-bpm-platform by camunda.

the class CaseExecutionRestServiceInteractionTest method setUpRuntime.

@Before
public void setUpRuntime() {
    CaseExecution mockCaseExecution = MockProvider.createMockCaseExecution();
    caseServiceMock = mock(CaseService.class);
    when(processEngine.getCaseService()).thenReturn(caseServiceMock);
    caseExecutionQueryMock = mock(CaseExecutionQuery.class);
    when(caseServiceMock.createCaseExecutionQuery()).thenReturn(caseExecutionQueryMock);
    when(caseExecutionQueryMock.caseExecutionId(MockProvider.EXAMPLE_CASE_EXECUTION_ID)).thenReturn(caseExecutionQueryMock);
    when(caseExecutionQueryMock.singleResult()).thenReturn(mockCaseExecution);
    when(caseServiceMock.getVariableTyped(anyString(), anyString(), eq(true))).thenReturn(EXAMPLE_VARIABLE_VALUE);
    when(caseServiceMock.getVariablesTyped(anyString(), eq(true))).thenReturn(EXAMPLE_VARIABLES);
    when(caseServiceMock.getVariableLocalTyped(anyString(), eq(EXAMPLE_VARIABLE_KEY), anyBoolean())).thenReturn(EXAMPLE_VARIABLE_VALUE);
    when(caseServiceMock.getVariableLocalTyped(anyString(), eq(EXAMPLE_BYTES_VARIABLE_KEY), eq(false))).thenReturn(EXAMPLE_VARIABLE_VALUE_BYTES);
    when(caseServiceMock.getVariablesLocalTyped(anyString(), eq(true))).thenReturn(EXAMPLE_VARIABLES);
    when(caseServiceMock.getVariablesTyped(anyString(), Matchers.<Collection<String>>any(), eq(true))).thenReturn(EXAMPLE_VARIABLES);
    when(caseServiceMock.getVariablesLocalTyped(anyString(), Matchers.<Collection<String>>any(), eq(true))).thenReturn(EXAMPLE_VARIABLES);
    caseExecutionCommandBuilderMock = mock(CaseExecutionCommandBuilder.class);
    when(caseServiceMock.withCaseExecution(MockProvider.EXAMPLE_CASE_EXECUTION_ID)).thenReturn(caseExecutionCommandBuilderMock);
    when(caseExecutionCommandBuilderMock.setVariable(anyString(), any())).thenReturn(caseExecutionCommandBuilderMock);
    when(caseExecutionCommandBuilderMock.setVariableLocal(anyString(), any())).thenReturn(caseExecutionCommandBuilderMock);
    when(caseExecutionCommandBuilderMock.setVariables(Matchers.<Map<String, Object>>any())).thenReturn(caseExecutionCommandBuilderMock);
    when(caseExecutionCommandBuilderMock.setVariablesLocal(Matchers.<Map<String, Object>>any())).thenReturn(caseExecutionCommandBuilderMock);
    when(caseExecutionCommandBuilderMock.removeVariable(anyString())).thenReturn(caseExecutionCommandBuilderMock);
    when(caseExecutionCommandBuilderMock.removeVariableLocal(anyString())).thenReturn(caseExecutionCommandBuilderMock);
    when(caseExecutionCommandBuilderMock.removeVariables(Matchers.<Collection<String>>any())).thenReturn(caseExecutionCommandBuilderMock);
    when(caseExecutionCommandBuilderMock.removeVariablesLocal(Matchers.<Collection<String>>any())).thenReturn(caseExecutionCommandBuilderMock);
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) CaseService(org.camunda.bpm.engine.CaseService) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) CaseExecutionCommandBuilder(org.camunda.bpm.engine.runtime.CaseExecutionCommandBuilder) CaseExecutionQuery(org.camunda.bpm.engine.runtime.CaseExecutionQuery) Before(org.junit.Before)

Example 3 with CaseExecution

use of org.camunda.bpm.engine.runtime.CaseExecution in project camunda-bpm-platform by camunda.

the class CaseExecutionResourceImpl method getCaseExecution.

public CaseExecutionDto getCaseExecution() {
    CaseService caseService = engine.getCaseService();
    CaseExecution execution = caseService.createCaseExecutionQuery().caseExecutionId(caseExecutionId).singleResult();
    if (execution == null) {
        throw new InvalidRequestException(Status.NOT_FOUND, "Case execution with id " + caseExecutionId + " does not exist.");
    }
    CaseExecutionDto result = CaseExecutionDto.fromCaseExecution(execution);
    return result;
}
Also used : CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) CaseExecutionDto(org.camunda.bpm.engine.rest.dto.runtime.CaseExecutionDto) CaseService(org.camunda.bpm.engine.CaseService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 4 with CaseExecution

use of org.camunda.bpm.engine.runtime.CaseExecution in project camunda-bpm-platform by camunda.

the class CaseServiceHumanTaskTest method testCompleteWithRemoveVariableLocal.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/twoTaskCase.cmmn" })
public void testCompleteWithRemoveVariableLocal() {
    // given:
    // a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    // an active case instance
    caseService.withCaseDefinition(caseDefinitionId).create();
    String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
    caseService.withCaseExecution(caseExecutionId).setVariableLocal("aVariableName", "abc").setVariableLocal("anotherVariableName", 999).manualStart();
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    // when
    caseService.withCaseExecution(caseExecutionId).removeVariableLocal("aVariableName").removeVariableLocal("anotherVariableName").complete();
    // then
    // the task has been completed and has been deleted
    task = taskService.createTaskQuery().singleResult();
    assertNull(task);
    // the corresponding case execution has been also
    // deleted and completed
    CaseExecution caseExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
    assertNull(caseExecution);
    // the case instance is still active
    CaseInstance caseInstance = caseService.createCaseInstanceQuery().active().singleResult();
    assertNotNull(caseInstance);
    assertTrue(caseInstance.isActive());
    List<VariableInstance> result = runtimeService.createVariableInstanceQuery().list();
    assertTrue(result.isEmpty());
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) Task(org.camunda.bpm.engine.task.Task) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 5 with CaseExecution

use of org.camunda.bpm.engine.runtime.CaseExecution in project camunda-bpm-platform by camunda.

the class CaseServiceHumanTaskTest method testManualStartWithLocalVariable.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCaseWithManualActivation.cmmn" })
public void testManualStartWithLocalVariable() {
    // given:
    // a deployed case definition
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
    // an active case instance
    String caseInstanceId = caseService.withCaseDefinition(caseDefinitionId).create().getId();
    CaseExecutionQuery caseExecutionQuery = caseService.createCaseExecutionQuery();
    // an enabled child case execution of
    // the case instance
    String caseExecutionId = caseExecutionQuery.activityId("PI_HumanTask_1").singleResult().getId();
    // when
    // activate child case execution
    caseService.withCaseExecution(caseExecutionId).setVariableLocal("aVariableName", "abc").setVariableLocal("anotherVariableName", 999).manualStart();
    // then
    // the child case execution is active...
    CaseExecution caseExecution = caseExecutionQuery.singleResult();
    assertTrue(caseExecution.isActive());
    // ... and not enabled
    assertFalse(caseExecution.isEnabled());
    // there exists a task
    Task task = taskService.createTaskQuery().caseExecutionId(caseExecutionId).singleResult();
    assertNotNull(task);
    // the case instance has two variables:
    // - aVariableName
    // - anotherVariableName
    List<VariableInstance> result = runtimeService.createVariableInstanceQuery().list();
    assertFalse(result.isEmpty());
    assertEquals(2, result.size());
    for (VariableInstance variable : result) {
        assertEquals(caseExecutionId, variable.getCaseExecutionId());
        assertEquals(caseInstanceId, variable.getCaseInstanceId());
        if (variable.getName().equals("aVariableName")) {
            assertEquals("aVariableName", variable.getName());
            assertEquals("abc", variable.getValue());
        } else if (variable.getName().equals("anotherVariableName")) {
            assertEquals("anotherVariableName", variable.getName());
            assertEquals(999, variable.getValue());
        } else {
            fail("Unexpected variable: " + variable.getName());
        }
    }
}
Also used : Task(org.camunda.bpm.engine.task.Task) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) CaseExecutionQuery(org.camunda.bpm.engine.runtime.CaseExecutionQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)280 Deployment (org.camunda.bpm.engine.test.Deployment)246 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)61 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)48 Task (org.camunda.bpm.engine.task.Task)28 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)27 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)18 Test (org.junit.Test)17 HashMap (java.util.HashMap)13 HistoricCaseActivityInstance (org.camunda.bpm.engine.history.HistoricCaseActivityInstance)11 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)11 NotAllowedException (org.camunda.bpm.engine.exception.NotAllowedException)9 VariableMap (org.camunda.bpm.engine.variable.VariableMap)7 DelegateCaseExecution (org.camunda.bpm.engine.delegate.DelegateCaseExecution)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)4 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)4 VariableMapImpl (org.camunda.bpm.engine.variable.impl.VariableMapImpl)3 ArrayList (java.util.ArrayList)2 CaseService (org.camunda.bpm.engine.CaseService)2