Search in sources :

Example 16 with Message

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();
}
Also used : Message(org.olat.modules.fo.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File64VO(org.olat.restapi.support.vo.File64VO) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity)

Example 17 with Message

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);
}
Also used : Message(org.olat.modules.fo.Message)

Example 18 with Message

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);
        }
    }
}
Also used : Message(org.olat.modules.fo.Message) Identity(org.olat.core.id.Identity)

Example 19 with Message

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;
}
Also used : Message(org.olat.modules.fo.Message) OLATResourceable(org.olat.core.id.OLATResourceable)

Example 20 with 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;
}
Also used : Status(org.olat.modules.fo.Status) Message(org.olat.modules.fo.Message) MessageImpl(org.olat.modules.fo.model.MessageImpl) ReadMessageImpl(org.olat.modules.fo.model.ReadMessageImpl)

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