Search in sources :

Example 21 with OLATRuntimeException

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

the class QuotaManagerImpl method listCustomQuotasKB.

/**
 * Get a list of all objects which have an individual quota.
 *
 * @return list of quotas.
 */
@Override
public List<Quota> listCustomQuotasKB() {
    if (defaultQuotas == null) {
        throw new OLATRuntimeException(QuotaManagerImpl.class, "Quota manager has not been initialized properly! Must call init() first.", null);
    }
    List<Quota> results = new ArrayList<Quota>();
    PropertyManager pm = PropertyManager.getInstance();
    List<Property> props = pm.listProperties(null, null, quotaResource, QUOTA_CATEGORY, null);
    if (props == null || props.size() == 0)
        return results;
    for (Iterator<Property> iter = props.iterator(); iter.hasNext(); ) {
        Property prop = iter.next();
        results.add(parseQuota(prop));
    }
    return results;
}
Also used : Quota(org.olat.core.util.vfs.Quota) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) PropertyManager(org.olat.properties.PropertyManager) ArrayList(java.util.ArrayList) Property(org.olat.properties.Property)

Example 22 with OLATRuntimeException

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

the class ICalFileCalendarManager method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    fStorageBase = new File(WebappHelper.getUserDataRoot(), "calendars");
    if (!fStorageBase.exists()) {
        if (!fStorageBase.mkdirs())
            throw new OLATRuntimeException("Error creating calendar base directory at: " + fStorageBase.getAbsolutePath(), null);
    }
    // create the directories
    String[] dirs = new String[] { TYPE_USER, TYPE_GROUP, TYPE_COURSE };
    for (String dir : dirs) {
        File fDirectory = new File(fStorageBase, dir);
        if (!fDirectory.exists()) {
            fDirectory.mkdirs();
        }
    }
    // set parser to relax (needed for allday events
    // see http://sourceforge.net/forum/forum.php?thread_id=1253735&forum_id=368291
    // made in module System.setProperty("ical4j.unfolding.relaxed", "true");
    // initialize timezone
    tz = calendarModule.getDefaultTimeZone();
    calendarCache = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(CalendarManager.class.getSimpleName(), "calendar");
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) File(java.io.File)

Example 23 with OLATRuntimeException

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

the class ICalServlet method outputCalendar.

private void outputCalendar(CalendarFileInfos fileInfos, Writer out, Agent agent, Set<String> timezoneIds) throws IOException {
    try {
        CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
        Calendar calendar = calendarManager.readCalendar(fileInfos.getCalendarFile());
        updateUrlProperties(calendar);
        String prefix = fileInfos.getType() + "-" + fileInfos.getCalendarId() + "-";
        updateUUID(calendar, prefix);
        outputCalendarComponents(calendar, out, agent, timezoneIds);
    } catch (IOException | OLATRuntimeException e) {
        log.error("", e);
    }
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Calendar(net.fortuna.ical4j.model.Calendar) IOException(java.io.IOException)

Example 24 with OLATRuntimeException

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

the class ICalServlet method outputCalendarComponents.

private void outputCalendarComponents(Calendar calendar, Writer out, Agent agent, Set<String> timezoneIds) throws IOException {
    try {
        ComponentList events = calendar.getComponents();
        for (final Iterator<?> i = events.iterator(); i.hasNext(); ) {
            Object comp = i.next();
            String event = comp.toString();
            if (agent == Agent.outlook && comp instanceof VEvent) {
                event = quoteTimeZone(event, (VEvent) comp, timezoneIds);
            }
            if (agent == Agent.googleCalendar) {
                event = event.replace("CLASS:PRIVATE" + Strings.LINE_SEPARATOR, "");
                event = event.replace("X-OLAT-MANAGED:all" + Strings.LINE_SEPARATOR, "");
                event = event.replace("DESCRIPTION:" + Strings.LINE_SEPARATOR, "");
                event = event.replace("LOCATION:" + Strings.LINE_SEPARATOR, "");
            }
            out.write(event);
        }
    } catch (IOException | OLATRuntimeException e) {
        log.error("", e);
    }
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) ComponentList(net.fortuna.ical4j.model.ComponentList) IOException(java.io.IOException)

Example 25 with OLATRuntimeException

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

the class CoreSpringFactory method getBean.

/**
 * @param beanName
 *            The bean name to check for. Be sure the bean does exist,
 *            otherwise an NoSuchBeanDefinitionException will be thrown
 * @return The bean
 */
public static Object getBean(Class<?> interfaceName) {
    ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(CoreSpringFactory.servletContext);
    Map<String, ?> m = context.getBeansOfType(interfaceName);
    if (m.size() > 1) {
        // more than one bean found -> excecption
        throw new OLATRuntimeException("found more than one bean for: " + interfaceName + ". Calling this method should only find one bean!", null);
    } else if (m.size() == 1) {
        return new ArrayList<Object>(m.values()).get(0);
    }
    // fallback for beans named like the fully qualified path (legacy)
    Object o = context.getBean(interfaceName.getName());
    return o;
}
Also used : WebApplicationContext(org.springframework.web.context.WebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) ArrayList(java.util.ArrayList)

Aggregations

OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)268 IOException (java.io.IOException)104 File (java.io.File)50 ModuleConfiguration (org.olat.modules.ModuleConfiguration)26 ArrayList (java.util.ArrayList)22 AssertException (org.olat.core.logging.AssertException)22 FileOutputStream (java.io.FileOutputStream)20 OutputStream (java.io.OutputStream)20 Properties (java.util.Properties)20 FileInputStream (java.io.FileInputStream)18 HashMap (java.util.HashMap)18 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)18 QTIItemObject (org.olat.ims.qti.export.helper.QTIItemObject)18 DefaultElement (org.dom4j.tree.DefaultElement)16 Element (org.jdom.Element)16 InputStream (java.io.InputStream)14 BufferedInputStream (java.io.BufferedInputStream)12 List (java.util.List)12 Document (org.dom4j.Document)12 CPItem (org.olat.ims.cp.objects.CPItem)12