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);
}
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);
}
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();
}
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);
}
}
}
}
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;
}
Aggregations