Skip to content
Snippets Groups Projects
Commit c4fd84af authored by srosse's avatar srosse
Browse files

OMA-14: return the informations about attachments with the messages

parent 5eb92eb8
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,7 @@ import java.io.File; ...@@ -28,6 +28,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -51,6 +52,7 @@ import javax.ws.rs.core.Request; ...@@ -51,6 +52,7 @@ import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.StreamingOutput; import javax.ws.rs.core.StreamingOutput;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
...@@ -579,7 +581,12 @@ public class ForumWebService { ...@@ -579,7 +581,12 @@ public class ForumWebService {
VFSContainer container = fom.getMessageContainer(mess.getForum().getKey(), mess.getKey()); VFSContainer container = fom.getMessageContainer(mess.getForum().getKey(), mess.getKey());
List<FileVO> attachments = new ArrayList<FileVO>(); List<FileVO> attachments = new ArrayList<FileVO>();
for(VFSItem item: container.getItems(new SystemItemFilter())) { for(VFSItem item: container.getItems(new SystemItemFilter())) {
String uri = uriInfo.getAbsolutePathBuilder().path(format(item.getName())).build().toString(); 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) { if(item instanceof VFSLeaf) {
attachments.add(new FileVO("self", uri, item.getName(), ((VFSLeaf)item).getSize())); attachments.add(new FileVO("self", uri, item.getName(), ((VFSLeaf)item).getSize()));
} else { } else {
......
...@@ -393,6 +393,17 @@ public class ForumTest extends OlatJerseyTestCase { ...@@ -393,6 +393,17 @@ public class ForumTest extends OlatJerseyTestCase {
assertNotNull(message.getAttachments()); assertNotNull(message.getAttachments());
assertEquals(2, message.getAttachments().length); assertEquals(2, message.getAttachments().length);
for(FileVO attachment:message.getAttachments()) {
String title = attachment.getTitle();
assertNotNull(title);
String href = attachment.getHref();
URI attachmentUri = new URI(href);
GetMethod getAttachment = createGet(attachmentUri, "*/*", true);
int attachmentCode = c.executeMethod(getAttachment);
assertEquals(200, attachmentCode);
}
//check if the file exists //check if the file exists
ForumManager fm = ForumManager.getInstance(); ForumManager fm = ForumManager.getInstance();
VFSContainer container = fm.getMessageContainer(message.getForumKey(), message.getKey()); VFSContainer container = fm.getMessageContainer(message.getForumKey(), message.getKey());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment