Search in sources :

Example 11 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class CaseSLAComplianceTest method testStartCaseWithSLANotification.

@Test
public void testStartCaseWithSLANotification() {
    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<NodeInstanceDesc> activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext());
        assertThat(activeNodes).hasSize(1);
        Iterator<NodeInstanceDesc> it = activeNodes.iterator();
        NodeInstanceDesc active = it.next();
        assertThat(active.getName()).isEqualTo("Hello1");
        CountDownListenerFactory.getExisting("slaCompliance").waitTillCompleted();
        cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals(ProcessInstance.SLA_VIOLATED, cInstance.getSlaCompliance().intValue());
        activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext());
        assertThat(activeNodes).hasSize(2);
        it = activeNodes.iterator();
        active = it.next();
        assertThat(active.getName()).isEqualTo("Hello1");
        active = it.next();
        assertThat(active.getName()).isEqualTo("[Dynamic] SLA Violation 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) 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) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 12 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class CaseServiceImplTest method testCaseRolesCardinality.

@Test
public void testCaseRolesCardinality() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "description");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, caseFile);
    try {
        caseService.assignToCaseRole(caseId, "contact", new UserImpl("mary"));
        caseService.assignToCaseRole(caseId, "contact", new UserImpl("steve"));
        Throwable error = Assertions.catchThrowable(() -> caseService.assignToCaseRole(caseId, "contact", new UserImpl("jack")));
        assertThat(error).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Cannot add more users for role contact, maximum cardinality 2 already reached");
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) 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 13 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class CaseServiceImplTest method testCaseAuthorization.

@Test
public void testCaseAuthorization() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    roleAssignments.put("contact", new GroupImpl("HR"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "description");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(HR_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(HR_CASE_ID, cInstance.getCaseId());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        identityProvider.setName("mary");
        try {
            caseService.cancelCase(caseId);
            fail("Mary is not owner of the case so should not be allowed to cancel the case");
        } catch (SecurityException e) {
        // expected
        }
        try {
            caseService.destroyCase(caseId);
            fail("Mary is not owner of the case so should not be allowed to destroy the case");
        } catch (SecurityException e) {
        // expected
        }
        identityProvider.setName("john");
        caseService.cancelCase(caseId);
        identityProvider.setName("mary");
        try {
            caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID);
            fail("Mary is not owner of the case so should not be allowed to reopen the case");
        } catch (SecurityException e) {
        // expected
        }
        identityProvider.setName("john");
        caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID);
        cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(HR_CASE_ID, cInstance.getCaseId());
    } 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) GroupImpl(org.jbpm.services.task.impl.model.GroupImpl) 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 14 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class CaseServiceImplTest method testUserTaskToCaseWithStageCompleteCaseDataItem.

@Test
public void testUserTaskToCaseWithStageCompleteCaseDataItem() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        Collection<CaseFileItem> caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(0, caseFileItems.size());
        Collection<CaseStageInstance> activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
        assertNotNull(activeStages);
        assertEquals(1, activeStages.size());
        caseService.addDataToCaseFile(caseId, "dataComplete", true);
        activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
        assertNotNull(activeStages);
        assertEquals(0, activeStages.size());
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(1, caseFileItems.size());
        CaseFileItem dataItem = caseFileItems.iterator().next();
        assertNotNull(dataItem);
        assertEquals(caseId, dataItem.getCaseId());
        assertEquals("dataComplete", dataItem.getName());
        assertEquals("true", dataItem.getValue());
        assertEquals(Boolean.class.getName(), dataItem.getType());
        assertEquals(identityProvider.getName(), dataItem.getLastModifiedBy());
        assertNotNull(dataItem.getLastModified());
        caseService.addDataToCaseFile(caseId, "anotherDataItem", "first version");
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(2, caseFileItems.size());
        dataItem = caseFileItems.iterator().next();
        assertNotNull(dataItem);
        assertEquals(caseId, dataItem.getCaseId());
        assertEquals("anotherDataItem", dataItem.getName());
        assertEquals("first version", dataItem.getValue());
        assertEquals(String.class.getName(), dataItem.getType());
        assertEquals(identityProvider.getName(), dataItem.getLastModifiedBy());
        assertNotNull(dataItem.getLastModified());
        caseService.addDataToCaseFile(caseId, "anotherDataItem", "second version");
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(2, caseFileItems.size());
        dataItem = caseFileItems.iterator().next();
        assertNotNull(dataItem);
        assertEquals(caseId, dataItem.getCaseId());
        assertEquals("anotherDataItem", dataItem.getName());
        assertEquals("second version", dataItem.getValue());
        assertEquals(String.class.getName(), dataItem.getType());
        assertEquals(identityProvider.getName(), dataItem.getLastModifiedBy());
        assertNotNull(dataItem.getLastModified());
        caseService.removeDataFromCaseFile(caseId, "anotherDataItem");
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(1, caseFileItems.size());
        identityProvider.setName("mary");
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        // mary is not involved in case isntance
        assertEquals(0, caseFileItems.size());
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        identityProvider.setName("john");
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) QueryContext(org.kie.api.runtime.query.QueryContext) 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) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) UserImpl(org.jbpm.services.task.impl.model.UserImpl) CaseFileItem(org.jbpm.casemgmt.api.model.CaseFileItem) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 15 with OrganizationalEntity

use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.

the class CaseServiceImplTest method testTriggerMultipleAdHocTasks.

@Test
public void testTriggerMultipleAdHocTasks() {
    identityProvider.setName("john");
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    Map<String, Object> data = new HashMap<>();
    data.put("customData", "none");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), TWO_STAGES_CONDITIONS_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CONDITIONS_CASE_P_ID, caseFile);
    assertThat(caseId).isNotNull();
    try {
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertThat(tasks).isNotNull().isEmpty();
        caseService.triggerAdHocFragment(caseId, "Task 1", null);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertThat(tasks).isNotNull().hasSize(1);
        assertThat(tasks).extracting(TaskSummary::getName).containsOnly("Task 1");
        caseService.triggerAdHocFragment(caseId, "Task 1", null);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertThat(tasks).isNotNull().hasSize(2);
        assertThat(tasks).extracting(TaskSummary::getName).containsOnly("Task 1");
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        caseService.cancelCase(caseId);
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) UserImpl(org.jbpm.services.task.impl.model.UserImpl) TaskSummary(org.kie.api.task.model.TaskSummary) QueryContext(org.kie.api.runtime.query.QueryContext) 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)

Aggregations

OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)146 Test (org.junit.Test)93 HashMap (java.util.HashMap)69 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)55 ArrayList (java.util.ArrayList)54 User (org.kie.api.task.model.User)52 UserImpl (org.jbpm.services.task.impl.model.UserImpl)51 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)48 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)41 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)36 InternalTask (org.kie.internal.task.api.model.InternalTask)35 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)34 Task (org.kie.api.task.model.Task)33 QueryContext (org.kie.api.runtime.query.QueryContext)32 Group (org.kie.api.task.model.Group)29 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)26 TaskSummary (org.kie.api.task.model.TaskSummary)25 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)24 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)24 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)24