Search in sources :

Example 71 with Message

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

the class ForumManager method getForumThreads.

public List<ForumThread> getForumThreads(Forum forum, Identity identity) {
    StringBuilder sb = new StringBuilder();
    sb.append("select msg ").append(" , (select count(replies.key) from fomessage as replies").append("  where replies.threadtop.key=msg.key and replies.forum.key=:forumKey").append(" ) as numOfMessages").append(" , (select max(replies.lastModified) from fomessage as replies").append("  where replies.threadtop.key=msg.key and replies.forum.key=:forumKey").append(" ) as lastModified");
    if (identity != null) {
        sb.append(" , (select count(read.key) from foreadmessage as read, fomessage as posts").append("  where (posts.threadtop.key=msg.key or posts.key=msg.key) and read.message.key=posts.key and read.identity.key=:identityKey").append(" ) as numOfReadMessages").append(" ,(select count(mark.key) from ").append(MarkImpl.class.getName()).append(" as mark, fomessage as mposts ").append("   where mark.creator.key=:identityKey and mark.resId=:forumKey and (mposts.threadtop.key=msg.key or mposts.key=msg.key)").append("    and mposts.key=cast(mark.resSubPath as long) and mark.resName='Forum'").append(" ) as marks");
    }
    sb.append(" from fomessage as msg ").append(" left join fetch msg.creator as creator").append(" where msg.forum.key=:forumKey and msg.threadtop is null");
    TypedQuery<Object[]> objectsQuery = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("forumKey", forum.getKey());
    if (identity != null) {
        objectsQuery.setParameter("identityKey", identity.getKey());
    }
    List<Object[]> objects = objectsQuery.getResultList();
    List<ForumThread> threadList = new ArrayList<>(objects.size());
    for (Object[] object : objects) {
        Message msg = (Message) object[0];
        Number numOfMessagesLong = (Number) object[1];
        Date lastModified = (Date) object[2];
        int numOfMessages = numOfMessagesLong == null ? 1 : numOfMessagesLong.intValue() + 1;
        String creator = userManager.getUserDisplayName(msg.getCreator());
        ForumThread thread = new ForumThread(msg, creator, lastModified, numOfMessages);
        if (identity != null) {
            Number readMessages = (Number) object[3];
            int numOfReadMessages = readMessages == null ? 0 : readMessages.intValue();
            thread.setNewMessages(numOfMessages - numOfReadMessages);
            Number numOfMarkedMessagesLong = (Number) object[4];
            int numOfMarkedMessages = numOfMarkedMessagesLong == null ? 0 : numOfMarkedMessagesLong.intValue();
            thread.setMarkedMessages(numOfMarkedMessages);
        }
        threadList.add(thread);
    }
    return threadList;
}
Also used : Message(org.olat.modules.fo.Message) ArrayList(java.util.ArrayList) MarkImpl(org.olat.core.commons.services.mark.impl.MarkImpl) Date(java.util.Date) ForumThread(org.olat.modules.fo.model.ForumThread)

Example 72 with Message

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

the class ForumManager method doDeleteForum.

/**
 * deletes all messages belonging to this forum and the forum entry itself
 *
 * @param forum
 */
private void doDeleteForum(final Forum forum) {
    final Long forumKey = forum.getKey();
    // delete read messsages
    String deleteReadMessages = "delete from foreadmessage as rmsg where rmsg.forum.key=:forumKey";
    dbInstance.getCurrentEntityManager().createQuery(deleteReadMessages).setParameter("forumKey", forumKey).executeUpdate();
    // delete messages
    String messagesToDelete = "select msg from fomessage as msg where msg.forum.key=:forumKey and msg.threadtop.key is null";
    List<Message> threadsToDelete = dbInstance.getCurrentEntityManager().createQuery(messagesToDelete, Message.class).setParameter("forumKey", forumKey).getResultList();
    for (Message threadToDelete : threadsToDelete) {
        deleteMessageTree(forumKey, threadToDelete);
        dbInstance.getCurrentEntityManager().remove(threadToDelete);
    }
    dbInstance.commit();
    // delete forum
    String deleteForum = "delete from forum as fo where fo.key=:forumKey";
    dbInstance.getCurrentEntityManager().createQuery(deleteForum).setParameter("forumKey", forumKey).executeUpdate();
    // delete all flags
    OLATResourceable ores = OresHelper.createOLATResourceableInstance(Forum.class, forum.getKey());
    markingService.getMarkManager().deleteMarks(ores);
}
Also used : Message(org.olat.modules.fo.Message) OLATResourceable(org.olat.core.id.OLATResourceable)

Example 73 with Message

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

the class ForumManager method splitThread.

/**
 * Splits the current thread starting from the current message.
 * It updates the messages of the selected subthread by setting the Parent and the Threadtop.
 * The method send a SPLIT event, and make a commit before sending it.
 *
 * @param msgid
 * @return the top message of the newly created thread.
 */
public Message splitThread(Message msg) {
    Message newTopMessage = null;
    if (msg.getThreadtop() == null) {
        newTopMessage = msg;
    } else {
        // it only make sense to split a thread if the current message is not a threadtop message.
        List<Message> threadList = getThread(msg.getThreadtop().getKey());
        List<Message> subthreadList = new ArrayList<>();
        getSubthread(msg, threadList, subthreadList);
        newTopMessage = getMessageById(msg.getKey());
        newTopMessage.setParent(null);
        newTopMessage.setThreadtop(null);
        newTopMessage = dbInstance.getCurrentEntityManager().merge(newTopMessage);
        for (Message message : subthreadList) {
            message.setThreadtop(newTopMessage);
            message = dbInstance.getCurrentEntityManager().merge(message);
        }
        // before sending async event
        dbInstance.commit();
        ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.SPLIT, newTopMessage.getKey(), null, null);
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, newTopMessage.getForum());
    }
    return newTopMessage;
}
Also used : ForumChangedEvent(org.olat.modules.fo.ForumChangedEvent) Message(org.olat.modules.fo.Message) ArrayList(java.util.ArrayList)

Example 74 with Message

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

the class ForumManager method moveThreadToAnotherForumRecursively.

/**
 * Move thread to another forum recursively.
 *
 * @param oldParent the OLD parent message
 * @param newParent the NEW parent message
 * @param topMsg the top message
 * @return the message
 */
private Message moveThreadToAnotherForumRecursively(Message oldParent, Message newParent, Message topMsg) {
    // 1) get direct children of the old top message
    List<Message> children = getMessageChildren(oldParent);
    Message message = null;
    // 2) iterate all first level children
    for (Message child : children) {
        Message oldMessage = getMessageById(child.getKey());
        topMsg = getMessageById(topMsg.getKey());
        message = persistMessageInAnotherLocation(oldMessage, topMsg.getForum(), topMsg, newParent);
        // 3) move the message container to a new destination
        moveMessageContainer(oldMessage.getForum().getKey(), oldMessage.getKey(), message.getForum().getKey(), message.getKey());
        // 4) do recursion if children are available
        if (hasChildren(child)) {
            moveThreadToAnotherForumRecursively(child, message, topMsg);
        }
    }
    return message;
}
Also used : Message(org.olat.modules.fo.Message)

Example 75 with Message

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

the class DialogCourseNodeRunController method activateByMessage.

private void activateByMessage(UserRequest ureq, List<ContextEntry> entries) {
    if (entries == null || entries.isEmpty())
        return;
    Long messageKey = entries.get(0).getOLATResourceable().getResourceableId();
    Message message = forumManager.getMessageById(messageKey);
    if (message == null)
        return;
    DialogElement element = dialogElmsMgr.getDialogElementByForum(message.getForum().getKey());
    if (!checkAccess(element)) {
        return;
    }
    dialogCtr = new DialogElementController(ureq, getWindowControl(), element, userCourseEnv, courseNode, nodeEvaluation);
    listenTo(dialogCtr);
    mainVC.put("forum", dialogCtr.getInitialComponent());
    // activate message
    dialogCtr.activate(ureq, entries, null);
}
Also used : Message(org.olat.modules.fo.Message) DialogElement(org.olat.course.nodes.dialog.DialogElement)

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