Search in sources :

Example 66 with Message

use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.

the class ForumTest method testNewThread.

@Test
public void testNewThread() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = getForumUriBuilder().path("threads").queryParam("authorKey", id1.getKey()).queryParam("title", "New thread").queryParam("body", "A very interesting thread").build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    MessageVO thread = conn.parse(response, MessageVO.class);
    assertNotNull(thread);
    assertNotNull(thread.getKey());
    assertEquals(thread.getForumKey(), forum.getKey());
    assertEquals(thread.getAuthorKey(), id1.getKey());
    // really saved?
    boolean saved = false;
    ForumManager fm = ForumManager.getInstance();
    List<Message> allMessages = fm.getMessagesByForum(forum);
    for (Message message : allMessages) {
        if (message.getKey().equals(thread.getKey())) {
            saved = true;
        }
    }
    assertTrue(saved);
    conn.shutdown();
}
Also used : Message(org.olat.modules.fo.Message) ForumManager(org.olat.modules.fo.manager.ForumManager) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) MessageVO(org.olat.modules.fo.restapi.MessageVO) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 67 with Message

use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.

the class ForumTest method testNewMessage.

@Test
public void testNewMessage() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = getForumUriBuilder().path("posts").path(m1.getKey().toString()).queryParam("authorKey", id1.getKey()).queryParam("title", "New message").queryParam("body", "A very interesting response in Thread-1").build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    MessageVO message = conn.parse(response, MessageVO.class);
    assertNotNull(message);
    assertNotNull(message.getKey());
    assertEquals(message.getForumKey(), forum.getKey());
    assertEquals(message.getAuthorKey(), id1.getKey());
    assertEquals(message.getParentKey(), m1.getKey());
    // really saved?
    boolean saved = false;
    ForumManager fm = ForumManager.getInstance();
    List<Message> allMessages = fm.getMessagesByForum(forum);
    for (Message msg : allMessages) {
        if (msg.getKey().equals(message.getKey())) {
            saved = true;
        }
    }
    assertTrue(saved);
    conn.shutdown();
}
Also used : Message(org.olat.modules.fo.Message) ForumManager(org.olat.modules.fo.manager.ForumManager) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) MessageVO(org.olat.modules.fo.restapi.MessageVO) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 68 with Message

use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.

the class SelectThreadStepForm method loadModel.

private void loadModel() {
    Identity identity = guestOnly ? null : getIdentity();
    Message messageToMove = (Message) getFromRunContext(SendMailStepForm.MESSAGE_TO_MOVE);
    messageToMove = messageToMove.getThreadtop() == null ? messageToMove : messageToMove.getThreadtop();
    List<ForumThread> threads = forumManager.getForumThreads(forum, identity);
    if (!foCallback.mayEditMessageAsModerator()) {
        for (Iterator<ForumThread> threadIt = threads.iterator(); threadIt.hasNext(); ) {
            ForumThread next = threadIt.next();
            if (Status.getStatus(next.getStatusCode()).isHidden()) {
                threadIt.remove();
            } else if (messageToMove.getKey().equals(next.getKey())) {
                threadIt.remove();
            }
        }
    }
    threadTableModel.setObjects(threads);
    threadTableModel.sort(new SortKey(ThreadListCols.thread.name(), true));
    threadTable.reloadData();
    threadTable.reset();
}
Also used : Message(org.olat.modules.fo.Message) ForumThread(org.olat.modules.fo.model.ForumThread) SortKey(org.olat.core.commons.persistence.SortKey) Identity(org.olat.core.id.Identity)

Example 69 with Message

use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.

the class ForumManager method moveMessageToAnotherForum.

/**
 * Move single message to another forum.
 *
 * @param msg the OLD parent message
 * @param topMsg the NEW top message
 * @return the message
 */
public Message moveMessageToAnotherForum(Message msg, Forum forum, Message topMsg) {
    Message targetThread = null;
    if (topMsg != null) {
        targetThread = topMsg.getThreadtop();
        if (targetThread == null) {
            targetThread = topMsg;
        }
        targetThread = getMessageById(targetThread.getKey());
    }
    final Message oldParent = getMessageById(msg.getKey());
    // one has to set a new parent for all children of the moved message
    Message newParent = persistMessageInAnotherLocation(oldParent, forum, targetThread, topMsg);
    moveMessageContainer(oldParent.getForum().getKey(), oldParent.getKey(), newParent.getForum().getKey(), newParent.getKey());
    targetThread = targetThread == null ? newParent : targetThread;
    if (hasChildren(oldParent)) {
        moveThreadToAnotherForumRecursively(oldParent, newParent, targetThread);
    }
    deleteMessageRecursion(oldParent.getForum().getKey(), oldParent);
    return newParent;
}
Also used : Message(org.olat.modules.fo.Message)

Example 70 with Message

use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.

the class ForumArchiveManager method addChildren.

private void addChildren(List<Message> messages, MessageNode mn) {
    for (Iterator<Message> iterMsg = messages.iterator(); iterMsg.hasNext(); ) {
        Message msg = iterMsg.next();
        if ((msg.getParent() != null) && (msg.getParent().getKey() == mn.getKey())) {
            MessageNode childNode = new MessageNode(msg);
            mn.addChild(childNode);
            // FIXME:as:c next line is not necessary
            childNode.setParent(mn);
            addChildren(messages, childNode);
        }
    }
}
Also used : Message(org.olat.modules.fo.Message)

Aggregations

Message (org.olat.modules.fo.Message)108 Identity (org.olat.core.id.Identity)18 OLATResourceable (org.olat.core.id.OLATResourceable)16 ErrorEditMessage (org.olat.modules.fo.ui.events.ErrorEditMessage)16 Forum (org.olat.modules.fo.Forum)14 ForumManager (org.olat.modules.fo.manager.ForumManager)12 Date (java.util.Date)8 HttpResponse (org.apache.http.HttpResponse)8 Test (org.junit.Test)8 VFSContainer (org.olat.core.util.vfs.VFSContainer)8 ICourse (org.olat.course.ICourse)8 FOCourseNode (org.olat.course.nodes.FOCourseNode)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 File (java.io.File)6 ArrayList (java.util.ArrayList)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 PublisherData (org.olat.core.commons.services.notifications.PublisherData)5