use of org.olat.core.commons.services.notifications.Publisher in project openolat by klemens.
the class NotificationsManagerTest method testValidSubscribers.
@Test
public void testValidSubscribers() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("valid1-" + UUID.randomUUID().toString());
Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("valid1-" + UUID.randomUUID().toString());
// create a publisher
String identifier = UUID.randomUUID().toString().replace("-", "");
SubscriptionContext context = new SubscriptionContext("Valid", new Long(123), identifier);
PublisherData publisherData = new PublisherData("testValidSubscribers", "e.g. forumdata=keyofforum", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(publisher);
// add subscribers
notificationManager.subscribe(id1, context, publisherData);
notificationManager.subscribe(id2, context, publisherData);
dbInstance.commitAndCloseSession();
// get valid subscribers
List<Subscriber> subscribers = notificationManager.getValidSubscribers(id1);
Assert.assertNotNull(subscribers);
Assert.assertEquals(1, subscribers.size());
Assert.assertEquals(publisher, subscribers.get(0).getPublisher());
Assert.assertEquals(id1, subscribers.get(0).getIdentity());
}
use of org.olat.core.commons.services.notifications.Publisher 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.Publisher in project openolat by klemens.
the class GTANotifications method getItems.
public List<SubscriptionListItem> getItems() {
Publisher p = subscriber.getPublisher();
ICourse course = CourseFactory.loadCourse(p.getResId());
CourseNode node = course.getRunStructure().getNode(p.getSubidentifier());
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
if (entry.getRepositoryEntryStatus().isClosed() || entry.getRepositoryEntryStatus().isUnpublished()) {
return Collections.emptyList();
}
if (entry != null && node instanceof GTACourseNode) {
gtaNode = (GTACourseNode) node;
displayName = entry.getDisplayname();
courseEnv = course.getCourseEnvironment();
taskList = gtaManager.getTaskList(entry, gtaNode);
if (GTAType.group.name().equals(gtaNode.getModuleConfiguration().getStringValue(GTACourseNode.GTASK_TYPE))) {
createBusinessGroupsSubscriptionInfo(subscriber.getIdentity());
} else {
createIndividualSubscriptionInfo(subscriber.getIdentity());
}
}
return items;
}
use of org.olat.core.commons.services.notifications.Publisher in project openolat by klemens.
the class DocumentPoolNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
try {
SubscriptionInfo si;
String taxonomyKey = documentPoolModule.getTaxonomyTreeKey();
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews) && StringHelper.isLong(taxonomyKey)) {
Taxonomy taxonomy = taxonomyService.getTaxonomy(new TaxonomyRefImpl(new Long(taxonomyKey)));
if (taxonomy == null) {
return notificationsManager.getNoSubscriptionInfo();
}
Identity identity = subscriber.getIdentity();
Roles roles = securityManager.getRoles(identity);
boolean isTaxonomyAdmin = roles.isOLATAdmin();
Translator translator = Util.createPackageTranslator(DocumentPoolMainController.class, locale);
String templates = translator.translate("document.pool.templates");
TaxonomyTreeBuilder builder = new TaxonomyTreeBuilder(taxonomy, identity, null, isTaxonomyAdmin, documentPoolModule.isTemplatesDirectoryEnabled(), templates, locale);
TreeModel model = builder.buildTreeModel();
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItemForPublisher(), null);
new TreeVisitor(node -> {
TaxonomyTreeNode tNode = (TaxonomyTreeNode) node;
if (tNode.getTaxonomyLevel() != null && tNode.isDocumentsLibraryEnabled() && tNode.isCanRead()) {
VFSContainer container = taxonomyService.getDocumentsLibrary(tNode.getTaxonomyLevel());
String prefixBusinessPath = "[DocumentPool:" + taxonomy.getKey() + "][TaxonomyLevel:" + tNode.getTaxonomyLevel().getKey() + "][path=";
createSubscriptionInfo(container, prefixBusinessPath, compareDate, si, p, translator);
} else if (tNode.getType() == TaxonomyTreeNodeType.templates) {
VFSContainer container = taxonomyService.getDocumentsLibrary(taxonomy);
String prefixBusinessPath = "[DocumentPool:" + taxonomy.getKey() + "][Templates:0s][path=";
createSubscriptionInfo(container, prefixBusinessPath, compareDate, si, p, translator);
}
}, model.getRootNode(), false).visitAll();
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
} catch (Exception e) {
log.error("Cannot create document pool notifications for subscriber: " + subscriber.getKey(), e);
return notificationsManager.getNoSubscriptionInfo();
}
}
use of org.olat.core.commons.services.notifications.Publisher in project openolat by klemens.
the class BusinessGroupMembershipProcessorTest method testUnlinkMemberOfBusinessGroup.
@Test
public void testUnlinkMemberOfBusinessGroup() {
// create a group with members
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-1");
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-2");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRole(id1, businessGroup, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, businessGroup, GroupRoles.participant.name());
// create a publisher
SubscriptionContext context = new SubscriptionContext(businessGroup, "");
PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
Assert.assertNotNull(publisher);
dbInstance.commitAndCloseSession();
// subscribe
notificationManager.subscribe(coach, context, publisherData);
notificationManager.subscribe(id1, context, publisherData);
notificationManager.subscribe(id2, context, publisherData);
dbInstance.commitAndCloseSession();
// remove id1 and check subscription
MailPackage mailing = new MailPackage(false);
List<Identity> identitiesToRemove = Collections.singletonList(id1);
businessGroupService.removeParticipants(coach, identitiesToRemove, businessGroup, mailing);
// wait for the remove of subscription
waitForCondition(new CheckUnsubscription(id1, context, dbInstance, notificationManager), 5000);
// check that subscription of id1 was deleted but not the ones of id2 and coach
boolean subscribedId1 = notificationManager.isSubscribed(id1, context);
Assert.assertFalse(subscribedId1);
boolean subscribedId2 = notificationManager.isSubscribed(id2, context);
Assert.assertTrue(subscribedId2);
boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
Assert.assertTrue(subscribedCoach);
}
Aggregations