use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class PortfolioNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si = null;
Publisher publisher = subscriber.getPublisher();
Binder binder = binderDao.loadByKey(publisher.getResId());
if (isInkoveValid(binder, compareDate, publisher)) {
BinderSecurityCallback secCallback = null;
Identity identity = subscriber.getIdentity();
if (binderDao.isMember(binder, identity, PortfolioRoles.owner.name())) {
secCallback = BinderSecurityCallbackFactory.getCallbackForOwnedBinder(binder);
} else {
List<AccessRights> rights = portfolioService.getAccessRights(binder, identity);
if (rights.size() > 0) {
secCallback = BinderSecurityCallbackFactory.getCallbackForCoach(binder, rights);
}
}
if (secCallback != null) {
si = new SubscriptionInfo(subscriber.getKey(), publisher.getType(), getTitleItemForBinder(binder), null);
List<SubscriptionListItem> allItems = getAllItems(binder, secCallback, compareDate, locale);
for (SubscriptionListItem item : allItems) {
// only a type of icon
SubscriptionListItem clonedItem = new SubscriptionListItem(item.getDescription(), item.getDescriptionTooltip(), item.getLink(), item.getBusinessPath(), item.getDate(), "o_ep_icon");
si.addSubscriptionListItem(clonedItem);
}
}
}
if (si == null) {
// no info, return empty
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class PFNotifications method getItems.
public List<SubscriptionListItem> getItems() throws Exception {
Publisher p = subscriber.getPublisher();
Identity identity = subscriber.getIdentity();
ICourse course = CourseFactory.loadCourse(p.getResId());
CourseEnvironment courseEnv = course.getCourseEnvironment();
CourseGroupManager groupManager = courseEnv.getCourseGroupManager();
CourseNode node = course.getRunStructure().getNode(p.getSubidentifier());
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
Date latestNews = p.getLatestNewsDate();
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
this.displayname = entry.getDisplayname();
if (groupManager.isIdentityCourseCoach(identity) || groupManager.isIdentityCourseAdministrator(identity)) {
List<Identity> participants = pfManager.getParticipants(identity, courseEnv, groupManager.isIdentityCourseAdministrator(identity));
for (Identity participant : participants) {
gatherItems(participant, p, courseEnv, node);
}
} else {
gatherItems(identity, p, courseEnv, node);
}
}
return items;
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class RepositoryEntryMembershipProcessorTest method testRemoveCoach_withBusinessGroups.
@Test
public void testRemoveCoach_withBusinessGroups() {
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
// create a group with members
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());
BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRelationToResource(businessGroup, re);
// create a publisher
SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
Assert.assertNotNull(publisher);
dbInstance.commitAndCloseSession();
// subscribe
notificationManager.subscribe(owner, context, publisherData);
notificationManager.subscribe(member, context, publisherData);
notificationManager.subscribe(coach, context, publisherData);
dbInstance.commitAndCloseSession();
// remove member and coach as coach of the repo entry
List<Identity> removeIdentities = new ArrayList<>(2);
removeIdentities.add(member);
removeIdentities.add(coach);
repositoryManager.removeTutors(owner, removeIdentities, re, new MailPackage(false));
// wait for the remove of subscription
waitForCondition(new CheckUnsubscription(member, context, dbInstance, notificationManager), 5000);
sleep(1000);
// check that subscription of id1 was deleted but not the ones of id2 and coach
boolean subscribedMember = notificationManager.isSubscribed(member, context);
Assert.assertFalse(subscribedMember);
boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
Assert.assertTrue(subscribedCoach);
boolean subscribedOwner = notificationManager.isSubscribed(owner, context);
Assert.assertTrue(subscribedOwner);
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class FeedNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si;
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
try {
final Translator translator = Util.createPackageTranslator(FeedMainController.class, locale);
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
String title;
try {
RepositoryEntry re = repoManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
if (re.getAccess() == RepositoryEntry.DELETED || re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return notificationsManager.getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
if ("CourseModule".equals(p.getResName())) {
ICourse course = CourseFactory.loadCourse(re);
CourseNode node = course.getRunStructure().getNode(p.getSubidentifier());
if (node == null) {
notificationsManager.deactivate(p);
return notificationsManager.getNoSubscriptionInfo();
}
title = translator.translate(NOTIFICATIONS_HEADER_COURSE, new String[] { displayName });
} else {
title = getHeader(translator, displayName);
}
} catch (Exception e) {
log.error("Unknown Exception", e);
return notificationsManager.getNoSubscriptionInfo();
}
OLATResourceable feedOres = OresHelper.createOLATResourceableInstance(p.getType(), new Long(p.getData()));
Feed feed = feedManager.loadFeed(feedOres);
List<Item> listItems = feedManager.loadItems(feed);
List<SubscriptionListItem> items = new ArrayList<>();
for (Item item : listItems) {
if (!item.isDraft()) {
appendSubscriptionItem(item, p, compareDate, translator, items);
}
}
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, getCssClassIcon()), items);
} else {
// no news
si = notificationsManager.getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Unknown Exception", e);
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
}
Aggregations