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