use of org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImpl method getCaseInstance.
@Override
public CaseInstance getCaseInstance(String caseId, boolean withData, boolean withRoles, boolean withMilestones, boolean withStages) throws CaseNotFoundException {
authorizationManager.checkAuthorization(caseId);
CaseInstanceImpl caseInstance = (CaseInstanceImpl) caseRuntimeDataService.getCaseInstanceById(caseId);
if (caseInstance.getStatus().equals(ProcessInstance.STATE_ACTIVE)) {
if (withData) {
CaseFileInstance caseFile = internalGetCaseFileInstance(caseId, caseInstance.getDeploymentId());
caseInstance.setCaseFile(caseFile);
}
if (withMilestones) {
Collection<CaseMilestoneInstance> milestones = caseRuntimeDataService.getCaseInstanceMilestones(caseId, false, new org.kie.internal.query.QueryContext(0, 100));
caseInstance.setCaseMilestones(milestones);
}
if (withRoles) {
Collection<CaseRoleInstance> roles = getCaseRoleAssignments(caseId);
caseInstance.setCaseRoles(roles);
}
if (withStages) {
Collection<CaseStageInstance> stages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new org.kie.internal.query.QueryContext(0, 100));
caseInstance.setCaseStages(stages);
}
}
return caseInstance;
}
use of org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartEmptyCaseChangeOwner.
@Test
public void testStartEmptyCaseChangeOwner() {
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data, new HashMap<>());
identityProvider.setName("mary");
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals("mary", cInstance.getOwner());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
String initiator = (String) processService.getProcessInstanceVariable(((CaseInstanceImpl) cInstance).getProcessInstanceId(), "initiator");
assertEquals("mary", initiator);
caseService.removeFromCaseRole(caseId, "owner", new UserImpl("mary"));
caseService.assignToCaseRole(caseId, "owner", new UserImpl("john"));
identityProvider.setName("john");
cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals("john", cInstance.getOwner());
initiator = (String) processService.getProcessInstanceVariable(((CaseInstanceImpl) cInstance).getProcessInstanceId(), "initiator");
assertEquals("mary", initiator);
caseService.cancelCase(caseId);
CaseInstance instance = caseService.getCaseInstance(caseId);
Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
caseId = null;
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartEmptyCaseUsingLoggedInOwner.
@Test
public void testStartEmptyCaseUsingLoggedInOwner() {
identityProvider.setName("mary");
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals("mary", cInstance.getOwner());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
String initiator = (String) processService.getProcessInstanceVariable(((CaseInstanceImpl) cInstance).getProcessInstanceId(), "initiator");
assertEquals("mary", initiator);
caseService.cancelCase(caseId);
CaseInstance instance = caseService.getCaseInstance(caseId);
Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
caseId = null;
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartEmptyCaseUsingCaseFileOwner.
@Test
public void testStartEmptyCaseUsingCaseFileOwner() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data, roleAssignments);
identityProvider.setName("mary");
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
identityProvider.setName("john");
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals("john", cInstance.getOwner());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
String initiator = (String) processService.getProcessInstanceVariable(((CaseInstanceImpl) cInstance).getProcessInstanceId(), "initiator");
assertEquals("mary", initiator);
caseService.cancelCase(caseId);
CaseInstance instance = caseService.getCaseInstance(caseId);
Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
caseId = null;
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.
the class StageCompletionConditionTest method testProcessVariable.
@Test
public void testProcessVariable() {
Map<String, Object> data = new HashMap<>();
data.put("continue", false);
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_PROCESS_VARIABLE, data, Collections.emptyMap());
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_PROCESS_VARIABLE, caseFile);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
assertCaseInstanceActive(caseId);
CaseInstance caseInstance = caseService.getCaseInstance(caseId);
assertThat(caseInstance).isNotNull();
Long processInstanceId = ((CaseInstanceImpl) caseInstance).getProcessInstanceId();
processService.setProcessVariable(processInstanceId, "continue", false);
caseService.addDataToCaseFile(caseId, "continue", true);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary insideTask = tasks.get(0);
assertThat(insideTask.getName()).isEqualTo(INSIDE_TASK);
userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
assertCaseInstanceActive(caseId);
processService.setProcessVariable(processInstanceId, "continue", true);
caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
assertThat(caseInstance.getCaseStages()).hasSize(1);
String stageId = caseInstance.getCaseStages().iterator().next().getId();
TaskSpecification dynamicTaskSpecification = caseService.newHumanTaskSpec(DYNAMIC_TASK, "", USER, null, Collections.emptyMap());
caseService.addDynamicTaskToStage(caseId, stageId, dynamicTaskSpecification);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary dynamicTask = tasks.get(0);
assertThat(dynamicTask.getName()).isEqualTo(DYNAMIC_TASK);
userTaskService.completeAutoProgress(dynamicTask.getId(), USER, null);
assertCaseInstanceNotActive(caseId);
}
Aggregations