Search in sources :

Example 51 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class EPChangelogController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    /* the subscription context + component */
    if (logger.isDebug())
        logger.debug("creating subscriptionContext for Map: " + map.getTitle() + ", getResourceableId: ->" + map.getResourceableId() + ", key: " + map.getKey());
    subsContext = new SubscriptionContext(EPNotificationsHandler.TYPENNAME, map.getResourceableId(), EPNotificationsHandler.TYPENNAME);
    if (subsContext != null) {
        String businessPath = "[EPDefaultMap:" + map.getKey() + "]";
        PublisherData data = new PublisherData(EPNotificationsHandler.TYPENNAME, null, businessPath);
        cSubscriptionCtrl = new ContextualSubscriptionController(ureq, getWindowControl(), subsContext, data);
        listenTo(cSubscriptionCtrl);
        flc.put("subscription", cSubscriptionCtrl.getInitialComponent());
    }
    /* the datechooser */
    dateChooser = uifactory.addDateChooser("dateChooser", "news.since", null, formLayout);
    dateChooser.setDate(new Date());
    dateChooser.addActionListener(FormEvent.ONCHANGE);
    /* display the changelog */
    updateChangelogDisplay();
}
Also used : ContextualSubscriptionController(org.olat.core.commons.services.notifications.ui.ContextualSubscriptionController) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Date(java.util.Date)

Example 52 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class NotificationsManagerTest method testValidSubscribersOf.

@Test
public void testValidSubscribersOf() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("valid1b-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("valid1b-" + UUID.randomUUID().toString());
    // create a publisher
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("Validb", 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 all subscribers of the publisher
    List<Subscriber> subscribers = notificationManager.getValidSubscribersOf(publisher);
    Assert.assertNotNull(subscribers);
    Assert.assertEquals(2, subscribers.size());
    Assert.assertEquals(publisher, subscribers.get(0).getPublisher());
    Assert.assertEquals(publisher, subscribers.get(1).getPublisher());
}
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 53 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class NotificationsManagerTest method testDuplicateSubscribers.

@Test(expected = DBRuntimeException.class)
public void testDuplicateSubscribers() throws Exception {
    try {
        PublisherData pd = new PublisherData("CreateSubscriber@2x", "e.g. forumdata=keyofforum", null);
        SubscriptionContext sc = new SubscriptionContext("Course", new Long(1238778567), UUID.randomUUID().toString().replace("-", ""));
        Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fci@2x-" + UUID.randomUUID().toString());
        Publisher publisher = notificationManager.getOrCreatePublisher(sc, pd);
        dbInstance.commit();
        ((NotificationsManagerImpl) notificationManager).doCreateAndPersistSubscriber(publisher, id);
        dbInstance.commit();
        ((NotificationsManagerImpl) notificationManager).doCreateAndPersistSubscriber(publisher, id);
        dbInstance.commit();
    } catch (Exception e) {
        dbInstance.rollback();
        throw e;
    }
}
Also used : NotificationsManagerImpl(org.olat.core.commons.services.notifications.manager.NotificationsManagerImpl) 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) DBRuntimeException(org.olat.core.logging.DBRuntimeException) Test(org.junit.Test)

Example 54 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class NotificationsManagerTest method testConcurrentSubscriberOperationsWithOneIdentity.

/**
 * Test creation of concurrent subscriber
 */
@Test
public void testConcurrentSubscriberOperationsWithOneIdentity() {
    final int NUM_OF_THREADS = 100;
    PublisherData pd = new PublisherData("MPSubscriber", "e.g. forumdata=keyofforum", null);
    SubscriptionContext sc = new SubscriptionContext("MPSubscriber", new Long(1238778566), UUID.randomUUID().toString().replace("-", ""));
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fci-" + UUID.randomUUID().toString());
    final CountDownLatch finishCount = new CountDownLatch(NUM_OF_THREADS);
    List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1));
    List<Boolean> statusList = Collections.synchronizedList(new ArrayList<Boolean>(1));
    List<MPSubscriberThread> threads = new ArrayList<MPSubscriberThread>();
    for (int i = 0; i < NUM_OF_THREADS; i++) {
        MPSubscriberThread thread = new MPSubscriberThread(sc, pd, id, exceptionHolder, statusList, finishCount);
        threads.add(thread);
    }
    for (MPSubscriberThread thread : threads) {
        thread.start();
    }
    // sleep until threads should have terminated/excepted
    try {
        finishCount.await(120, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        log.error("", e);
        Assert.fail();
    }
    for (Exception e : exceptionHolder) {
        log.error("Excpetion during concurrent subscription: ", e);
    }
    assertTrue("It throws an exception in test", exceptionHolder.isEmpty());
    assertEquals("Thread(s) did not finish", NUM_OF_THREADS, statusList.size());
    assertTrue("Subscriber does not exists", NotificationsManager.getInstance().isSubscribed(id, sc));
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) PublisherData(org.olat.core.commons.services.notifications.PublisherData) DBRuntimeException(org.olat.core.logging.DBRuntimeException) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 55 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class NotificationsManagerTest method testConcurrentFindOrCreatePublisher.

/**
 * Test synchronized 'findOrCreatePublisher' triggered by method 'subscribe'.
 * Start 10 threads which call 'subscribe' with same SubscriptionContext.
 */
@Test
public void testConcurrentFindOrCreatePublisher() {
    final int NUM_OF_THREADS = 10;
    PublisherData pd = new PublisherData("Forum", "e.g. forumdata=keyofforum", null);
    SubscriptionContext sc = new SubscriptionContext("Course", new Long(1238778565), UUID.randomUUID().toString().replace("-", ""));
    final CountDownLatch finishCount = new CountDownLatch(NUM_OF_THREADS);
    List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1));
    List<Boolean> statusList = Collections.synchronizedList(new ArrayList<Boolean>(1));
    List<SubscribeThread> threads = new ArrayList<SubscribeThread>();
    for (int i = 0; i < NUM_OF_THREADS; i++) {
        Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fci-" + i + "-" + UUID.randomUUID().toString());
        SubscribeThread thread = new SubscribeThread(sc, pd, id, exceptionHolder, statusList, finishCount);
        threads.add(thread);
    }
    for (SubscribeThread thread : threads) {
        thread.start();
    }
    // sleep until threads should have terminated/excepted
    try {
        finishCount.await(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        log.error("", e);
        Assert.fail();
    }
    assertTrue("It throws an exception in test", exceptionHolder.isEmpty());
    assertEquals("Thread(s) did not finish", NUM_OF_THREADS, statusList.size());
    for (SubscribeThread thread : threads) {
        assertTrue("Subscriber does not exists", NotificationsManager.getInstance().isSubscribed(thread.getIdentity(), sc));
    }
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) PublisherData(org.olat.core.commons.services.notifications.PublisherData) DBRuntimeException(org.olat.core.logging.DBRuntimeException) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)204 PublisherData (org.olat.core.commons.services.notifications.PublisherData)84 Identity (org.olat.core.id.Identity)72 Test (org.junit.Test)66 Publisher (org.olat.core.commons.services.notifications.Publisher)58 RepositoryEntry (org.olat.repository.RepositoryEntry)38 VFSContainer (org.olat.core.util.vfs.VFSContainer)32 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)28 BusinessGroup (org.olat.group.BusinessGroup)28 ArrayList (java.util.ArrayList)20 Subscriber (org.olat.core.commons.services.notifications.Subscriber)20 HttpResponse (org.apache.http.HttpResponse)18 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)18 Forum (org.olat.modules.fo.Forum)18 File (java.io.File)16 HttpGet (org.apache.http.client.methods.HttpGet)16 CollaborationTools (org.olat.collaboration.CollaborationTools)14 OLATResourceable (org.olat.core.id.OLATResourceable)14 NamedContainerImpl (org.olat.core.util.vfs.NamedContainerImpl)14 Roles (org.olat.core.id.Roles)12