* @see org.olat.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.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.getInstance().deactivate(p);
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
try {
Date latestNews = p.getLatestNewsDate();
Identity identity = subscriber.getIdentity();
// do not try to create a subscription info if state is deleted - results in
// exceptions, course
// can't be loaded when already deleted
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
Long courseId = new Long(p.getData());
final ICourse course = loadCourseFromId(courseId);
if (course != null) {
// 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 List<Identity> coachedUsers = new ArrayList<Identity>();
if (!hasFullAccess) {
// initialize list of users, only when user has not full access
List<BusinessGroup> coachedGroups = cgm.getOwnedLearningGroupsFromAllContexts(identity);
Manager securityManager = ManagerFactory.getManager();
for (Iterator<BusinessGroup> iter = coachedGroups.iterator(); iter.hasNext();) {
BusinessGroup group = iter.next();
coachedUsers.addAll(securityManager.getIdentitiesOfSecurityGroup(group.getPartipiciantGroup()));
}
}
List<IQTESTCourseNode> testNodes = getCourseTestNodes(course);
Translator translator = Util.createPackageTranslator(AssessmentNotificationsHandler.class, locale);
String title = translator.translate("notifications.header", new String[]{course.getCourseTitle()});
si = new SubscriptionInfo(new TitleItem(title, CSS_CLASSS_IQTEST_ICON), null);
for (Iterator<IQTESTCourseNode> i = testNodes.iterator(); i.hasNext();) {
IQTESTCourseNode test = i.next();
QTIResultManager qrm = QTIResultManager.getInstance();
List testResultSets = qrm.getResultSets(course.getResourceableId(), test.getIdent(),
test.getReferencedRepositoryEntry().getKey(), null);
for (Iterator j = testResultSets.iterator(); j.hasNext();) {
QTIResultSet qrs = (QTIResultSet) j.next();
// - modify date on test set must be newer than last visit of
// assessment tool
// - user must either be course administrator (access to all
// users granted)
// or in a course right group with the assessment tool right or
// a course
// coach. in the second case, only tests of users are shown that
// the coach does actually
// coach himself. he does not have access to other users
Date modDate = qrs.getLastModified();
if (modDate.after(compareDate) && (hasFullAccess || PersistenceHelper.listContainsObjectByKey(coachedUsers, qrs.getIdentity()))) {
String score = (new Float(qrs.getScore())).toString();
String desc = translator.translate("notifications.entry", new String[] { test.getShortTitle(),
NotificationHelper.getFormatedName(qrs.getIdentity()), score });
String urlToSend = null;
if(p.getBusinessPath() != null) {
String businessPath = p.getBusinessPath() + "[assessmentTool:0][Identity:" + qrs.getIdentity().getKey() + "][CourseNode:" + test.getIdent() + "]";
urlToSend = NotificationHelper.getURLFromBusinessPathString(p, businessPath);
}
SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, modDate, CSS_CLASS_USER_ICON);
si.addSubscriptionListItem(subListItem);
}