Search in sources :

Example 1 with MessageLight

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

the class MessageListController method loadThread.

private List<MessageView> loadThread(UserRequest ureq, List<MessageLight> messages, boolean reorder) {
    Set<Long> rms = null;
    Map<String, Mark> marks = Collections.emptyMap();
    Map<String, Long> artefactStats = Collections.emptyMap();
    if (!guestOnly) {
        rms = forumManager.getReadSet(getIdentity(), forum);
        String businessPath = BusinessControlFactory.getInstance().getAsString(getWindowControl().getBusinessControl()) + "[Message:";
        artefactStats = epMgr.getNumOfArtefactsByStartingBusinessPath(businessPath, getIdentity());
        marks = new HashMap<>(marks.size() * 2 + 1);
        List<Mark> markList = markingService.getMarkManager().getMarks(forumOres, getIdentity(), null);
        for (Mark mark : markList) {
            marks.put(mark.getResSubPath(), mark);
        }
    }
    List<MarkResourceStat> statList = markingService.getMarkManager().getStats(forumOres, null, getIdentity());
    Map<String, MarkResourceStat> stats = new HashMap<String, MarkResourceStat>(statList.size() * 2 + 1);
    for (MarkResourceStat stat : statList) {
        stats.put(stat.getSubPath(), stat);
    }
    if (reorder) {
        List<MessageLight> orderedMessages = new ArrayList<MessageLight>();
        orderMessagesThreaded(messages, orderedMessages, thread);
        messages = orderedMessages;
    }
    List<MessageView> views = new ArrayList<>(messages.size());
    Map<Long, MessageView> keyToViews = new HashMap<>();
    for (MessageLight msg : messages) {
        MessageView view = new MessageView(msg, userPropertyHandlers, getLocale());
        view.setNumOfChildren(0);
        views.add(view);
        keyToViews.put(msg.getKey(), view);
    }
    // calculate depth and number of children
    for (MessageView view : views) {
        if (view.getParentKey() == null) {
            view.setDepth(0);
        } else {
            view.setDepth(1);
            for (MessageView parent = keyToViews.get(view.getParentKey()); parent != null; parent = keyToViews.get(parent.getParentKey())) {
                parent.setNumOfChildren(parent.getNumOfChildren() + 1);
                view.setDepth(view.getDepth() + 1);
            }
        }
    }
    // append ui things
    for (MessageLight msg : messages) {
        addMessageToCurrentMessagesAndVC(ureq, msg, keyToViews.get(msg.getKey()), marks, stats, artefactStats, rms);
    }
    mainVC.contextPut("messages", views);
    return views;
}
Also used : MarkResourceStat(org.olat.core.commons.services.mark.MarkResourceStat) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Mark(org.olat.core.commons.services.mark.Mark) MessageLight(org.olat.modules.fo.MessageLight)

Example 2 with MessageLight

use of org.olat.modules.fo.MessageLight 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)

Example 3 with MessageLight

use of org.olat.modules.fo.MessageLight in project openolat by klemens.

the class MessageListController method loadThread.

private List<MessageView> loadThread(UserRequest ureq, List<MessageLight> messages, boolean reorder) {
    Set<Long> rms = null;
    Map<String, Mark> marks = Collections.emptyMap();
    Map<String, Long> artefactStats = Collections.emptyMap();
    if (!guestOnly) {
        rms = forumManager.getReadSet(getIdentity(), forum);
        String businessPath = BusinessControlFactory.getInstance().getAsString(getWindowControl().getBusinessControl()) + "[Message:";
        artefactStats = epMgr.getNumOfArtefactsByStartingBusinessPath(businessPath, getIdentity());
        marks = new HashMap<>(marks.size() * 2 + 1);
        List<Mark> markList = markingService.getMarkManager().getMarks(forumOres, getIdentity(), null);
        for (Mark mark : markList) {
            marks.put(mark.getResSubPath(), mark);
        }
    }
    List<MarkResourceStat> statList = markingService.getMarkManager().getStats(forumOres, null, getIdentity());
    Map<String, MarkResourceStat> stats = new HashMap<String, MarkResourceStat>(statList.size() * 2 + 1);
    for (MarkResourceStat stat : statList) {
        stats.put(stat.getSubPath(), stat);
    }
    if (reorder) {
        List<MessageLight> orderedMessages = new ArrayList<MessageLight>();
        orderMessagesThreaded(messages, orderedMessages, thread);
        messages = orderedMessages;
    }
    List<MessageView> views = new ArrayList<>(messages.size());
    Map<Long, MessageView> keyToViews = new HashMap<>();
    for (MessageLight msg : messages) {
        MessageView view = new MessageView(msg, userPropertyHandlers, getLocale());
        view.setNumOfChildren(0);
        views.add(view);
        keyToViews.put(msg.getKey(), view);
    }
    // calculate depth and number of children
    for (MessageView view : views) {
        if (view.getParentKey() == null) {
            view.setDepth(0);
        } else {
            view.setDepth(1);
            for (MessageView parent = keyToViews.get(view.getParentKey()); parent != null; parent = keyToViews.get(parent.getParentKey())) {
                parent.setNumOfChildren(parent.getNumOfChildren() + 1);
                view.setDepth(view.getDepth() + 1);
            }
        }
    }
    // append ui things
    for (MessageLight msg : messages) {
        addMessageToCurrentMessagesAndVC(ureq, msg, keyToViews.get(msg.getKey()), marks, stats, artefactStats, rms);
    }
    mainVC.contextPut("messages", views);
    return views;
}
Also used : MarkResourceStat(org.olat.core.commons.services.mark.MarkResourceStat) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Mark(org.olat.core.commons.services.mark.Mark) MessageLight(org.olat.modules.fo.MessageLight)

Example 4 with MessageLight

use of org.olat.modules.fo.MessageLight in project openolat by klemens.

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)

Example 5 with MessageLight

use of org.olat.modules.fo.MessageLight in project openolat by klemens.

the class ForumMessageListController method loadAllMessages.

public void loadAllMessages() {
    List<MessageLight> allMessages = forumManager.getLightMessagesByForum(forum);
    List<MessageLightView> views = new ArrayList<>(allMessages.size());
    Map<Long, MessageLightView> keyToViews = new HashMap<>();
    for (MessageLight message : allMessages) {
        MessageLightView view = new MessageLightView(message, userPropertyHandlers, getLocale());
        views.add(view);
        keyToViews.put(view.getKey(), view);
    }
    // calculate depth
    Map<Long, List<Long>> keyToParentline = new HashMap<>();
    for (MessageLightView view : views) {
        if (view.getParentKey() == null) {
            view.setDepth(0);
        } else {
            List<Long> parentLine = new ArrayList<>(5);
            view.setDepth(1);
            for (MessageLightView parent = keyToViews.get(view.getParentKey()); parent != null; parent = keyToViews.get(parent.getParentKey())) {
                view.setDepth(view.getDepth() + 1);
                parentLine.add(parent.getKey());
            }
            keyToParentline.put(view.getKey(), parentLine);
        }
    }
    // order
    List<MessageNode> threads = convertToThreadTrees(views);
    Collections.sort(threads, new MessageNodeComparator());
    List<MessageLightView> orderedViews = new ArrayList<>(allMessages.size());
    flatTree(threads, orderedViews);
    dataModel.setObjects(orderedViews);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MessageLight(org.olat.modules.fo.MessageLight)

Aggregations

MessageLight (org.olat.modules.fo.MessageLight)10 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 File (java.io.File)2 List (java.util.List)2 Mark (org.olat.core.commons.services.mark.Mark)2 MarkResourceStat (org.olat.core.commons.services.mark.MarkResourceStat)2 Message (org.olat.modules.fo.Message)2 Media (org.olat.modules.portfolio.Media)2 MediaInformations (org.olat.modules.portfolio.MediaInformations)2