Search in sources :

Example 81 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class I18nManager method getPropertiesFile.

/**
 * Get the property file for a given locale and bundle. If the locale is null,
 * the metadata for this bundle are returned instead.
 *
 * @param locale the locale or NULL to get the bundle metadata file
 * @param bundleName
 * @param sourceDir the source directory where to search for the properties
 *          file
 * @return a file object. The file might not exist, but the mehod never return
 *         NULL!
 */
public File getPropertiesFile(Locale locale, String bundleName, File sourceDir) {
    if (bundleName == null)
        throw new AssertException("getPropertyFile(): bundleName can not be null");
    if (sourceDir == null)
        throw new AssertException("getPropertyFile(): sourceDir can not be null");
    // Create relative path to sourceDir
    bundleName = bundleName.replace('.', '/');
    String fileName = (locale == null ? METADATA_FILENAME : buildI18nFilename(locale));
    String relPath = "/" + bundleName + "/" + I18N_DIRNAME + "/" + fileName;
    // Load file from path
    File f = new File(sourceDir, relPath);
    if (f.exists() || i18nModule.isTransToolEnabled()) {
        return f;
    }
    return f;
}
Also used : AssertException(org.olat.core.logging.AssertException) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 82 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class TreeHelper method resolveTreeNode.

public static TreeNode resolveTreeNode(String treePath, TreeModel treeModel) {
    // even for the root node, our parameter may not be the empty string, therefore the prefix to be chopped here
    treePath = treePath.substring(1);
    TreeNode cur = treeModel.getRootNode();
    if (!treePath.equals("")) {
        // if we are not the root node
        String[] res = treePath.split("_");
        for (int i = res.length - 1; i >= 0; i--) {
            String spos = res[i];
            Integer chdPos = Integer.parseInt(spos);
            TreeNode chd = (TreeNode) cur.getChildAt(chdPos);
            if (chd == null)
                throw new AssertException("cannot find: " + treePath);
            cur = chd;
        }
    }
    return cur;
}
Also used : AssertException(org.olat.core.logging.AssertException) TreeNode(org.olat.core.gui.components.tree.TreeNode)

Example 83 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class OLATResourceableEvent method targetEquals.

/**
 * @param ores the OLATResourceable to test against.
 * @param exceptIfFalse if true = throw an exception if the target does not match ores
 * @return True on equality.
 */
public boolean targetEquals(OLATResourceable ores, boolean exceptIfFalse) {
    String derived = OresHelper.createStringRepresenting(ores);
    boolean res = derived.equals(derivedOres);
    if (!res && exceptIfFalse)
        throw new AssertException("expected ores to be the same as target, but failed: ores =" + ores.getResourceableTypeName() + " / " + ores.getResourceableId() + ", but event was for " + derived);
    return res;
}
Also used : AssertException(org.olat.core.logging.AssertException)

Example 84 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class ModifyCourseEvent method loadCourse.

public static ICourse loadCourse(final Long resourceableId) {
    if (resourceableId == null)
        throw new AssertException("No resourceable ID found.");
    PersistingCourseImpl course = loadedCourses.get(resourceableId);
    if (course == null) {
        // o_clusterOK by:ld - load and put in cache in doInSync block to ensure
        // that no invalidate cache event was missed
        OLATResource resource = OLATResourceManager.getInstance().findResourceable(resourceableId, "CourseModule");
        PersistingCourseImpl theCourse = new PersistingCourseImpl(resource);
        theCourse.load();
        PersistingCourseImpl cachedCourse = loadedCourses.putIfAbsent(resourceableId, theCourse);
        if (cachedCourse != null) {
            course = cachedCourse;
        } else {
            course = theCourse;
        }
    }
    return course;
}
Also used : AssertException(org.olat.core.logging.AssertException) OLATResource(org.olat.resource.OLATResource)

Example 85 with AssertException

use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.

the class ModifyCourseEvent method clearCalenderSubscriptions.

/**
 * Checks all learning group calendars and the course calendar for publishers (of subscriptions)
 * and sets their state to "1" which indicates that the ressource is deleted.
 */
private static void clearCalenderSubscriptions(OLATResourceable res, ICourse course) {
    // set Publisher state to 1 (= ressource is deleted) for all calendars of the course
    CalendarManager calMan = CoreSpringFactory.getImpl(CalendarManager.class);
    CalendarNotificationManager notificationManager = CoreSpringFactory.getImpl(CalendarNotificationManager.class);
    NotificationsManager nfm = NotificationsManager.getInstance();
    if (course != null) {
        CourseGroupManager courseGroupManager = course.getCourseEnvironment().getCourseGroupManager();
        List<BusinessGroup> learningGroups = courseGroupManager.getAllBusinessGroups();
        // all learning and right group calendars
        for (BusinessGroup bg : learningGroups) {
            KalendarRenderWrapper calRenderWrapper = calMan.getGroupCalendar(bg);
            SubscriptionContext subsContext = notificationManager.getSubscriptionContext(calRenderWrapper);
            Publisher pub = nfm.getPublisher(subsContext);
            if (pub != null) {
                // int 0 is OK -> all other is not OK
                pub.setState(1);
            }
        }
    }
    // the course calendar
    try {
        /**
         * TODO:gs 2010-01-26
         * OLAT-4947: if we do not have an repo entry we get an exception here.
         * This is normal in the case of courseimport and click canceling.
         */
        KalendarRenderWrapper courseCalendar = calMan.getCalendarForDeletion(res);
        if (courseCalendar != null) {
            SubscriptionContext subContext = notificationManager.getSubscriptionContext(courseCalendar, res);
            OLATResourceable oresToDelete = OresHelper.createOLATResourceableInstance(subContext.getResName(), subContext.getResId());
            nfm.deletePublishersOf(oresToDelete);
        }
    } catch (AssertException e) {
    // if we have a broken course (e.g. canceled import or no repo entry somehow) skip calendar deletion...
    }
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) PersistingCourseGroupManager(org.olat.course.groupsandrights.PersistingCourseGroupManager) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) CalendarManager(org.olat.commons.calendar.CalendarManager) CalendarNotificationManager(org.olat.commons.calendar.CalendarNotificationManager) AssertException(org.olat.core.logging.AssertException) BusinessGroup(org.olat.group.BusinessGroup) OLATResourceable(org.olat.core.id.OLATResourceable) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Aggregations

AssertException (org.olat.core.logging.AssertException)364 IOException (java.io.IOException)38 File (java.io.File)28 Identity (org.olat.core.id.Identity)28 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)24 Controller (org.olat.core.gui.control.Controller)22 OLATResourceable (org.olat.core.id.OLATResourceable)22 RepositoryEntry (org.olat.repository.RepositoryEntry)22 WindowControl (org.olat.core.gui.control.WindowControl)20 UnsupportedEncodingException (java.io.UnsupportedEncodingException)18 JSONException (org.json.JSONException)18 BusinessGroup (org.olat.group.BusinessGroup)18 JSONObject (org.json.JSONObject)16 UserRequest (org.olat.core.gui.UserRequest)16 VFSContainer (org.olat.core.util.vfs.VFSContainer)16 VFSItem (org.olat.core.util.vfs.VFSItem)16 Date (java.util.Date)14 Properties (java.util.Properties)14 Property (org.olat.properties.Property)14