use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class ForumWebService method replyToPost.
private Response replyToPost(Long messageKey, ReplyVO reply, Long authorKey, HttpServletRequest httpRequest, UriInfo uriInfo) {
Identity identity = getIdentity(httpRequest);
if (identity == null) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
Identity author;
if (isAdmin(httpRequest)) {
if (authorKey == null) {
author = identity;
} else {
author = getMessageAuthor(authorKey, httpRequest);
}
} else {
if (authorKey == null) {
author = identity;
} else if (authorKey.equals(identity.getKey())) {
author = identity;
} else {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
}
// load message
Message mess = fom.loadMessage(messageKey);
if (mess == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
if (!forum.equalsByPersistableKey(mess.getForum())) {
return Response.serverError().status(Status.CONFLICT).build();
}
// creating the thread (a message without a parent message)
Message newMessage = fom.createMessage(forum, author, false);
newMessage.setTitle(reply.getTitle());
newMessage.setBody(reply.getBody());
fom.replyToMessage(newMessage, mess);
if (reply.getAttachments() != null) {
for (File64VO attachment : reply.getAttachments()) {
byte[] fileAsBytes = Base64.decodeBase64(attachment.getFile());
InputStream in = new ByteArrayInputStream(fileAsBytes);
attachToPost(newMessage, attachment.getFilename(), in, httpRequest);
}
}
MessageVO vo = new MessageVO(newMessage);
vo.setAttachments(getAttachments(newMessage, uriInfo));
return Response.ok(vo).build();
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class ForumManager method replyToMessage.
/**
* sets the parent and threadtop of the message automatically
*
* @param newMessage the new message which has title and body set
* @param creator
* @param replyToMessage
*/
public void replyToMessage(Message newMessage, Message replyToMessage) {
Message top = replyToMessage.getThreadtop();
newMessage.setThreadtop((top != null ? top : replyToMessage));
newMessage.setParent(replyToMessage);
saveMessage(newMessage);
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class ForumManager method collectThreadMembersRecursively.
/**
* Collect message children recursively.
*
* @param oldParent
* @param setOfIdentity
*/
public void collectThreadMembersRecursively(Message oldParent, Set<Identity> setOfIdentity, Map<Identity, String> pseudonymes) {
List<Message> children = getMessageChildren(oldParent);
children.sort(new Comparator<Message>() {
@Override
public int compare(Message o1, Message o2) {
if (o1 == null)
return 1;
if (o2 == null)
return -1;
// move posts with pseudonyms toward low indices in list
if (o1.getPseudonym() == null && o2.getPseudonym() != null) {
return 1;
} else if (o1.getPseudonym() != null && o2.getPseudonym() == null) {
return -1;
} else {
return o1.getCreationDate().compareTo(o2.getCreationDate());
}
}
});
for (Message child : children) {
if (!child.isGuest()) {
Identity creator = child.getCreator();
if (creator != null) {
setOfIdentity.add(creator);
String pseudonym = child.getPseudonym();
if (pseudonym != null) {
pseudonymes.put(creator, pseudonym);
} else if (pseudonymes.containsKey(creator)) {
// remove entry if thread also contains same identity without pseudonym
pseudonymes.remove(creator);
}
}
Identity modifier = child.getModifier();
if (creator != null && modifier != null) {
setOfIdentity.add(modifier);
}
}
if (hasChildren(child)) {
collectThreadMembersRecursively(child, setOfIdentity, pseudonymes);
}
}
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class ForumManager method moveMessage.
/**
* Moves the current message from the current thread in another thread.
*
* @param msg
* @param topMsg
* @return the moved message
*/
public Message moveMessage(Message msg, Message topMsg) {
// one has to set a new parent for all children of the moved message
// first message of sublist has to get the parent from the moved message
List<Message> children = getMessageChildren(msg);
for (Message child : children) {
child.setParent(msg.getParent());
dbInstance.getCurrentEntityManager().merge(child);
}
// now move the message to the chosen thread
Message targetThread = topMsg.getThreadtop();
if (targetThread == null) {
targetThread = topMsg;
}
final Message oldMessage = getMessageById(msg.getKey());
Message message = persistMessageInAnotherLocation(msg, oldMessage.getForum(), targetThread, topMsg);
// move marks
OLATResourceable ores = OresHelper.createOLATResourceableInstance(Forum.class, msg.getForum().getKey());
markingService.getMarkManager().moveMarks(ores, msg.getKey().toString(), message.getKey().toString());
moveMessageContainer(oldMessage.getForum().getKey(), oldMessage.getKey(), message.getForum().getKey(), message.getKey());
deleteMessageRecursion(oldMessage.getForum().getKey(), oldMessage);
return message;
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class ForumManager method persistMessageInAnotherLocation.
/**
* Persist message in another location.
*/
private Message persistMessageInAnotherLocation(Message oldMessage, Forum forum, Message top, Message parent) {
// 1) take the new top messages forum to create a new child
Message message = createMessage(forum, oldMessage.getCreator(), oldMessage.isGuest());
((MessageImpl) message).setCreationDate(oldMessage.getCreationDate());
message.setLastModified(oldMessage.getLastModified());
message.setModifier(oldMessage.getModifier());
message.setTitle(oldMessage.getTitle());
message.setBody(oldMessage.getBody());
message.setPseudonym(oldMessage.getPseudonym());
// 2) set the thread top to the new top message
message.setThreadtop(top);
// 3) maintain the hierarchy, parent and top message can be equal
message.setParent(parent);
Status status = Status.getStatus(oldMessage.getStatusCode());
if (status != null) {
status.setMoved(true);
message.setStatusCode(Status.getStatusCode(status));
}
// 4) save the new massage in the new destination
message = saveMessage(message);
return message;
}
Aggregations