Search in sources :

Example 51 with Message

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

the class ForumManager method splitThread.

/**
 * Splits the current thread starting from the current message.
 * It updates the messages of the selected subthread by setting the Parent and the Threadtop.
 * The method send a SPLIT event, and make a commit before sending it.
 *
 * @param msgid
 * @return the top message of the newly created thread.
 */
public Message splitThread(Message msg) {
    Message newTopMessage = null;
    if (msg.getThreadtop() == null) {
        newTopMessage = msg;
    } else {
        // it only make sense to split a thread if the current message is not a threadtop message.
        List<Message> threadList = getThread(msg.getThreadtop().getKey());
        List<Message> subthreadList = new ArrayList<>();
        getSubthread(msg, threadList, subthreadList);
        newTopMessage = getMessageById(msg.getKey());
        newTopMessage.setParent(null);
        newTopMessage.setThreadtop(null);
        newTopMessage = dbInstance.getCurrentEntityManager().merge(newTopMessage);
        for (Message message : subthreadList) {
            message.setThreadtop(newTopMessage);
            message = dbInstance.getCurrentEntityManager().merge(message);
        }
        // before sending async event
        dbInstance.commit();
        ForumChangedEvent event = new ForumChangedEvent(ForumChangedEvent.SPLIT, newTopMessage.getKey(), null, null);
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, newTopMessage.getForum());
    }
    return newTopMessage;
}
Also used : ForumChangedEvent(org.olat.modules.fo.ForumChangedEvent) Message(org.olat.modules.fo.Message) ArrayList(java.util.ArrayList)

Example 52 with Message

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

the class ForumManager method replyToMessage.

/**
 * sets the parent and threadtop of the message automatically
 *
 * @param newMessage the new message which has title and body set
 * @param creator
 * @param replyToMessage
 */
public void replyToMessage(Message newMessage, Message replyToMessage) {
    Message top = replyToMessage.getThreadtop();
    newMessage.setThreadtop((top != null ? top : replyToMessage));
    newMessage.setParent(replyToMessage);
    saveMessage(newMessage);
}
Also used : Message(org.olat.modules.fo.Message)

Example 53 with Message

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

the class ForumManager method deleteMessageRecursion.

private void deleteMessageRecursion(final Long forumKey, Message m) {
    deleteMessageContainer(forumKey, m.getKey());
    deleteReadMessages(m.getKey());
    String query = "select msg from fomessage as msg where msg.parent.key=:parentKey";
    List<Message> messages = dbInstance.getCurrentEntityManager().createQuery(query, Message.class).setParameter("parentKey", m.getKey()).getResultList();
    for (Message element : messages) {
        deleteMessageRecursion(forumKey, element);
    }
    // make sure the message is reloaded if it is not in the hibernate session cache
    Message reloadedMessage = dbInstance.getCurrentEntityManager().find(MessageImpl.class, m.getKey());
    if (reloadedMessage != null) {
        // delete all properties of one single message
        dbInstance.getCurrentEntityManager().remove(reloadedMessage);
        // delete all flags
        OLATResourceable ores = OresHelper.createOLATResourceableInstance(Forum.class, forumKey);
        markingService.getMarkManager().deleteMarks(ores, m.getKey().toString());
    }
    if (log.isDebug()) {
        log.debug("Deleting message ", m.getKey().toString());
    }
}
Also used : Message(org.olat.modules.fo.Message) OLATResourceable(org.olat.core.id.OLATResourceable)

Example 54 with Message

use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.

the class WikiPageChangeOrCreateNotificationHandler method createSubscriptionInfo.

/**
 * @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
 *      java.util.Locale, java.util.Date)
 */
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, final Locale locale, Date compareDate) {
    Publisher p = subscriber.getPublisher();
    final Date latestNews = p.getLatestNewsDate();
    Long resId = p.getResId();
    SubscriptionInfo si;
    final boolean debug = log.isDebug();
    // there could be news for me, investigate deeper
    if (debug)
        log.debug("compareDate=" + compareDate + " ; latestNews=" + latestNews, null);
    try {
        if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
            OLATResourceable ores = null;
            if (p.getResName().equals(CourseModule.getCourseTypeName())) {
                // resId = CourseResourceableId           p.getSubidentifier() = wikiCourseNode.getIdent()
                ICourse course = CourseFactory.loadCourse(resId);
                if (!courseStatus(course)) {
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
                CourseEnvironment cenv = course.getCourseEnvironment();
                CourseNode courseNode = cenv.getRunStructure().getNode(p.getSubidentifier());
                if (courseNode == null) {
                    // OLAT-3356 because removing wikicoursenodes was not propagated to
                    // disable subcriptions, we may end up here with a NULL wikicoursenode
                    // Best we can do here -> return noSubsInfo and clean up
                    NotificationsManager.getInstance().deactivate(p);
                    // return nothing available
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
                ModuleConfiguration config = ((WikiCourseNode) courseNode).getModuleConfiguration();
                RepositoryEntry re = WikiEditController.getWikiRepoReference(config, true);
                resId = re.getOlatResource().getResourceableId();
                if (debug)
                    log.debug("resId=" + resId, null);
                ores = OresHelper.createOLATResourceableInstance(WikiResource.TYPE_NAME, resId);
                businessControlString = p.getBusinessPath() + "[path=";
            } else {
                // resName = 'BusinessGroup' or 'FileResource.WIKI'
                if (debug)
                    log.debug("p.getResName()=" + p.getResName(), null);
                ores = OresHelper.createOLATResourceableInstance(p.getResName(), resId);
                businessControlString = p.getBusinessPath() + "[path=";
            }
            Wiki wiki = WikiManager.getInstance().getOrLoadWiki(ores);
            final List<WikiPage> pages = wiki.getPagesByDate();
            Translator translator = Util.createPackageTranslator(WikiPageChangeOrCreateNotificationHandler.class, locale);
            Translator forumTranslator = Util.createPackageTranslator(ForumNotificationsHandler.class, locale);
            TitleItem title = getTitleItem(p, translator);
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), title, null);
            for (Iterator<WikiPage> it = pages.listIterator(); it.hasNext(); ) {
                WikiPage element = it.next();
                // do only show entries newer then the ones already seen
                Date modDate = new Date(element.getModificationTime());
                if (debug)
                    log.debug("modDate=" + modDate + " ; compareDate=" + compareDate, null);
                if (modDate.after(compareDate)) {
                    if ((element.getPageName().startsWith("O_") || element.getPageName().startsWith(WikiPage.WIKI_MENU_PAGE)) && (element.getModifyAuthor() <= 0)) {
                        // theses pages are created sometimes automatically. Check if this is the case
                        continue;
                    }
                    // build Businesscontrol-Path
                    String businessPath = null;
                    String urlToSend = null;
                    if (p.getBusinessPath() != null) {
                        businessPath = businessControlString + element.getPageName() + "]";
                        urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                    }
                    // string[] gets filled into translation key by adding {0...n} to
                    // the string
                    Identity ident = BaseSecurityManager.getInstance().loadIdentityByKey(Long.valueOf(element.getModifyAuthor()));
                    String desc = translator.translate("notifications.entry", new String[] { element.getPageName(), NotificationHelper.getFormatedName(ident) });
                    SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_WIKI_PAGE_CHANGED_ICON);
                    si.addSubscriptionListItem(subListItem);
                }
                long forumKey = element.getForumKey();
                List<Message> mInfos = ForumManager.getInstance().getNewMessageInfo(forumKey, compareDate);
                for (Message mInfo : mInfos) {
                    String messageTitle = mInfo.getTitle();
                    Identity creator = mInfo.getCreator();
                    Identity modifier = mInfo.getModifier();
                    Date messageModDate = mInfo.getLastModified();
                    String name;
                    if (modifier != null) {
                        name = NotificationHelper.getFormatedName(modifier);
                    } else {
                        name = NotificationHelper.getFormatedName(creator);
                    }
                    final String descKey = "notifications.entry" + (mInfo.getCreationDate().equals(messageModDate) ? "" : ".modified");
                    final String desc = forumTranslator.translate(descKey, new String[] { messageTitle, name });
                    String urlToSend = null;
                    String businessPath = null;
                    if (p.getBusinessPath() != null) {
                        businessPath = businessControlString + element.getPageName() + "][message:" + mInfo.getKey().toString() + "]";
                        urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                    }
                    SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, messageModDate, CSS_CLASS_WIKI_PAGE_CHANGED_ICON);
                    si.addSubscriptionListItem(subListItem);
                }
            }
        } else {
            // no news
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        log.error("Error creating wiki's notifications for subscriber: " + subscriber.getKey(), e);
        checkPublisher(p);
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : Message(org.olat.modules.fo.Message) OLATResourceable(org.olat.core.id.OLATResourceable) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) CourseNode(org.olat.course.nodes.CourseNode) WikiCourseNode(org.olat.course.nodes.WikiCourseNode) Identity(org.olat.core.id.Identity) WikiCourseNode(org.olat.course.nodes.WikiCourseNode) ModuleConfiguration(org.olat.modules.ModuleConfiguration) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) Publisher(org.olat.core.commons.services.notifications.Publisher) Date(java.util.Date)

Example 55 with Message

use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.

the class ForumIndexer method doIndexAllMessages.

public void doIndexAllMessages(SearchResourceContext parentResourceContext, Forum forum, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (forum == null) {
        logWarn("tried to index a forum that could not be found! skipping. context: " + parentResourceContext.getResourceUrl(), null);
        return;
    }
    // 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);
        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)

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