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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations