use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class DialogCourseNodeIndexer method doIndexAllMessages.
private void doIndexAllMessages(SearchResourceContext parentResourceContext, Forum forum, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
// loop over all messages of a forum
List<Message> messages = ForumManager.getInstance().getMessagesByForum(forum);
for (Message message : messages) {
SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
searchResourceContext.setBusinessControlFor(message);
searchResourceContext.setDocumentType(TYPE_MESSAGE);
Document document = ForumMessageDocument.createDocument(searchResourceContext, message);
indexWriter.addDocument(document);
}
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class MessageListController method doEditMessage.
private void doEditMessage(UserRequest ureq, MessageView message) {
// user has clicked on button 'edit'
boolean userIsMsgCreator = message.isAuthor();
boolean children = forumManager.countMessageChildren(message.getKey()) > 0;
if (foCallback.mayEditMessageAsModerator() || (userIsMsgCreator && !children)) {
Message reloadedMessage = forumManager.loadMessage(message.getKey());
if (reloadedMessage == null) {
showWarning("error.message.deleted");
reloadModel(ureq, null);
} else {
editMessageCtrl = new MessageEditController(ureq, getWindowControl(), forum, foCallback, reloadedMessage, null, EditMode.edit);
listenTo(editMessageCtrl);
String title = translate("msg.update");
cmc = new CloseableModalController(getWindowControl(), "close", editMessageCtrl.getInitialComponent(), true, title);
listenTo(editMessageCtrl);
cmc.activate();
}
} else if ((userIsMsgCreator) && (children == true)) {
// user is author of the current message but it has already at least
// one child
showWarning("may.not.save.msg.as.author");
} else {
// user isn't author of the current message
showInfo("may.not.edit.msg");
}
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class MessageListController method event.
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
if (source == exportCtrl) {
if (event == Event.CANCELLED_EVENT || event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
if (event == Event.CHANGED_EVENT) {
StepsRunContext runContext = exportCtrl.getRunContext();
Message originTopMessage = (Message) runContext.get(SendMailStepForm.START_THREADTOP);
originTopMessage = forumManager.loadMessage(originTopMessage.getKey());
if (originTopMessage != null) {
// refresh origin thread
fireEvent(ureq, new SelectMessageEvent(SelectMessageEvent.SELECT_THREAD, originTopMessage.getKey()));
} else {
fireEvent(ureq, Event.BACK_EVENT);
}
}
getWindowControl().pop();
removeAsListenerAndDispose(exportCtrl);
exportCtrl = null;
}
} else if (source == confirmDeleteCtrl) {
if (DialogBoxUIFactory.isYesEvent(event) || DialogBoxUIFactory.isOkEvent(event)) {
MessageView deletedMessage = (MessageView) confirmDeleteCtrl.getUserObject();
doDeleteMessage(ureq, deletedMessage);
}
} else if (editMessageCtrl == source) {
// edit done -> save
if (event instanceof ErrorEditMessage) {
handleEditError(ureq);
} else {
Message message = editMessageCtrl.getMessage();
if (message != null) {
if (thread != null && thread.getKey().equals(message.getKey())) {
thread = message;
}
reloadModel(ureq, message);
} else {
showInfo("header.cannoteditmessage");
}
}
cmc.deactivate();
} else if (replyMessageCtrl == source) {
if (event instanceof ErrorEditMessage) {
handleEditError(ureq);
} else {
Message reply = replyMessageCtrl.getMessage();
if (reply != null) {
reloadModel(ureq, reply);
} else {
showInfo("header.cannotsavemessage");
}
}
cmc.deactivate();
} else if (messageTableCtrl == source) {
if (event instanceof SelectMessageEvent) {
SelectMessageEvent sme = (SelectMessageEvent) event;
doSelectTheOne(ureq, sme.getMessageKey());
}
} else if (moveCtrl == source) {
if (event instanceof SelectMessageEvent) {
SelectMessageEvent sme = (SelectMessageEvent) event;
doFinalizeMove(ureq, moveCtrl.getSelectView(), sme.getMessageKey());
cmc.deactivate();
}
} else if (confirmSplitCtrl == source) {
if (DialogBoxUIFactory.isYesEvent(event) || DialogBoxUIFactory.isOkEvent(event)) {
MessageView splitedMessage = (MessageView) confirmSplitCtrl.getUserObject();
doSplitThread(ureq, splitedMessage);
}
} else if (source == cmc) {
cleanUp();
}
super.event(ureq, source, event);
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class MessageListController method doSplitThread.
private void doSplitThread(UserRequest ureq, MessageView message) {
if (foCallback.mayEditMessageAsModerator()) {
Message reloadedMessage = forumManager.getMessageById(message.getKey());
Message newTopMessage = forumManager.splitThread(reloadedMessage);
// do logging
ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_THREAD_SPLIT, getClass(), LoggingResourceable.wrap(newTopMessage));
showInfo("new.thread.location");
// open the new thread
fireEvent(ureq, new SelectMessageEvent(SelectMessageEvent.SELECT_THREAD, newTopMessage.getKey()));
} else {
showWarning("may.not.split.thread");
}
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class ForumCourseNodeWebService method addMessage.
/**
* Internal helper method to add a message to a forum.
* @param courseId
* @param nodeId
* @param parentMessageId can be null (will lead to new thread)
* @param title
* @param body
* @param identityName
* @param isSticky only necessary when adding new thread
* @param request
* @return
*/
private Response addMessage(Long courseId, String nodeId, Long parentMessageId, String title, String body, String identityName, Boolean isSticky, HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
BaseSecurity securityManager = BaseSecurityManager.getInstance();
Identity identity;
if (identityName != null) {
identity = securityManager.findIdentityByName(identityName);
} else {
identity = RestSecurityHelper.getIdentity(request);
}
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
// load forum
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(course, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CourseNode courseNode = getParentNode(course, nodeId);
if (courseNode == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
Property forumKeyProp = cpm.findCourseNodeProperty(courseNode, null, null, FOCourseNode.FORUM_KEY);
Forum forum = null;
ForumManager fom = ForumManager.getInstance();
if (forumKeyProp != null) {
// Forum does already exist, load forum with key from properties
Long forumKey = forumKeyProp.getLongValue();
forum = fom.loadForum(forumKey);
}
if (forum == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
MessageVO vo;
if (parentMessageId == null || parentMessageId == 0L) {
// creating the thread (a message without a parent message)
Message newThread = fom.createMessage(forum, identity, false);
if (isSticky != null && isSticky.booleanValue()) {
// set sticky
org.olat.modules.fo.Status status = new org.olat.modules.fo.Status();
status.setSticky(true);
newThread.setStatusCode(org.olat.modules.fo.Status.getStatusCode(status));
}
newThread.setTitle(title);
newThread.setBody(body);
// open a new thread
fom.addTopMessage(newThread);
vo = new MessageVO(newThread);
} else {
// adding response message (a message with a parent message)
Message threadMessage = fom.loadMessage(parentMessageId);
if (threadMessage == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
// create new message
Message message = fom.createMessage(forum, identity, false);
message.setTitle(title);
message.setBody(body);
fom.replyToMessage(message, threadMessage);
vo = new MessageVO(message);
}
return Response.ok(vo).build();
}
Aggregations