use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_7_1_0 method migrateNotificationPublishers.
private void migrateNotificationPublishers(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
if (!uhd.getBooleanDataValue(TASK_CHECK_NOTIFICATIONS)) {
log.audit("+-----------------------------------------------------------------------------+");
log.audit("+... Check the businesspath for the publishers (notifications) ...+");
log.audit("+-----------------------------------------------------------------------------+");
if (!portletRepositoryTeacherEnabled && !portletRepositoryStudentEnabled) {
log.audit("**** Repository portlets disabled: don't need to check publishers. ****");
uhd.setBooleanDataValue(TASK_CHECK_NOTIFICATIONS, true);
upgradeManager.setUpgradesHistory(uhd, VERSION);
return;
}
int counter = 0;
NotificationsManager notificationMgr = NotificationsManager.getInstance();
List<Publisher> allPublishers = notificationMgr.getAllPublisher();
if (log.isDebug())
log.info("Found " + allPublishers.size() + " publishers to check.");
for (Publisher publisher : allPublishers) {
if (publisher != null && StringHelper.containsNonWhitespace(publisher.getBusinessPath()) && (publisher.getBusinessPath().startsWith("[Identity") || publisher.getBusinessPath().startsWith("ROOT[Identity"))) {
try {
String businessPath = publisher.getBusinessPath();
int startIndex = businessPath.indexOf("[Identity");
int stopIndex = businessPath.indexOf("]", startIndex);
int wide = stopIndex - startIndex;
if (wide > 30) {
// Identity:326394598 cannot be too wide
continue;
} else if (stopIndex + 1 >= businessPath.length()) {
// only identity
continue;
}
String correctPath = businessPath.substring(stopIndex + 1);
publisher.setBusinessPath(correctPath);
DBFactory.getInstance().updateObject(publisher);
} catch (ObjectDeletedException e) {
log.warn("Publisher was already deleted, no update possible! Publisher key: " + publisher.getKey());
} catch (Exception e) {
log.warn("Publisher was already deleted, no update possible! Publisher key: " + publisher.getKey());
}
counter++;
}
if (counter > 0 && counter % 100 == 0) {
log.audit("Another 100 publishers done");
DBFactory.getInstance().intermediateCommit();
}
}
DBFactory.getInstance().intermediateCommit();
log.audit("**** Checked " + counter + " publishers. ****");
uhd.setBooleanDataValue(TASK_CHECK_NOTIFICATIONS, true);
upgradeManager.setUpgradesHistory(uhd, VERSION);
}
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
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 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());
}
use of org.olat.core.commons.services.notifications.Publisher 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;
}
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
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