Search in sources :

Example 16 with InternalPeopleAssignments

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

the class RoundRobinAssignmentStrategy method getExcludedEntities.

private static List<OrganizationalEntity> getExcludedEntities(Task task, UserInfo userInfo) {
    List<OrganizationalEntity> excluded = ((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners();
    List<OrganizationalEntity> excludedUsers = new ArrayList<>();
    for (OrganizationalEntity entity : excluded) {
        if (entity instanceof Group) {
            userInfo.getMembersForGroup((Group) entity).forEachRemaining(excludedUsers::add);
        }
    }
    excluded.addAll(excludedUsers);
    return excluded;
}
Also used : Group(org.kie.api.task.model.Group) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) ArrayList(java.util.ArrayList)

Example 17 with InternalPeopleAssignments

use of org.kie.internal.task.api.model.InternalPeopleAssignments 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 18 with InternalPeopleAssignments

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

the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskSkipped.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskSkipped() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task.getTaskData()).setSkipable(true);
    InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Administrator");
    ba.add(user);
    assignments.setBusinessAdministrators(ba);
    List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Administrator");
    po.add(user2);
    assignments.setPotentialOwners(po);
    task.setPeopleAssignments(assignments);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    taskService.skip(taskId, "Administrator");
    // emails should not be set yet
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    countDownListener.waitTillCompleted();
    // no email should ne sent as task was completed before deadline was triggered
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    task = (InternalTask) taskService.getTaskById(taskId);
    assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Obsolete);
    assertThat(task.getDeadlines().getStartDeadlines().size()).isEqualTo(0);
    assertThat(task.getDeadlines().getEndDeadlines().size()).isEqualTo(0);
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Example 19 with InternalPeopleAssignments

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

the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskFailed.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskFailed() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task.getTaskData()).setSkipable(true);
    InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Administrator");
    ba.add(user);
    assignments.setBusinessAdministrators(ba);
    List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Administrator");
    po.add(user2);
    assignments.setPotentialOwners(po);
    task.setPeopleAssignments(assignments);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    taskService.start(taskId, "Administrator");
    taskService.fail(taskId, "Administrator", null);
    // emails should not be set yet
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    countDownListener.waitTillCompleted();
    // no email should ne sent as task was completed before deadline was triggered
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    task = (InternalTask) taskService.getTaskById(taskId);
    assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Failed);
    assertThat(task.getDeadlines().getStartDeadlines().size()).isEqualTo(0);
    assertThat(task.getDeadlines().getEndDeadlines().size()).isEqualTo(0);
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Example 20 with InternalPeopleAssignments

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

the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskExited.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskExited() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task.getTaskData()).setSkipable(true);
    InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Administrator");
    ba.add(user);
    assignments.setBusinessAdministrators(ba);
    List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Administrator");
    po.add(user2);
    assignments.setPotentialOwners(po);
    task.setPeopleAssignments(assignments);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    taskService.exit(taskId, "Administrator");
    // emails should not be set yet
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    countDownListener.waitTillCompleted();
    // no email should ne sent as task was completed before deadline was triggered
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    task = (InternalTask) taskService.getTaskById(taskId);
    assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Exited);
    assertThat(task.getDeadlines().getStartDeadlines().size()).isEqualTo(0);
    assertThat(task.getDeadlines().getEndDeadlines().size()).isEqualTo(0);
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Aggregations

InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)29 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)27 InternalTask (org.kie.internal.task.api.model.InternalTask)20 User (org.kie.api.task.model.User)19 Test (org.junit.Test)18 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)17 ArrayList (java.util.ArrayList)15 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)15 InputStreamReader (java.io.InputStreamReader)10 Reader (java.io.Reader)10 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)10 ContentData (org.kie.internal.task.api.model.ContentData)10 InternalContent (org.kie.internal.task.api.model.InternalContent)10 Task (org.kie.api.task.model.Task)9 HashMap (java.util.HashMap)7 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)6 Date (java.util.Date)5 WorkItem (org.drools.core.process.instance.WorkItem)5 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)5 Group (org.kie.api.task.model.Group)4