protected long createAndAssertTask(TaskFluent tf, String expectedOwner) { Task task = tf.getTask(); taskService.addTask(task, data); long taskId = task.getId(); assertEquals("Owner mismatch",expectedOwner,taskService.getTaskById(taskId).getTaskData().getActualOwner().getId()); return taskId; }
@Override public <T> T execute(Command<T> command) { synchronized (ksession) { return taskService.execute(command); } }
@Override public void executeReminderForTask( long taskId, String initiator ) { synchronized( ksession ) { taskService.executeReminderForTask(taskId, initiator); } }
@Override public void afterProcessCompleted(ProcessCompletedEvent event) { List<Status> statuses = new ArrayList<Status>(); statuses.add(Status.Error); statuses.add(Status.Failed); statuses.add(Status.Obsolete); statuses.add(Status.Suspended); statuses.add(Status.Completed); statuses.add(Status.Exited); List<TaskSummary> completedTasksByProcessId = ((InternalTaskService)taskService).execute(new GetTasksForProcessCommand(event.getProcessInstance().getId(), statuses, "en-UK")); // archive and remove taskService.archiveTasks(completedTasksByProcessId); taskService.removeTasks(completedTasksByProcessId); }
protected void completeTask(long taskId, long delay) { Task task = taskService.getTaskById(taskId); String owner = task.getTaskData().getActualOwner().getId(); logger.debug("Starting task {} with user {}",taskId,owner); taskService.start(taskId, owner); if (delay > 0) { try { Thread.sleep(delay); } catch (InterruptedException e) { // swallowing this exception } } taskService.complete(taskId, owner, data); } }
@Test public void testSkipFromReserved() { String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { skipable = true} ), "; 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(); // Go straight from Ready taskService.claim(taskId, "Darth Vader"); // Check is Complete taskService.skip(taskId, "Darth Vader"); taskService.getTaskById(taskId); Task task1 = taskService.getTaskById(taskId); assertEquals(Status.Obsolete, task1.getTaskData().getStatus()); assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId()); }
@Test public void testGetTasksAssignedAsPotentialOwnerWithUserGroupsMultipleUsersExcluded() { String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), "; str += " peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new Group('Crusaders'), ], excludedOwners = [new User('Luke Cage'), 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<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Luke Cage", "en-UK"); assertEquals(0, tasks.size()); tasks = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", "en-UK"); assertEquals(0, tasks.size()); }
@Test public void testExitFromReady() { String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { skipable = false} ), "; 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(); task = taskService.getTaskById(taskId); assertEquals(Status.Ready, task.getTaskData().getStatus()); taskService.exit(taskId, "Administrator"); Task task1 = taskService.getTaskById(taskId); assertEquals(Status.Exited, task1.getTaskData().getStatus()); }
@Test public void testGetTasksAssignedAsBusinessAdministratorWithUserLangOneTask() { // 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() ) { 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"); assertEquals(1, tasks.size()); }
@Test public void testActivate() { String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { "; str += "businessAdministrators = [ new User('Darth Vader') ] } ),"; 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(); taskService.activate(taskId, "Darth Vader"); Task task1 = taskService.getTaskById(taskId); assertEquals(task1.getTaskData().getStatus(), Status.Ready); //When we are not using remoting the object is the same //assertTrue(task1.equals(task)); //When we use remoting this will be false //assertFalse(task1.equals(task)); }
@Test public void testGetTasksAssignedByGroupWithGroupLangOneTask() { // 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 Group('Crusaders') ],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.getTasksAssignedByGroup("Crusaders"); assertEquals(1, tasks.size()); }
@Test public void testAssignmentsWhenNoRuleWasFired() throws Exception { String str = "(with (new Task()) { priority = 51, taskData = (with( new TaskData()) { } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Ben Dover') ],businessAdministrators = [ new User('Administrator') ],}),"; str += "name = 'Not Bobbas tasks' })"; Task task = TaskFactory.evalTask(new StringReader(str)); assertPotentialOwners(task, 1); long taskId = taskService.addTask(task, Collections.emptyMap()); task = taskService.getTaskById(taskId); assertPotentialOwners(task, 0); User actualOwner = task.getTaskData().getActualOwner(); Assertions.assertThat(actualOwner).isNull(); }
@Test public void testGetTasksByProcessInstanceId() { // One potential owner, should go straight to state Reserved String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) {processInstanceId = 99 } ), "; 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>()); str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) {processInstanceId = 100 } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet')],businessAdministrators = [ new User('Administrator') ], }),"; str += "name = 'Another name' })"; task = TaskFactory.evalTask(new StringReader(str)); taskService.addTask(task, new HashMap<String, Object>()); List<Long> tasks = taskService.getTasksByProcessInstanceId(99L); assertEquals(1, tasks.size()); }
@Test public void testDelegateFromReady() 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(); // Check is Delegated taskService.delegate(taskId, "Darth Vader", "Tony Stark"); Task task2 = taskService.getTaskById(taskId); User user = createUser("Darth Vader"); assertTrue(task2.getPeopleAssignments().getPotentialOwners().contains(user)); user = createUser("Tony Stark"); assertTrue(task2.getPeopleAssignments().getPotentialOwners().contains(user)); assertEquals("Tony Stark", task2.getTaskData().getActualOwner().getId()); // this was checking for ready, but it should be reserved.. it was an old bug assertEquals(Status.Reserved, task2.getTaskData().getStatus()); }
protected long createAndAssertTask(String taskExpression, String actualOwner, int expectedPotentialOwners, String... expectedPotentialOwnerNames) { Task task = TaskFactory.evalTask(new StringReader(taskExpression)); assertPotentialOwners(task, expectedPotentialOwners); long taskId = taskService.addTask(task, Collections.emptyMap()); task = taskService.getTaskById(taskId); assertPotentialOwners(task, expectedPotentialOwners, expectedPotentialOwnerNames); assertActualOwner(task, actualOwner); return taskId; }
@Test public void testExpirationDate() { 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"); assertEquals(1, tasks.size()); TaskSummary taskSum = tasks.get(0); assertNull(taskService.getExpirationDate(taskSum.getId())); taskService.setExpirationDate(taskSum.getId(), TODAY); Date date = taskService.getExpirationDate(taskSum.getId()); assertNotNull(date); Assertions.assertThat(date).isCloseTo(TODAY, 1000); } }
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ],businessAdministrators = [ new User('Administrator') ], }),"; str += "name = '"+taskName+"' })"; Task task = TaskFactory.evalTask(new StringReader(str)); List<I18NText> names = new ArrayList<I18NText>(); I18NText text = TaskModelProvider.getFactory().newI18NText(); names.add(text); ((InternalTask)task).setNames(names); taskService.addTask(task, new HashMap<String, Object>()); List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", "en-UK"); assertEquals(1, tasks.size()); assertEquals(taskName, tasks.get(0).getName()); Task newTask = taskService.getTaskById(tasks.get(0).getId()); List<I18NText> updatedNames = new ArrayList<I18NText>(); I18NText updatedName = TaskModelProvider.getFactory().newI18NText(); ((InternalI18NText) updatedName).setLanguage(newTask.getNames().get(0).getLanguage()); ((InternalI18NText) updatedName).setText("New task name"); updatedNames.add(updatedName); taskService.setTaskNames(newTask.getId(), updatedNames); List<TaskSummary> newTasks = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", "en-UK"); assertEquals(1, newTasks.size()); newTask = taskService.getTaskById(newTasks.get(0).getId()); assertEquals("New task name", newTask.getNames().get(0).getText());
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"); 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()); 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()); taskService.deleteComment(taskSum.getId(), commentId2); assertFalse(taskService.getAllCommentsByTaskId(taskSum.getId()).isEmpty());
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"); ((InternalContent)content).setContent(ContentMarshallerHelper.marshallContent(task, "This is my first inline document", null)); long attachId = taskService.addAttachment(taskSum.getId(), attach, content); Assert.assertNotEquals(0, attachId); Attachment attachmentById = taskService.getAttachmentById(attachId); Assert.assertNotNull(attachmentById); attachId = taskService.addAttachment(taskSum.getId(), attach2, content2); Assert.assertNotEquals(0, attachId); attachmentById = taskService.getAttachmentById(attachId); Assert.assertNotNull(attachmentById); List<Attachment> allAttachmentsByTaskId = taskService.getAllAttachmentsByTaskId(taskSum.getId()); Content firstAttachContent = taskService.getContentById(firstAttachContentId); String firstDocString = (String)ContentMarshallerHelper.unmarshall(firstAttachContent.getContent(), null); assertEquals("This is my first inline document", firstDocString); Content secondAttachContent = taskService.getContentById(secondAttachContentId); String secondDocString = (String)ContentMarshallerHelper.unmarshall(secondAttachContent.getContent(), null); assertEquals("This is my second inline document", secondDocString);
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); ((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()); Assertions.assertThat(comment.getAddedAt()).isCloseTo(TODAY, 1000); assertEquals(savedComment.getText(), comment.getText()); assertEquals("Troll", comment.getAddedBy().getId()); lastId = comment.getId();