Search in sources :

Example 76 with Publisher

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;
}
Also used : DBQuery(org.olat.core.commons.persistence.DBQuery) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 77 with Publisher

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);
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 78 with Publisher

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);
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 79 with Publisher

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);
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 80 with Publisher

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);
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Aggregations

Publisher (org.olat.core.commons.services.notifications.Publisher)150 Identity (org.olat.core.id.Identity)62 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)60 PublisherData (org.olat.core.commons.services.notifications.PublisherData)44 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)44 Date (java.util.Date)42 Test (org.junit.Test)42 Subscriber (org.olat.core.commons.services.notifications.Subscriber)42 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)38 RepositoryEntry (org.olat.repository.RepositoryEntry)34 Translator (org.olat.core.gui.translator.Translator)30 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)28 OLATResourceable (org.olat.core.id.OLATResourceable)18 ICourse (org.olat.course.ICourse)18 BusinessGroup (org.olat.group.BusinessGroup)16 ArrayList (java.util.ArrayList)14 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)14 NotificationsHandler (org.olat.core.commons.services.notifications.NotificationsHandler)12 AssertException (org.olat.core.logging.AssertException)12 CourseNode (org.olat.course.nodes.CourseNode)8