@Override public void complete(long taskId, String userId, Map<String, Object> data) { synchronized (ksession) { taskService.complete(taskId, userId, data); } }
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); } }
taskService.complete(taskId, "mary", data);
protected void testCompleteWithContentAndVarListener(TaskLifeCycleEventListener listener) { // 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' })"; ((EventService<TaskLifeCycleEventListener>)taskService).registerTaskEventListener(listener); Map<String, Object> params = new HashMap<String, Object>(); params.put("input", "simple input"); Task task = TaskFactory.evalTask(new StringReader(str)); taskService.addTask(task, params); long taskId = task.getId(); // start task taskService.start(taskId, "Darth Vader"); Task task1 = taskService.getTaskById(taskId); assertEquals(Status.InProgress, task1.getTaskData().getStatus()); assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId()); // complete task with output params = new HashMap<String, Object>(); params.put("content", "content"); taskService.complete(taskId, "Darth Vader", params); }
@Test(timeout = 15000) public void testTaskNotStartedReassign() throws Exception { Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithMultipleReassignment)); Map<String, Object> vars = new HashMap<String, Object>(); vars.put("now", new Date()); Task task = (InternalTask) TaskFactory.evalTask(reader, vars); Environment environment = EnvironmentFactory.newEnvironment(); Map<String, Object> inputVars = new HashMap<String, Object>(); inputVars.put("NotStartedReassign", "[users:Tony Stark,Bobba Fet,Jabba Hutt|groups:]@[2s]"); ((InternalTask) task).setDeadlines(HumanTaskHandlerHelper.setDeadlines(inputVars, Collections.emptyList(), environment)); taskService.addTask(task, inputVars); CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, true, false); addCountDownListner(countDownListener); long taskId = task.getId(); String []owners = new String[] { "Tony Stark", "Bobba Fet", "Jabba Hutt" }; for(String owner : owners) { countDownListener.reset(1); taskService.claim(taskId, owner); task = taskService.getTaskById(taskId); assertThat(task.getTaskData().getActualOwner().getId()).isEqualTo(owner); countDownListener.waitTillCompleted(); task = taskService.getTaskById(taskId); assertThat(task.getTaskData().getActualOwner()).as("Task was not reclaimed").isNull(); } taskService.claim(taskId, "Bobba Fet"); taskService.start(taskId, "Bobba Fet"); taskService.complete(taskId, "Bobba Fet", Collections.<String, Object>emptyMap()); }
protected void completeTask(Task task) { taskService.start(task.getId(), task.getTaskData().getActualOwner().getId()); taskService.complete(task.getId(), task.getTaskData().getActualOwner().getId(), new HashMap<String,Object>()); }
taskService.complete(taskId, "Bobba Fet", Collections.<String, Object>emptyMap());
taskService.complete(taskId, "Darth Vader", null);
params.put("response", "let's do it"); params.put("feedback", "ok"); taskService.complete(taskId, "Darth Vader", params);
taskService.complete(taskId, "Darth Vader", params);
@Test public void testCompleteAlreadyCompleted() { // 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(); 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()); try { taskService.complete(taskId, "Darth Vader", null); Fail.fail("Task should already be completed and thus can't be completed again"); } catch (PermissionDeniedException e) { // expected } }
@Test public void testCompleteWithResults() { // 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(); // 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()); Map<String, Object> params = new HashMap<String, Object>(); params.put("content", "content"); taskService.complete(taskId, "Darth Vader", params); Task task2 = taskService.getTaskById(taskId); assertEquals(AccessType.Inline, ((InternalTaskData) task2.getTaskData()).getOutputAccessType()); assertEquals("java.util.HashMap", task2.getTaskData().getOutputType()); long contentId = task2.getTaskData().getOutputContentId(); assertTrue(contentId != -1); Content content = taskService.getContentById(contentId); Map<String, Object> unmarshalledObject = (Map<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), null); assertEquals("content", unmarshalledObject.get("content")); }
assertEquals(0, outputs.size()); taskService.complete(taskId, "Darth Vader", null);
@Test public void testCompleteWithRestrictedGroups() { // 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('analyst'), 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>()); long taskId = task.getId(); List<OrganizationalEntity> potOwners = task.getPeopleAssignments().getPotentialOwners(); assertNotNull(potOwners); assertEquals(1, potOwners.size()); assertEquals("Crusaders", potOwners.get(0).getId()); // 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()); }
@Test public void testComplete() { // 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(); // 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()); }
taskService.complete(child1TaskId, "Darth Vader", null);
@Test public void testCompleteWithIncorrectUser() { // 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(); // 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()); // Should not complete as wrong user PermissionDeniedException denied = null; try { taskService.complete(taskId, "Bobba Fet", null); } catch (PermissionDeniedException e) { denied = e; } assertNotNull("Should get permissed denied exception", denied); Task task2 = taskService.getTaskById(taskId); assertEquals(Status.InProgress, task2.getTaskData().getStatus()); assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId()); }
taskService.complete(taskId, "Darth Vader", null);
@Test public void testResumeFromCompleted() { 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(); taskService.claim(taskId, "Darth Vader"); Task task1 = taskService.getTaskById(taskId); assertEquals(Status.Reserved, task1.getTaskData().getStatus()); assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId()); taskService.start(taskId, "Darth Vader"); task1 = taskService.getTaskById(taskId); assertEquals(Status.InProgress, task1.getTaskData().getStatus()); assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId()); taskService.complete(taskId, "Darth Vader", null); task1 = taskService.getTaskById(taskId); assertEquals(Status.Completed, task1.getTaskData().getStatus()); assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId()); assertThatExceptionOfType(PermissionDeniedException.class).isThrownBy(() -> { taskService.resume(taskId, "Darth Vader"); }) .withMessageContaining("was unable to execute operation 'Resume' on task id"); task1 = taskService.getTaskById(taskId); assertEquals(Status.Completed, task1.getTaskData().getStatus()); assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId()); }