Search in sources :

Example 11 with ObjectDeletedException

use of org.hibernate.ObjectDeletedException in project openolat by klemens.

the class OLATUpgrade_7_0_1 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("+-----------------------------------------------------------------------------+");
        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 ObjectDeletedException

use of org.hibernate.ObjectDeletedException in project openolat by klemens.

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)

Aggregations

ObjectDeletedException (org.hibernate.ObjectDeletedException)12 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)4 Publisher (org.olat.core.commons.services.notifications.Publisher)4 EntityEntry (org.hibernate.engine.spi.EntityEntry)3 EntityPersister (org.hibernate.persister.entity.EntityPersister)3 HibernateProxy (org.hibernate.proxy.HibernateProxy)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 MappingException (org.hibernate.MappingException)2 UnknownSqlResultSetMappingException (org.hibernate.procedure.UnknownSqlResultSetMappingException)2 LazyInitializer (org.hibernate.proxy.LazyInitializer)2 VideoManager (org.olat.modules.video.VideoManager)2 Serializable (java.io.Serializable)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 LockMode (org.hibernate.LockMode)1 LockOptions (org.hibernate.LockOptions)1 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)1 PersistentObjectException (org.hibernate.PersistentObjectException)1