Search in sources :

Example 51 with User

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

the class CommentNotificationEventListenerTest method testCollectOrgEntitiesByRole.

@Test
public void testCollectOrgEntitiesByRole() {
    CommentNotificationEventListener listener = new CommentNotificationEventListener();
    List<String> mentionedRoles = new ArrayList<>();
    mentionedRoles.add("owner");
    mentionedRoles.add("manager");
    CommentInstanceImpl comment = new CommentInstanceImpl("john", "simple comment for @owner and @manager", new ArrayList<>());
    CaseFileInstance caseFile = buildCaseFile(mentionedRoles);
    CaseCommentEvent event = new CaseCommentEvent("john", caseFile.getCaseId(), caseFile, comment);
    StringBuilder commentContent = new StringBuilder(comment.getComment());
    Set<OrganizationalEntity> collected = listener.collectOrgEntitiesByRole(mentionedRoles, event, commentContent);
    assertThat(collected).hasSize(2);
    assertThat(collected).allMatch(item -> item instanceof User);
    assertThat(commentContent.toString()).isEqualTo("simple comment for john and mary");
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) CaseCommentEvent(org.jbpm.casemgmt.api.event.CaseCommentEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 52 with User

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

the class CommentNotificationEventListenerTest method testCollectOrgEntitiesByRoleNotExistingRole.

@Test
public void testCollectOrgEntitiesByRoleNotExistingRole() {
    CommentNotificationEventListener listener = new CommentNotificationEventListener();
    List<String> mentionedRoles = new ArrayList<>();
    mentionedRoles.add("owner");
    mentionedRoles.add("manager");
    CommentInstanceImpl comment = new CommentInstanceImpl("john", "simple comment for @owner and @manager", new ArrayList<>());
    CaseFileInstance caseFile = buildCaseFile(mentionedRoles);
    CaseCommentEvent event = new CaseCommentEvent("john", caseFile.getCaseId(), caseFile, comment);
    // add additional role that is not in case file
    mentionedRoles.add("notexisting");
    StringBuilder commentContent = new StringBuilder(comment.getComment());
    Set<OrganizationalEntity> collected = listener.collectOrgEntitiesByRole(mentionedRoles, event, commentContent);
    assertThat(collected).hasSize(2);
    assertThat(collected).allMatch(item -> item instanceof User);
    assertThat(commentContent.toString()).isEqualTo("simple comment for john and mary");
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) CaseCommentEvent(org.jbpm.casemgmt.api.event.CaseCommentEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 53 with User

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

the class LifeCycleBaseTest method testCompleteWithComments.

@Test
public void testCompleteWithComments() {
    // 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();
    List<Comment> comments = taskService.getAllCommentsByTaskId(taskId);
    assertNotNull(comments);
    assertEquals(0, comments.size());
    User user = createUser("Bobba Fet");
    Comment comment = TaskModelProvider.getFactory().newComment();
    ((InternalComment) comment).setAddedAt(new Date());
    ((InternalComment) comment).setAddedBy(user);
    ((InternalComment) comment).setText("Simple test comment");
    taskService.addComment(taskId, comment);
    comments = taskService.getAllCommentsByTaskId(taskId);
    assertNotNull(comments);
    assertEquals(1, comments.size());
    // Go straight from Ready to Inprogress
    taskService.start(taskId, "Darth Vader");
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(Status.InProgress, task1.getTaskData().getStatus());
    assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
    // Check is Complete
    taskService.complete(taskId, "Darth Vader", null);
    Task task2 = taskService.getTaskById(taskId);
    assertEquals(Status.Completed, task2.getTaskData().getStatus());
    assertEquals("Darth Vader", task2.getTaskData().getActualOwner().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) InternalTask(org.kie.internal.task.api.model.InternalTask) User(org.kie.api.task.model.User) InternalComment(org.kie.internal.task.api.model.InternalComment) StringReader(java.io.StringReader) Date(java.util.Date) Test(org.junit.Test)

Example 54 with User

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

the class LifeCycleBaseTest method testRemoveNotInRecipientList.

// 
// /**
// * The issue here has to do with the fact that hibernate uses lazy initialization.
// * Actually, what's happening is that one of the collections retrieved isn't retrieved "for update",
// * so that the proxy collection instance retrieved can't be updated.
// * (The collection instance can't be updated because hibernate doesn't allowed that unless the collection
// * has been retrieved "for update" -- which is actually logical.)
// *
// * This, of course, only happens when using the LocalTaskService. Why? Because the LocalTaskService
// * "shares" a persistence context with the taskService. If I spent another half-hour, I could explain
// * why that causes this particular problem.
// * Regardless,  I can't stress enough how much that complicates the situation here, and, especially,
// * why that makes the LocalTaskService a significantly different variant of the TaskService
// * than the HornetQ, Mina or other transport medium based instances.
// */
// public void FIXME_testRegisterRemove() throws Exception {
// Map <String, Object> vars = fillVariables();
// 
// 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') ], }),";
// str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })";
// 
// 
// Task task = ( Task )  TaskFactory.eval( new StringReader( str ), vars );
// taskService.addTask( task, null );
// 
// long taskId = task.getId();
// 
// taskService.register(taskId, "Bobba Fet");
// 
// 
// Task task1 = taskService.getTaskById(taskId);
// List<OrganizationalEntity> myRecipientTasks = task1.getPeopleAssignments().getRecipients();
// 
// assertNotNull(myRecipientTasks);
// assertEquals(1, myRecipientTasks.size());
// assertTrue(task1.getPeopleAssignments().getRecipients().contains("Bobba Fet"));
// 
// taskService.remove(taskId, "Bobba Fet");
// 
// Task task2 = taskService.getTaskById( taskId );
// assertFalse(task2.getPeopleAssignments().getRecipients().contains("Bobba Fet"));
// }
// 
@Test
public void testRemoveNotInRecipientList() {
    // One potential owner, should go straight to state Reserved
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { status = Status.Ready } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ],businessAdministrators = [ new User('Administrator') ],";
    str += "recipients = [new User('Bobba Fet') ] }),";
    str += "name = 'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str), null);
    // We need to add the Admin if we don't initialize the task
    if (task.getPeopleAssignments() != null && task.getPeopleAssignments().getBusinessAdministrators() != null) {
        List<OrganizationalEntity> businessAdmins = new ArrayList<OrganizationalEntity>();
        User user = createUser("Administrator");
        businessAdmins.add(user);
        businessAdmins.addAll(task.getPeopleAssignments().getBusinessAdministrators());
        ((InternalPeopleAssignments) task.getPeopleAssignments()).setBusinessAdministrators(businessAdmins);
    }
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    // Do nominate and fail due to Ready status
    List<TaskSummary> myRecipientTasks = taskService.getTasksAssignedAsRecipient("Jabba Hutt");
    assertNotNull(myRecipientTasks);
    assertEquals(0, myRecipientTasks.size());
    List<TaskSummary> myPotentialTasks = taskService.getTasksAssignedAsPotentialOwner("Jabba Hutt", "en-UK");
    assertNotNull(myPotentialTasks);
    assertEquals(0, myPotentialTasks.size());
    try {
        taskService.remove(taskId, "Jabba Hutt");
        fail("Shouldn't be successful");
    } catch (RuntimeException e) {
    // expected
    }
    // shouldn't affect the assignments
    Task task1 = taskService.getTaskById(taskId);
    User user = createUser("Bobba Fet");
    assertTrue(((InternalPeopleAssignments) task1.getPeopleAssignments()).getRecipients().contains(user));
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) ArrayList(java.util.ArrayList) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) Test(org.junit.Test)

Example 55 with User

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

the class LifeCycleBaseTest method testForwardFromReserved.

@Test
public void testForwardFromReserved() throws Exception {
    // 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();
    // Claim and Reserved
    taskService.claim(taskId, "Darth Vader");
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(Status.Reserved, task1.getTaskData().getStatus());
    assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
    // Check is Delegated
    taskService.forward(taskId, "Darth Vader", "Tony Stark");
    Task task2 = taskService.getTaskById(taskId);
    User user = createUser("Darth Vader");
    assertFalse(task2.getPeopleAssignments().getPotentialOwners().contains(user));
    user = createUser("Tony Stark");
    assertTrue(task2.getPeopleAssignments().getPotentialOwners().contains(user));
    assertNull(task2.getTaskData().getActualOwner());
    assertEquals(Status.Ready, task2.getTaskData().getStatus());
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) User(org.kie.api.task.model.User) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

User (org.kie.api.task.model.User)83 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)52 Test (org.junit.Test)44 InternalTask (org.kie.internal.task.api.model.InternalTask)38 ArrayList (java.util.ArrayList)35 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)33 Task (org.kie.api.task.model.Task)31 Group (org.kie.api.task.model.Group)27 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)27 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)20 StringReader (java.io.StringReader)17 HashMap (java.util.HashMap)14 InputStreamReader (java.io.InputStreamReader)11 Reader (java.io.Reader)11 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)11 ContentData (org.kie.internal.task.api.model.ContentData)11 InternalContent (org.kie.internal.task.api.model.InternalContent)11 Date (java.util.Date)10 List (java.util.List)10 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)10