use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
the class PFNotifications method gatherItems.
private void gatherItems(Identity participant, Publisher p, CourseEnvironment courseEnv, CourseNode node) {
Path folderRoot = Paths.get(courseEnv.getCourseBaseContainer().getRelPath(), PFManager.FILENAME_PARTICIPANTFOLDER, node.getIdent(), pfManager.getIdFolderName(participant));
final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot.toString(), compareDate);
SubscriptionListItem subListItem;
for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
FileInfo fi = it_infos.next();
MetaInfo metaInfo = fi.getMetaInfo();
String filePath = fi.getRelPath();
Date modDate = fi.getLastModified();
String action = "upload";
try {
Path basepath = courseEnv.getCourseBaseContainer().getBasefile().toPath();
Path completepath = Paths.get(basepath.toString(), PFManager.FILENAME_PARTICIPANTFOLDER, node.getIdent(), pfManager.getIdFolderName(participant), filePath);
BasicFileAttributes attrs = Files.readAttributes(completepath, BasicFileAttributes.class);
if (attrs.creationTime().toMillis() < attrs.lastModifiedTime().toMillis()) {
action = "modify";
}
} catch (IOException ioe) {
log.error("IOException", ioe);
}
String forby = translator.translate("notifications.entry." + (filePath.contains(PFManager.FILENAME_DROPBOX) ? "by" : "for"));
String userDisplayName = userManager.getUserDisplayName(participant);
String desc = translator.translate("notifications.entry." + action, new String[] { filePath, forby, userDisplayName });
String businessPath = p.getBusinessPath();
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String iconCssClass = null;
if (metaInfo != null) {
iconCssClass = metaInfo.getIconCssClass();
}
if (metaInfo != null && !metaInfo.getName().startsWith(".")) {
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
items.add(subListItem);
}
}
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
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;
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
the class PortfolioNotificationsHandler method getCommentNotifications.
public List<SubscriptionListItem> getCommentNotifications(Binder binder, BinderSecurityCallback secCallback, Date compareDate, String rootBusinessPath, Translator translator) {
StringBuilder sb = new StringBuilder();
sb.append("select").append(" comment.id as commentId,").append(" comment.creationDate as commentDate,").append(" author.key as authorKey,").append(" author.name as authorName,").append(" authorUser.firstName as authorFirstName,").append(" authorUser.lastName as authorLastName, ").append(" page").append(" from usercomment as comment").append(" inner join comment.creator as author").append(" inner join author.user as authorUser").append(" inner join pfpage as page on (comment.resId=page.key and comment.resName='Page')").append(" inner join fetch pfsection as section on (section.key = page.section.key)").append(" inner join fetch pfbinder as binder on (binder.key=section.binder.key)").append(" where binder.key=:binderKey and comment.creationDate>=: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) {
Long commentId = (Long) object[0];
Date commentDate = (Date) object[1];
NotificationIdentityNames author = getIdentityNames(object, 2);
Page page = (Page) object[6];
Long pageKey = page.getKey();
String pageTitle = page.getTitle();
if (secCallback.canViewElement(page)) {
String bPath = rootBusinessPath + "[Page:" + pageKey + "][Comment:" + commentId + "]";
String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
String[] title = new String[] { pageTitle, userManager.getUserDisplayName(author) };
SubscriptionListItem item = new SubscriptionListItem(translator.translate("notifications.new.comment", title), linkUrl, bPath, commentDate, "o_icon_comments");
item.setUserObject(pageKey);
items.add(item);
}
}
return items;
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
the class PortfolioNotificationsHandler method sectionModifiedItem.
private SubscriptionListItem sectionModifiedItem(Long sectionKey, String sectionTitle, Date sectionLastModified, String rootBusinessPath, Translator translator) {
String title = translator.translate("notifications.modified.section", new String[] { sectionTitle });
String bPath = rootBusinessPath + "[Section:" + sectionKey + "]";
String linkUrl = BusinessControlFactory.getInstance().getURLFromBusinessPathString(bPath);
SubscriptionListItem item = new SubscriptionListItem(title, linkUrl, bPath, sectionLastModified, "o_icon_pf_section");
item.setUserObject(sectionKey);
return item;
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project openolat by klemens.
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;
}
Aggregations