use of org.kie.api.task.model.Task 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());
}
use of org.kie.api.task.model.Task 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();
}
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class TaskContentTest method testTaskContent.
@Test
public void testTaskContent() throws Exception {
String userId = "Bobba Fet";
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { businessAdministrators = [new User('" + userId + "')], }),";
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();
Map<String, Object> outputParams = new HashMap<String, Object>();
outputParams.put("str", "str");
outputParams.put("int", new Integer(23));
try {
taskService.addOutputContentFromUser(task.getId(), "Jabba Hutt", outputParams);
fail("This should not have succeeded (Jabba doesn't have permissions)");
} catch (Exception e) {
// do nothing
}
long contentId = taskService.addOutputContentFromUser(task.getId(), userId, outputParams);
Map<String, Object> gotOutputParams = taskService.getOutputContentMapForUser(taskId, userId);
for (Entry<String, Object> origEntry : outputParams.entrySet()) {
String key = origEntry.getKey();
assertEquals("Entry: " + key, origEntry.getValue(), gotOutputParams.get(key));
}
try {
taskService.getOutputContentMapForUser(taskId, "Jabba Hutt");
fail("This should not have succeeded (Jabba doesn't have permissions)");
} catch (Exception e) {
// do nothing
}
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class TaskQueryServiceBaseTest method testGetTasksAssignedAsPotentialOwnerCheckSubject.
@Test
public void testGetTasksAssignedAsPotentialOwnerCheckSubject() {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { subject = 'test subject', priority = 55, taskData = (with( new TaskData()) {skipable=true } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ],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>());
List<String> groupIds = new ArrayList<String>();
groupIds.add("Crusaders");
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", groupIds);
assertEquals(1, tasks.size());
assertEquals("Bobba Fet", tasks.get(0).getActualOwnerId());
assertEquals(true, tasks.get(0).isSkipable());
assertEquals("test subject", tasks.get(0).getSubject());
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class TaskQueryServiceBaseTest method testGetTasksAssignedAsPotentialOwnerWithExcluded.
@Test
public void testGetTasksAssignedAsPotentialOwnerWithExcluded() {
// 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') ], excludedOwners = [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>());
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", "en-UK");
assertEquals(1, tasks.size());
tasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK");
assertEquals(0, tasks.size());
}
Aggregations