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();
}
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();
}
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();
}
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;
}
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);
}
}
}
Aggregations