Search in sources :

Example 46 with SubscriptionListItem

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

the class HistoryController method updateChangeLog.

protected void updateChangeLog() {
    Date date = dateChooser.getDate();
    List<SubscriptionListItem> items = notificationsHandler.getAllItems(binder, secCallback, date, getLocale());
    Formatter formatter = Formatter.getInstance(getLocale());
    List<SubscriptionListItemWrapper> wrappers = new ArrayList<>(items.size());
    for (SubscriptionListItem item : items) {
        String dateString = formatter.formatDate(item.getDate());
        String linkName = "subscrIL_" + (counter++);
        String linkLabel = StringHelper.escapeHtml(item.getDescription());
        FormLink link = uifactory.addFormLink(linkName, linkLabel, null, flc, Link.NONTRANSLATED);
        link.setUserObject(item.getBusinessPath());
        SubscriptionListItemWrapper bundle = new SubscriptionListItemWrapper(linkName, dateString, item.getIconCssClass());
        wrappers.add(bundle);
    }
    flc.contextPut("subscriptionItems", wrappers);
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Formatter(org.olat.core.util.Formatter) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Date(java.util.Date)

Example 47 with SubscriptionListItem

use of org.olat.core.commons.services.notifications.model.SubscriptionListItem 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 48 with SubscriptionListItem

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

the class InfoMessagePortletRunController method reloadModel.

@Override
protected void reloadModel(SortingCriteria criteria) {
    List<SubscriptionInfo> infos = NotificationsManager.getInstance().getSubscriptionInfos(getIdentity(), "InfoMessage");
    List<InfoSubscriptionItem> items = new ArrayList<InfoSubscriptionItem>();
    for (SubscriptionInfo info : infos) {
        for (SubscriptionListItem item : info.getSubscriptionListItems()) {
            items.add(new InfoSubscriptionItem(info, item));
        }
    }
    items = getSortedList(items, criteria);
    List<PortletEntry<InfoSubscriptionItem>> entries = convertToPortletEntryList(items);
    InfosTableModel model = new InfosTableModel(entries);
    tableController.setTableDataModel(model);
}
Also used : PortletEntry(org.olat.core.gui.control.generic.portal.PortletEntry) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) ArrayList(java.util.ArrayList) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo)

Example 49 with SubscriptionListItem

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

the class InfoPortletEntryComparator method compare.

@Override
public int compare(InfoSubscriptionItem isi1, InfoSubscriptionItem isi2) {
    if (isi1 == null)
        return -1;
    else if (isi2 == null)
        return 1;
    SubscriptionListItem m1 = isi1.getItem();
    SubscriptionListItem m2 = isi2.getItem();
    if (m1 == null)
        return -1;
    else if (m2 == null)
        return 1;
    // only sorting per date
    Date d1 = m1.getDate();
    Date d2 = m2.getDate();
    if (d1 == null)
        return -1;
    else if (d2 == null)
        return 1;
    int result = d1.compareTo(d2);
    return criteria.isAscending() ? result : -result;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Date(java.util.Date)

Example 50 with SubscriptionListItem

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

the class NotificationsWebService method createSubscriptionInfoVO.

private SubscriptionInfoVO createSubscriptionInfoVO(Publisher publisher, SubscriptionInfo info) {
    SubscriptionInfoVO infoVO = new SubscriptionInfoVO(info);
    if (info.getSubscriptionListItems() != null && !info.getSubscriptionListItems().isEmpty()) {
        List<SubscriptionListItemVO> itemVOes = new ArrayList<SubscriptionListItemVO>(info.getSubscriptionListItems().size());
        String publisherType = publisher.getType();
        String resourceType = publisher.getResName();
        for (SubscriptionListItem item : info.getSubscriptionListItems()) {
            SubscriptionListItemVO itemVO = new SubscriptionListItemVO(item);
            // resource specific
            if ("BusinessGroup".equals(resourceType)) {
                itemVO.setGroupKey(publisher.getResId());
            } else if ("CourseModule".equals(resourceType)) {
                itemVO.setCourseKey(publisher.getResId());
                itemVO.setCourseNodeId(publisher.getSubidentifier());
            }
            // publisher specififc
            if ("Forum".equals(publisherType)) {
                // extract the message id
                List<ContextEntry> ces = BusinessControlFactory.getInstance().createCEListFromString(item.getBusinessPath());
                if (ces.size() > 0) {
                    ContextEntry lastCe = ces.get(ces.size() - 1);
                    if ("Message".equals(lastCe.getOLATResourceable().getResourceableTypeName())) {
                        itemVO.setMessageKey(lastCe.getOLATResourceable().getResourceableId());
                    }
                }
            } else if ("FolderModule".equals(publisherType)) {
                List<ContextEntry> ces = BusinessControlFactory.getInstance().createCEListFromString(item.getBusinessPath());
                if (ces.size() > 0) {
                    ContextEntry lastCe = ces.get(ces.size() - 1);
                    if (lastCe.getOLATResourceable().getResourceableTypeName().startsWith("path=")) {
                        String path = BusinessControlFactory.getInstance().getPath(lastCe);
                        itemVO.setPath(path);
                    }
                }
            }
            itemVOes.add(itemVO);
        }
        infoVO.setItems(itemVOes);
    }
    return infoVO;
}
Also used : SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SubscriptionListItemVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO) ContextEntry(org.olat.core.id.context.ContextEntry)

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