@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);
   }
 }
Ejemplo n.º 2
0
  @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"));
  }