protected void getAllTasks() { error = null; errorMessage = null; userTasks = new ArrayList<>(); CoreSession coreSession = getCoreSession(); boolean filterTrashDocs = getFilterDocumentsInTrash(); NuxeoPrincipal pal = (NuxeoPrincipal) coreSession.getPrincipal(); TaskService taskService = Framework.getService(TaskService.class); List<Task> tasks = taskService.getAllCurrentTaskInstances(coreSession, getSortInfos()); if (tasks != null) { for (Task task : tasks) { List<String> targetDocumentsIds = task.getTargetDocumentsIds(); boolean hasTargetDocuments = targetDocumentsIds != null && !targetDocumentsIds.isEmpty(); if (task.hasEnded() || task.isCancelled() || !hasTargetDocuments) { continue; } DocumentModel doc = taskService.getTargetDocumentModel(task, coreSession); if (doc != null) { if (filterTrashDocs && LifeCycleConstants.DELETED_STATE.equals(doc.getCurrentLifeCycleState())) { continue; } else { userTasks.add(new DashBoardItemImpl(task, doc, getLocale())); } } else { log.warn( String.format( "User '%s' has a task of type '%s' on a missing or deleted document", pal.getName(), task.getName())); } } } }
@Override public void startModeration( CoreSession session, DocumentModel doc, String commentID, ArrayList<String> moderators) { TaskService taskService = Framework.getService(TaskService.class); if (moderators == null || moderators.isEmpty()) { throw new NuxeoException("No moderators defined"); } Map<String, String> vars = new HashMap<String, String>(); vars.put(CommentsConstants.COMMENT_ID, commentID); vars.put(Task.TaskVariableName.needi18n.name(), "true"); vars.put(Task.TaskVariableName.taskType.name(), CommentConstants.COMMENT_TASK_TYPE); vars.put(CreateTask.OperationTaskVariableName.createdFromCreateTaskOperation.name(), "false"); vars.put( CreateTask.OperationTaskVariableName.acceptOperationChain.name(), CommentsConstants.ACCEPT_CHAIN_NAME); vars.put( CreateTask.OperationTaskVariableName.rejectOperationChain.name(), CommentsConstants.REJECT_CHAIN_NAME); taskService.createTask( session, (NuxeoPrincipal) session.getPrincipal(), doc, CommentsConstants.MODERATION_DIRECTIVE_NAME, moderators, false, null, null, null, vars, null); }
@Override public void rejectComment(CoreSession session, DocumentModel doc, String commentId) { TaskService taskService = Framework.getService(TaskService.class); Task moderationTask = getModerationTask(taskService, session, doc, commentId); if (moderationTask == null) { session.followTransition(new IdRef(commentId), CommentsConstants.REJECT_STATE); } else { taskService.rejectTask( session, (NuxeoPrincipal) session.getPrincipal(), moderationTask, null); } }
@Test public void testCreateSingleTaskChainWithoutActors() throws Exception { OperationContext ctx = new OperationContext(coreSession); ctx.setInput(document); List<Task> tasks = taskService.getTaskInstances(document, (NuxeoPrincipal) null, coreSession); assertNotNull(tasks); assertEquals(0, tasks.size()); automationService.run(ctx, "createSingleTaskChainWithoutActors"); tasks = taskService.getTaskInstances(document, (NuxeoPrincipal) null, coreSession); assertEquals(0, tasks.size()); }
@Override public void approveComent(CoreSession session, DocumentModel doc, String commentId) { TaskService taskService = Framework.getService(TaskService.class); Task moderationTask = getModerationTask(taskService, session, doc, commentId); if (moderationTask == null) { session.followTransition( new IdRef(commentId), CommentsConstants.TRANSITION_TO_PUBLISHED_STATE); } else { taskService.acceptTask( session, (NuxeoPrincipal) session.getPrincipal(), moderationTask, null); } Map<String, Serializable> eventInfo = new HashMap<String, Serializable>(); eventInfo.put("emailDetails", "test"); notifyEvent(session, CommentsConstants.COMMENT_PUBLISHED, null, null, null, doc); }
@Test public void testCreateSingleTaskAndRunOperationChain() throws Exception { OperationContext ctx = new OperationContext(coreSession); ctx.setInput(document); List<Task> tasks = taskService.getTaskInstances(document, (NuxeoPrincipal) null, coreSession); assertNotNull(tasks); assertEquals(0, tasks.size()); automationService.run(ctx, "createSingleTaskAndRunOperationChain"); tasks = taskService.getTaskInstances(document, (NuxeoPrincipal) null, coreSession); assertEquals(1, tasks.size()); Task task = tasks.get(0); // accept task taskService.acceptTask( coreSession, (NuxeoPrincipal) coreSession.getPrincipal(), task, "ok i'm in"); coreSession.save(); // test task again tasks = taskService.getTaskInstances(document, (NuxeoPrincipal) null, coreSession); // ended tasks are filtered assertEquals(0, tasks.size()); // check document metadata, refetching doc from core document = coreSession.getDocument(document.getRef()); assertEquals("This document has been accepted", document.getPropertyValue("dc:description")); // run another time, and this time reject automationService.run(ctx, "createSingleTaskAndRunOperationChain"); tasks = taskService.getTaskInstances(document, (NuxeoPrincipal) null, coreSession); assertEquals(1, tasks.size()); taskService.rejectTask( coreSession, (NuxeoPrincipal) coreSession.getPrincipal(), tasks.get(0), "i don't agree with what you're saying"); document = coreSession.getDocument(document.getRef()); assertEquals( "This document has been rejected !!!", document.getPropertyValue("dc:description")); }
@Test public void testCreateSingleTaskChain() throws Exception { OperationContext ctx = new OperationContext(coreSession); ctx.setInput(document); List<Task> tasks = taskService.getTaskInstances(document, (NuxeoPrincipal) null, coreSession); assertNotNull(tasks); assertEquals(0, tasks.size()); automationService.run(ctx, "createSingleTaskChain"); tasks = taskService.getTaskInstances(document, (NuxeoPrincipal) null, coreSession); assertEquals(1, tasks.size()); Task task = tasks.get(0); assertEquals("single test task", task.getName()); List<String> pooledActorIds = task.getActors(); assertEquals(3, pooledActorIds.size()); assertTrue(pooledActorIds.contains(SecurityConstants.MEMBERS)); assertTrue(pooledActorIds.contains("myuser")); assertTrue(pooledActorIds.contains(SecurityConstants.ADMINISTRATOR)); List<TaskComment> comments = task.getComments(); assertEquals(1, comments.size()); TaskComment comment = comments.get(0); assertEquals(SecurityConstants.ADMINISTRATOR, comment.getAuthor()); assertEquals("test comment", comment.getText()); Calendar calendar = Calendar.getInstance(); calendar.set(2006, 6, 6, 15, 10, 15); calendar.set(Calendar.MILLISECOND, 0); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); assertEquals(calendar.getTime(), task.getDueDate()); // task status assertTrue(task.isOpened()); assertFalse(task.isCancelled()); assertFalse(task.hasEnded()); assertEquals(6, task.getVariables().size()); assertEquals( document.getRepositoryName(), task.getVariable(TaskService.VariableName.documentRepositoryName.name())); assertEquals(document.getId(), task.getVariable(TaskService.VariableName.documentId.name())); assertEquals("test directive", task.getVariable(TaskService.VariableName.directive.name())); assertEquals( "true", task.getVariable(OperationTaskVariableName.createdFromCreateTaskOperation.name())); assertEquals("true", task.getVariable(TaskService.VariableName.createdFromTaskService.name())); assertEquals(SecurityConstants.ADMINISTRATOR, task.getInitiator()); // accept task taskService.acceptTask( coreSession, (NuxeoPrincipal) coreSession.getPrincipal(), task, "ok i'm in"); coreSession.save(); // test task again tasks = taskService.getTaskInstances(document, (NuxeoPrincipal) null, coreSession); // ended tasks are filtered assertEquals(0, tasks.size()); // check document metadata assertNull(document.getPropertyValue("dc:description")); }
@Test public void testCreateSeveralTasksChain() throws Exception { OperationContext ctx = new OperationContext(coreSession); ctx.setInput(document); List<Task> tasks = taskService.getTaskInstances(document, (NuxeoPrincipal) null, coreSession); assertNotNull(tasks); assertEquals(0, tasks.size()); automationService.run(ctx, "createSeveralTasksChain"); tasks = taskService.getTaskInstances(document, (NuxeoPrincipal) null, coreSession); Collections.sort(tasks, new TaskInstanceComparator()); assertEquals(3, tasks.size()); Task task1 = tasks.get(0); assertEquals("several test tasks", task1.getName()); List<String> pooledActorIds = task1.getActors(); assertEquals(1, pooledActorIds.size()); assertEquals(SecurityConstants.ADMINISTRATOR, pooledActorIds.get(0)); List<TaskComment> comments = task1.getComments(); assertEquals(0, comments.size()); // task status assertTrue(task1.isOpened()); assertFalse(task1.isCancelled()); assertFalse(task1.hasEnded()); assertEquals(5, task1.getVariables().size()); assertEquals( document.getRepositoryName(), task1.getVariable(TaskService.VariableName.documentRepositoryName.name())); assertEquals(document.getId(), task1.getVariable(TaskService.VariableName.documentId.name())); assertNull(task1.getVariable(TaskService.VariableName.directive.name())); assertEquals( "true", task1.getVariable(OperationTaskVariableName.createdFromCreateTaskOperation.name())); assertEquals("true", task1.getVariable(TaskService.VariableName.createdFromTaskService.name())); assertEquals(SecurityConstants.ADMINISTRATOR, task1.getInitiator()); // accept task taskService.acceptTask( coreSession, (NuxeoPrincipal) coreSession.getPrincipal(), task1, "ok i'm in"); coreSession.save(); // test task again tasks = taskService.getTaskInstances(document, (NuxeoPrincipal) null, coreSession); // ended tasks are filtered assertEquals(2, tasks.size()); Collections.sort(tasks, new TaskInstanceComparator()); // check other tasks Task task2 = tasks.get(0); assertEquals("several test tasks", task2.getName()); pooledActorIds = task2.getActors(); assertEquals(1, pooledActorIds.size()); assertEquals(SecurityConstants.MEMBERS, pooledActorIds.get(0)); comments = task2.getComments(); assertEquals(0, comments.size()); // task status assertTrue(task2.isOpened()); assertFalse(task2.isCancelled()); assertFalse(task2.hasEnded()); assertEquals(5, task2.getVariables().size()); assertEquals( document.getRepositoryName(), task2.getVariable(TaskService.VariableName.documentRepositoryName.name())); assertEquals(document.getId(), task2.getVariable(TaskService.VariableName.documentId.name())); assertNull(task2.getVariable(TaskService.VariableName.directive.name())); assertEquals( "true", task2.getVariable(OperationTaskVariableName.createdFromCreateTaskOperation.name())); assertEquals("true", task2.getVariable(TaskService.VariableName.createdFromTaskService.name())); assertEquals(SecurityConstants.ADMINISTRATOR, task2.getInitiator()); Task task3 = tasks.get(1); assertEquals("several test tasks", task3.getName()); pooledActorIds = task3.getActors(); assertEquals(1, pooledActorIds.size()); assertEquals("myuser", pooledActorIds.get(0)); comments = task3.getComments(); assertEquals(0, comments.size()); // task status assertTrue(task3.isOpened()); assertFalse(task3.isCancelled()); assertFalse(task3.hasEnded()); assertEquals(5, task3.getVariables().size()); assertEquals( document.getRepositoryName(), task3.getVariable(TaskService.VariableName.documentRepositoryName.name())); assertEquals(document.getId(), task3.getVariable(TaskService.VariableName.documentId.name())); assertNull(task3.getVariable(TaskService.VariableName.directive.name())); assertEquals( "true", task3.getVariable(OperationTaskVariableName.createdFromCreateTaskOperation.name())); assertEquals("true", task3.getVariable(TaskService.VariableName.createdFromTaskService.name())); assertEquals(SecurityConstants.ADMINISTRATOR, task3.getInitiator()); // check document metadata assertNull(document.getPropertyValue("dc:description")); }