Search in sources :

Example 81 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class TaxonomyServiceImpl method deleteTaxonomyLevel.

@Override
public boolean deleteTaxonomyLevel(TaxonomyLevelRef taxonomyLevel, TaxonomyLevelRef mergeTo) {
    // save the documents
    TaxonomyLevel reloadedTaxonomyLevel = taxonomyLevelDao.loadByKey(taxonomyLevel.getKey());
    if (mergeTo != null) {
        TaxonomyLevel reloadedMergeTo = taxonomyLevelDao.loadByKey(mergeTo.getKey());
        merge(reloadedTaxonomyLevel, reloadedMergeTo);
    } else {
        VFSContainer library = taxonomyLevelDao.getDocumentsLibrary(reloadedTaxonomyLevel);
        if (library != null) {
            Taxonomy taxonomy = reloadedTaxonomyLevel.getTaxonomy();
            VFSContainer lostAndFound = taxonomyDao.getLostAndFoundDirectoryLibrary(taxonomy);
            String dir = StringHelper.transformDisplayNameToFileSystemName(reloadedTaxonomyLevel.getIdentifier());
            dir += "_" + taxonomyLevel.getKey();
            VFSContainer lastStorage = lostAndFound.createChildContainer(dir);
            if (lastStorage == null) {
                VFSItem storageItem = lostAndFound.resolve(dir);
                if (storageItem instanceof VFSContainer) {
                    lastStorage = (VFSContainer) storageItem;
                } else {
                    lastStorage = lostAndFound.createChildContainer(UUID.randomUUID().toString());
                }
            }
            VFSManager.copyContent(library, lastStorage);
        }
        // delete the competences
        taxonomyCompetenceDao.deleteCompetences(taxonomyLevel);
        // questions
        taxonomyRelationsDao.removeFromQuestionItems(taxonomyLevel);
    }
    return taxonomyLevelDao.delete(reloadedTaxonomyLevel);
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 82 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class ScormAssessmentManager method visitScoDatas.

/**
 * Return all the datas in the sco datamodels of a SCORM course
 * @param username
 * @param courseEnv
 * @param node
 * @return
 */
public List<CmiData> visitScoDatas(String username, CourseEnvironment courseEnv, ScormCourseNode node) {
    VFSContainer scoContainer = ScormDirectoryHelper.getScoDirectory(username, courseEnv, node);
    if (scoContainer == null) {
        return Collections.emptyList();
    }
    List<VFSItem> contents = scoContainer.getItems(new XMLFilter());
    if (contents.isEmpty()) {
        return Collections.emptyList();
    }
    if (contents.size() > 1) {
        Collections.sort(contents, new FileDateComparator());
    }
    VFSItem file = contents.get(0);
    List<CmiData> datas = collectData(file);
    return datas;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 83 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class DialogCourseNode method doArchiveElement.

/**
 * Archive a single dialog element with files and forum
 * @param element
 * @param exportDirectory
 */
public void doArchiveElement(DialogElement element, File exportDirectory, Locale locale) {
    DialogElementsManager depm = CoreSpringFactory.getImpl(DialogElementsManager.class);
    VFSContainer dialogContainer = depm.getDialogContainer(element);
    // there is only one file (leave) in the top forum container
    VFSItem dialogFile = dialogContainer.getItems(new VFSLeafFilter()).get(0);
    VFSContainer exportContainer = new LocalFolderImpl(exportDirectory);
    // append export timestamp to avoid overwriting previous export
    String exportDirName = Formatter.makeStringFilesystemSave(getShortTitle()) + "_" + element.getForum().getKey() + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
    VFSContainer diaNodeElemExportContainer = exportContainer.createChildContainer(exportDirName);
    // don't check quota
    diaNodeElemExportContainer.setLocalSecurityCallback(new FullAccessCallback());
    diaNodeElemExportContainer.copyFrom(dialogFile);
    ForumArchiveManager fam = ForumArchiveManager.getInstance();
    ForumFormatter ff = new ForumRTFFormatter(diaNodeElemExportContainer, false, locale);
    fam.applyFormatter(ff, element.getForum().getKey(), null);
}
Also used : ForumFormatter(org.olat.modules.fo.archiver.formatters.ForumFormatter) FullAccessCallback(org.olat.core.util.vfs.callbacks.FullAccessCallback) ForumArchiveManager(org.olat.modules.fo.archiver.ForumArchiveManager) ForumRTFFormatter(org.olat.modules.fo.archiver.formatters.ForumRTFFormatter) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) DialogElementsManager(org.olat.course.nodes.dialog.DialogElementsManager) Date(java.util.Date) VFSLeafFilter(org.olat.core.util.vfs.filters.VFSLeafFilter) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 84 with VFSItem

use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.

the class GTACourseNode method archiveNodeData.

@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
    final GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
    final ModuleConfiguration config = getModuleConfiguration();
    String prefix;
    if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
        prefix = "grouptask_";
    } else {
        prefix = "ita_";
    }
    String dirName = prefix + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
    TaskList taskList = gtaManager.getTaskList(course.getCourseEnvironment().getCourseGroupManager().getCourseEntry(), this);
    // save assessment datas
    List<Identity> users = null;
    if (config.getBooleanSafe(GTASK_GRADING)) {
        users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment(), options);
        String courseTitle = course.getCourseTitle();
        String fileName = ExportUtil.createFileNameWithTimeStamp(courseTitle, "xlsx");
        List<AssessableCourseNode> nodes = Collections.<AssessableCourseNode>singletonList(this);
        try (OutputStream out = new ShieldOutputStream(exportStream)) {
            exportStream.putNextEntry(new ZipEntry(dirName + "/" + fileName));
            ScoreAccountingHelper.createCourseResultsOverviewXMLTable(users, nodes, course, locale, out);
            exportStream.closeEntry();
        } catch (Exception e) {
            log.error("", e);
        }
    }
    // copy tasks
    if (taskList != null) {
        if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
            List<BusinessGroup> selectedGroups;
            if (options != null && options.getGroup() != null) {
                selectedGroups = Collections.singletonList(options.getGroup());
            } else {
                selectedGroups = gtaManager.getBusinessGroups(this);
            }
            for (BusinessGroup businessGroup : selectedGroups) {
                archiveNodeData(course, businessGroup, taskList, dirName, exportStream);
            }
        } else {
            if (users == null) {
                users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment(), options);
            }
            Set<Identity> uniqueUsers = new HashSet<>(users);
            for (Identity user : uniqueUsers) {
                archiveNodeData(course, user, taskList, dirName, exportStream);
            }
        }
    }
    // copy solutions
    if (config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION)) {
        VFSContainer solutions = gtaManager.getSolutionsContainer(course.getCourseEnvironment(), this);
        if (solutions.exists()) {
            String solutionDirName = dirName + "/solutions";
            for (VFSItem solution : solutions.getItems(new SystemItemFilter())) {
                ZipUtil.addToZip(solution, solutionDirName, exportStream);
            }
        }
    }
    return true;
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) BusinessGroup(org.olat.group.BusinessGroup) TaskList(org.olat.course.nodes.gta.TaskList) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ZipEntry(java.util.zip.ZipEntry) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) Date(java.util.Date) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) GTAManager(org.olat.course.nodes.gta.GTAManager) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 85 with VFSItem

use of org.olat.core.util.vfs.VFSItem 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)

Aggregations

VFSItem (org.olat.core.util.vfs.VFSItem)546 VFSContainer (org.olat.core.util.vfs.VFSContainer)356 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)272 File (java.io.File)78 Test (org.junit.Test)68 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)68 ArrayList (java.util.ArrayList)64 InputStream (java.io.InputStream)52 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)52 Identity (org.olat.core.id.Identity)50 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)48 IOException (java.io.IOException)42 Date (java.util.Date)40 URI (java.net.URI)38 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)38 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)34 OutputStream (java.io.OutputStream)30 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)28 HttpResponse (org.apache.http.HttpResponse)22 URL (java.net.URL)20