use of org.olat.restapi.support.vo.FileVO in project openolat by klemens.
the class VFSWebservice method get.
protected Response get(List<PathSegment> path, UriInfo uriInfo, Request request) {
VFSItem vItem = resolveFile(path);
if (vItem == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (vItem instanceof VFSContainer) {
VFSContainer directory = (VFSContainer) vItem;
List<VFSItem> items = directory.getItems(new SystemItemFilter());
int count = 0;
FileVO[] links = new FileVO[items.size()];
for (VFSItem item : items) {
UriBuilder builder = uriInfo.getAbsolutePathBuilder();
String uri = builder.path(normalize(item.getName())).build().toString();
if (item instanceof VFSLeaf) {
links[count++] = new FileVO("self", uri, item.getName(), ((VFSLeaf) item).getSize());
} else {
links[count++] = new FileVO("self", uri, item.getName());
}
}
return Response.ok(links).build();
} else if (vItem instanceof VFSLeaf) {
VFSLeaf leaf = (VFSLeaf) vItem;
Date lastModified = new Date(leaf.getLastModified());
Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
if (response == null) {
String mimeType = WebappHelper.getMimeType(leaf.getName());
if (mimeType == null) {
mimeType = MediaType.APPLICATION_OCTET_STREAM;
}
response = Response.ok(leaf.getInputStream(), mimeType).lastModified(lastModified).cacheControl(cc);
}
return response.build();
}
return Response.serverError().status(Status.BAD_REQUEST).build();
}
use of org.olat.restapi.support.vo.FileVO in project openolat by klemens.
the class ForumWebService method getAttachments.
private FileVO[] getAttachments(Message mess, UriInfo uriInfo) {
VFSContainer container = fom.getMessageContainer(mess.getForum().getKey(), mess.getKey());
List<FileVO> attachments = new ArrayList<FileVO>();
for (VFSItem item : container.getItems(new SystemItemFilter())) {
UriBuilder attachmentUri = uriInfo.getBaseUriBuilder().path("repo").path("forums").path(mess.getForum().getKey().toString()).path("posts").path(mess.getKey().toString()).path("attachments").path(format(item.getName()));
String uri = attachmentUri.build().toString();
if (item instanceof VFSLeaf) {
attachments.add(new FileVO("self", uri, item.getName(), ((VFSLeaf) item).getSize()));
} else {
attachments.add(new FileVO("self", uri, item.getName()));
}
}
FileVO[] attachmentArr = new FileVO[attachments.size()];
attachmentArr = attachments.toArray(attachmentArr);
return attachmentArr;
}
use of org.olat.restapi.support.vo.FileVO in project OpenOLAT by OpenOLAT.
the class GroupFoldersTest method testGetSubFolder.
@Test
public void testGetSubFolder() throws IOException, URISyntaxException {
// create some sub folders
CollaborationTools collabTools1 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
String folderRelPath = collabTools1.getFolderRelPath();
OlatRootFolderImpl folder = new OlatRootFolderImpl(folderRelPath, null);
VFSContainer newFolder1 = folder.createChildContainer("New folder 1");
if (newFolder1 == null) {
newFolder1 = (VFSContainer) folder.resolve("New folder 1");
}
assertNotNull(newFolder1);
VFSContainer newFolder11 = newFolder1.createChildContainer("New folder 1_1");
if (newFolder11 == null) {
newFolder11 = (VFSContainer) newFolder1.resolve("New folder 1_1");
}
assertNotNull(newFolder11);
assertTrue(conn.login("rest-one", "A6B7C8"));
// get root folder
URI request0 = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/").build();
HttpGet method0 = conn.createGet(request0, MediaType.APPLICATION_JSON, true);
HttpResponse code0 = conn.execute(method0);
assertEquals(200, code0.getStatusLine().getStatusCode());
InputStream body0 = code0.getEntity().getContent();
assertNotNull(body0);
List<FileVO> fileVos0 = parseFileArray(body0);
assertNotNull(fileVos0);
assertEquals(1, fileVos0.size());
// get sub folder
URI request1 = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/New_folder_1").build();
HttpGet method1 = conn.createGet(request1, MediaType.APPLICATION_JSON, true);
HttpResponse code1 = conn.execute(method1);
assertEquals(200, code1.getStatusLine().getStatusCode());
InputStream body1 = code1.getEntity().getContent();
assertNotNull(body1);
List<FileVO> fileVos1 = parseFileArray(body1);
assertNotNull(fileVos1);
assertEquals(1, fileVos1.size());
// get sub folder by link
FileVO fileVO = fileVos1.get(0);
URI fileUri = new URI(fileVO.getHref());
HttpGet brutMethod = conn.createGet(fileUri, "*/*", true);
brutMethod.addHeader("Accept", MediaType.APPLICATION_JSON);
HttpResponse codeBrut = conn.execute(brutMethod);
assertEquals(200, codeBrut.getStatusLine().getStatusCode());
EntityUtils.consume(codeBrut.getEntity());
// get sub sub folder
URI request2 = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/New_folder_1/New_folder_1_1").build();
HttpGet method2 = conn.createGet(request2, MediaType.APPLICATION_JSON, true);
HttpResponse code2 = conn.execute(method2);
assertEquals(200, code2.getStatusLine().getStatusCode());
InputStream body2 = code2.getEntity().getContent();
assertNotNull(body2);
EntityUtils.consume(code2.getEntity());
// get sub folder with end /
URI request3 = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/New_folder_1/").build();
HttpGet method3 = conn.createGet(request3, MediaType.APPLICATION_JSON, true);
HttpResponse code3 = conn.execute(method3);
assertEquals(200, code3.getStatusLine().getStatusCode());
InputStream body3 = code3.getEntity().getContent();
assertNotNull(body3);
List<FileVO> fileVos3 = parseFileArray(body3);
assertNotNull(fileVos3);
assertEquals(1, fileVos3.size());
}
use of org.olat.restapi.support.vo.FileVO in project OpenOLAT by OpenOLAT.
the class GroupFoldersTest method testCreateFoldersWithSpecialCharacter.
// @Test not working -> Jersey ignore the request and return 200 (why?)
public void testCreateFoldersWithSpecialCharacter() throws IOException, URISyntaxException {
assertTrue(conn.login("rest-one", "A6B7C8"));
URI request = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/New_folder_1/New_folder_1_1/New_folder_1 1 2").build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
FileVO file = conn.parse(response, FileVO.class);
assertNotNull(file);
}
use of org.olat.restapi.support.vo.FileVO in project OpenOLAT by OpenOLAT.
the class GroupFoldersTest method testCreateFoldersWithSpecialCharacter2.
@Test
public void testCreateFoldersWithSpecialCharacter2() throws IOException, URISyntaxException {
assertTrue(conn.login("rest-one", "A6B7C8"));
URI request = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/New_folder_1/New_folder_1_1/").build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addTextBody("foldername", "New folder 1 2 3").build();
method.setEntity(entity);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
FileVO file = conn.parse(response, FileVO.class);
assertNotNull(file);
assertNotNull(file.getHref());
assertNotNull(file.getTitle());
assertEquals("New folder 1 2 3", file.getTitle());
}
Aggregations