use of org.olat.core.commons.services.notifications.model.TitleItem in project openolat by klemens.
the class NewUsersNotificationHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
Translator translator = Util.createPackageTranslator(this.getClass(), locale);
// there could be news for me, investigate deeper
try {
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
List<Identity> identities = UsersSubscriptionManager.getInstance().getNewIdentityCreated(compareDate);
if (identities.isEmpty()) {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
} else {
translator = Util.createPackageTranslator(this.getClass(), locale);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(getItemTitle(identities, translator), CSSHelper.CSS_CLASS_GROUP), null);
SubscriptionListItem subListItem;
for (Identity newUser : identities) {
String desc = translator.translate("notifications.entry", new String[] { NotificationHelper.getFormatedName(newUser) });
String businessPath = "[Identity:" + newUser.getKey() + "]";
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
Date modDate = newUser.getCreationDate();
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSSHelper.CSS_CLASS_USER);
si.addSubscriptionListItem(subListItem);
}
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Error creating new identity's notifications for subscriber: " + subscriber.getKey(), e);
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.model.TitleItem in project openolat by klemens.
the class WikiPageChangeOrCreateNotificationHandler method createTitleInfo.
@Override
public String createTitleInfo(Subscriber subscriber, Locale locale) {
try {
Translator translator = Util.createPackageTranslator(WikiPageChangeOrCreateNotificationHandler.class, locale);
TitleItem title = getTitleItem(subscriber.getPublisher(), translator);
return title.getInfoContent("text/plain");
} catch (Exception e) {
log.error("Error while creating assessment notifications for subscriber: " + subscriber.getKey(), e);
checkPublisher(subscriber.getPublisher());
return "-";
}
}
use of org.olat.core.commons.services.notifications.model.TitleItem in project openolat by klemens.
the class WikiPageChangeOrCreateNotificationHandler method getTitleItem.
private TitleItem getTitleItem(Publisher p, Translator translator) {
Long resId = p.getResId();
String type = p.getResName();
String title;
if ("BusinessGroup".equals(type)) {
BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(resId);
title = translator.translate("notifications.header.group", new String[] { bg.getName() });
} else if (CourseModule.getCourseTypeName().equals(type)) {
String displayName = RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(resId);
title = translator.translate("notifications.header.course", new String[] { displayName });
} else {
title = translator.translate("notifications.header");
}
return new TitleItem(title, Wiki.CSS_CLASS_WIKI_ICON);
}
use of org.olat.core.commons.services.notifications.model.TitleItem in project openolat by klemens.
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();
}
}
use of org.olat.core.commons.services.notifications.model.TitleItem in project openolat by klemens.
the class FolderNotificationsHandler method getTitleItem.
private TitleItem getTitleItem(Publisher p, Translator translator) {
String title;
try {
String resName = p.getResName();
if ("BusinessGroup".equals(resName)) {
BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(p.getResId());
title = translator.translate("notifications.header.group", new String[] { bg.getName() });
} else if ("CourseModule".equals(resName)) {
String displayName = RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(p.getResId());
title = translator.translate("notifications.header.course", new String[] { displayName });
} else {
title = translator.translate("notifications.header");
}
} catch (Exception e) {
log.error("", e);
checkPublisher(p);
title = translator.translate("notifications.header");
}
return new TitleItem(title, CSSHelper.CSS_CLASS_FILETYPE_FOLDER);
}
Aggregations