Search in sources :

Example 6 with PFCourseNode

use of org.olat.course.nodes.PFCourseNode 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 7 with PFCourseNode

use of org.olat.course.nodes.PFCourseNode in project openolat by klemens.

the class ArchiverMainController method launchArchiveControllers.

private void launchArchiveControllers(UserRequest ureq, String menuCommand) {
    if (menuCommand.equals(CMD_INDEX)) {
        main.setContent(intro);
    } else {
        removeAsListenerAndDispose(contentCtr);
        if (menuCommand.equals(CMD_QTISURVRESULTS)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new IQSURVCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_QTITESTRESULTS)) {
            contentCtr = new TestArchiveController(ureq, getWindowControl(), ores, new IQTESTCourseNode(), new IQSELFCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_SCOREACCOUNTING)) {
            contentCtr = new ScoreAccountingArchiveController(ureq, getWindowControl(), ores);
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_ARCHIVELOGFILES)) {
            contentCtr = new CourseLogsArchiveController(ureq, getWindowControl(), ores);
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_HANDEDINTASKS)) {
            // TACourseNode
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new TACourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_GROUPTASKS)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new GTACourseNode(), new GTACourseNode(GTACourseNode.TYPE_INDIVIDUAL));
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_PROJECTBROKER)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new ProjectBrokerCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_FORUMS)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new FOCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_DIALOGS)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new DialogCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_WIKIS)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new WikiCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_SCORM)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new ScormCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_CHECKLIST)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new CheckListCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_PARTICIPANTFOLDER)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new PFCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        }
        listenTo(contentCtr);
    }
}
Also used : PFCourseNode(org.olat.course.nodes.PFCourseNode) IQSURVCourseNode(org.olat.course.nodes.IQSURVCourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode) FOCourseNode(org.olat.course.nodes.FOCourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode) CheckListCourseNode(org.olat.course.nodes.CheckListCourseNode) ScormCourseNode(org.olat.course.nodes.ScormCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) IQSELFCourseNode(org.olat.course.nodes.IQSELFCourseNode) DialogCourseNode(org.olat.course.nodes.DialogCourseNode) WikiCourseNode(org.olat.course.nodes.WikiCourseNode) ProjectBrokerCourseNode(org.olat.course.nodes.ProjectBrokerCourseNode)

Example 8 with PFCourseNode

use of org.olat.course.nodes.PFCourseNode in project OpenOLAT by OpenOLAT.

the class PFManagerTest method uploadFileToDropBox.

@Test
public void uploadFileToDropBox() throws URISyntaxException {
    // prepare
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("check-17");
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(initialAuthor);
    PFCourseNode pfNode = new PFCourseNode();
    pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_COACHBOX, true);
    pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_PARTICIPANTBOX, true);
    // import "Demo course" into the bcroot_junittest
    RepositoryEntry entry = JunitTestHelper.deployDemoCourse(initialAuthor);
    Long resourceableId = entry.getOlatResource().getResourceableId();
    ICourse course = CourseFactory.loadCourse(resourceableId);
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    // create files
    URL portraitUrl = JunitTestHelper.class.getResource("file_resources/IMG_1482.JPG");
    assertNotNull(portraitUrl);
    File portrait = new File(portraitUrl.toURI());
    boolean fileCreated = pfManager.uploadFileToDropBox(portrait, "textfile1", 1, courseEnv, pfNode, initialAuthor);
    boolean fileNotCreated = pfManager.uploadFileToDropBox(portrait, "textfile2", 0, courseEnv, pfNode, initialAuthor);
    Path relPath = Paths.get(PFManager.FILENAME_PARTICIPANTFOLDER, pfNode.getIdent(), pfManager.getIdFolderName(initialAuthor), PFManager.FILENAME_DROPBOX);
    OlatRootFolderImpl baseContainer = courseEnv.getCourseBaseContainer();
    VFSContainer dropboxContainer = VFSManager.resolveOrCreateContainerFromPath(baseContainer, relPath.toString());
    // check
    Assert.assertTrue(fileCreated);
    Assert.assertTrue(!fileNotCreated);
    Assert.assertTrue("textfile1".equals(dropboxContainer.getItems().get(0).getName()));
}
Also used : Path(java.nio.file.Path) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) URL(java.net.URL) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) File(java.io.File) Test(org.junit.Test)

Example 9 with PFCourseNode

use of org.olat.course.nodes.PFCourseNode in project OpenOLAT by OpenOLAT.

the class PFManagerTest method uploadFileToAllReturnBoxes.

@Test
public void uploadFileToAllReturnBoxes() throws URISyntaxException {
    // prepare
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("check-18");
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(initialAuthor);
    PFCourseNode pfNode = new PFCourseNode();
    pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_COACHBOX, true);
    pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_PARTICIPANTBOX, true);
    // import "Demo course" into the bcroot_junittest
    RepositoryEntry entry = JunitTestHelper.deployDemoCourse(initialAuthor);
    Long resourceableId = entry.getOlatResource().getResourceableId();
    ICourse course = CourseFactory.loadCourse(resourceableId);
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    List<Identity> identities = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        identities.add(JunitTestHelper.createAndPersistIdentityAsRndUser("pf-user-" + i));
    }
    URL portraitUrl = JunitTestHelper.class.getResource("file_resources/IMG_1482.JPG");
    assertNotNull(portraitUrl);
    File portrait = new File(portraitUrl.toURI());
    pfManager.uploadFileToAllReturnBoxes(portrait, "textfile3", courseEnv, pfNode, identities);
    // check
    for (Identity identity : identities) {
        Path relPath = Paths.get(PFManager.FILENAME_PARTICIPANTFOLDER, pfNode.getIdent(), pfManager.getIdFolderName(identity), PFManager.FILENAME_RETURNBOX);
        OlatRootFolderImpl baseContainer = courseEnv.getCourseBaseContainer();
        VFSContainer returnboxContainer = VFSManager.resolveOrCreateContainerFromPath(baseContainer, relPath.toString());
        Assert.assertTrue("textfile3".equals(returnboxContainer.getItems().get(0).getName()));
    }
}
Also used : Path(java.nio.file.Path) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) URL(java.net.URL) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) File(java.io.File) Test(org.junit.Test)

Example 10 with PFCourseNode

use of org.olat.course.nodes.PFCourseNode in project OpenOLAT by OpenOLAT.

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)

Aggregations

PFCourseNode (org.olat.course.nodes.PFCourseNode)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)10 Test (org.junit.Test)8 Identity (org.olat.core.id.Identity)8 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)8 ICourse (org.olat.course.ICourse)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)6 File (java.io.File)4 URL (java.net.URL)4 Path (java.nio.file.Path)4 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)4 MergeSource (org.olat.core.util.vfs.MergeSource)4 NamedContainerImpl (org.olat.core.util.vfs.NamedContainerImpl)4 ReadOnlyCallback (org.olat.core.util.vfs.callbacks.ReadOnlyCallback)4 BCCourseNode (org.olat.course.nodes.BCCourseNode)4 CourseNode (org.olat.course.nodes.CourseNode)4 PFManager (org.olat.course.nodes.pf.manager.PFManager)4 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)4