Search in sources :

Example 61 with OLATRuntimeException

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

the class FileResourceManager method getFileResource.

/**
 * @param res
 * @return Get resourceable as file.
 */
private File getFileResource(OLATResourceable res, String resourceFolderName) {
    FileResource fr = getAsGenericFileResource(res);
    File f = getFile(fr, resourceFolderName);
    if (f == null) {
        // folder not existing or no file in it
        throw new OLATRuntimeException(FileResourceManager.class, "could not getFileResource for OLATResourceable " + res.getResourceableId() + ":" + res.getResourceableTypeName(), null);
    }
    return f;
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) FileResource(org.olat.fileresource.types.FileResource) File(java.io.File)

Example 62 with OLATRuntimeException

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

the class ParserManager method parse.

/**
 * @see org.olat.ims.qti.editor.beecom.parser.IParser#parse(org.dom4j.Element)
 */
public Object parse(Element element) {
    try {
        if (element == null)
            return null;
        String name = element.getName();
        String parserClassName = null;
        String tmpName = parserMap.get(name);
        if (tmpName == null) {
            parserClassName = parserMap.get(PARSER_DEFAULT);
        } else {
            parserClassName = tmpName;
        }
        if (log.isDebug()) {
            log.debug("ELEMENTNAME:" + name + "PARSERNAME" + parserClassName);
        }
        Class<?> parserClass = this.getClass().getClassLoader().loadClass(parserClassName);
        IParser parser = (IParser) parserClass.newInstance();
        return parser.parse(element);
    } catch (ClassNotFoundException e) {
        throw new OLATRuntimeException(this.getClass(), "Class not found in QTI editor", e);
    } catch (InstantiationException e) {
        throw new OLATRuntimeException(this.getClass(), "Instatiation problem in QTI editor", e);
    } catch (IllegalAccessException e) {
        throw new OLATRuntimeException(this.getClass(), "Illegal Access in QTI editor", e);
    }
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 63 with OLATRuntimeException

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

the class ForumNodeForumCallback method loadForum.

private Forum loadForum(CourseEnvironment courseEnv, Property prop) {
    final ForumManager fom = CoreSpringFactory.getImpl(ForumManager.class);
    Long forumKey = prop.getLongValue();
    Forum forum = fom.loadForum(forumKey);
    if (forum == null) {
        throw new OLATRuntimeException(FOCourseNode.class, "Tried to load forum with key " + forumKey.longValue() + " in course " + courseEnv.getCourseResourceableId() + " for node " + getIdent() + " as defined in course node property but forum manager could not load forum.", null);
    }
    return forum;
}
Also used : ForumManager(org.olat.modules.fo.manager.ForumManager) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Forum(org.olat.modules.fo.Forum)

Example 64 with OLATRuntimeException

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

the class QTI21ServiceImpl method loadFilteredStateDocument.

private Document loadFilteredStateDocument(File sessionFile) {
    try (InputStream in = new FileInputStream(sessionFile)) {
        String xmlContent = IOUtils.toString(in, "UTF-8");
        String filteredContent = FilterFactory.getXMLValidEntityFilter().filter(xmlContent);
        DocumentBuilder documentBuilder = XmlFactories.newDocumentBuilder();
        return documentBuilder.parse(new InputSource(new StringReader(filteredContent)));
    } catch (final Exception e) {
        throw new OLATRuntimeException("Could not parse serialized state XML. This is an internal error as we currently don't expose this data to clients", e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StringReader(java.io.StringReader) FileInputStream(java.io.FileInputStream) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) XmlResourceNotFoundException(uk.ac.ed.ph.jqtiplus.xmlutils.XmlResourceNotFoundException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 65 with OLATRuntimeException

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

the class OLATUpgrade_11_0_0 method checkEssay.

private boolean checkEssay(RepositoryEntry testEntry) {
    if (qtiEssayMap.containsKey(testEntry.getKey())) {
        return qtiEssayMap.get(testEntry.getKey()).booleanValue();
    }
    TestFileResource fr = new TestFileResource();
    fr.overrideResourceableId(testEntry.getOlatResource().getResourceableId());
    TransientIdentity pseudoIdentity = new TransientIdentity();
    pseudoIdentity.setName("transient");
    Translator translator = Util.createPackageTranslator(QTIModule.class, Locale.ENGLISH);
    try {
        QTIEditorPackage qtiPackage = new QTIEditorPackageImpl(pseudoIdentity, fr, null, translator);
        if (qtiPackage.getQTIDocument() != null && qtiPackage.getQTIDocument().getAssessment() != null) {
            Assessment ass = qtiPackage.getQTIDocument().getAssessment();
            // Sections with their Items
            List<Section> sections = ass.getSections();
            for (Section section : sections) {
                List<Item> items = section.getItems();
                for (Item item : items) {
                    String ident = item.getIdent();
                    if (ident != null && ident.startsWith("QTIEDIT:ESSAY")) {
                        qtiEssayMap.put(testEntry.getKey(), Boolean.TRUE);
                        return true;
                    }
                }
            }
        }
    } catch (OLATRuntimeException e) {
        log.warn("QTI without content in repository entry: " + testEntry.getKey(), e);
    }
    qtiEssayMap.put(testEntry.getKey(), Boolean.FALSE);
    return false;
}
Also used : TransientIdentity(org.olat.admin.user.imp.TransientIdentity) Item(org.olat.ims.qti.editor.beecom.objects.Item) Translator(org.olat.core.gui.translator.Translator) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) QTIEditorPackageImpl(org.olat.ims.qti.editor.QTIEditorPackageImpl) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) TestFileResource(org.olat.ims.qti.fileresource.TestFileResource) QTIEditorPackage(org.olat.ims.qti.editor.QTIEditorPackage) Section(org.olat.ims.qti.editor.beecom.objects.Section)

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