Search in sources :

Example 31 with FileResourceManager

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

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 32 with FileResourceManager

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

the class QTIEditorPackageImpl method unzipPackage.

/**
 * Unzip package into temporary directory.
 * @return true if successfull, false otherwise
 */
private boolean unzipPackage() {
    FileResourceManager frm = FileResourceManager.getInstance();
    File fPackageZIP = frm.getFileResource(fileResource);
    return ZipUtil.unzip(fPackageZIP, packageDir);
}
Also used : FileResourceManager(org.olat.fileresource.FileResourceManager) File(java.io.File)

Example 33 with FileResourceManager

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

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)

Example 34 with FileResourceManager

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

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 35 with FileResourceManager

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

the class QTI21AssessmentRunController method doShowResults.

private void doShowResults(UserRequest ureq) {
    removeAsListenerAndDispose(resultCtrl);
    AssessmentTestSession session = null;
    if (courseNode instanceof SelfAssessableCourseNode) {
        RepositoryEntry courseEntry = userCourseEnv.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        session = qtiService.getLastAssessmentTestSessions(courseEntry, courseNode.getIdent(), testEntry, getIdentity());
    } else {
        AssessmentManager am = userCourseEnv.getCourseEnvironment().getAssessmentManager();
        AssessmentEntry assessmentEntry = am.getAssessmentEntry(courseNode, getIdentity());
        if (assessmentEntry.getAssessmentId() != null) {
            session = qtiService.getAssessmentTestSession(assessmentEntry.getAssessmentId());
        } else {
            RepositoryEntry courseEntry = userCourseEnv.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
            session = qtiService.getLastAssessmentTestSessions(courseEntry, courseNode.getIdent(), testEntry, getIdentity());
        }
    }
    if (session == null) {
        mainVC.contextPut("showResults", Boolean.FALSE);
    } else {
        FileResourceManager frm = FileResourceManager.getInstance();
        File fUnzippedDirRoot = frm.unzipFileResource(session.getTestEntry().getOlatResource());
        URI assessmentObjectUri = qtiService.createAssessmentTestUri(fUnzippedDirRoot);
        File submissionDir = qtiService.getAssessmentResultFile(session);
        String mapperUri = registerCacheableMapper(ureq, "QTI21CNResults::" + session.getTestEntry().getKey(), new ResourcesMapper(assessmentObjectUri, submissionDir));
        resultCtrl = new AssessmentResultController(ureq, getWindowControl(), getIdentity(), true, session, fUnzippedDirRoot, mapperUri, null, getDeliveryOptions().getAssessmentResultsOptions(), false, false, true);
        listenTo(resultCtrl);
        mainVC.put("resultReport", resultCtrl.getInitialComponent());
        mainVC.contextPut("showResults", Boolean.TRUE);
    }
    saveOpenPanel(ureq, "results", Boolean.TRUE);
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) FileResourceManager(org.olat.fileresource.FileResourceManager) AssessmentManager(org.olat.course.assessment.AssessmentManager) ResourcesMapper(org.olat.ims.qti21.ui.ResourcesMapper) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessmentResultController(org.olat.ims.qti21.ui.AssessmentResultController) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) File(java.io.File) URI(java.net.URI) SelfAssessableCourseNode(org.olat.course.nodes.SelfAssessableCourseNode)

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