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;
}
}
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());
}
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()));
}
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));
}
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();
}
Aggregations