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