Search in sources :

Example 6 with SharedFolderHandler

use of org.olat.repository.handlers.SharedFolderHandler in project openolat by klemens.

the class SharedFolderTest method getFiles.

/**
 * Check simple GET for the directory.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void getFiles() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("shared-owner-");
    RepositoryEntry sharedFolder = new SharedFolderHandler().createResource(owner, "Shared 2", "Shared files", null, Locale.ENGLISH);
    VFSContainer container = SharedFolderManager.getInstance().getNamedSharedFolder(sharedFolder, true);
    copyFileInResourceFolder(container, "portrait.jpg", "2_");
    URI uri = UriBuilder.fromUri(getFolderURI(sharedFolder)).path("files").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<FileVO> links = parseFileArray(body);
    Assert.assertNotNull(links);
    Assert.assertEquals(1, links.size());
    Assert.assertTrue(links.get(0).getHref().contains("2_portrait.jpg"));
    conn.shutdown();
}
Also used : SharedFolderHandler(org.olat.repository.handlers.SharedFolderHandler) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) HttpGet(org.apache.http.client.methods.HttpGet) FileVO(org.olat.restapi.support.vo.FileVO) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 7 with SharedFolderHandler

use of org.olat.repository.handlers.SharedFolderHandler in project openolat by klemens.

the class SharedFolderTest method putDirectories_owner.

/**
 * The root /** is read only
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void putDirectories_owner() throws IOException, URISyntaxException {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("shared-owner-");
    RepositoryEntry sharedFolder = new SharedFolderHandler().createResource(owner, "Shared 2", "A shared folder", null, Locale.ENGLISH);
    VFSContainer container = SharedFolderManager.getInstance().getNamedSharedFolder(sharedFolder, true);
    copyFileInResourceFolder(container, "portrait.jpg", "2_");
    // owner want to upload a file
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login(owner.getName(), "A6B7C8"));
    // create single page
    URL fileUrl = CoursesFoldersTest.class.getResource("certificate.pdf");
    File file = new File(fileUrl.toURI());
    URI uri = UriBuilder.fromUri(getFolderURI(sharedFolder)).build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    conn.addMultipart(method, file.getName(), file);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(405, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    conn.shutdown();
}
Also used : SharedFolderHandler(org.olat.repository.handlers.SharedFolderHandler) VFSContainer(org.olat.core.util.vfs.VFSContainer) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) File(java.io.File) URI(java.net.URI) URL(java.net.URL) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 8 with SharedFolderHandler

use of org.olat.repository.handlers.SharedFolderHandler in project openolat by klemens.

the class SharedFolderTest method getDirectories.

/**
 * Check simple GET for the directory.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void getDirectories() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("shared-owner-");
    RepositoryEntry sharedFolder = new SharedFolderHandler().createResource(owner, "Shared 1", "A shared folder", null, Locale.ENGLISH);
    VFSContainer container = SharedFolderManager.getInstance().getNamedSharedFolder(sharedFolder, true);
    copyFileInResourceFolder(container, "portrait.jpg", "1_");
    URI uri = UriBuilder.fromUri(getFolderURI(sharedFolder)).build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<LinkVO> links = parseLinkArray(body);
    Assert.assertNotNull(links);
    Assert.assertEquals(1, links.size());
    Assert.assertTrue(links.get(0).getHref().contains("1_portrait.jpg"));
    conn.shutdown();
}
Also used : SharedFolderHandler(org.olat.repository.handlers.SharedFolderHandler) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) HttpGet(org.apache.http.client.methods.HttpGet) LinkVO(org.olat.restapi.support.vo.LinkVO) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 9 with SharedFolderHandler

use of org.olat.repository.handlers.SharedFolderHandler in project OpenOLAT by OpenOLAT.

the class SharedFolderTest method getFiles.

/**
 * Check simple GET for the directory.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void getFiles() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("shared-owner-");
    RepositoryEntry sharedFolder = new SharedFolderHandler().createResource(owner, "Shared 2", "Shared files", null, Locale.ENGLISH);
    VFSContainer container = SharedFolderManager.getInstance().getNamedSharedFolder(sharedFolder, true);
    copyFileInResourceFolder(container, "portrait.jpg", "2_");
    URI uri = UriBuilder.fromUri(getFolderURI(sharedFolder)).path("files").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<FileVO> links = parseFileArray(body);
    Assert.assertNotNull(links);
    Assert.assertEquals(1, links.size());
    Assert.assertTrue(links.get(0).getHref().contains("2_portrait.jpg"));
    conn.shutdown();
}
Also used : SharedFolderHandler(org.olat.repository.handlers.SharedFolderHandler) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) HttpGet(org.apache.http.client.methods.HttpGet) FileVO(org.olat.restapi.support.vo.FileVO) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 10 with SharedFolderHandler

use of org.olat.repository.handlers.SharedFolderHandler in project OpenOLAT by OpenOLAT.

the class SharedFolderTest method putFiles_participant.

/**
 * Participants have only read-only access to the shared folder.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void putFiles_participant() throws IOException, URISyntaxException {
    // a shared folder with a participant
    Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("shared-owner-");
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("shared-part-");
    RepositoryEntry sharedFolder = new SharedFolderHandler().createResource(owner, "Shared 5", "Shared files", null, Locale.ENGLISH);
    VFSContainer container = SharedFolderManager.getInstance().getNamedSharedFolder(sharedFolder, true);
    copyFileInResourceFolder(container, "portrait.jpg", "5_");
    repositoryEntryRelationDao.addRole(participant, sharedFolder, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // participant want to upload a file
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login(participant.getName(), "A6B7C8"));
    URL fileUrl = CoursesFoldersTest.class.getResource("certificate.pdf");
    File file = new File(fileUrl.toURI());
    URI uri = UriBuilder.fromUri(getFolderURI(sharedFolder)).path("files").build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    conn.addMultipart(method, file.getName(), file);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(401, response.getStatusLine().getStatusCode());
    // check the absence of the file
    VFSItem item = container.resolve("certificate.pdf");
    Assert.assertNull(item);
}
Also used : SharedFolderHandler(org.olat.repository.handlers.SharedFolderHandler) VFSContainer(org.olat.core.util.vfs.VFSContainer) HttpResponse(org.apache.http.HttpResponse) VFSItem(org.olat.core.util.vfs.VFSItem) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) File(java.io.File) URI(java.net.URI) URL(java.net.URL) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Aggregations

URI (java.net.URI)12 HttpResponse (org.apache.http.HttpResponse)12 Test (org.junit.Test)12 Identity (org.olat.core.id.Identity)12 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 SharedFolderHandler (org.olat.repository.handlers.SharedFolderHandler)12 File (java.io.File)6 InputStream (java.io.InputStream)6 URL (java.net.URL)6 HttpGet (org.apache.http.client.methods.HttpGet)6 HttpPut (org.apache.http.client.methods.HttpPut)6 VFSItem (org.olat.core.util.vfs.VFSItem)4 FileVO (org.olat.restapi.support.vo.FileVO)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 LinkVO (org.olat.restapi.support.vo.LinkVO)2