use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testHistoricVariableUpdateCaseDefinitionProperty.
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn")
public void testHistoricVariableUpdateCaseDefinitionProperty() {
// given
String key = "oneTaskCase";
CaseInstance caseInstance = caseService.createCaseInstanceByKey(key);
String caseInstanceId = caseInstance.getId();
String humanTask = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
String taskId = taskService.createTaskQuery().singleResult().getId();
caseService.setVariable(caseInstanceId, "aVariable", "aValue");
taskService.setVariableLocal(taskId, "aLocalVariable", "anotherValue");
String firstVariable = runtimeService.createVariableInstanceQuery().variableName("aVariable").singleResult().getId();
String secondVariable = runtimeService.createVariableInstanceQuery().variableName("aLocalVariable").singleResult().getId();
// when (1)
HistoricVariableUpdate instance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(firstVariable).singleResult();
// then (1)
assertNotNull(instance.getCaseDefinitionKey());
assertEquals(key, instance.getCaseDefinitionKey());
assertNotNull(instance.getCaseDefinitionId());
assertEquals(caseInstance.getCaseDefinitionId(), instance.getCaseDefinitionId());
assertNull(instance.getProcessDefinitionKey());
assertNull(instance.getProcessDefinitionId());
// when (2)
instance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(secondVariable).singleResult();
// then (2)
assertNotNull(instance.getCaseDefinitionKey());
assertEquals(key, instance.getCaseDefinitionKey());
assertNotNull(instance.getCaseDefinitionId());
assertEquals(caseInstance.getCaseDefinitionId(), instance.getCaseDefinitionId());
assertNull(instance.getProcessDefinitionKey());
assertNull(instance.getProcessDefinitionId());
}
use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.
the class MockProvider method createMockCaseInstance.
public static CaseInstance createMockCaseInstance(String tenantId) {
CaseInstance mock = mock(CaseInstance.class);
when(mock.getId()).thenReturn(EXAMPLE_CASE_INSTANCE_ID);
when(mock.getBusinessKey()).thenReturn(EXAMPLE_CASE_INSTANCE_BUSINESS_KEY);
when(mock.getCaseDefinitionId()).thenReturn(EXAMPLE_CASE_INSTANCE_CASE_DEFINITION_ID);
when(mock.getTenantId()).thenReturn(tenantId);
when(mock.isActive()).thenReturn(EXAMPLE_CASE_INSTANCE_IS_ACTIVE);
when(mock.isCompleted()).thenReturn(EXAMPLE_CASE_INSTANCE_IS_COMPLETED);
when(mock.isTerminated()).thenReturn(EXAMPLE_CASE_INSTANCE_IS_TERMINATED);
return mock;
}
use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.
the class CaseDefinitionResourceImpl method createCaseInstance.
public CaseInstanceDto createCaseInstance(UriInfo context, CreateCaseInstanceDto parameters) {
CaseService caseService = engine.getCaseService();
CaseInstance instance = null;
try {
String businessKey = parameters.getBusinessKey();
VariableMap variables = VariableValueDto.toMap(parameters.getVariables(), engine, objectMapper);
instance = caseService.withCaseDefinition(caseDefinitionId).businessKey(businessKey).setVariables(variables).create();
} catch (RestException e) {
String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
throw new InvalidRequestException(e.getStatus(), e, errorMessage);
} catch (NotFoundException e) {
String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
throw new InvalidRequestException(Status.NOT_FOUND, e, errorMessage);
} catch (NotValidException e) {
String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
throw new InvalidRequestException(Status.BAD_REQUEST, e, errorMessage);
} catch (NotAllowedException e) {
String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
throw new InvalidRequestException(Status.FORBIDDEN, e, errorMessage);
} catch (ProcessEngineException e) {
String errorMessage = String.format("Cannot instantiate case definition %s: %s", caseDefinitionId, e.getMessage());
throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
}
CaseInstanceDto result = CaseInstanceDto.fromCaseInstance(instance);
URI uri = context.getBaseUriBuilder().path(rootResourcePath).path(CaseInstanceRestService.PATH).path(instance.getId()).build();
result.addReflexiveLink(uri, HttpMethod.GET, "self");
return result;
}
use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.
the class TenantIdProviderTest method setsTenantId_SubCaseInstance.
@Test
public void setsTenantId_SubCaseInstance() {
String tenantId = TENANT_ID;
SetValueOnSubCaseInstanceTenantIdProvider tenantIdProvider = new SetValueOnSubCaseInstanceTenantIdProvider(tenantId);
TestTenantIdProvider.delegate = tenantIdProvider;
testRule.deploy(CMMN_SUBPROCESS_FILE, CMMN_FILE);
// if a case instance is created
engineRule.getCaseService().withCaseDefinitionByKey(CASE_DEFINITION_KEY).create();
// then the tenant id provider can set the tenant id to a value
CaseInstance subCaseInstance = engineRule.getCaseService().createCaseInstanceQuery().caseDefinitionKey("oneTaskCase").singleResult();
assertThat(subCaseInstance.getTenantId(), is(tenantId));
// and the super case instance is not assigned a tenant id
CaseInstance superCaseInstance = engineRule.getCaseService().createCaseInstanceQuery().caseDefinitionKey(CASE_DEFINITION_KEY).singleResult();
assertThat(superCaseInstance.getTenantId(), is(nullValue()));
}
use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.
the class TenantIdProviderTest method setsTenantIdForCaseInstance.
@Test
public void setsTenantIdForCaseInstance() {
String tenantId = TENANT_ID;
StaticTenantIdTestProvider tenantIdProvider = new StaticTenantIdTestProvider(tenantId);
TestTenantIdProvider.delegate = tenantIdProvider;
testRule.deploy(CMMN_FILE_WITH_MANUAL_ACTIVATION);
// if a case instance is created
engineRule.getCaseService().withCaseDefinitionByKey(CASE_DEFINITION_KEY).create();
// then the tenant id provider can set the tenant id to a value
CaseInstance caseInstance = engineRule.getCaseService().createCaseInstanceQuery().singleResult();
assertThat(caseInstance.getTenantId(), is(tenantId));
}
Aggregations