Search in sources :

Example 1 with FileMetadataVO

use of org.olat.restapi.support.vo.FileMetadataVO in project OpenOLAT by OpenOLAT.

the class VFSWebservice method getFMetadata.

protected Response getFMetadata(List<PathSegment> path, UriInfo uriInfo) {
    VFSItem vItem = resolveFile(path);
    if (vItem == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (vItem instanceof VFSContainer) {
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    } else if (vItem instanceof VFSLeaf) {
        VFSLeaf leaf = (VFSLeaf) vItem;
        UriBuilder builder = uriInfo.getAbsolutePathBuilder();
        String uri = builder.build().toString();
        String[] uriArray = uri.split("metadata/");
        uri = uriArray[0] + uriArray[1];
        FileMetadataVO metaVo = new FileMetadataVO(uri, leaf);
        return Response.ok(metaVo).build();
    }
    return Response.serverError().status(Status.BAD_REQUEST).build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileMetadataVO(org.olat.restapi.support.vo.FileMetadataVO) VFSItem(org.olat.core.util.vfs.VFSItem) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 2 with FileMetadataVO

use of org.olat.restapi.support.vo.FileMetadataVO in project OpenOLAT by OpenOLAT.

the class GroupFoldersTest method testGetFileMetadata.

@Test
public void testGetFileMetadata() throws IOException, URISyntaxException {
    // create some sub folders and copy file
    CollaborationTools collabTools2 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
    String folderRelPath = collabTools2.getFolderRelPath();
    OlatRootFolderImpl folder = new OlatRootFolderImpl(folderRelPath, null);
    VFSContainer newFolder1 = folder.createChildContainer("Metadata folder");
    if (newFolder1 == null) {
        newFolder1 = (VFSContainer) folder.resolve("Metadata folder");
    }
    VFSLeaf file = (VFSLeaf) newFolder1.resolve("portrait.jpg");
    if (file == null) {
        file = newFolder1.createChildLeaf("portrait.jpg");
        OutputStream out = file.getOutputStream(true);
        InputStream in = GroupFoldersTest.class.getResourceAsStream("portrait.jpg");
        FileUtils.copy(in, out);
        FileUtils.closeSafely(in);
        FileUtils.closeSafely(out);
    }
    // get the file
    assertTrue(conn.login("rest-one", "A6B7C8"));
    URI request = UriBuilder.fromUri(getContextURI()).path("/groups/" + g2.getKey() + "/folder/metadata/Metadata_folder/portrait.jpg").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    FileMetadataVO fileMetadataVO = conn.parse(response, FileMetadataVO.class);
    Assert.assertNotNull(fileMetadataVO);
    Assert.assertEquals("portrait.jpg", fileMetadataVO.getFileName());
    Assert.assertNotNull(fileMetadataVO.getSize());
    Assert.assertEquals(file.getSize(), fileMetadataVO.getSize().longValue());
    Assert.assertNotNull(fileMetadataVO.getHref());
    Assert.assertNotNull(fileMetadataVO.getLastModified());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) OutputStream(java.io.OutputStream) HttpGet(org.apache.http.client.methods.HttpGet) CollaborationTools(org.olat.collaboration.CollaborationTools) FileMetadataVO(org.olat.restapi.support.vo.FileMetadataVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 3 with FileMetadataVO

use of org.olat.restapi.support.vo.FileMetadataVO in project openolat by klemens.

the class GroupFoldersTest method testGetFileMetadata.

@Test
public void testGetFileMetadata() throws IOException, URISyntaxException {
    // create some sub folders and copy file
    CollaborationTools collabTools2 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
    String folderRelPath = collabTools2.getFolderRelPath();
    OlatRootFolderImpl folder = new OlatRootFolderImpl(folderRelPath, null);
    VFSContainer newFolder1 = folder.createChildContainer("Metadata folder");
    if (newFolder1 == null) {
        newFolder1 = (VFSContainer) folder.resolve("Metadata folder");
    }
    VFSLeaf file = (VFSLeaf) newFolder1.resolve("portrait.jpg");
    if (file == null) {
        file = newFolder1.createChildLeaf("portrait.jpg");
        OutputStream out = file.getOutputStream(true);
        InputStream in = GroupFoldersTest.class.getResourceAsStream("portrait.jpg");
        FileUtils.copy(in, out);
        FileUtils.closeSafely(in);
        FileUtils.closeSafely(out);
    }
    // get the file
    assertTrue(conn.login("rest-one", "A6B7C8"));
    URI request = UriBuilder.fromUri(getContextURI()).path("/groups/" + g2.getKey() + "/folder/metadata/Metadata_folder/portrait.jpg").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    FileMetadataVO fileMetadataVO = conn.parse(response, FileMetadataVO.class);
    Assert.assertNotNull(fileMetadataVO);
    Assert.assertEquals("portrait.jpg", fileMetadataVO.getFileName());
    Assert.assertNotNull(fileMetadataVO.getSize());
    Assert.assertEquals(file.getSize(), fileMetadataVO.getSize().longValue());
    Assert.assertNotNull(fileMetadataVO.getHref());
    Assert.assertNotNull(fileMetadataVO.getLastModified());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) OutputStream(java.io.OutputStream) HttpGet(org.apache.http.client.methods.HttpGet) CollaborationTools(org.olat.collaboration.CollaborationTools) FileMetadataVO(org.olat.restapi.support.vo.FileMetadataVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 4 with FileMetadataVO

use of org.olat.restapi.support.vo.FileMetadataVO in project openolat by klemens.

the class VFSWebservice method getFMetadata.

protected Response getFMetadata(List<PathSegment> path, UriInfo uriInfo) {
    VFSItem vItem = resolveFile(path);
    if (vItem == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (vItem instanceof VFSContainer) {
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    } else if (vItem instanceof VFSLeaf) {
        VFSLeaf leaf = (VFSLeaf) vItem;
        UriBuilder builder = uriInfo.getAbsolutePathBuilder();
        String uri = builder.build().toString();
        String[] uriArray = uri.split("metadata/");
        uri = uriArray[0] + uriArray[1];
        FileMetadataVO metaVo = new FileMetadataVO(uri, leaf);
        return Response.ok(metaVo).build();
    }
    return Response.serverError().status(Status.BAD_REQUEST).build();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileMetadataVO(org.olat.restapi.support.vo.FileMetadataVO) VFSItem(org.olat.core.util.vfs.VFSItem) UriBuilder(javax.ws.rs.core.UriBuilder)

Aggregations

VFSContainer (org.olat.core.util.vfs.VFSContainer)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 FileMetadataVO (org.olat.restapi.support.vo.FileMetadataVO)4 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 URI (java.net.URI)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 HttpResponse (org.apache.http.HttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 Test (org.junit.Test)2 CollaborationTools (org.olat.collaboration.CollaborationTools)2 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)2 VFSItem (org.olat.core.util.vfs.VFSItem)2