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;
}
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));
}
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);
}
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);
}
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);
}
Aggregations