Search in sources :

Example 91 with PublisherData

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

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

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

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());
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) ArrayList(java.util.ArrayList) 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 93 with PublisherData

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

the class NotificationsManagerTest method testCreateUpdatePublisher.

@Test
public void testCreateUpdatePublisher() {
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("PS2", new Long(124), 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("PS2", publisher.getResName());
    Assert.assertEquals(new Long(124), publisher.getResId());
    sleep(2000);
    // update the publisher
    notificationManager.markPublisherNews(context, null, false);
    // check if exists and last news date is updated
    Publisher reloadedPublisher = notificationManager.getPublisher(context);
    Assert.assertNotNull(reloadedPublisher);
    Assert.assertEquals(publisher, reloadedPublisher);
    Assert.assertTrue(publisher.getLatestNewsDate().before(reloadedPublisher.getLatestNewsDate()));
}
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 94 with PublisherData

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

the class InfoMessageFrontendManagerTest method getInfoSubscribers.

@Test
public void getInfoSubscribers() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("info-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("info-2");
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup businessGroup = groupService.createBusinessGroup(null, "gdao", "gdao-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 publisher data
    String identifier = InfoMessageFrontendManager.businessGroupResSubPath;
    SubscriptionContext context = new SubscriptionContext(businessGroup.getResourceableTypeName(), businessGroup.getResourceableId(), identifier);
    PublisherData publisherData = new PublisherData("testGetSubscriberIdentities", "e.g. data=infomessage", null);
    dbInstance.commitAndCloseSession();
    // add subscribers
    notificationManager.subscribe(id1, context, publisherData);
    notificationManager.subscribe(id2, context, publisherData);
    dbInstance.commitAndCloseSession();
    // get identities
    List<Identity> identities = infoManager.getInfoSubscribers(ores, identifier);
    Assert.assertNotNull(identities);
    Assert.assertEquals(2, identities.size());
    Assert.assertTrue(identities.contains(id1));
    Assert.assertTrue(identities.contains(id2));
}
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) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 95 with PublisherData

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

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)

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