Search in sources :

Example 61 with Message

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

the class ForumWebService method newThreadToForum.

/**
 * Creates a new thread in the forum of the course node
 * @response.representation.200.qname {http://www.example.com}messageVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The root message of the thread
 * @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_MESSAGEVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The author, forum or message not found
 * @param title The title for the first post in the thread
 * @param body The body for the first post in the thread
 * @param authorKey The author user key (optional)
 * @param httpRequest The HTTP request
 * @return The new thread
 */
@PUT
@Path("threads")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response newThreadToForum(@QueryParam("title") String title, @QueryParam("body") String body, @QueryParam("authorKey") Long authorKey, @Context HttpServletRequest httpRequest) {
    Identity author = getMessageAuthor(authorKey, httpRequest);
    // creating the thread (a message without a parent message)
    Message newThread = fom.createMessage(forum, author, false);
    newThread.setTitle(title);
    newThread.setBody(body);
    // open a new thread
    fom.addTopMessage(newThread);
    MessageVO vo = new MessageVO(newThread);
    return Response.ok(vo).build();
}
Also used : Message(org.olat.modules.fo.Message) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 62 with Message

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

the class ForumWebService method getAttachment.

/**
 * Retrieves the attachment of the message
 * @response.representation.200.mediaType application/octet-stream
 * @response.representation.200.doc The portrait as image
 * @response.representation.404.doc The identity or the portrait not found
 * @param messageKey The identity key of the user being searched
 * @param filename The name of the attachment
 * @param request The REST request
 * @return The attachment
 */
@GET
@Path("posts/{messageKey}/attachments/{filename}")
@Produces({ "*/*", MediaType.APPLICATION_OCTET_STREAM })
public Response getAttachment(@PathParam("messageKey") Long messageKey, @PathParam("filename") String filename, @Context Request request) {
    // 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();
    }
    VFSContainer container = fom.getMessageContainer(mess.getForum().getKey(), mess.getKey());
    VFSItem item = container.resolve(filename);
    if (item instanceof LocalFileImpl) {
        // local file -> the length is given to the client which is good
        Date lastModified = new Date(item.getLastModified());
        Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
        if (response == null) {
            File attachment = ((LocalFileImpl) item).getBasefile();
            String mimeType = WebappHelper.getMimeType(attachment.getName());
            if (mimeType == null)
                mimeType = "application/octet-stream";
            response = Response.ok(attachment).lastModified(lastModified).type(mimeType).cacheControl(cc);
        }
        return response.build();
    } else if (item instanceof VFSLeaf) {
        // stream -> the length is not given to the client which is not nice
        Date lastModified = new Date(item.getLastModified());
        Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
        if (response == null) {
            StreamingOutput attachment = new VFSStreamingOutput((VFSLeaf) item);
            String mimeType = WebappHelper.getMimeType(item.getName());
            if (mimeType == null)
                mimeType = "application/octet-stream";
            response = Response.ok(attachment).lastModified(lastModified).type(mimeType).cacheControl(cc);
        }
        return response.build();
    }
    return Response.serverError().status(Status.NOT_FOUND).build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Message(org.olat.modules.fo.Message) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) VFSStreamingOutput(org.olat.core.util.vfs.restapi.VFSStreamingOutput) VFSStreamingOutput(org.olat.core.util.vfs.restapi.VFSStreamingOutput) StreamingOutput(javax.ws.rs.core.StreamingOutput) Date(java.util.Date) Response(javax.ws.rs.core.Response) File(java.io.File) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 63 with Message

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

the class ForumWebService method toArrayOfVO.

private MessageVO[] toArrayOfVO(List<Message> threads, UriInfo uriInfo) {
    MessageVO[] threadArr = new MessageVO[threads.size()];
    int i = 0;
    for (Message thread : threads) {
        MessageVO msg = new MessageVO(thread);
        msg.setAttachments(getAttachments(thread, uriInfo));
        threadArr[i++] = msg;
    }
    return threadArr;
}
Also used : Message(org.olat.modules.fo.Message)

Example 64 with Message

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

the class ForumController method activate.

@Override
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
    if (entries == null || entries.isEmpty()) {
        doThreadList(ureq);
    } else {
        String type = entries.get(0).getOLATResourceable().getResourceableTypeName();
        if ("Message".equalsIgnoreCase(type)) {
            Long resId = entries.get(0).getOLATResourceable().getResourceableId();
            if (resId.longValue() != 0) {
                Message message = fm.getMessageById(resId);
                if (message != null) {
                    doThreadList(ureq);
                    Message thread = message.getThreadtop() == null ? message : message.getThreadtop();
                    if (focallback.mayEditMessageAsModerator() || !Status.getStatus(thread.getStatusCode()).isHidden()) {
                        String subType = null;
                        if (entries.size() > 1) {
                            subType = entries.get(1).getOLATResourceable().getResourceableTypeName();
                        }
                        if ("Marked".equalsIgnoreCase(subType)) {
                            doMarkedView(ureq, thread, message);
                        } else if ("New".equalsIgnoreCase(subType)) {
                            doMarkedView(ureq, thread, message);
                        } else {
                            doThreadView(ureq, thread, message);
                        }
                    }
                }
            }
        } else if ("Identity".equalsIgnoreCase(type)) {
            Long resId = entries.get(0).getOLATResourceable().getResourceableId();
            doUserList(ureq);
            if (resId.longValue() > 0) {
                doUserMessageList(ureq, resId);
            }
        }
    }
}
Also used : Message(org.olat.modules.fo.Message)

Example 65 with Message

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

the class ForumController method doProcessSelectEvent.

private void doProcessSelectEvent(UserRequest ureq, SelectMessageEvent sme) {
    Message thread = fm.getMessageById(sme.getMessageKey());
    if (thread == null) {
        logError("Thread doesn't exists: " + sme.getMessageKey(), new Exception());
        reloadThreadList = true;
        doThreadList(ureq);
    } else {
        Message scrollTo = null;
        if (sme.getScrollToMessageKey() != null) {
            scrollTo = fm.getMessageById(sme.getScrollToMessageKey());
        }
        if (SelectMessageEvent.SELECT_THREAD.equals(sme.getCommand())) {
            doThreadView(ureq, thread, scrollTo);
        } else if (SelectMessageEvent.SELECT_MARKED.equals(sme.getCommand())) {
            doMarkedView(ureq, thread, scrollTo);
        } else if (SelectMessageEvent.SELECT_NEW.equals(sme.getCommand())) {
            doNewView(ureq, thread, scrollTo);
        }
    }
}
Also used : Message(org.olat.modules.fo.Message)

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