Search in sources :

Example 26 with UserImpl

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

the class CaseCommentNotificationTest method testCommentsNotificationWithTemplate.

@Test
public void testCommentsNotificationWithTemplate() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    TestNotificationPublisher publisher = new TestNotificationPublisher(false);
    CommentNotificationEventListener listener = CommentNotificationEventListenerFactory.get("test");
    listener.addPublisher(publisher);
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_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<CommentInstance> caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
        assertNotNull(caseComments);
        assertEquals(0, caseComments.size());
        caseService.addCaseComment(FIRST_CASE_ID, "poul", "just a tiny comment refering to @owner");
        caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
        assertNotNull(caseComments);
        assertEquals(1, caseComments.size());
        CommentInstance comment = caseComments.iterator().next();
        assertComment(comment, "poul", "just a tiny comment refering to @owner");
        String expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-0000000001) comment to [[UserImpl:'john']] with template mentioned-in-comment";
        List<String> published = publisher.get();
        assertThat(published).hasSize(1);
        assertThat(published.get(0)).isEqualTo(expectedNotification);
        caseService.updateCaseComment(FIRST_CASE_ID, comment.getId(), comment.getAuthor(), "Updated " + comment.getComment());
        caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
        assertNotNull(caseComments);
        assertEquals(1, caseComments.size());
        comment = caseComments.iterator().next();
        assertComment(comment, "poul", "Updated just a tiny comment refering to @owner");
        expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-0000000001) comment to [[UserImpl:'john']] with template mentioned-in-comment";
        published = publisher.get();
        assertThat(published).hasSize(1);
        assertThat(published.get(0)).isEqualTo(expectedNotification);
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : CommentNotificationEventListener(org.jbpm.casemgmt.impl.event.CommentNotificationEventListener) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) TestNotificationPublisher(org.jbpm.casemgmt.impl.util.TestNotificationPublisher) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) UserImpl(org.jbpm.services.task.impl.model.UserImpl) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 27 with UserImpl

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

the class TaskFluent method addPotentialUser.

public TaskFluent addPotentialUser(String userId) {
    if (assignments.getPotentialOwners().isEmpty()) {
        List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>();
        assignments.setPotentialOwners(potentialOwners);
    }
    assignments.getPotentialOwners().add(new UserImpl(userId));
    return this;
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) ArrayList(java.util.ArrayList) UserImpl(org.jbpm.services.task.impl.model.UserImpl)

Example 28 with UserImpl

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

the class CaseRuntimeDataServiceImplTest method testTransitionBetweenStagesInCaseWithActiveElements.

@Test
public void testTransitionBetweenStagesInCaseWithActiveElements() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl(USER));
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    try {
        Collection<CaseStageInstance> stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        CaseStageInstance stageInstance = stage.iterator().next();
        assertEquals("Stage One", stageInstance.getName());
        assertEquals(StageStatus.Active, stageInstance.getStatus());
        Collection<NodeInstanceDesc> activeNodes = stageInstance.getActiveNodes();
        assertNotNull(activeNodes);
        assertEquals(0, activeNodes.size());
        caseService.triggerAdHocFragment(caseId, "Task 1", data);
        stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        stageInstance = stage.iterator().next();
        assertEquals("Stage One", stageInstance.getName());
        assertEquals(StageStatus.Active, stageInstance.getStatus());
        activeNodes = stageInstance.getActiveNodes();
        assertNotNull(activeNodes);
        assertEquals(1, activeNodes.size());
        assertEquals("Task 1", activeNodes.iterator().next().getName());
        caseService.addDataToCaseFile(caseId, "customData", "nextStagePlease");
        stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        assertEquals("Stage Two", stage.iterator().next().getName());
        assertEquals(StageStatus.Active, stage.iterator().next().getStatus());
        stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        stageInstance = stage.iterator().next();
        assertEquals("Stage Two", stageInstance.getName());
        assertEquals(StageStatus.Active, stageInstance.getStatus());
        activeNodes = stageInstance.getActiveNodes();
        assertNotNull(activeNodes);
        assertEquals(0, activeNodes.size());
        caseService.triggerAdHocFragment(caseId, "Task 2", data);
        stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        stageInstance = stage.iterator().next();
        assertEquals("Stage Two", stageInstance.getName());
        assertEquals(StageStatus.Active, stageInstance.getStatus());
        activeNodes = stageInstance.getActiveNodes();
        assertNotNull(activeNodes);
        assertEquals(1, activeNodes.size());
        assertEquals("Task 2", activeNodes.iterator().next().getName());
    } 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) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) 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 29 with UserImpl

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

the class CaseRuntimeDataServiceImplTest method testUserTasksInCase.

@Test
public void testUserTasksInCase() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl(USER));
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
    String caseId2 = null;
    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());
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(0, tasks.size());
        Map<String, Object> taskInput = new HashMap<>();
        taskInput.put("ActorId", "john");
        taskInput.put("Comment", "Need to provide data");
        caseService.triggerAdHocFragment(caseId, "Missing data", taskInput);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary task = tasks.get(0);
        assertEquals("Missing data", task.getName());
        assertEquals("Need to provide data", task.getSubject());
        caseId2 = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
        assertNotNull(caseId2);
        assertEquals("CASE-0000000002", caseId2);
        caseService.triggerAdHocFragment(caseId2, "Missing data", taskInput);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId2, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        task = tasks.get(0);
        assertEquals("Missing data", task.getName());
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        task = tasks.get(0);
        assertEquals("Missing data", task.getName());
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
        if (caseId2 != null) {
            caseService.cancelCase(caseId2);
        }
    }
}
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) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 30 with UserImpl

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

the class CaseRuntimeDataServiceImplTest method testUserTasksInCaseWithSubprocess.

@Test
public void testUserTasksInCaseWithSubprocess() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl(USER));
    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());
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(0, tasks.size());
        Map<String, Object> taskInput = new HashMap<>();
        taskInput.put("ActorId", "john");
        caseService.triggerAdHocFragment(caseId, "Missing data", taskInput);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary task = tasks.get(0);
        assertEquals("Missing data", task.getName());
        caseService.addDynamicSubprocess(caseId, "UserTask", null);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(2, tasks.size());
        task = tasks.get(0);
        assertEquals("Hello", task.getName());
        task = tasks.get(1);
        assertEquals("Missing data", task.getName());
    } 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) TaskSummary(org.kie.api.task.model.TaskSummary) 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