Search in sources :

Example 21 with Message

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

the class ForumManager method getSubthread.

/**
 * This is a recursive method. The subthreadList in an ordered list with all descendents of the input msg.
 * @param msg
 * @param threadList
 * @param subthreadList
 */
private void getSubthread(Message msg, List<Message> threadList, List<Message> subthreadList) {
    Iterator<Message> listIterator = threadList.iterator();
    while (listIterator.hasNext()) {
        Message currMessage = listIterator.next();
        if (currMessage.getParent() != null && currMessage.getParent().getKey().equals(msg.getKey())) {
            subthreadList.add(currMessage);
            getSubthread(currMessage, threadList, subthreadList);
        }
    }
}
Also used : Message(org.olat.modules.fo.Message)

Example 22 with Message

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

the class ForumManager method createOrAppendThreadInAnotherForum.

/**
 * Creates new thread in another forum or appends selected thread to another thread in another forum.
 *
 * @param msg the OLD parent message
 * @param the destination forum
 * @param topMsg the top message
 * @return the message
 */
public Message createOrAppendThreadInAnotherForum(Message msg, Forum forum, Message topMsg) {
    Message oldMessage = getMessageById(msg.getKey());
    Message message = persistMessageInAnotherLocation(oldMessage, forum, topMsg, topMsg);
    // reload message from database
    message = getMessageById(message.getKey());
    moveMessageContainer(oldMessage.getForum().getKey(), oldMessage.getKey(), message.getForum().getKey(), message.getKey());
    if (hasChildren(oldMessage)) {
        if (topMsg != null) {
            // if added to an existing thread choose its top message
            message = moveThreadToAnotherForumRecursively(oldMessage, message, message.getThreadtop());
        } else {
            // if a new thread is created in a forum the parent message is also the top message
            message = moveThreadToAnotherForumRecursively(oldMessage, message, message);
        }
    }
    // deletes all children of the old top message recursively
    deleteMessageRecursion(oldMessage.getForum().getKey(), oldMessage);
    return message;
}
Also used : Message(org.olat.modules.fo.Message)

Example 23 with Message

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

the class ForumManager method deleteMessageRecursion.

private void deleteMessageRecursion(final Long forumKey, Message m) {
    deleteMessageContainer(forumKey, m.getKey());
    deleteReadMessages(m.getKey());
    String query = "select msg from fomessage as msg where msg.parent.key=:parentKey";
    List<Message> messages = dbInstance.getCurrentEntityManager().createQuery(query, Message.class).setParameter("parentKey", m.getKey()).getResultList();
    for (Message element : messages) {
        deleteMessageRecursion(forumKey, element);
    }
    // make sure the message is reloaded if it is not in the hibernate session cache
    Message reloadedMessage = dbInstance.getCurrentEntityManager().find(MessageImpl.class, m.getKey());
    if (reloadedMessage != null) {
        // delete all properties of one single message
        dbInstance.getCurrentEntityManager().remove(reloadedMessage);
        // delete all flags
        OLATResourceable ores = OresHelper.createOLATResourceableInstance(Forum.class, forumKey);
        markingService.getMarkManager().deleteMarks(ores, m.getKey().toString());
    }
    if (log.isDebug()) {
        log.debug("Deleting message ", m.getKey().toString());
    }
}
Also used : Message(org.olat.modules.fo.Message) OLATResourceable(org.olat.core.id.OLATResourceable)

Example 24 with Message

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

the class ForumManager method markAsRead.

/**
 * Implementation with one entry per forum message.
 * Adds a new entry into the ReadMessage for the input message and identity.
 * @param msg
 * @param identity
 */
public void markAsRead(Identity identity, Forum forum, MessageLight msg) {
    // Check if the message was not already deleted
    Message retrievedMessage = loadMessage(msg.getKey());
    if (retrievedMessage != null) {
        ReadMessageImpl readMessage = new ReadMessageImpl();
        readMessage.setIdentity(identity);
        if (msg instanceof MessageLightImpl) {
            readMessage.setMessage(msg);
        } else {
            msg = dbInstance.getCurrentEntityManager().getReference(MessageLightImpl.class, msg.getKey());
            readMessage.setMessage(msg);
        }
        readMessage.setForum(forum);
        dbInstance.getCurrentEntityManager().persist(readMessage);
    }
}
Also used : Message(org.olat.modules.fo.Message) MessageLightImpl(org.olat.modules.fo.model.MessageLightImpl) ReadMessageImpl(org.olat.modules.fo.model.ReadMessageImpl)

Example 25 with Message

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

the class ForumMediaHandler method createMedia.

@Override
public Media createMedia(String title, String description, Object mediaObject, String businessPath, Identity author) {
    Message message = null;
    if (mediaObject instanceof Message) {
        // reload the message
        message = (Message) mediaObject;
        message = forumManager.loadMessage(message.getKey());
    } else if (mediaObject instanceof MessageLight) {
        MessageLight messageLight = (MessageLight) mediaObject;
        message = forumManager.loadMessage(messageLight.getKey());
    }
    String content = message.getBody();
    Media media = mediaDao.createMedia(title, description, content, FORUM_HANDLER, businessPath, null, 70, author);
    ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
    File messageDir = forumManager.getMessageDirectory(message.getForum().getKey(), message.getKey(), false);
    if (messageDir != null && messageDir.exists()) {
        File[] attachments = messageDir.listFiles();
        if (attachments.length > 0) {
            File mediaDir = fileStorage.generateMediaSubDirectory(media);
            for (File attachment : attachments) {
                FileUtils.copyFileToDir(attachment, mediaDir, "Forum media");
            }
            String storagePath = fileStorage.getRelativePath(mediaDir);
            media = mediaDao.updateStoragePath(media, storagePath, null);
        }
    }
    return media;
}
Also used : Message(org.olat.modules.fo.Message) Media(org.olat.modules.portfolio.Media) MessageLight(org.olat.modules.fo.MessageLight) File(java.io.File)

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