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