Search in sources :

Example 81 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project openolat by klemens.

the class WebDAVCommandsTest method testMkcol_public.

@Test
public void testMkcol_public() throws IOException, URISyntaxException {
    // create a user
    Identity user = JunitTestHelper.createAndPersistIdentityAsAuthor("webdav-2a-" + UUID.randomUUID().toString());
    // create a file
    String publicPath = FolderConfig.getUserHomes() + "/" + user.getName() + "/public";
    VFSContainer vfsPublic = new OlatRootFolderImpl(publicPath, null);
    Assert.assertTrue(vfsPublic.exists());
    WebDAVConnection conn = new WebDAVConnection();
    conn.setCredentials(user.getName(), "A6B7C8");
    // author check course folder
    URI publicUri = conn.getBaseURI().path("webdav").path("home").path("public").build();
    String publicXml = conn.propfind(publicUri, 2);
    Assert.assertTrue(publicXml.indexOf("<D:href>/webdav/home/public/</D:href>") > 0);
    // make a folder
    URI newUri = UriBuilder.fromUri(publicUri).path("newFolder").build();
    int returnMkcol = conn.mkcol(newUri);
    Assert.assertEquals(201, returnMkcol);
    // check if folder exists
    VFSItem newItem = vfsPublic.resolve("newFolder");
    Assert.assertNotNull(newItem);
    Assert.assertTrue(newItem instanceof VFSContainer);
    Assert.assertTrue(newItem.exists());
    IOUtils.closeQuietly(conn);
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test) CoursePublishTest(org.olat.restapi.CoursePublishTest)

Example 82 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project openolat by klemens.

the class WebDAVCommandsTest method testMove_public.

@Test
public void testMove_public() throws IOException, URISyntaxException {
    // create a user
    Identity user = JunitTestHelper.createAndPersistIdentityAsAuthor("webdav-2b-" + UUID.randomUUID().toString());
    // create a file
    String publicPath = FolderConfig.getUserHomes() + "/" + user.getName() + "/public";
    VFSContainer vfsPublic = new OlatRootFolderImpl(publicPath, null);
    createFile(vfsPublic, "test.txt");
    VFSContainer subPublic = vfsPublic.createChildContainer("moveto");
    WebDAVConnection conn = new WebDAVConnection();
    conn.setCredentials(user.getName(), "A6B7C8");
    // author check course folder
    URI publicUri = conn.getBaseURI().path("webdav").path("home").path("public").build();
    URI fileUri = UriBuilder.fromUri(publicUri).path("test.txt").build();
    String destination = UriBuilder.fromUri(publicUri).path("moveto").path("test.txt").build().toString();
    int returnMove = conn.move(fileUri, destination);
    Assert.assertEquals(201, returnMove);
    // check move
    VFSItem movedItem = subPublic.resolve("test.txt");
    Assert.assertNotNull(movedItem);
    Assert.assertTrue(movedItem instanceof VFSLeaf);
    Assert.assertTrue(movedItem.exists());
    VFSItem sourceItem = vfsPublic.resolve("test.txt");
    Assert.assertNull(sourceItem);
    IOUtils.closeQuietly(conn);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test) CoursePublishTest(org.olat.restapi.CoursePublishTest)

Example 83 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project openolat by klemens.

the class WebDAVCommandsTest method testHead.

@Test
public void testHead() throws IOException, URISyntaxException {
    // create a user
    Identity user = JunitTestHelper.createAndPersistIdentityAsUser("webdav-2-" + UUID.randomUUID().toString());
    WebDAVConnection conn = new WebDAVConnection();
    conn.setCredentials(user.getName(), "A6B7C8");
    // create a file
    String publicPath = FolderConfig.getUserHomes() + "/" + user.getName() + "/public";
    VFSContainer vfsPublic = new OlatRootFolderImpl(publicPath, null);
    createFile(vfsPublic, "test_head.txt");
    // head file
    URI publicUri = conn.getBaseURI().path("webdav").path("home").path("public").path("test_head.txt").build();
    HttpResponse response = conn.head(publicUri);
    Header lengthHeader = response.getFirstHeader("Content-Length");
    Assert.assertNotNull(lengthHeader);
    Assert.assertEquals("10", lengthHeader.getValue());
    Header typeHeader = response.getFirstHeader("Content-Type");
    Assert.assertNotNull(typeHeader);
    Assert.assertEquals("text/plain", typeHeader.getValue());
    EntityUtils.consume(response.getEntity());
    IOUtils.closeQuietly(conn);
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Header(org.apache.http.Header) VFSContainer(org.olat.core.util.vfs.VFSContainer) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test) CoursePublishTest(org.olat.restapi.CoursePublishTest)

Example 84 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project openolat by klemens.

the class WebDAVCommandsTest method testLock_public_samePathLock.

@Test
public void testLock_public_samePathLock() throws IOException, URISyntaxException {
    // create a user
    Identity user1 = JunitTestHelper.createAndPersistIdentityAsRndUser("webdav-2d");
    Identity user2 = JunitTestHelper.createAndPersistIdentityAsRndUser("webdav-2e");
    // create a file
    String publicPath1 = FolderConfig.getUserHomes() + "/" + user1.getName() + "/public";
    VFSContainer vfsPublic1 = new OlatRootFolderImpl(publicPath1, null);
    VFSItem item1 = createFile(vfsPublic1, "test.txt");
    Assert.assertNotNull(item1);
    String publicPath2 = FolderConfig.getUserHomes() + "/" + user2.getName() + "/public";
    VFSContainer vfsPublic2 = new OlatRootFolderImpl(publicPath2, null);
    VFSItem item2 = createFile(vfsPublic2, "test.txt");
    Assert.assertNotNull(item2);
    // lock the item with WebDAV
    WebDAVConnection conn1 = new WebDAVConnection();
    conn1.setCredentials(user1.getName(), "A6B7C8");
    // user 1 lock the file
    URI textUri = conn1.getBaseURI().path("webdav").path("home").path("public").path("test.txt").build();
    String textPropfind1 = conn1.propfind(textUri, 0);
    Assert.assertNotNull(textPropfind1);
    // lock the path /webdav/home/public/test.txt
    String lockToken1 = conn1.lock(textUri, UUID.randomUUID().toString());
    Assert.assertNotNull(lockToken1);
    // user 2 lock its own file
    WebDAVConnection conn2 = new WebDAVConnection();
    conn2.setCredentials(user2.getName(), "A6B7C8");
    String textPropfind2 = conn2.propfind(textUri, 0);
    Assert.assertNotNull(textPropfind2);
    // lock the path /webdav/home/public/test.txt
    String lockToken2 = conn2.lock(textUri, UUID.randomUUID().toString());
    Assert.assertNotNull(lockToken2);
    // closes
    conn1.close();
    conn2.close();
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test) CoursePublishTest(org.olat.restapi.CoursePublishTest)

Example 85 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project openolat by klemens.

the class BulkAssessmentTask method getReturnBox.

/**
 * Return the target folder of the assessed identity. This is a factory method which take care
 * of the type of the course node.
 *
 * @param uce
 * @param courseNode
 * @param identity
 * @return
 */
private VFSContainer getReturnBox(UserCourseEnvironment uce, CourseNode courseNode, Identity identity) {
    VFSContainer returnContainer = null;
    if (courseNode instanceof GTACourseNode) {
        final GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
        CourseEnvironment courseEnv = uce.getCourseEnvironment();
        returnContainer = gtaManager.getCorrectionContainer(courseEnv, (GTACourseNode) courseNode, identity);
    } else {
        String returnPath = ReturnboxController.getReturnboxPathRelToFolderRoot(uce.getCourseEnvironment(), courseNode);
        OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(returnPath, null);
        VFSItem assessedItem = rootFolder.resolve(identity.getName());
        if (assessedItem == null) {
            returnContainer = rootFolder.createChildContainer(identity.getName());
        } else if (assessedItem instanceof VFSContainer) {
            returnContainer = (VFSContainer) assessedItem;
        }
    }
    return returnContainer;
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) GTACourseNode(org.olat.course.nodes.GTACourseNode) GTAManager(org.olat.course.nodes.gta.GTAManager) VFSItem(org.olat.core.util.vfs.VFSItem)

Aggregations

OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)214 VFSContainer (org.olat.core.util.vfs.VFSContainer)86 VFSItem (org.olat.core.util.vfs.VFSItem)68 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)58 Identity (org.olat.core.id.Identity)50 Test (org.junit.Test)48 File (java.io.File)36 InputStream (java.io.InputStream)30 OlatNamedContainerImpl (org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl)28 OutputStream (java.io.OutputStream)26 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)24 URI (java.net.URI)22 RepositoryEntry (org.olat.repository.RepositoryEntry)22 ByteArrayInputStream (java.io.ByteArrayInputStream)20 Path (java.nio.file.Path)20 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)18 IOException (java.io.IOException)16 HttpResponse (org.apache.http.HttpResponse)14 CollaborationTools (org.olat.collaboration.CollaborationTools)14 FolderRunController (org.olat.core.commons.modules.bc.FolderRunController)14