Search in sources :

Example 36 with SubscriptionListItem

use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.

the class EPNotificationsHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher publisher = subscriber.getPublisher();
    EPFrontendManager epMgr = CoreSpringFactory.getImpl(EPFrontendManager.class);
    EPMapShort amap = epMgr.loadMapShortByResourceId(publisher.getResId());
    if (isInkoveValid(amap, compareDate, publisher)) {
        // init the helper;
        String rootBusinessPath = "[EPDefaultMap:" + amap.getKey() + "]";
        EPNotificationsHelper helper = new EPNotificationsHelper(rootBusinessPath, locale);
        String resName = amap.getOlatResource().getResourceableTypeName();
        si = new SubscriptionInfo(subscriber.getKey(), publisher.getType(), getTitleItemForMap(amap), null);
        List<SubscriptionListItem> allItems = new ArrayList<SubscriptionListItem>(0);
        // get subscriptionListItems according to map type
        if ("EPDefaultMap".equals(resName) || "EPStructuredMapTemplate".equals(resName)) {
            allItems = helper.getAllSubscrItemsDefault(compareDate, amap);
        } else if ("EPStructuredMap".equals(resName)) {
            allItems = helper.getAllSubscrItemsStructured(compareDate, amap);
        }
        for (SubscriptionListItem item : allItems) {
            si.addSubscriptionListItem(item);
        }
    }
    if (si == null) {
        // no info, return empty
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) ArrayList(java.util.ArrayList) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) EPMapShort(org.olat.portfolio.model.structel.EPMapShort)

Example 37 with SubscriptionListItem

use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.

the class NewUsersNotificationHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    SubscriptionInfo si;
    Translator translator = Util.createPackageTranslator(this.getClass(), locale);
    // there could be news for me, investigate deeper
    try {
        if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
            List<Identity> identities = UsersSubscriptionManager.getInstance().getNewIdentityCreated(compareDate);
            if (identities.isEmpty()) {
                si = NotificationsManager.getInstance().getNoSubscriptionInfo();
            } else {
                translator = Util.createPackageTranslator(this.getClass(), locale);
                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(getItemTitle(identities, translator), CSSHelper.CSS_CLASS_GROUP), null);
                SubscriptionListItem subListItem;
                for (Identity newUser : identities) {
                    String desc = translator.translate("notifications.entry", new String[] { NotificationHelper.getFormatedName(newUser) });
                    String businessPath = "[Identity:" + newUser.getKey() + "]";
                    String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                    Date modDate = newUser.getCreationDate();
                    subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSSHelper.CSS_CLASS_USER);
                    si.addSubscriptionListItem(subListItem);
                }
            }
        } else {
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        log.error("Error creating new identity's notifications for subscriber: " + subscriber.getKey(), e);
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 38 with SubscriptionListItem

use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.

the class FeedNotificationsHandler method appendSubscriptionItem.

private void appendSubscriptionItem(Item item, Publisher p, Date compareDate, Translator translator, List<SubscriptionListItem> items) {
    String title = item.getTitle();
    String author = item.getAuthor();
    String businessPath = p.getBusinessPath();
    String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
    String iconCssClass = item.extraCSSClass();
    Date publishDate = item.getPublishDate();
    if (publishDate != null) {
        if (compareDate.before(publishDate)) {
            String desc = translator.translate("notifications.entry.published", new String[] { title, author });
            items.add(new SubscriptionListItem(desc, urlToSend, businessPath, publishDate, iconCssClass));
        }
        // modified date.
        if (item.getModifierKey() != null || (item.getFeed().isExternal() && !item.getCreationDate().equals(item.getLastModified()) && item.getPublishDate().before(item.getLastModified()))) {
            Date modDate = item.getLastModified();
            if (compareDate.before(modDate)) {
                String desc;
                String modifier = item.getModifier();
                if (StringHelper.containsNonWhitespace(modifier)) {
                    desc = translator.translate("notifications.entry.modified", new String[] { title, modifier });
                } else {
                    desc = translator.translate("notifications.entry.modified", new String[] { title, "???" });
                }
                items.add(new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass));
            }
        }
        List<UserComment> comments = commentAndRatingService.getComments(item.getFeed(), item.getGuid());
        for (UserComment comment : comments) {
            if (compareDate.before(comment.getCreationDate())) {
                String desc;
                String modifier = UserManager.getInstance().getUserDisplayName(comment.getCreator().getKey());
                if (StringHelper.containsNonWhitespace(modifier)) {
                    desc = translator.translate("notifications.entry.commented", new String[] { title, modifier });
                } else {
                    desc = translator.translate("notifications.entry.commented", new String[] { title, "???" });
                }
                items.add(new SubscriptionListItem(desc, urlToSend, businessPath, comment.getCreationDate(), iconCssClass));
            }
        }
    }
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment) Date(java.util.Date)

Example 39 with SubscriptionListItem

use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.

the class FeedNotifications method getItems.

public List<SubscriptionListItem> getItems() throws Exception {
    try {
        Publisher p = subscriber.getPublisher();
        String data = p.getData();
        Date latestNews = p.getLatestNewsDate();
        if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
            String resName = p.getResName();
            Long resId = p.getResId();
            Feed feed;
            if ("CourseModule".equals(resName)) {
                OLATResourceable ores = OresHelper.createOLATResourceableInstance(resName, Long.parseLong(data));
                feed = feedManager.loadFeed(ores);
            } else {
                OLATResourceable ores = OresHelper.createOLATResourceableInstance(resName, resId);
                feed = feedManager.loadFeed(ores);
            }
            List<Item> listItems = feedManager.loadItems(feed);
            for (Item item : listItems) {
                createSubscriptionItem(item, p);
            }
        }
    } catch (Exception e) {
        log.error("error in Feed notification", e);
    }
    return items;
}
Also used : Item(org.olat.modules.webFeed.Item) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) OLATResourceable(org.olat.core.id.OLATResourceable) Publisher(org.olat.core.commons.services.notifications.Publisher) Date(java.util.Date) Feed(org.olat.modules.webFeed.Feed)

Example 40 with SubscriptionListItem

use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.

the class FeedNotifications method createSubscriptionItem.

private void createSubscriptionItem(Item item, Publisher p) {
    Date modDate = item.getPublishDate();
    if (compareDate.before(modDate)) {
        String title = item.getTitle();
        String author = item.getAuthor();
        String desc;
        if (item.isDraft()) {
            return;
        } else {
            desc = translator.translate("notifications.entry", new String[] { title, author });
        }
        String businessPath = p.getBusinessPath();
        String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
        String iconCssClass = item.extraCSSClass();
        SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
        items.add(subListItem);
    }
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Date(java.util.Date)

Aggregations

SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)92 Date (java.util.Date)54 Publisher (org.olat.core.commons.services.notifications.Publisher)36 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)36 ArrayList (java.util.ArrayList)32 Translator (org.olat.core.gui.translator.Translator)30 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)26 Identity (org.olat.core.id.Identity)20 RepositoryEntry (org.olat.repository.RepositoryEntry)20 OLATResourceable (org.olat.core.id.OLATResourceable)12 ICourse (org.olat.course.ICourse)10 FileInfo (org.olat.core.commons.modules.bc.FileInfo)8 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)8 Formatter (org.olat.core.util.Formatter)6 BusinessGroup (org.olat.group.BusinessGroup)6 Page (org.olat.modules.portfolio.Page)6 HashSet (java.util.HashSet)4 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)4 CourseNode (org.olat.course.nodes.CourseNode)4 Section (org.olat.modules.portfolio.Section)4