Search in sources :

Example 6 with InfoMessage

use of org.olat.commons.info.InfoMessage in project openolat by klemens.

the class InfoMessageFrontendManagerImpl method removeInfoMessagesAndSubscriptionContext.

@Override
public void removeInfoMessagesAndSubscriptionContext(BusinessGroup group) {
    List<InfoMessage> messages = infoMessageManager.loadInfoMessageByResource(group, InfoMessageFrontendManager.businessGroupResSubPath, null, null, null, 0, 0);
    List<String> pathToDelete = new ArrayList<>();
    for (InfoMessage im : messages) {
        infoMessageManager.deleteInfoMessage(im);
        if (StringHelper.containsNonWhitespace(im.getAttachmentPath())) {
            pathToDelete.add(im.getAttachmentPath());
        }
    }
    String resName = group.getResourceableTypeName();
    Long resId = group.getResourceableId();
    SubscriptionContext subscriptionContext = new SubscriptionContext(resName, resId, "");
    infoSubscriptionManager.deleteSubscriptionContext(subscriptionContext);
    deleteAttachments(pathToDelete);
}
Also used : InfoMessage(org.olat.commons.info.InfoMessage) ArrayList(java.util.ArrayList) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext)

Example 7 with InfoMessage

use of org.olat.commons.info.InfoMessage in project OpenOLAT by OpenOLAT.

the class GroupInfoIndexer method doIndexInfos.

private void doIndexInfos(SearchResourceContext parentResourceContext, BusinessGroup businessGroup, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    List<InfoMessage> messages = infoMessageManager.loadInfoMessageByResource(businessGroup, InfoMessageFrontendManager.businessGroupResSubPath, null, null, null, 0, -1);
    for (InfoMessage message : messages) {
        SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
        OLATResourceable ores = OresHelper.createOLATResourceableInstance(InfoMessage.class, message.getKey());
        searchResourceContext.setBusinessControlFor(ores);
        Document document = InfoMessageDocument.createDocument(searchResourceContext, message);
        indexWriter.addDocument(document);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) OLATResourceable(org.olat.core.id.OLATResourceable) InfoMessage(org.olat.commons.info.InfoMessage) Document(org.apache.lucene.document.Document) InfoMessageDocument(org.olat.search.service.document.InfoMessageDocument)

Example 8 with InfoMessage

use of org.olat.commons.info.InfoMessage in project OpenOLAT by OpenOLAT.

the class InfoCourseNodeIndexer method doIndexInfos.

private void doIndexInfos(SearchResourceContext parentResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    List<InfoMessage> messages = infoMessageManager.loadInfoMessageByResource(course, courseNode.getIdent(), null, null, null, 0, -1);
    for (InfoMessage message : messages) {
        SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
        OLATResourceable ores = OresHelper.createOLATResourceableInstance(InfoMessage.class, message.getKey());
        searchResourceContext.setBusinessControlFor(ores);
        Document document = InfoMessageDocument.createDocument(searchResourceContext, message);
        indexWriter.addDocument(document);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) OLATResourceable(org.olat.core.id.OLATResourceable) InfoMessage(org.olat.commons.info.InfoMessage) Document(org.apache.lucene.document.Document) InfoMessageDocument(org.olat.search.service.document.InfoMessageDocument) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument)

Example 9 with InfoMessage

use of org.olat.commons.info.InfoMessage in project OpenOLAT by OpenOLAT.

the class InfoMessageNotificationHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    // can't be loaded when already deleted
    if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
        try {
            final Long resId = subscriber.getPublisher().getResId();
            final String resName = subscriber.getPublisher().getResName();
            String resSubPath = subscriber.getPublisher().getSubidentifier();
            String displayName, notificationtitle;
            if ("BusinessGroup".equals(resName)) {
                BusinessGroupService groupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
                BusinessGroup group = groupService.loadBusinessGroup(resId);
                displayName = group.getName();
                notificationtitle = "notification.title.group";
            } else {
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(resName, resId), false);
                if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
                displayName = re.getDisplayname();
                notificationtitle = "notification.title";
            }
            Translator translator = Util.createPackageTranslator(this.getClass(), locale);
            String title = translator.translate(notificationtitle, new String[] { displayName });
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_ICON), null);
            OLATResourceable ores = OresHelper.createOLATResourceableInstance(resName, resId);
            List<InfoMessage> infos = infoMessageManager.loadInfoMessageByResource(ores, resSubPath, null, compareDate, null, 0, 0);
            for (InfoMessage info : infos) {
                Identity ident = info.getAuthor();
                String desc = translator.translate("notifications.entry", new String[] { info.getTitle(), NotificationHelper.getFormatedName(ident) });
                String tooltip = info.getMessage();
                String infoBusinessPath = info.getBusinessPath() + "[InfoMessage:" + info.getKey() + "]";
                String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(infoBusinessPath);
                Date dateInfo = info.getModificationDate() == null ? info.getCreationDate() : info.getModificationDate();
                SubscriptionListItem subListItem = new SubscriptionListItem(desc, tooltip, urlToSend, infoBusinessPath, dateInfo, CSS_CLASS_ICON);
                si.addSubscriptionListItem(subListItem);
            }
        } catch (Exception e) {
            log.error("Unexpected exception", e);
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } else {
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResourceable(org.olat.core.id.OLATResourceable) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) RepositoryEntry(org.olat.repository.RepositoryEntry) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Date(java.util.Date) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) BusinessGroupService(org.olat.group.BusinessGroupService) Translator(org.olat.core.gui.translator.Translator) InfoMessage(org.olat.commons.info.InfoMessage) Identity(org.olat.core.id.Identity)

Example 10 with InfoMessage

use of org.olat.commons.info.InfoMessage in project OpenOLAT by OpenOLAT.

the class InfoMessageManagerImpl method loadInfoMessageByResource.

@Override
public List<InfoMessage> loadInfoMessageByResource(OLATResourceable ores, String subPath, String businessPath, Date after, Date before, int firstResult, int maxResults) {
    DBQuery query = queryInfoMessageByResource(ores, subPath, businessPath, after, before, false);
    if (firstResult >= 0) {
        query.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    @SuppressWarnings("unchecked") List<InfoMessage> msgs = query.list();
    return msgs;
}
Also used : InfoMessage(org.olat.commons.info.InfoMessage) DBQuery(org.olat.core.commons.persistence.DBQuery)

Aggregations

InfoMessage (org.olat.commons.info.InfoMessage)24 OLATResourceable (org.olat.core.id.OLATResourceable)8 InfoMessageFrontendManager (org.olat.commons.info.InfoMessageFrontendManager)6 Identity (org.olat.core.id.Identity)6 ArrayList (java.util.ArrayList)4 Document (org.apache.lucene.document.Document)4 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)4 SearchResourceContext (org.olat.search.service.SearchResourceContext)4 InfoMessageDocument (org.olat.search.service.document.InfoMessageDocument)4 Date (java.util.Date)2 HashMap (java.util.HashMap)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 InfoMessageImpl (org.olat.commons.info.model.InfoMessageImpl)2 DBQuery (org.olat.core.commons.persistence.DBQuery)2 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)2 Publisher (org.olat.core.commons.services.notifications.Publisher)2 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)2