Search in sources :

Example 56 with SubscriptionListItem

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

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 57 with SubscriptionListItem

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

the class PortfolioNotificationsHandler method pageModifiedItem.

private SubscriptionListItem pageModifiedItem(Long pageKey, String pageTitle, Date pageLastModified, Date partLastModified, String rootBusinessPath, Translator translator) {
    String title = translator.translate("notifications.modified.page", new String[] { pageTitle });
    Date date;
    if (partLastModified != null && partLastModified.compareTo(pageLastModified) > 0) {
        date = partLastModified;
    } else {
        date = pageLastModified;
    }
    String bPath = rootBusinessPath + "[Page:" + pageKey + "]";
    String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
    SubscriptionListItem item = new SubscriptionListItem(title, linkUrl, bPath, date, "o_icon_pf_page");
    item.setUserObject(pageKey);
    return item;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Date(java.util.Date)

Example 58 with SubscriptionListItem

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

the class PortfolioNotificationsHandler method getAllItems.

public List<SubscriptionListItem> getAllItems(Binder binder, BinderSecurityCallback secCallback, Date compareDate, Locale locale) {
    String rootBusinessPath = "[Binder:" + binder.getKey() + "]";
    if (binder.getOlatResource() != null) {
        RepositoryEntry re = repositoryService.loadByResourceKey(binder.getOlatResource().getKey());
        rootBusinessPath = "[RepositoryEntry:" + re.getKey() + "]";
    } else {
        rootBusinessPath = "[Binder:" + binder.getKey() + "]";
    }
    Translator translator = Util.createPackageTranslator(PortfolioHomeController.class, locale);
    List<SubscriptionListItem> items = new ArrayList<>();
    items.addAll(getCommentNotifications(binder, secCallback, compareDate, rootBusinessPath, translator));
    items.addAll(getPageNotifications(binder, secCallback, compareDate, rootBusinessPath, translator));
    items.addAll(getSectionNotifications(binder, secCallback, compareDate, rootBusinessPath, translator));
    items.addAll(getEvaluationNotifications(binder, secCallback, compareDate, rootBusinessPath, translator));
    Collections.sort(items, new PortfolioNotificationComparator());
    return items;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 59 with SubscriptionListItem

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

the class PortfolioNotificationsHandler method getEvaluationNotifications.

public List<SubscriptionListItem> getEvaluationNotifications(Binder binder, BinderSecurityCallback secCallback, Date compareDate, String rootBusinessPath, Translator translator) {
    StringBuilder sb = new StringBuilder();
    sb.append("select page, evasession").append(" from pfpage as page").append(" inner join fetch page.section as section").append(" inner join fetch section.binder as binder").append(" left join evaluationformsession as evasession on (page.body.key = evasession.pageBody.key)").append(" where binder.key=:binderKey and evasession.status='done' and evasession.submissionDate>=:compareDate");
    List<Object[]> objects = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("binderKey", binder.getKey()).setParameter("compareDate", compareDate).getResultList();
    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();
        // session
        EvaluationFormSession evaluationSession = (EvaluationFormSession) object[1];
        Date submissionDate = evaluationSession.getSubmissionDate();
        Date firstSubmissionDate = evaluationSession.getFirstSubmissionDate();
        if (submissionDate != null && secCallback.canViewElement(page)) {
            if (submissionDate.compareTo(firstSubmissionDate) == 0) {
                SubscriptionListItem item = evaluationNewItem(pageKey, pageTitle, submissionDate, rootBusinessPath, translator);
                items.add(item);
            } else {
                SubscriptionListItem item = evaluationModifiedItem(pageKey, pageTitle, submissionDate, rootBusinessPath, translator);
                items.add(item);
            }
        }
    }
    return items;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) EvaluationFormSession(org.olat.modules.forms.EvaluationFormSession) ArrayList(java.util.ArrayList) Page(org.olat.modules.portfolio.Page) Date(java.util.Date)

Example 60 with SubscriptionListItem

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

the class PortfolioNotificationsHandler method evaluationNewItem.

private SubscriptionListItem evaluationNewItem(Long pageKey, String pageTitle, Date pageCreationDate, String rootBusinessPath, Translator translator) {
    String title = translator.translate("notifications.new.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)

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