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