use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class PortfolioNotificationsHandler method getSectionNotifications.
public List<SubscriptionListItem> getSectionNotifications(Binder binder, BinderSecurityCallback secCallback, Date compareDate, String rootBusinessPath, Translator translator) {
StringBuilder sb = new StringBuilder();
sb.append("select section").append(" from pfsection as section").append(" inner join fetch section.binder as binder").append(" where binder.key=:binderKey and section.lastModified>=:compareDate");
List<Section> sections = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Section.class).setParameter("binderKey", binder.getKey()).setParameter("compareDate", compareDate).getResultList();
Set<Long> uniqueSectionKeys = new HashSet<>();
Set<Long> uniqueCreateSectionKeys = new HashSet<>();
List<SubscriptionListItem> items = new ArrayList<>(sections.size());
for (Section section : sections) {
// section
Long sectionKey = section.getKey();
String sectionTitle = section.getTitle();
Date sectionCreationDate = section.getCreationDate();
Date sectionLastModified = section.getLastModified();
if (secCallback.canViewElement(section)) {
if (isSameDay(sectionCreationDate, sectionLastModified)) {
if (!uniqueCreateSectionKeys.contains(sectionKey)) {
uniqueCreateSectionKeys.add(sectionKey);
SubscriptionListItem item = sectionCreateItem(sectionKey, sectionTitle, sectionCreationDate, rootBusinessPath, translator);
items.add(item);
}
} else if (!uniqueSectionKeys.contains(sectionKey)) {
uniqueSectionKeys.add(sectionKey);
SubscriptionListItem item = sectionModifiedItem(sectionKey, sectionTitle, sectionLastModified, 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 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 OpenOLAT.
the class FileUploadNotificationHandler method createSubscriptionInfo.
/**
* @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
* java.util.Locale, java.util.Date)
*/
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
final Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
// there could be news for me, investigate deeper
try {
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
if (re == null) {
if (!checkPublisher(subscriber.getPublisher())) {
return notificationsManager.getNoSubscriptionInfo();
}
} else if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return notificationsManager.getNoSubscriptionInfo();
}
String displayname = re.getDisplayname();
OLATResourceable ores = OresHelper.createOLATResourceableInstance("CourseModule", p.getResId());
RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(ores, false);
List<DialogElement> dialogElements = dialogElementsMgr.getDialogElements(entry, p.getSubidentifier());
final Translator translator = Util.createPackageTranslator(DialogCourseNodeRunController.class, locale);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(translator.translate("notifications.header", new String[] { displayname }), CSSS_CLASS_UPLOAD_ICON), null);
for (DialogElement element : dialogElements) {
// do only show entries newer then the ones already seen
if (element.getCreationDate().after(compareDate)) {
String filename = element.getFilename();
Identity author = element.getAuthor();
Date modDate = element.getCreationDate();
String[] params = new String[] { filename, NotificationHelper.getFormatedName(author) };
String desc = translator.translate("notifications.entry", params);
String businessPath = p.getBusinessPath() + "[Element:" + element.getKey() + "]";
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String cssClass = CSSHelper.createFiletypeIconCssClassFor(filename);
si.addSubscriptionListItem(new SubscriptionListItem(desc, urlToSend, businessPath, modDate, cssClass));
}
}
} else {
si = notificationsManager.getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Error creating file upload's notifications for subscriber: " + subscriber.getKey(), e);
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.model.SubscriptionListItem in project OpenOLAT by OpenOLAT.
the class AssessmentNotificationsHandler method createSubscriptionInfo.
/**
* @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
* java.util.Locale, java.util.Date)
*/
public SubscriptionInfo createSubscriptionInfo(final Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si = null;
Publisher p = subscriber.getPublisher();
if (!NotificationsUpgradeHelper.checkCourse(p)) {
// course don't exist anymore
notificationsManager.deactivate(p);
return notificationsManager.getNoSubscriptionInfo();
}
try {
Date latestNews = p.getLatestNewsDate();
Identity identity = subscriber.getIdentity();
// can't be loaded when already deleted
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
Long courseId = new Long(p.getData());
final ICourse course = loadCourseFromId(courseId);
if (courseStatus(course)) {
// course admins or users with the course right to have full access to
// the assessment tool will have full access to user tests
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
final boolean hasFullAccess = (cgm.isIdentityCourseAdministrator(identity) ? true : cgm.hasRight(identity, CourseRights.RIGHT_ASSESSMENT));
final Set<Identity> coachedUsers = new HashSet<Identity>();
if (!hasFullAccess) {
// initialize list of users, only when user has not full access
List<BusinessGroup> coachedGroups = cgm.getOwnedBusinessGroups(identity);
List<Identity> coachedIdentites = businessGroupService.getMembers(coachedGroups, GroupRoles.participant.name());
coachedUsers.addAll(coachedIdentites);
}
List<AssessableCourseNode> testNodes = getCourseTestNodes(course);
Translator translator = Util.createPackageTranslator(AssessmentManager.class, locale);
for (AssessableCourseNode test : testNodes) {
List<AssessmentEntry> assessments = courseNodeAssessmentDao.loadAssessmentEntryBySubIdent(cgm.getCourseEntry(), test.getIdent());
for (AssessmentEntry assessment : assessments) {
Date modDate = assessment.getLastModified();
Identity assessedIdentity = assessment.getIdentity();
if (modDate.after(compareDate) && (hasFullAccess || coachedUsers.contains(assessedIdentity))) {
BigDecimal score = assessment.getScore();
if (test instanceof ScormCourseNode) {
ScormCourseNode scormTest = (ScormCourseNode) test;
// check if completed or passed
String status = ScormAssessmentManager.getInstance().getLastLessonStatus(assessedIdentity.getName(), course.getCourseEnvironment(), scormTest);
if (!"passed".equals(status) && !"completed".equals(status)) {
continue;
}
}
String desc;
String type = translator.translate("notifications.entry." + test.getType());
if (score == null) {
desc = translator.translate("notifications.entry.attempt", new String[] { test.getShortTitle(), NotificationHelper.getFormatedName(assessedIdentity), type });
} else {
String scoreStr = AssessmentHelper.getRoundedScore(score);
desc = translator.translate("notifications.entry", new String[] { test.getShortTitle(), NotificationHelper.getFormatedName(assessedIdentity), scoreStr, type });
}
String urlToSend = null;
String businessPath = null;
if (p.getBusinessPath() != null) {
businessPath = p.getBusinessPath() + "[Users:0][Node:" + test.getIdent() + "][Identity:" + assessedIdentity.getKey() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_USER_ICON);
if (si == null) {
String title = translator.translate("notifications.header", new String[] { course.getCourseTitle() });
String css = CourseNodeFactory.getInstance().getCourseNodeConfigurationEvenForDisabledBB(test.getType()).getIconCSSClass();
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, css), null);
}
si.addSubscriptionListItem(subListItem);
}
}
}
}
}
if (si == null) {
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
} catch (Exception e) {
log.error("Error while creating assessment notifications", e);
checkPublisher(p);
return notificationsManager.getNoSubscriptionInfo();
}
}
Aggregations