Search in sources :

Example 11 with PFCourseNode

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

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 12 with PFCourseNode

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

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 13 with PFCourseNode

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

the class PFManagerTest method provideParticipantContainer.

@Test
public void provideParticipantContainer() {
    // prepare
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("check-15");
    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);
    UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
    Identity check3 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-3");
    repositoryEntryRelationDao.addRole(check3, entry, GroupRoles.participant.name());
    VFSContainer vfsContainer = pfManager.provideCoachOrParticipantContainer(pfNode, userCourseEnv, check3, false);
    Assert.assertNotNull(vfsContainer);
    Assert.assertTrue(vfsContainer.exists());
}
Also used : PFCourseNode(org.olat.course.nodes.PFCourseNode) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) Test(org.junit.Test)

Example 14 with PFCourseNode

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

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)

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