Search in sources :

Example 41 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

the class InfoMessageFrontendManagerTest method removeInfoMessagesAndSubscriptionContext.

@Test
public void removeInfoMessagesAndSubscriptionContext() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("info-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("info-2");
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup businessGroup = groupService.createBusinessGroup(null, "gdao1", "gdao1-desc", -1, -1, false, false, resource);
    final OLATResourceable ores = new OLATResourceable() {

        @Override
        public String getResourceableTypeName() {
            return businessGroup.getResourceableTypeName();
        }

        @Override
        public Long getResourceableId() {
            return businessGroup.getResourceableId();
        }
    };
    // create, save
    InfoMessage msg1 = infoManager.createInfoMessage(ores, InfoMessageFrontendManager.businessGroupResSubPath, null, id2);
    msg1.setTitle("title-1");
    msg1.setMessage("message-1");
    assertNotNull(msg1);
    infoManager.saveInfoMessage(msg1);
    // create, save
    InfoMessage msg2 = infoManager.createInfoMessage(ores, InfoMessageFrontendManager.businessGroupResSubPath, null, id1);
    msg2.setTitle("title-2");
    msg2.setMessage("message-2");
    assertNotNull(msg2);
    infoManager.saveInfoMessage(msg2);
    // create, save
    InfoMessage msg3 = infoManager.createInfoMessage(ores, InfoMessageFrontendManager.businessGroupResSubPath, null, id1);
    msg3.setTitle("title-3");
    msg3.setMessage("message-3");
    assertNotNull(msg3);
    infoManager.saveInfoMessage(msg3);
    dbInstance.commitAndCloseSession();
    SubscriptionContext sc = new SubscriptionContext(businessGroup.getResourceableTypeName(), businessGroup.getResourceableId(), InfoMessageFrontendManager.businessGroupResSubPath);
    PublisherData pd = new PublisherData("InfoMessage", "e.g. infoMessage=anyMessage", null);
    // subscribe
    notificationManager.subscribe(id1, sc, pd);
    notificationManager.subscribe(id2, sc, pd);
    dbInstance.closeSession();
    // check if publisher was created
    Publisher p = notificationManager.getPublisher(sc);
    assertNotNull(p);
    // check before message deletion
    List<InfoMessage> loadedMessages1 = infoManager.loadInfoMessageByResource(ores, InfoMessageFrontendManager.businessGroupResSubPath, null, null, null, 0, 0);
    Assert.assertEquals(3, loadedMessages1.size());
    Assert.assertTrue(loadedMessages1.contains(msg1));
    Assert.assertTrue(loadedMessages1.contains(msg2));
    Assert.assertTrue(loadedMessages1.contains(msg3));
    // delete
    infoManager.removeInfoMessagesAndSubscriptionContext(businessGroup);
    dbInstance.commitAndCloseSession();
    // check if messages are deleted
    List<InfoMessage> loadedMessages2 = infoManager.loadInfoMessageByResource(ores, InfoMessageFrontendManager.businessGroupResSubPath, null, null, null, 0, 0);
    Assert.assertEquals(0, loadedMessages2.size());
    Assert.assertFalse(loadedMessages2.contains(msg1));
    Assert.assertFalse(loadedMessages2.contains(msg2));
    Assert.assertFalse(loadedMessages2.contains(msg3));
    // check if pubisher is deleted
    Publisher p2 = notificationManager.getPublisher(sc);
    assertNull("publisher marked deleted should not be found", p2);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResourceable(org.olat.core.id.OLATResourceable) RepositoryEntry(org.olat.repository.RepositoryEntry) 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 42 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

the class FeedMainController method display.

/**
 * Sets up the velocity container for displaying the view
 *
 * @param ores
 * @param ureq
 * @param wControl
 * @param previewMode
 * @param isCourseNode
 */
private void display(UserRequest ureq, WindowControl wControl, FeedItemDisplayConfig displayConfig) {
    vcMain = createVelocityContainer("feed_main");
    vcInfo = uiFactory.createInfoVelocityContainer(this);
    vcInfo.contextPut("feed", feed);
    vcInfo.contextPut("helper", helper);
    if (subsContext != null) {
        String businessPath = wControl.getBusinessControl().getAsString();
        PublisherData data = new PublisherData(ores.getResourceableTypeName(), ores.getResourceableId().toString(), businessPath);
        cSubscriptionCtrl = new ContextualSubscriptionController(ureq, getWindowControl(), subsContext, data);
        listenTo(cSubscriptionCtrl);
        vcInfo.put("subscription", cSubscriptionCtrl.getInitialComponent());
    }
    vcRightCol = uiFactory.createRightColumnVelocityContainer(this);
    vcMain.put("rightColumn", vcRightCol);
    RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(feed, false);
    if (repositoryEntry == null && callback.mayEditMetadata()) {
        editFeedButton = LinkFactory.createButtonSmall("feed.edit", vcInfo, this);
        editFeedButton.setElementCssClass("o_sel_feed_edit");
    }
    vcInfo.contextPut("callback", callback);
    displayUrlCtr = new DisplayFeedUrlController(ureq, wControl, feed, helper, uiFactory.getTranslator());
    listenTo(displayUrlCtr);
    vcInfo.put("feedUrlComponent", displayUrlCtr.getInitialComponent());
    vcMain.put("info", vcInfo);
    itemsCtr = new ItemsController(ureq, wControl, feed, helper, uiFactory, callback, vcRightCol, displayConfig);
    listenTo(itemsCtr);
    vcMain.put("items", itemsCtr.getInitialComponent());
    putInitialPanel(vcMain);
}
Also used : ContextualSubscriptionController(org.olat.core.commons.services.notifications.ui.ContextualSubscriptionController) RepositoryEntry(org.olat.repository.RepositoryEntry) PublisherData(org.olat.core.commons.services.notifications.PublisherData)

Example 43 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

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)

Example 44 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

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 45 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

the class NotificationsManagerTest method testAllPublishers.

@Test
public void testAllPublishers() {
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("All", new Long(123), identifier);
    PublisherData publisherData = new PublisherData("testAllPublishers", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(publisher);
    List<Publisher> publishers = notificationManager.getAllPublisher();
    Assert.assertNotNull(publishers);
    Assert.assertTrue(publishers.contains(publisher));
}
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)

Aggregations

PublisherData (org.olat.core.commons.services.notifications.PublisherData)100 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)84 Test (org.junit.Test)64 Identity (org.olat.core.id.Identity)60 Publisher (org.olat.core.commons.services.notifications.Publisher)42 RepositoryEntry (org.olat.repository.RepositoryEntry)22 BusinessGroup (org.olat.group.BusinessGroup)20 HttpResponse (org.apache.http.HttpResponse)16 HttpGet (org.apache.http.client.methods.HttpGet)16 Subscriber (org.olat.core.commons.services.notifications.Subscriber)16 ArrayList (java.util.ArrayList)14 ContextualSubscriptionController (org.olat.core.commons.services.notifications.ui.ContextualSubscriptionController)12 Forum (org.olat.modules.fo.Forum)12 UriBuilder (javax.ws.rs.core.UriBuilder)10 SubscriptionInfoVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO)8 SubscriptionListItemVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO)8 DBRuntimeException (org.olat.core.logging.DBRuntimeException)8 ICourse (org.olat.course.ICourse)8 File (java.io.File)6 URI (java.net.URI)6