use of org.olat.core.commons.services.notifications.Publisher in project openolat by klemens.
the class NewUsersNotificationHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
Translator translator = Util.createPackageTranslator(this.getClass(), locale);
// there could be news for me, investigate deeper
try {
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
List<Identity> identities = UsersSubscriptionManager.getInstance().getNewIdentityCreated(compareDate);
if (identities.isEmpty()) {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
} else {
translator = Util.createPackageTranslator(this.getClass(), locale);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(getItemTitle(identities, translator), CSSHelper.CSS_CLASS_GROUP), null);
SubscriptionListItem subListItem;
for (Identity newUser : identities) {
String desc = translator.translate("notifications.entry", new String[] { NotificationHelper.getFormatedName(newUser) });
String businessPath = "[Identity:" + newUser.getKey() + "]";
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
Date modDate = newUser.getCreationDate();
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSSHelper.CSS_CLASS_USER);
si.addSubscriptionListItem(subListItem);
}
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Error creating new identity's notifications for subscriber: " + subscriber.getKey(), e);
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.Publisher in project openolat by klemens.
the class UsersSubscriptionManagerImpl method getNewUsersSubscriber.
public Subscriber getNewUsersSubscriber(Identity identity) {
SubscriptionContext context = getNewUsersSubscriptionContext();
Publisher publisher = NotificationsManager.getInstance().getPublisher(context);
if (publisher == null) {
return null;
}
return NotificationsManager.getInstance().getSubscriber(identity, publisher);
}
use of org.olat.core.commons.services.notifications.Publisher 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);
}
use of org.olat.core.commons.services.notifications.Publisher in project openolat by klemens.
the class OLATUpgrade_9_4_0 method fixBusinessPathPublisher.
private boolean fixBusinessPathPublisher(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
if (!uhd.getBooleanDataValue(FIX_PUBLISHER_BUSINESSPATH)) {
List<Publisher> publishers = getPublishers();
int count = 0;
int updates = 0;
for (Publisher publisher : publishers) {
boolean updated = processPublisher(publisher);
if (count % 10 == 0) {
dbInstance.commit();
}
if (updated)
updates++;
}
dbInstance.commit();
log.audit("Update " + updates + " publisher with partial business path.");
uhd.setBooleanDataValue(FIX_PUBLISHER_BUSINESSPATH, true);
upgradeManager.setUpgradesHistory(uhd, VERSION);
}
return true;
}
use of org.olat.core.commons.services.notifications.Publisher 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));
}
Aggregations