Search in sources :

Example 1 with CaseInstanceImpl

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;
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) CaseRoleInstance(org.jbpm.casemgmt.api.model.instance.CaseRoleInstance)

Example 2 with CaseInstanceImpl

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);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) HashMap(java.util.HashMap) UserImpl(org.jbpm.services.task.impl.model.UserImpl) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 3 with CaseInstanceImpl

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);
        }
    }
}
Also used : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 4 with CaseInstanceImpl

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);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) HashMap(java.util.HashMap) UserImpl(org.jbpm.services.task.impl.model.UserImpl) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 5 with CaseInstanceImpl

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);
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) QueryFilter(org.kie.internal.query.QueryFilter) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

CaseInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl)12 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)11 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)11 Test (org.junit.Test)11 HashMap (java.util.HashMap)8 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)8 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)8 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)8 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)8 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)8 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)8 TaskSummary (org.kie.api.task.model.TaskSummary)5 QueryFilter (org.kie.internal.query.QueryFilter)5 UserImpl (org.jbpm.services.task.impl.model.UserImpl)4 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)3 TaskSpecification (org.jbpm.casemgmt.api.dynamic.TaskSpecification)2 CaseMilestoneInstance (org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance)2 CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)2 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)2 QueryContext (org.kie.api.runtime.query.QueryContext)2