Search in sources :

Example 61 with TaskSummary

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

the class LifeCycleBaseTest method testStartFromReadyStateWithIncorrectPotentialOwner.

@Test
public void testStartFromReadyStateWithIncorrectPotentialOwner() {
    // One potential owner, should go straight to state Reserved
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ], businessAdministrators = [ new User('Administrator') ],}),";
    str += "name = 'This is my task name'})";
    Task task = TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    // A Task with multiple potential owners moves to "Ready" state until someone claims it.
    List<TaskSummary> tasksAssignedAsPotentialOwner = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", "en-UK");
    assertEquals(1, tasksAssignedAsPotentialOwner.size());
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(Status.Ready, task1.getTaskData().getStatus());
    // State should not change as user isn't potential owner
    PermissionDeniedException denied = null;
    try {
        taskService.start(taskId, "Tony Stark");
    } catch (PermissionDeniedException e) {
        denied = e;
    }
    assertNotNull("Should get permissed denied exception", denied);
    Task task2 = taskService.getTaskById(taskId);
    assertEquals(Status.Ready, task2.getTaskData().getStatus());
    assertNull(task2.getTaskData().getActualOwner());
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) Test(org.junit.Test)

Example 62 with TaskSummary

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

the class LifeCycleLocalWithRuleServiceTest method testCompleteTaskWithCheckByRule.

@Test
public void testCompleteTaskWithCheckByRule() {
    // One potential owner, should go straight to state Reserved
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { workItemId = 1 } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('mary')],businessAdministrators = [ new User('Administrator') ], }),";
    str += "description =  'This is my description', ";
    str += "subject = 'This is my subject', ";
    str += "name = 'This is my task name' })";
    Task task = (Task) TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, new HashMap<String, Object>());
    List<TaskSummary> tasks = taskService.getTasksOwned("mary", "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    long taskId = tasks.get(0).getId();
    taskService.start(taskId, "mary");
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("approved", "false");
    try {
        taskService.complete(taskId, "mary", data);
        fail("Task should not be created due to rule violation");
    } catch (PermissionDeniedException e) {
        assertTrue(e.getMessage().indexOf("Mary is not allowed to complete task with approved false") != -1);
    }
}
Also used : Task(org.kie.api.task.model.Task) HashMap(java.util.HashMap) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) Test(org.junit.Test)

Example 63 with TaskSummary

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

the class LifeCycleLocalWithRuleServiceTest method testCreateTaskWithExcludedActorByRule.

@Test
public void testCreateTaskWithExcludedActorByRule() {
    // One potential owner, should go straight to state Reserved
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { workItemId = 1 } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('john')],businessAdministrators = [ new User('Administrator') ], }),";
    str += "description =  'This is my description', ";
    str += "subject = 'This is my subject', ";
    str += "name =  'This is my task name' })";
    Task task = (Task) TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, new HashMap<String, Object>());
    List<TaskSummary> tasks = taskService.getTasksOwned("john", "en-UK");
    assertNotNull(tasks);
    assertEquals(0, tasks.size());
}
Also used : Task(org.kie.api.task.model.Task) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) Test(org.junit.Test)

Example 64 with TaskSummary

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

the class TaskCommentTest method testTaskComment.

@Test
public void testTaskComment() throws Exception {
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { businessAdministrators = [new User('Bobba Fet')], }),";
    str += "name =  'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, new HashMap<String, Object>());
    List<TaskSummary> tasks = taskService.getTasksAssignedAsBusinessAdministrator("Bobba Fet", "en-UK");
    String txt = "brainwashArmitageRecruitCaseGetPasswordFromLady3JaneAscentToStraylightIcebreakerUniteWithNeuromancer";
    assertEquals(1, tasks.size());
    TaskSummary taskSum = tasks.get(0);
    Comment comment = TaskModelProvider.getFactory().newComment();
    ((InternalComment) comment).setAddedAt(TODAY);
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Troll");
    ((InternalComment) comment).setAddedBy(user);
    ((InternalComment) comment).setText(txt);
    Long commentId = taskService.addComment(taskSum.getId().longValue(), comment);
    assertNotNull(commentId);
    assertTrue(commentId.longValue() > 0l);
    Comment commentById = taskService.getCommentById(commentId.longValue());
    assertNotNull(commentById);
    assertEquals(commentId, commentById.getId());
    Assertions.assertThat(commentById.getAddedAt()).isCloseTo(TODAY, 1000);
    assertEquals(user, commentById.getAddedBy());
    assertEquals(txt, commentById.getText());
    Comment comment2 = TaskModelProvider.getFactory().newComment();
    ((InternalComment) comment2).setAddedAt(new Date());
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Master");
    ((InternalComment) comment2).setAddedBy(user2);
    ((InternalComment) comment2).setText(txt + "asdf");
    Long commentId2 = taskService.addComment(taskSum.getId(), comment2);
    assertNotNull(commentId2);
    assertTrue(commentId2.longValue() > 0l);
    assertNotEquals(commentId, commentId2);
    Comment commentById2 = taskService.getCommentById(commentId2.longValue());
    assertNotNull(commentById2);
    assertNotEquals(commentById, commentById2);
    List<Comment> allCommentList = taskService.getAllCommentsByTaskId(taskSum.getId());
    assertEquals(2, allCommentList.size());
    // check id
    assertEquals(commentId, allCommentList.get(0).getId());
    assertEquals(commentId2, allCommentList.get(1).getId());
    taskService.deleteComment(taskSum.getId(), commentId2);
    assertFalse(taskService.getAllCommentsByTaskId(taskSum.getId()).isEmpty());
    // one item
    allCommentList = taskService.getAllCommentsByTaskId(taskSum.getId());
    assertEquals(1, allCommentList.size());
    taskService.deleteComment(taskSum.getId(), commentId);
    assertTrue(taskService.getAllCommentsByTaskId(taskSum.getId()).isEmpty());
}
Also used : InternalComment(org.kie.internal.task.api.model.InternalComment) Comment(org.kie.api.task.model.Comment) Task(org.kie.api.task.model.Task) User(org.kie.api.task.model.User) InternalComment(org.kie.internal.task.api.model.InternalComment) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Date(java.util.Date) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) Test(org.junit.Test)

Example 65 with TaskSummary

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

the class TaskCommentTest method testTaskCommentsOrder.

@Test
public void testTaskCommentsOrder() {
    int commentsCount = 50;
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { businessAdministrators = [new User('Bobba Fet')], }),";
    str += "name =  'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader((str)));
    taskService.addTask(task, new HashMap<String, Object>());
    List<TaskSummary> tasks = taskService.getTasksAssignedAsBusinessAdministrator("Bobba Fet", "en-UK");
    TaskSummary taskSum = tasks.get(0);
    final Map<Long, Comment> savedComments = new HashMap<>();
    for (int i = 0; i < commentsCount; i++) {
        Comment comment = TaskModelProvider.getFactory().newComment();
        ((InternalComment) comment).setAddedAt(TODAY);
        User user = TaskModelProvider.getFactory().newUser();
        ((InternalOrganizationalEntity) user).setId("Troll");
        ((InternalComment) comment).setAddedBy(user);
        ((InternalComment) comment).setText("Comment " + i + ".");
        final Long commentId = taskService.addComment(taskSum.getId(), comment);
        assertNotNull(commentId);
        savedComments.put(commentId, comment);
    }
    List<Comment> allCommentList = taskService.getAllCommentsByTaskId(taskSum.getId());
    assertEquals(commentsCount, allCommentList.size());
    Long lastId = 0L;
    for (Comment comment : allCommentList) {
        assertNotNull(comment);
        assertNotNull(comment.getId());
        assertTrue(comment.getId() > lastId);
        Comment savedComment = savedComments.get(comment.getId());
        assertNotNull(savedComment);
        assertNotNull(comment.getAddedAt());
        Assertions.assertThat(comment.getAddedAt()).isCloseTo(TODAY, 1000);
        assertEquals(savedComment.getText(), comment.getText());
        assertEquals("Troll", comment.getAddedBy().getId());
        lastId = comment.getId();
    }
}
Also used : InternalComment(org.kie.internal.task.api.model.InternalComment) Comment(org.kie.api.task.model.Comment) Task(org.kie.api.task.model.Task) User(org.kie.api.task.model.User) HashMap(java.util.HashMap) InternalComment(org.kie.internal.task.api.model.InternalComment) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) Test(org.junit.Test)

Aggregations

TaskSummary (org.kie.api.task.model.TaskSummary)371 Test (org.junit.Test)327 HashMap (java.util.HashMap)132 QueryFilter (org.kie.internal.query.QueryFilter)126 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)100 Task (org.kie.api.task.model.Task)91 ArrayList (java.util.ArrayList)87 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)86 KieSession (org.kie.api.runtime.KieSession)84 TaskService (org.kie.api.task.TaskService)66 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)58 StringReader (java.io.StringReader)55 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)49 QueryContext (org.kie.api.runtime.query.QueryContext)49 Status (org.kie.api.task.model.Status)47 InternalTask (org.kie.internal.task.api.model.InternalTask)47 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)41 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)38 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)36 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)28