use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class NotificationsManagerTest method testGetSubscriptionInfos.
// markPublisherNews
@Test
public void testGetSubscriptionInfos() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fi1-" + UUID.randomUUID().toString());
SubscriptionContext context = new SubscriptionContext("Course", new Long(789521), UUID.randomUUID().toString());
PublisherData publisherData = new PublisherData("Forum", "e.g. forumdata=keyofforum", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
dbInstance.commitAndCloseSession();
notificationManager.subscribe(id, context, publisherData);
dbInstance.commitAndCloseSession();
// get infos
List<SubscriptionInfo> infos = notificationManager.getSubscriptionInfos(id, publisher.getType());
Assert.assertNotNull(infos);
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class NotificationsManagerTest method testGetSubscribersByTypes.
@Test
public void testGetSubscribersByTypes() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("type1-" + UUID.randomUUID().toString());
// create a first publisher
String identifier = UUID.randomUUID().toString().replace("-", "");
SubscriptionContext context1 = new SubscriptionContext("Subscribers", new Long(123), identifier);
PublisherData publisherData1 = new PublisherData("testGetSubscribersByType1", "e.g. forumdata=keyofforum", null);
Publisher publisher1 = notificationManager.getOrCreatePublisher(context1, publisherData1);
dbInstance.commitAndCloseSession();
String identifier2 = UUID.randomUUID().toString().replace("-", "");
SubscriptionContext context2 = new SubscriptionContext("Subscribers", new Long(123), identifier2);
PublisherData publisherData2 = new PublisherData("testGetSubscribersByType2", "e.g. forumdata=keyofforum", null);
Publisher publisher2 = notificationManager.getOrCreatePublisher(context2, publisherData2);
dbInstance.commitAndCloseSession();
// add subscribers
notificationManager.subscribe(id, context1, publisherData1);
notificationManager.subscribe(id, context2, publisherData2);
dbInstance.commitAndCloseSession();
// get subscribers without types
List<Subscriber> emptySubscribers = notificationManager.getSubscribers(id, null);
Assert.assertNotNull(emptySubscribers);
Assert.assertEquals(2, emptySubscribers.size());
// get subscribers with 1 type
List<String> types = Collections.singletonList(publisher1.getType());
List<Subscriber> typedSubscribers = notificationManager.getSubscribers(id, types);
Assert.assertNotNull(typedSubscribers);
Assert.assertEquals(1, typedSubscribers.size());
// get subscribers with 2 types
List<String> allTypes = new ArrayList<String>(2);
allTypes.add(publisher1.getType());
allTypes.add(publisher2.getType());
List<Subscriber> allSubscribers = notificationManager.getSubscribers(id, allTypes);
Assert.assertNotNull(allSubscribers);
Assert.assertEquals(2, allSubscribers.size());
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class RepositoryEntryMembershipProcessorTest method testRemoveParticipant.
@Test
public void testRemoveParticipant() {
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
// create a group with members
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
repositoryEntryRelationDao.addRole(member, re, GroupRoles.participant.name());
repositoryEntryRelationDao.addRole(participant, re, GroupRoles.participant.name());
// 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(participant, context, publisherData);
dbInstance.commitAndCloseSession();
// remove member and participant as participant of the repo entry
List<Identity> removeIdentities = new ArrayList<>(2);
removeIdentities.add(member);
removeIdentities.add(participant);
MailPackage mailing = new MailPackage(false);
repositoryManager.removeParticipants(owner, removeIdentities, re, mailing, false);
// wait for the remove of subscription
waitForCondition(new CheckUnsubscription(participant, context, dbInstance, notificationManager), 5000);
sleep(1000);
// check that subscription of id1 was deleted but not the ones of id2 and coach
boolean subscribedPart = notificationManager.isSubscribed(participant, context);
Assert.assertFalse(subscribedPart);
boolean subscribedMember = notificationManager.isSubscribed(member, context);
Assert.assertTrue(subscribedMember);
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 PFNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si = null;
Publisher p = subscriber.getPublisher();
try {
final Translator translator = Util.createPackageTranslator(PFRunController.class, locale);
PFNotifications notifications = new PFNotifications(subscriber, locale, compareDate, pfManager, notificationsManager, userManager);
List<SubscriptionListItem> items = notifications.getItems();
if (items.isEmpty()) {
si = notificationsManager.getNoSubscriptionInfo();
} else {
String displayName = notifications.getDisplayname();
String title = translator.translate("notifications.header", new String[] { displayName });
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_ICON), items);
}
} catch (Exception e) {
log.error("Unknown Exception", e);
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
}
Aggregations