use of org.olat.restapi.support.vo.File64VO in project openolat by klemens.
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();
}
Aggregations