use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_8_1_0 method getAssessmentPublishers.
private List<Publisher> getAssessmentPublishers() {
StringBuilder sb = new StringBuilder();
sb.append("select pub from notipublisher pub where pub.resName='AssessmentManager' and type='AssessmentManager'");
DBQuery query = dbInstance.createQuery(sb.toString());
@SuppressWarnings("unchecked") List<Publisher> res = query.list();
return res;
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class NotificationsManagerTest method testCreatePublisher.
@Test
public void testCreatePublisher() {
String identifier = UUID.randomUUID().toString().replace("-", "");
SubscriptionContext context = new SubscriptionContext("PS", new Long(123), identifier);
PublisherData publisherData = new PublisherData("testPublisherSubscriber", "e.g. forumdata=keyofforum", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
dbInstance.commitAndCloseSession();
// check values
Assert.assertNotNull(publisher);
Assert.assertNotNull(publisher.getKey());
Assert.assertNotNull(publisher.getCreationDate());
Assert.assertNotNull(publisher.getLatestNewsDate());
Assert.assertEquals("PS", publisher.getResName());
Assert.assertEquals(new Long(123), publisher.getResId());
Assert.assertEquals(identifier, publisher.getSubidentifier());
// check if exists
Publisher reloadedPublisher = notificationManager.getPublisher(context);
Assert.assertNotNull(reloadedPublisher);
Assert.assertEquals(publisher, reloadedPublisher);
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class NotificationsManagerTest method testUnsubscribe_v1.
@Test
public void testUnsubscribe_v1() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("unsubs-" + UUID.randomUUID().toString());
// create a publisher
String identifier = UUID.randomUUID().toString().replace("-", "");
SubscriptionContext context = new SubscriptionContext("All", new Long(123), identifier);
PublisherData publisherData = new PublisherData("testUnsubscribe", "e.g. forumdata=keyofforum", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(publisher);
// subscribe
notificationManager.subscribe(id, context, publisherData);
dbInstance.commitAndCloseSession();
// check
Subscriber subscriber = notificationManager.getSubscriber(id, publisher);
Assert.assertNotNull(subscriber);
// unsubscribe
notificationManager.unsubscribe(subscriber);
dbInstance.commitAndCloseSession();
// check
boolean subscribed = notificationManager.isSubscribed(id, context);
Assert.assertFalse(subscribed);
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class NotificationsManagerTest method testUnsubscribe_v2.
@Test
public void testUnsubscribe_v2() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("unsubs-" + UUID.randomUUID().toString());
// create a publisher
String identifier = UUID.randomUUID().toString().replace("-", "");
SubscriptionContext context = new SubscriptionContext("All", new Long(123), identifier);
PublisherData publisherData = new PublisherData("testUnsubscribe", "e.g. forumdata=keyofforum", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(publisher);
// subscribe
notificationManager.subscribe(id, context, publisherData);
dbInstance.commitAndCloseSession();
// check
Subscriber subscriber = notificationManager.getSubscriber(id, publisher);
Assert.assertNotNull(subscriber);
// unsubscribe
notificationManager.unsubscribe(id, context);
dbInstance.commitAndCloseSession();
// check
boolean subscribed = notificationManager.isSubscribed(id, context);
Assert.assertFalse(subscribed);
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class NotificationsManagerTest method testSubscriptions.
@Test
public void testSubscriptions() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("fi1-" + UUID.randomUUID().toString());
Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("fi2-" + UUID.randomUUID().toString());
Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("fi3-" + UUID.randomUUID().toString());
SubscriptionContext sc = new SubscriptionContext("Course", new Long(123), UUID.randomUUID().toString());
PublisherData pd = new PublisherData("Forum", "e.g. forumdata=keyofforum", null);
SubscriptionContext sc2 = new SubscriptionContext("Course2", new Long(123), UUID.randomUUID().toString());
PublisherData pd2 = new PublisherData("Forum", "e.g. forumdata=keyofforum2", null);
dbInstance.closeSession();
notificationManager.subscribe(id1, sc, pd);
notificationManager.subscribe(id3, sc, pd);
notificationManager.subscribe(id2, sc2, pd2);
notificationManager.subscribe(id1, sc2, pd2);
dbInstance.closeSession();
Publisher p = notificationManager.getPublisher(sc);
assertNotNull(p);
assertEquals(p.getResName(), sc.getResName());
assertEquals(p.getResId(), sc.getResId());
assertEquals(p.getSubidentifier(), sc.getSubidentifier());
boolean isSub = notificationManager.isSubscribed(id1, sc);
assertTrue("subscribed::", isSub);
notificationManager.notifyAllSubscribersByEmail();
dbInstance.closeSession();
notificationManager.unsubscribe(id1, sc);
dbInstance.closeSession();
boolean isStillSub = notificationManager.isSubscribed(id1, sc);
assertFalse("subscribed::", isStillSub);
notificationManager.delete(sc);
dbInstance.commitAndCloseSession();
Publisher p2 = notificationManager.getPublisher(sc);
assertNull("publisher marked deleted should not be found", p2);
}
Aggregations