Search in sources :

Example 1 with MergeSource

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

the class MergedCourseContainer method init.

protected void init(PersistingCourseImpl persistingCourse) {
    super.init();
    RepositoryEntry courseRe = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    courseReadOnly = !overrideReadOnly && (courseRe.getRepositoryEntryStatus().isClosed() || courseRe.getRepositoryEntryStatus().isUnpublished());
    if (courseReadOnly) {
        setLocalSecurityCallback(new ReadOnlyCallback());
    }
    if (identityEnv == null || identityEnv.getRoles().isOLATAdmin()) {
        VFSContainer courseContainer = persistingCourse.getIsolatedCourseFolder();
        if (courseReadOnly) {
            courseContainer.setLocalSecurityCallback(new ReadOnlyCallback());
        }
        addContainersChildren(courseContainer, true);
    } else {
        RepositoryEntry re = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        RepositoryEntrySecurity reSecurity = RepositoryManager.getInstance().isAllowed(identityEnv.getIdentity(), identityEnv.getRoles(), re);
        if (reSecurity.isEntryAdmin()) {
            VFSContainer courseContainer = persistingCourse.getIsolatedCourseFolder();
            if (courseReadOnly) {
                courseContainer.setLocalSecurityCallback(new ReadOnlyCallback());
            }
            addContainersChildren(courseContainer, true);
        }
    }
    initSharedFolder(persistingCourse);
    // add all course building blocks of type BC to a virtual folder
    MergeSource nodesContainer = new MergeSource(null, "_courseelementdata");
    if (identityEnv == null) {
        CourseNode rootNode = persistingCourse.getRunStructure().getRootNode();
        addFoldersForAdmin(persistingCourse, nodesContainer, rootNode);
    } else {
        TreeEvaluation treeEval = new TreeEvaluation();
        GenericTreeModel treeModel = new GenericTreeModel();
        UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, persistingCourse.getCourseEnvironment());
        CourseNode rootCn = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
        NodeEvaluation rootNodeEval = rootCn.eval(userCourseEnv.getConditionInterpreter(), treeEval, new VisibleTreeFilter());
        TreeNode treeRoot = rootNodeEval.getTreeNode();
        treeModel.setRootNode(treeRoot);
        addFolders(persistingCourse, nodesContainer, treeRoot);
    }
    if (nodesContainer.getItems().size() > 0) {
        addContainer(nodesContainer);
    }
}
Also used : ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) MergeSource(org.olat.core.util.vfs.MergeSource) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) TreeNode(org.olat.core.gui.components.tree.TreeNode) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 2 with MergeSource

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

the class MergedCourseContainer method addFoldersForAdmin.

/**
 * Internal method to recursively add all course building blocks of type
 * BC to a given VFS container. This should only be used for an author view,
 * it does not test for security.
 *
 * @param course
 * @param nodesContainer
 * @param courseNode
 * @return container for the current course node
 */
private void addFoldersForAdmin(PersistingCourseImpl course, MergeSource nodesContainer, CourseNode courseNode) {
    for (int i = 0; i < courseNode.getChildCount(); i++) {
        CourseNode child = (CourseNode) courseNode.getChildAt(i);
        String folderName = RequestUtil.normalizeFilename(child.getShortTitle());
        if (child instanceof BCCourseNode) {
            final BCCourseNode bcNode = (BCCourseNode) child;
            // add folder not to merge source. Use name and node id to have unique name
            VFSContainer rootFolder = getBCContainer(course, bcNode, null, true);
            if (courseReadOnly) {
                rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
            }
            folderName = getFolderName(nodesContainer, bcNode, folderName);
            if (rootFolder != null) {
                // Create a container for this node content and wrap it with a merge source which is attached to tree
                VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
                MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
                courseNodeContainer.addContainersChildren(nodeContentContainer, true);
                nodesContainer.addContainer(courseNodeContainer);
                // Do recursion for all children
                addFoldersForAdmin(course, courseNodeContainer, child);
            }
        } else if (child instanceof PFCourseNode) {
            final PFCourseNode pfNode = (PFCourseNode) child;
            // add folder not to merge source. Use name and node id to have unique name
            PFManager pfManager = CoreSpringFactory.getImpl(PFManager.class);
            folderName = getFolderName(nodesContainer, pfNode, folderName);
            MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
            VFSContainer rootFolder = pfManager.provideAdminContainer(pfNode, course.getCourseEnvironment());
            VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
            courseNodeContainer.addContainersChildren(nodeContentContainer, true);
            nodesContainer.addContainer(courseNodeContainer);
            // Do recursion for all children
            addFoldersForAdmin(course, courseNodeContainer, child);
        } else {
            // For non-folder course nodes, add merge source (no files to show) ...
            MergeSource courseNodeContainer = new MergeSource(null, folderName);
            // , then do recursion for all children ...
            addFoldersForAdmin(course, courseNodeContainer, child);
            // ... but only add this container if it contains any children with at least one BC course node
            if (!courseNodeContainer.getItems().isEmpty()) {
                nodesContainer.addContainer(courseNodeContainer);
            }
        }
    }
}
Also used : PFCourseNode(org.olat.course.nodes.PFCourseNode) PFManager(org.olat.course.nodes.pf.manager.PFManager) BCCourseNode(org.olat.course.nodes.BCCourseNode) MergeSource(org.olat.core.util.vfs.MergeSource) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) VFSContainer(org.olat.core.util.vfs.VFSContainer) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Example 3 with MergeSource

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

the class SimpleVersionConfig method versionEnabled.

public boolean versionEnabled(VFSContainer container) {
    int versionsAllowed = getVersionAllowed();
    if (versionsAllowed == 0) {
        return false;
    }
    if (container instanceof NamedContainerImpl) {
        container = ((NamedContainerImpl) container).getDelegate();
    }
    if (container instanceof MergeSource) {
        container = ((MergeSource) container).getRootWriteContainer();
    }
    if (container instanceof LocalFolderImpl) {
        try {
            LocalFolderImpl folderImpl = (LocalFolderImpl) container;
            String path = folderImpl.getBasefile().getCanonicalPath();
            List<String> excludedRoots = getExcludedRoots();
            for (String excludedRoot : excludedRoots) {
                if (path.startsWith(excludedRoot)) {
                    return false;
                }
            }
            String root = getCourseRoot();
            if (path.startsWith(root)) {
                for (String exclusion : EXCLUSIONS_IN_COURSE_PATH) {
                    if (path.indexOf(exclusion) > 0) {
                        return false;
                    }
                }
            }
            return getVersionAllowed() != 0;
        } catch (IOException e) {
        // fail silently;
        }
    }
    return false;
}
Also used : MergeSource(org.olat.core.util.vfs.MergeSource) IOException(java.io.IOException) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 4 with MergeSource

use of org.olat.core.util.vfs.MergeSource in project openolat by klemens.

the class MergedCourseContainer method addFolders.

private void addFolders(PersistingCourseImpl course, MergeSource nodesContainer, TreeNode courseNode) {
    if (courseNode == null)
        return;
    for (int i = 0; i < courseNode.getChildCount(); i++) {
        TreeNode child = (TreeNode) courseNode.getChildAt(i);
        NodeEvaluation nodeEval;
        if (child.getUserObject() instanceof NodeEvaluation) {
            nodeEval = (NodeEvaluation) child.getUserObject();
        } else {
            continue;
        }
        if (nodeEval != null && nodeEval.getCourseNode() != null) {
            CourseNode courseNodeChild = nodeEval.getCourseNode();
            String folderName = RequestUtil.normalizeFilename(courseNodeChild.getShortTitle());
            if (courseNodeChild instanceof BCCourseNode) {
                final BCCourseNode bcNode = (BCCourseNode) courseNodeChild;
                // add folder not to merge source. Use name and node id to have unique name
                VFSContainer rootFolder = getBCContainer(course, bcNode, nodeEval, false);
                boolean canDownload = nodeEval.isCapabilityAccessible("download");
                if (canDownload && rootFolder != null) {
                    if (courseReadOnly) {
                        rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
                    } else if (nodeEval.isCapabilityAccessible("upload")) {
                    // inherit the security callback from the course as for author
                    } else {
                        rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
                    }
                    folderName = getFolderName(nodesContainer, bcNode, folderName);
                    // Create a container for this node content and wrap it with a merge source which is attached to tree
                    VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
                    MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
                    courseNodeContainer.addContainersChildren(nodeContentContainer, true);
                    nodesContainer.addContainer(courseNodeContainer);
                    // Do recursion for all children
                    addFolders(course, courseNodeContainer, child);
                } else {
                    // For non-folder course nodes, add merge source (no files to show) ...
                    MergeSource courseNodeContainer = new MergeSource(null, folderName);
                    // , then do recursion for all children ...
                    addFolders(course, courseNodeContainer, child);
                    // ... but only add this container if it contains any children with at least one BC course node
                    if (courseNodeContainer.getItems().size() > 0) {
                        nodesContainer.addContainer(courseNodeContainer);
                    }
                }
            } else if (courseNodeChild instanceof PFCourseNode) {
                final PFCourseNode pfNode = (PFCourseNode) courseNodeChild;
                // add folder not to merge source. Use name and node id to have unique name
                PFManager pfManager = CoreSpringFactory.getImpl(PFManager.class);
                folderName = getFolderName(nodesContainer, pfNode, folderName);
                MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
                UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
                VFSContainer rootFolder = pfManager.provideCoachOrParticipantContainer(pfNode, userCourseEnv, identityEnv.getIdentity(), courseReadOnly);
                VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
                courseNodeContainer.addContainersChildren(nodeContentContainer, true);
                addFolders(course, courseNodeContainer, child);
                nodesContainer.addContainer(courseNodeContainer);
            } else {
                // For non-folder course nodes, add merge source (no files to show) ...
                MergeSource courseNodeContainer = new MergeSource(null, folderName);
                // , then do recursion for all children ...
                addFolders(course, courseNodeContainer, child);
                // ... but only add this container if it contains any children with at least one BC course node
                if (courseNodeContainer.getItems().size() > 0) {
                    nodesContainer.addContainer(courseNodeContainer);
                }
            }
        }
    }
}
Also used : PFCourseNode(org.olat.course.nodes.PFCourseNode) PFManager(org.olat.course.nodes.pf.manager.PFManager) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) BCCourseNode(org.olat.course.nodes.BCCourseNode) MergeSource(org.olat.core.util.vfs.MergeSource) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) TreeNode(org.olat.core.gui.components.tree.TreeNode) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Example 5 with MergeSource

use of org.olat.core.util.vfs.MergeSource in project openolat by klemens.

the class MergedCourseContainer method init.

protected void init(PersistingCourseImpl persistingCourse) {
    super.init();
    RepositoryEntry courseRe = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    courseReadOnly = !overrideReadOnly && (courseRe.getRepositoryEntryStatus().isClosed() || courseRe.getRepositoryEntryStatus().isUnpublished());
    if (courseReadOnly) {
        setLocalSecurityCallback(new ReadOnlyCallback());
    }
    if (identityEnv == null || identityEnv.getRoles().isOLATAdmin()) {
        VFSContainer courseContainer = persistingCourse.getIsolatedCourseFolder();
        if (courseReadOnly) {
            courseContainer.setLocalSecurityCallback(new ReadOnlyCallback());
        }
        addContainersChildren(courseContainer, true);
    } else {
        RepositoryEntry re = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        RepositoryEntrySecurity reSecurity = RepositoryManager.getInstance().isAllowed(identityEnv.getIdentity(), identityEnv.getRoles(), re);
        if (reSecurity.isEntryAdmin()) {
            VFSContainer courseContainer = persistingCourse.getIsolatedCourseFolder();
            if (courseReadOnly) {
                courseContainer.setLocalSecurityCallback(new ReadOnlyCallback());
            }
            addContainersChildren(courseContainer, true);
        }
    }
    initSharedFolder(persistingCourse);
    // add all course building blocks of type BC to a virtual folder
    MergeSource nodesContainer = new MergeSource(null, "_courseelementdata");
    if (identityEnv == null) {
        CourseNode rootNode = persistingCourse.getRunStructure().getRootNode();
        addFoldersForAdmin(persistingCourse, nodesContainer, rootNode);
    } else {
        TreeEvaluation treeEval = new TreeEvaluation();
        GenericTreeModel treeModel = new GenericTreeModel();
        UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, persistingCourse.getCourseEnvironment());
        CourseNode rootCn = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
        NodeEvaluation rootNodeEval = rootCn.eval(userCourseEnv.getConditionInterpreter(), treeEval, new VisibleTreeFilter());
        TreeNode treeRoot = rootNodeEval.getTreeNode();
        treeModel.setRootNode(treeRoot);
        addFolders(persistingCourse, nodesContainer, treeRoot);
    }
    if (nodesContainer.getItems().size() > 0) {
        addContainer(nodesContainer);
    }
}
Also used : ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) VFSContainer(org.olat.core.util.vfs.VFSContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) MergeSource(org.olat.core.util.vfs.MergeSource) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) TreeNode(org.olat.core.gui.components.tree.TreeNode) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Aggregations

MergeSource (org.olat.core.util.vfs.MergeSource)8 NamedContainerImpl (org.olat.core.util.vfs.NamedContainerImpl)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 ReadOnlyCallback (org.olat.core.util.vfs.callbacks.ReadOnlyCallback)6 BCCourseNode (org.olat.course.nodes.BCCourseNode)6 CourseNode (org.olat.course.nodes.CourseNode)6 PFCourseNode (org.olat.course.nodes.PFCourseNode)6 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 PFManager (org.olat.course.nodes.pf.manager.PFManager)4 NodeEvaluation (org.olat.course.run.userview.NodeEvaluation)4 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)4 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)4 IOException (java.io.IOException)2 GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)2 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)2 TreeEvaluation (org.olat.course.run.userview.TreeEvaluation)2 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 RepositoryEntrySecurity (org.olat.repository.model.RepositoryEntrySecurity)2