Search in sources :

Example 31 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CaseSLAComplianceTest method testStartCaseWithSLAForGoldCustomerByRules.

@Test
public void testStartCaseWithSLAForGoldCustomerByRules() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    roleAssignments.put("admin", new UserImpl("mary"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "Case with SLA");
    data.put("CustomerType", "Gold");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_SLA_EXPR_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_SLA_EXPR_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(HR_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals(ProcessInstance.SLA_PENDING, cInstance.getSlaCompliance().intValue());
        Object calcualtedSlaDueDate = cInstance.getCaseFile().getData("slaDueDate");
        assertNotNull(calcualtedSlaDueDate);
        assertThat(calcualtedSlaDueDate).isEqualTo("1s");
        CountDownListenerFactory.getExisting("slaCompliance").waitTillCompleted();
        cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals(ProcessInstance.SLA_VIOLATED, cInstance.getSlaCompliance().intValue());
        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) HashMap(java.util.HashMap) UserImpl(org.jbpm.services.task.impl.model.UserImpl) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 32 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CaseSLAComplianceTest method testStartCaseWithSLAForSilverCustomerByRules.

@Test
public void testStartCaseWithSLAForSilverCustomerByRules() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    roleAssignments.put("admin", new UserImpl("mary"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "Case with SLA");
    data.put("CustomerType", "Silver");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_SLA_EXPR_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_SLA_EXPR_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(HR_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals(ProcessInstance.SLA_PENDING, cInstance.getSlaCompliance().intValue());
        Object calcualtedSlaDueDate = cInstance.getCaseFile().getData("slaDueDate");
        assertNotNull(calcualtedSlaDueDate);
        assertThat(calcualtedSlaDueDate).isEqualTo("2s");
        CountDownListenerFactory.getExisting("slaCompliance").waitTillCompleted();
        cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals(ProcessInstance.SLA_VIOLATED, cInstance.getSlaCompliance().intValue());
        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) HashMap(java.util.HashMap) UserImpl(org.jbpm.services.task.impl.model.UserImpl) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 33 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CaseSLAComplianceTest method testStartCaseWithSLAEscalation.

@Test
public void testStartCaseWithSLAEscalation() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    roleAssignments.put("admin", new UserImpl("mary"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "Case with SLA");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_SLA_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_SLA_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(HR_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals(ProcessInstance.SLA_PENDING, cInstance.getSlaCompliance().intValue());
        List<TaskSummary> escalationTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
        assertThat(escalationTasks).hasSize(0);
        CountDownListenerFactory.getExisting("slaCompliance").waitTillCompleted();
        cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals(ProcessInstance.SLA_VIOLATED, cInstance.getSlaCompliance().intValue());
        escalationTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
        assertThat(escalationTasks).hasSize(1);
        TaskSummary task = escalationTasks.get(0);
        assertThat(task.getName()).isEqualTo("SLA violation for case " + caseId);
        assertThat(task.getDescription()).isEqualTo("Service Level Agreement has been violated for case " + caseId);
        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 : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) UserImpl(org.jbpm.services.task.impl.model.UserImpl) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 34 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CaseSLAComplianceTest method testStartCaseWithSLASubprocess.

@Test
public void testStartCaseWithSLASubprocess() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    roleAssignments.put("admin", new UserImpl("mary"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "Case with SLA");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_SLA_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_SLA_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(HR_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals(ProcessInstance.SLA_PENDING, cInstance.getSlaCompliance().intValue());
        Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertNotNull(caseProcessInstances);
        assertEquals(1, caseProcessInstances.size());
        CountDownListenerFactory.getExisting("slaCompliance").waitTillCompleted();
        cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals(ProcessInstance.SLA_VIOLATED, cInstance.getSlaCompliance().intValue());
        caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertNotNull(caseProcessInstances);
        assertEquals(2, caseProcessInstances.size());
        for (ProcessInstanceDesc pi : caseProcessInstances) {
            assertThat(pi.getCorrelationKey()).startsWith(HR_CASE_ID);
        }
        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 : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) UserImpl(org.jbpm.services.task.impl.model.UserImpl) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 35 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CaseSLAComplianceTest method testStartCaseWithSLAForNewCustomerByRules.

@Test
public void testStartCaseWithSLAForNewCustomerByRules() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    roleAssignments.put("admin", new UserImpl("mary"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "Case with SLA");
    data.put("CustomerType", "New");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_SLA_EXPR_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_SLA_EXPR_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(HR_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals(ProcessInstance.SLA_NA, cInstance.getSlaCompliance().intValue());
        Object calcualtedSlaDueDate = cInstance.getCaseFile().getData("slaDueDate");
        assertNotNull(calcualtedSlaDueDate);
        assertThat(calcualtedSlaDueDate).isEqualTo("");
        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) HashMap(java.util.HashMap) UserImpl(org.jbpm.services.task.impl.model.UserImpl) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

UserImpl (org.jbpm.services.task.impl.model.UserImpl)57 Test (org.junit.Test)52 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)51 HashMap (java.util.HashMap)49 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)49 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)49 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)42 QueryContext (org.kie.api.runtime.query.QueryContext)33 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)25 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)25 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)25 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)25 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)25 TaskSummary (org.kie.api.task.model.TaskSummary)21 QueryFilter (org.kie.internal.query.QueryFilter)10 ArrayList (java.util.ArrayList)9 GroupImpl (org.jbpm.services.task.impl.model.GroupImpl)9 CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)8 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)7 CaseAssignment (org.kie.api.runtime.process.CaseAssignment)7