Search in sources :

Example 6 with FileResourceManager

use of org.olat.fileresource.FileResourceManager in project OpenOLAT by OpenOLAT.

the class ScormMainManager method getScormPackageConfig.

public ScormPackageConfig getScormPackageConfig(OLATResourceable ores) {
    FileResourceManager frm = FileResourceManager.getInstance();
    File reFolder = frm.getFileResourceRoot(ores);
    File configXml = new File(reFolder, PACKAGE_CONFIG_FILE_NAME);
    if (configXml.exists()) {
        ScormPackageConfig config = (ScormPackageConfig) configXstream.fromXML(configXml);
        return config;
    }
    return null;
}
Also used : FileResourceManager(org.olat.fileresource.FileResourceManager) File(java.io.File)

Example 7 with FileResourceManager

use of org.olat.fileresource.FileResourceManager in project OpenOLAT by OpenOLAT.

the class IQ12EditForm method update.

/**
 * Update the module configuration from the qti file: read min/max/cut values
 * @param res
 */
protected void update(OLATResource res) {
    FileResourceManager frm = FileResourceManager.getInstance();
    File unzippedRoot = frm.unzipFileResource(res);
    // with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if no longer needed.
    VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedRoot);
    VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml");
    if (vfsQTI == null) {
        throw new AssertException("qti file did not exist even it should be guaranteed by repositor check-in ");
    }
    // ensures that InputStream is closed in every case.
    Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
    if (doc == null) {
        // error reading qti file (existence check was made before)
        throw new AssertException("qti file could not be read " + ((LocalFileImpl) vfsQTI).getBasefile().getAbsolutePath());
    }
    // Extract min, max and cut value
    Float minValue = null, maxValue = null, cutValue = null;
    Element decvar = (Element) doc.selectSingleNode("questestinterop/assessment/outcomes_processing/outcomes/decvar");
    if (decvar != null) {
        Attribute minval = decvar.attribute("minvalue");
        if (minval != null) {
            String mv = minval.getValue();
            try {
                minValue = new Float(Float.parseFloat(mv));
            } catch (NumberFormatException e1) {
            // if not correct in qti file -> ignore
            }
        }
        Attribute maxval = decvar.attribute("maxvalue");
        if (maxval != null) {
            String mv = maxval.getValue();
            try {
                maxValue = new Float(Float.parseFloat(mv));
            } catch (NumberFormatException e1) {
            // if not correct in qti file -> ignore
            }
        }
        Attribute cutval = decvar.attribute("cutvalue");
        if (cutval != null) {
            String cv = cutval.getValue();
            try {
                cutValue = new Float(Float.parseFloat(cv));
            } catch (NumberFormatException e1) {
            // if not correct in qti file -> ignore
            }
        }
    }
    // Put values to module configuration
    minScoreEl.setValue(minValue == null ? "" : AssessmentHelper.getRoundedScore(minValue));
    minScoreEl.setVisible(minValue != null);
    maxScoreEl.setValue(maxValue == null ? "" : AssessmentHelper.getRoundedScore(maxValue));
    maxScoreEl.setVisible(maxValue != null);
    cutValueEl.setValue(cutValue == null ? "" : AssessmentHelper.getRoundedScore(cutValue));
    cutValueEl.setVisible(cutValue != null);
}
Also used : AssertException(org.olat.core.logging.AssertException) FileResourceManager(org.olat.fileresource.FileResourceManager) Attribute(org.dom4j.Attribute) VFSContainer(org.olat.core.util.vfs.VFSContainer) SelectionElement(org.olat.core.gui.components.form.flexible.elements.SelectionElement) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) Element(org.dom4j.Element) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 8 with FileResourceManager

use of org.olat.fileresource.FileResourceManager in project OpenOLAT by OpenOLAT.

the class QTI21AssessmentRunController method getAssessmentTestMaxTimeLimit.

/**
 * @return The maximum time limit in seconds.
 */
private Long getAssessmentTestMaxTimeLimit() {
    if (overrideOptions != null && overrideOptions.getAssessmentTestMaxTimeLimit() != null) {
        Long timeLimits = overrideOptions.getAssessmentTestMaxTimeLimit();
        return timeLimits.longValue() > 0 ? timeLimits.longValue() : null;
    }
    FileResourceManager frm = FileResourceManager.getInstance();
    File fUnzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
    ResolvedAssessmentTest resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(fUnzippedDirRoot, false, false);
    AssessmentTest assessmentTest = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
    if (assessmentTest != null && assessmentTest.getTimeLimits() != null && assessmentTest.getTimeLimits().getMaximum() != null) {
        return assessmentTest.getTimeLimits().getMaximum().longValue();
    }
    return null;
}
Also used : ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) FileResourceManager(org.olat.fileresource.FileResourceManager) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) File(java.io.File)

Example 9 with FileResourceManager

use of org.olat.fileresource.FileResourceManager in project OpenOLAT by OpenOLAT.

the class ImsRepositoryResolver method init.

private void init(OLATResourceable fileResource) {
    FileResourceManager frm = FileResourceManager.getInstance();
    fUnzippedDirRoot = frm.unzipFileResource(fileResource);
    sUnzippedDirRel = frm.getUnzippedDirRel(fileResource);
}
Also used : FileResourceManager(org.olat.fileresource.FileResourceManager)

Example 10 with FileResourceManager

use of org.olat.fileresource.FileResourceManager in project OpenOLAT by OpenOLAT.

the class QTIEditorPackageImpl method savePackageToRepository.

/**
 * @return True upon success, false otherwise.
 */
public boolean savePackageToRepository() {
    FileResourceManager frm = FileResourceManager.getInstance();
    File tmpZipFile = new File(WebappHelper.getTmpDir(), CodeHelper.getUniqueID() + ".zip");
    // first save complete ZIP package to repository
    if (!savePackageTo(tmpZipFile))
        return false;
    // move file from temp to repository root and rename
    File fRepositoryZip = frm.getFileResource(fileResource);
    if (!FileUtils.moveFileToDir(tmpZipFile, frm.getFileResourceRoot(fileResource))) {
        tmpZipFile.delete();
        return false;
    }
    fRepositoryZip.delete();
    new File(frm.getFileResourceRoot(fileResource), tmpZipFile.getName()).renameTo(fRepositoryZip);
    // delete old unzip content. If the repository entry gets called in the meantime,
    // the package will get unzipped again.
    tmpZipFile.delete();
    frm.deleteUnzipContent(fileResource);
    // to be prepared for the next start, unzip right now.
    return (frm.unzipFileResource(fileResource) != null);
}
Also used : FileResourceManager(org.olat.fileresource.FileResourceManager) File(java.io.File)

Aggregations

FileResourceManager (org.olat.fileresource.FileResourceManager)62 File (java.io.File)60 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)16 IOException (java.io.IOException)14 AssessmentTest (uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest)12 OutputStream (java.io.OutputStream)10 FileOutputStream (java.io.FileOutputStream)8 AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 URI (java.net.URI)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)4 OpenXMLWorkbook (org.olat.core.util.openxml.OpenXMLWorkbook)4 AssessmentResultController (org.olat.ims.qti21.ui.AssessmentResultController)4 QuestionItem (org.olat.modules.qpool.QuestionItem)4 OpenXMLWorksheet (org.olat.core.util.openxml.OpenXMLWorksheet)3 AssessmentResponse (org.olat.ims.qti21.AssessmentResponse)3 ZipOutputStream (java.util.zip.ZipOutputStream)2 Attribute (org.dom4j.Attribute)2