Search in sources :

Example 66 with SubscriptionListItem

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

the class PortfolioNotificationsHandler method evaluationModifiedItem.

private SubscriptionListItem evaluationModifiedItem(Long pageKey, String pageTitle, Date pageCreationDate, String rootBusinessPath, Translator translator) {
    String title = translator.translate("notifications.modified.evaluation", new String[] { pageTitle });
    String bPath = rootBusinessPath + "[Page:" + pageKey + "]";
    String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
    SubscriptionListItem item = new SubscriptionListItem(title, linkUrl, bPath, pageCreationDate, "o_icon_pf_page");
    item.setUserObject(pageKey);
    return item;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem)

Example 67 with SubscriptionListItem

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

the class PortfolioNotificationsHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher publisher = subscriber.getPublisher();
    Binder binder = binderDao.loadByKey(publisher.getResId());
    if (isInkoveValid(binder, compareDate, publisher)) {
        BinderSecurityCallback secCallback = null;
        Identity identity = subscriber.getIdentity();
        if (binderDao.isMember(binder, identity, PortfolioRoles.owner.name())) {
            secCallback = BinderSecurityCallbackFactory.getCallbackForOwnedBinder(binder);
        } else {
            List<AccessRights> rights = portfolioService.getAccessRights(binder, identity);
            if (rights.size() > 0) {
                secCallback = BinderSecurityCallbackFactory.getCallbackForCoach(binder, rights);
            }
        }
        if (secCallback != null) {
            si = new SubscriptionInfo(subscriber.getKey(), publisher.getType(), getTitleItemForBinder(binder), null);
            List<SubscriptionListItem> allItems = getAllItems(binder, secCallback, compareDate, locale);
            for (SubscriptionListItem item : allItems) {
                // only a type of icon
                SubscriptionListItem clonedItem = new SubscriptionListItem(item.getDescription(), item.getDescriptionTooltip(), item.getLink(), item.getBusinessPath(), item.getDate(), "o_ep_icon");
                si.addSubscriptionListItem(clonedItem);
            }
        }
    }
    if (si == null) {
        // no info, return empty
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : AccessRights(org.olat.modules.portfolio.model.AccessRights) Binder(org.olat.modules.portfolio.Binder) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) BinderSecurityCallback(org.olat.modules.portfolio.BinderSecurityCallback) Identity(org.olat.core.id.Identity)

Example 68 with SubscriptionListItem

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

the class PortfolioNotificationsHandler method getPageNotifications.

/**
 * Query the changes in the binder from the section to the page part.
 *
 * @param binder
 * @param compareDate
 * @param rootBusinessPath
 * @param translator
 * @return
 */
public List<SubscriptionListItem> getPageNotifications(Binder binder, BinderSecurityCallback secCallback, Date compareDate, String rootBusinessPath, Translator translator) {
    StringBuilder sb = new StringBuilder();
    sb.append("select page,").append("  pagepart.lastModified as pagepartLastModified").append(" from pfpage as page").append(" inner join fetch page.section as section").append(" inner join fetch section.binder as binder").append(" left join pfpagepart as pagepart on (pagepart.body.key = page.body.key)").append(" where binder.key=:binderKey and (pagepart.lastModified>=:compareDate or page.lastModified>=:compareDate)");
    List<Object[]> objects = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("binderKey", binder.getKey()).setParameter("compareDate", compareDate).getResultList();
    Map<Long, SubscriptionListItem> uniquePartKeys = new HashMap<>();
    Map<Long, SubscriptionListItem> uniqueCreatePageKeys = new HashMap<>();
    List<SubscriptionListItem> items = new ArrayList<>(objects.size());
    for (Object[] object : objects) {
        // page
        Page page = (Page) object[0];
        Long pageKey = page.getKey();
        String pageTitle = page.getTitle();
        Date pageCreationDate = page.getCreationDate();
        Date pageLastModified = page.getLastModified();
        // page part
        Date partLastModified = (Date) object[1];
        Section section = page.getSection();
        if (secCallback.canViewElement(page) && secCallback.canViewElement(section)) {
            // page created
            if (isSameDay(pageCreationDate, pageLastModified) && pageCreationDate.compareTo(compareDate) >= 0) {
                if (!uniqueCreatePageKeys.containsKey(pageKey)) {
                    SubscriptionListItem item = pageCreateItem(pageKey, pageTitle, pageCreationDate, rootBusinessPath, translator);
                    uniqueCreatePageKeys.put(pageKey, item);
                }
            } else {
                if (uniquePartKeys.containsKey(pageKey)) {
                    SubscriptionListItem item = uniquePartKeys.get(pageKey);
                    SubscriptionListItem potentitalItem = pageModifiedItem(pageKey, pageTitle, pageLastModified, partLastModified, rootBusinessPath, translator);
                    if (item.getDate().before(potentitalItem.getDate())) {
                        uniquePartKeys.put(pageKey, potentitalItem);
                    }
                } else if (pageLastModified.compareTo(compareDate) >= 0 || (partLastModified != null && partLastModified.compareTo(compareDate) >= 0)) {
                    SubscriptionListItem item = pageModifiedItem(pageKey, pageTitle, pageLastModified, partLastModified, rootBusinessPath, translator);
                    boolean overlapCreate = false;
                    if (uniqueCreatePageKeys.containsKey(pageKey)) {
                        SubscriptionListItem createItem = uniqueCreatePageKeys.get(pageKey);
                        overlapCreate = isSameDay(item.getDate(), createItem.getDate());
                    }
                    if (!overlapCreate) {
                        uniquePartKeys.put(pageKey, item);
                    }
                }
            }
        }
    }
    items.addAll(uniquePartKeys.values());
    items.addAll(uniqueCreatePageKeys.values());
    return items;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Page(org.olat.modules.portfolio.Page) Section(org.olat.modules.portfolio.Section) Date(java.util.Date) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem)

Example 69 with SubscriptionListItem

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

the class PortfolioNotificationsHandler method pageCreateItem.

private SubscriptionListItem pageCreateItem(Long pageKey, String pageTitle, Date pageCreationDate, String rootBusinessPath, Translator translator) {
    String title = translator.translate("notifications.new.page", new String[] { pageTitle });
    String bPath = rootBusinessPath + "[Page:" + pageKey + "]";
    String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
    SubscriptionListItem item = new SubscriptionListItem(title, linkUrl, bPath, pageCreationDate, "o_icon_pf_page");
    item.setUserObject(pageKey);
    return item;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem)

Example 70 with SubscriptionListItem

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

the class PortfolioNotificationsHandler method sectionCreateItem.

private SubscriptionListItem sectionCreateItem(Long sectionKey, String sectionTitle, Date sectionCreationDate, String rootBusinessPath, Translator translator) {
    String title = translator.translate("notifications.new.section", new String[] { sectionTitle });
    String bPath = rootBusinessPath + "[Section:" + sectionKey + "]";
    String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
    SubscriptionListItem item = new SubscriptionListItem(title, linkUrl, bPath, sectionCreationDate, "o_icon_pf_section");
    item.setUserObject(sectionKey);
    return item;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem)

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