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