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