Search in sources :

Example 21 with FileResourceManager

use of org.olat.fileresource.FileResourceManager in project openolat by klemens.

the class RepositoryEntryResource method replaceFileResource.

private RepositoryEntry replaceFileResource(Identity identity, RepositoryEntry re, File fResource) {
    if (re == null)
        throw new NullPointerException("RepositoryEntry cannot be null");
    FileResourceManager frm = FileResourceManager.getInstance();
    File currentResource = frm.getFileResource(re.getOlatResource());
    if (currentResource == null || !currentResource.exists()) {
        log.debug("Current resource file doesn't exist");
        return null;
    }
    String typeName = re.getOlatResource().getResourceableTypeName();
    if (typeName.equals(ImsCPFileResource.TYPE_NAME)) {
        if (currentResource.delete()) {
            FileUtils.copyFileToFile(fResource, currentResource, false);
            String repositoryHome = FolderConfig.getCanonicalRepositoryHome();
            String relUnzipDir = frm.getUnzippedDirRel(re.getOlatResource());
            File unzipDir = new File(repositoryHome, relUnzipDir);
            if (unzipDir != null && unzipDir.exists()) {
                FileUtils.deleteDirsAndFiles(unzipDir, true, true);
            }
            frm.unzipFileResource(re.getOlatResource());
        }
        log.audit("Resource: " + re.getOlatResource() + " replaced by " + identity.getName());
        return re;
    }
    log.debug("Cannot replace a resource of the type: " + typeName);
    return null;
}
Also used : FileResourceManager(org.olat.fileresource.FileResourceManager) File(java.io.File)

Example 22 with FileResourceManager

use of org.olat.fileresource.FileResourceManager in project openolat by klemens.

the class QTI21ServiceImpl method getDeliveryOptions.

@Override
public QTI21DeliveryOptions getDeliveryOptions(RepositoryEntry testEntry) {
    FileResourceManager frm = FileResourceManager.getInstance();
    File reFolder = frm.getFileResourceRoot(testEntry.getOlatResource());
    File configXml = new File(reFolder, PACKAGE_CONFIG_FILE_NAME);
    QTI21DeliveryOptions config;
    if (configXml.exists()) {
        config = (QTI21DeliveryOptions) configXstream.fromXML(configXml);
    } else {
        // set default config
        config = QTI21DeliveryOptions.defaultSettings();
        setDeliveryOptions(testEntry, config);
    }
    return config;
}
Also used : QTI21DeliveryOptions(org.olat.ims.qti21.QTI21DeliveryOptions) FileResourceManager(org.olat.fileresource.FileResourceManager) File(java.io.File)

Example 23 with FileResourceManager

use of org.olat.fileresource.FileResourceManager in project openolat by klemens.

the class QTI21ServiceImpl method needManualCorrection.

@Override
public boolean needManualCorrection(RepositoryEntry testEntry) {
    FileResourceManager frm = FileResourceManager.getInstance();
    File fUnzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
    ResolvedAssessmentTest resolvedAssessmentTest = loadAndResolveAssessmentTest(fUnzippedDirRoot, false, false);
    return AssessmentTestHelper.needManualCorrection(resolvedAssessmentTest);
}
Also used : FileResourceManager(org.olat.fileresource.FileResourceManager) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) File(java.io.File)

Example 24 with FileResourceManager

use of org.olat.fileresource.FileResourceManager in project openolat by klemens.

the class QTI21ServiceImpl method setDeliveryOptions.

@Override
public void setDeliveryOptions(RepositoryEntry testEntry, QTI21DeliveryOptions options) {
    FileResourceManager frm = FileResourceManager.getInstance();
    File reFolder = frm.getFileResourceRoot(testEntry.getOlatResource());
    File configXml = new File(reFolder, PACKAGE_CONFIG_FILE_NAME);
    if (options == null) {
        if (configXml.exists()) {
            configXml.delete();
        }
    } else {
        try (OutputStream out = new FileOutputStream(configXml)) {
            configXstream.toXML(options, out);
        } catch (IOException e) {
            log.error("", e);
        }
    }
}
Also used : FileResourceManager(org.olat.fileresource.FileResourceManager) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 25 with FileResourceManager

use of org.olat.fileresource.FileResourceManager in project openolat by klemens.

the class QTI21ArchiveFormat method exportCourseElement.

public MediaResource exportCourseElement() {
    FileResourceManager frm = FileResourceManager.getInstance();
    File unzippedDirRoot = frm.unzipFileResource(searchParams.getTestEntry().getOlatResource());
    resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
    ICourse course = CourseFactory.loadCourse(searchParams.getCourseEntry());
    courseNode = course.getRunStructure().getNode(searchParams.getNodeIdent());
    String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".xlsx";
    if ("iqself".equals(courseNode.getType())) {
        anonymizerCallback = course.getCourseEnvironment().getCoursePropertyManager();
    }
    // content
    final List<AssessmentTestSession> sessions = testSessionDao.getTestSessionsOfResponse(searchParams);
    final List<AssessmentResponse> responses = responseDao.getResponse(searchParams);
    return new OpenXMLWorkbookResource(label) {

        @Override
        protected void generate(OutputStream out) {
            try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
                // headers
                OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
                exportSheet.setHeaderRows(2);
                writeHeaders_1(exportSheet, workbook);
                writeHeaders_2(exportSheet, workbook);
                writeData(sessions, responses, exportSheet, workbook);
            } catch (Exception e) {
                log.error("", e);
            }
        }
    };
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ICourse(org.olat.course.ICourse) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) Date(java.util.Date) IOException(java.io.IOException) FileResourceManager(org.olat.fileresource.FileResourceManager) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) 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