Search in sources :

Example 56 with Message

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);
    }
}
Also used : Message(org.olat.modules.fo.Message) SearchResourceContext(org.olat.search.service.SearchResourceContext) Document(org.apache.lucene.document.Document) ForumMessageDocument(org.olat.search.service.document.ForumMessageDocument) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument)

Example 57 with Message

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");
    }
}
Also used : ErrorEditMessage(org.olat.modules.fo.ui.events.ErrorEditMessage) Message(org.olat.modules.fo.Message) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)

Example 58 with Message

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);
}
Also used : ErrorEditMessage(org.olat.modules.fo.ui.events.ErrorEditMessage) ErrorEditMessage(org.olat.modules.fo.ui.events.ErrorEditMessage) Message(org.olat.modules.fo.Message) SelectMessageEvent(org.olat.modules.fo.ui.events.SelectMessageEvent) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext)

Example 59 with Message

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

Example 60 with Message

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();
}
Also used : Status(javax.ws.rs.core.Response.Status) Message(org.olat.modules.fo.Message) ICourse(org.olat.course.ICourse) BaseSecurity(org.olat.basesecurity.BaseSecurity) Forum(org.olat.modules.fo.Forum) ForumManager(org.olat.modules.fo.manager.ForumManager) FOCourseNode(org.olat.course.nodes.FOCourseNode) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

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