Search in sources :

Example 36 with Message

use of org.olat.modules.fo.Message in project openolat by klemens.

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 37 with Message

use of org.olat.modules.fo.Message in project openolat by klemens.

the class DialogCourseNodeIndexer method checkAccess.

@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
    ContextEntry ce = businessControl.popLauncherContextEntry();
    if (ce == null || ce.getOLATResourceable() == null || ce.getOLATResourceable().getResourceableId() == null) {
        // it's the node itself
        return true;
    }
    OLATResourceable ores = ce.getOLATResourceable();
    if (isLogDebugEnabled())
        logDebug("OLATResourceable=" + ores);
    if (ores.getResourceableTypeName().startsWith("path=")) {
        // => it is a file element, typeName format: 'path=/test1/test2/readme.txt'
        return true;
    } else if (ores.getResourceableTypeName().equals(OresHelper.calculateTypeName(Message.class))) {
        // it is message => check message access
        Long resourceableId = ores.getResourceableId();
        Message message = ForumManager.getInstance().loadMessage(resourceableId);
        Message threadtop = message.getThreadtop();
        if (threadtop == null) {
            threadtop = message;
        }
        boolean isMessageHidden = Status.getStatus(threadtop.getStatusCode()).isHidden();
        // TODO: (LD) fix this!!! - the contextEntry is not the right context for this check
        if (isMessageHidden) {
            boolean isOwner = BaseSecurityManager.getInstance().isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_ACCESS, contextEntry.getOLATResourceable());
            return isOwner;
        }
        return true;
    } else {
        logWarn("In DialogCourseNode unkown OLATResourceable=" + ores, null);
        return false;
    }
}
Also used : Message(org.olat.modules.fo.Message) OLATResourceable(org.olat.core.id.OLATResourceable) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 38 with Message

use of org.olat.modules.fo.Message in project openolat by klemens.

the class MessageListController method doDeleteMessage.

private void doDeleteMessage(UserRequest ureq, MessageView message) {
    boolean userIsMsgCreator = message.isAuthor();
    if (foCallback.mayDeleteMessageAsModerator() || (userIsMsgCreator && forumManager.countMessageChildren(message.getKey()) == 0)) {
        Message reloadedMessage = forumManager.getMessageById(message.getKey());
        if (reloadedMessage != null) {
            // this delete the topic / thread
            if (reloadedMessage.getParent() == null) {
                forumManager.deleteMessageTree(forum.getKey(), reloadedMessage);
                // delete topics
                ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_THREAD_DELETE, getClass(), LoggingResourceable.wrap(reloadedMessage));
                // back to thread list
                fireEvent(ureq, new DeleteThreadEvent());
                ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.DELETED_THREAD, reloadedMessage.getKey(), reloadedMessage.getKey(), getIdentity());
                CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
            } else {
                Message threadTop = reloadedMessage.getThreadtop();
                forumManager.deleteMessageTree(forum.getKey(), reloadedMessage);
                threadTop = forumManager.updateMessage(threadTop, true);
                if (thread != null) {
                    // update with the fresh version
                    thread = threadTop;
                }
                showInfo("deleteok");
                ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_MESSAGE_DELETE, getClass(), LoggingResourceable.wrap(reloadedMessage));
                // reload
                reloadModelAfterDelete(ureq, message);
                fireEvent(ureq, new DeleteMessageEvent());
                ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.DELETED_MESSAGE, threadTop.getKey(), message.getKey(), getIdentity());
                CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, forum);
            }
        }
    } else {
        showWarning("may.not.delete.msg.as.author");
    }
}
Also used : ForumChangedEvent(org.olat.modules.fo.ForumChangedEvent) DeleteThreadEvent(org.olat.modules.fo.ui.events.DeleteThreadEvent) ErrorEditMessage(org.olat.modules.fo.ui.events.ErrorEditMessage) Message(org.olat.modules.fo.Message) DeleteMessageEvent(org.olat.modules.fo.ui.events.DeleteMessageEvent)

Example 39 with Message

use of org.olat.modules.fo.Message in project openolat by klemens.

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 40 with Message

use of org.olat.modules.fo.Message in project openolat by klemens.

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)

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