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