Search in sources :

Example 51 with OlatRootFolderImpl

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

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 52 with OlatRootFolderImpl

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

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 53 with OlatRootFolderImpl

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

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 54 with OlatRootFolderImpl

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

the class OlatRootFolderTreeModel method makeChildren.

/**
 * Add children to the node
 *
 * @param node
 * @param root
 */
protected void makeChildren(OlatRootFolderTreeNode node, OlatRootFolderImpl root) {
    List<VFSItem> children = root.getItems(filter);
    if (comparator != null) {
        Collections.sort(children, comparator);
    }
    for (VFSItem child : children) {
        // create a node for each child and add it
        if (child instanceof OlatRelPathImpl) {
            OlatRootFolderTreeNode childNode = createNode((OlatRelPathImpl) child);
            node.addChild(childNode);
            if (child instanceof OlatRootFolderImpl) {
                // add the child's children recursively
                makeChildren(childNode, (OlatRootFolderImpl) child);
            }
        }
    }
}
Also used : OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 55 with OlatRootFolderImpl

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

the class VFSManager method resolveFile.

/**
 * @see org.olat.core.util.vfs.VFSItem#resolveFile(java.lang.String)
 */
public static VFSItem resolveFile(VFSContainer rootContainer, String path) {
    path = VFSManager.sanitizePath(path);
    if (path.equals("/")) {
        // slash or empty path -> return this vfsitem
        return rootContainer;
    }
    // to be returned as, the proper type of, VFSItem.
    if (rootContainer instanceof LocalFolderImpl) {
        String childName = extractChild(path);
        LocalFolderImpl l = (LocalFolderImpl) rootContainer;
        File t = new File(l.getBasefile().getAbsolutePath(), childName);
        if (t.exists()) {
            String bcroot = FolderConfig.getCanonicalRoot();
            String fsPath = t.getAbsolutePath();
            if (t.isDirectory()) {
                VFSContainer subContainer;
                if (fsPath.startsWith(bcroot)) {
                    fsPath = fsPath.substring(bcroot.length(), fsPath.length());
                    subContainer = new OlatRootFolderImpl(fsPath, rootContainer);
                } else {
                    subContainer = new LocalFolderImpl(t, rootContainer);
                }
                String subPath = path.substring(childName.length() + 1);
                return resolveFile(subContainer, subPath);
            } else {
                if (fsPath.startsWith(bcroot)) {
                    fsPath = fsPath.replace(bcroot, "");
                    return new OlatRootFileImpl(fsPath, rootContainer);
                } else {
                    return new LocalFileImpl(t, rootContainer);
                }
            }
        } else {
            return null;
        }
    }
    // leave original code block as fall-back for non-file-system-based implementations
    String childName = extractChild(path);
    List<VFSItem> children = rootContainer.getItems();
    for (VFSItem child : children) {
        String curName = child.getName();
        if (childName.equals(curName)) {
            // found , let child further resolve if needed
            return child.resolve(path.substring(childName.length() + 1));
        }
    }
    return null;
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl) File(java.io.File) ContainerAndFile(org.olat.core.util.vfs.util.ContainerAndFile)

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