Search in sources :

Example 11 with Publisher

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);
    }
}
Also used : NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) ObjectDeletedException(org.hibernate.ObjectDeletedException) Publisher(org.olat.core.commons.services.notifications.Publisher) ObjectDeletedException(org.hibernate.ObjectDeletedException)

Example 12 with Publisher

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;
}
Also used : Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 13 with Publisher

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());
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) 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 14 with Publisher

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;
    }
}
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 15 with Publisher

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

Publisher (org.olat.core.commons.services.notifications.Publisher)150 Identity (org.olat.core.id.Identity)62 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)60 PublisherData (org.olat.core.commons.services.notifications.PublisherData)44 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)44 Date (java.util.Date)42 Test (org.junit.Test)42 Subscriber (org.olat.core.commons.services.notifications.Subscriber)42 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)38 RepositoryEntry (org.olat.repository.RepositoryEntry)34 Translator (org.olat.core.gui.translator.Translator)30 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)28 OLATResourceable (org.olat.core.id.OLATResourceable)18 ICourse (org.olat.course.ICourse)18 BusinessGroup (org.olat.group.BusinessGroup)16 ArrayList (java.util.ArrayList)14 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)14 NotificationsHandler (org.olat.core.commons.services.notifications.NotificationsHandler)12 AssertException (org.olat.core.logging.AssertException)12 CourseNode (org.olat.course.nodes.CourseNode)8