use of org.olat.modules.fo.manager.ForumManager in project openolat by klemens.
the class ForumTest method testNewThread.
@Test
public void testNewThread() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI uri = getForumUriBuilder().path("threads").queryParam("authorKey", id1.getKey()).queryParam("title", "New thread").queryParam("body", "A very interesting thread").build();
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
MessageVO thread = conn.parse(response, MessageVO.class);
assertNotNull(thread);
assertNotNull(thread.getKey());
assertEquals(thread.getForumKey(), forum.getKey());
assertEquals(thread.getAuthorKey(), id1.getKey());
// really saved?
boolean saved = false;
ForumManager fm = ForumManager.getInstance();
List<Message> allMessages = fm.getMessagesByForum(forum);
for (Message message : allMessages) {
if (message.getKey().equals(thread.getKey())) {
saved = true;
}
}
assertTrue(saved);
conn.shutdown();
}
use of org.olat.modules.fo.manager.ForumManager in project openolat by klemens.
the class ForumTest method testReplyWithTwoAttachments.
@Test
public void testReplyWithTwoAttachments() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id1.getName(), "A6B7C8"));
ReplyVO vo = new ReplyVO();
vo.setTitle("Reply with attachment");
vo.setBody("Reply with attachment body");
File64VO[] files = new File64VO[2];
// upload portrait
InputStream portraitStream = CoursesElementsTest.class.getResourceAsStream("portrait.jpg");
assertNotNull(portraitStream);
byte[] portraitBytes = IOUtils.toByteArray(portraitStream);
byte[] portrait64 = Base64.encodeBase64(portraitBytes, true);
files[0] = new File64VO("portrait64.jpg", new String(portrait64));
// upload single page
InputStream indexStream = ForumTest.class.getResourceAsStream("singlepage.html");
assertNotNull(indexStream);
byte[] indexBytes = IOUtils.toByteArray(indexStream);
byte[] index64 = Base64.encodeBase64(indexBytes, true);
files[1] = new File64VO("singlepage64.html", new String(index64));
vo.setAttachments(files);
URI uri = getForumUriBuilder().path("posts").path(m1.getKey().toString()).build();
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(method, vo);
method.addHeader("Accept-Language", "en");
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
MessageVO message = conn.parse(response, MessageVO.class);
assertNotNull(message);
assertNotNull(message.getAttachments());
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);
HttpGet getAttachment = conn.createGet(attachmentUri, "*/*", true);
HttpResponse attachmentCode = conn.execute(getAttachment);
assertEquals(200, attachmentCode.getStatusLine().getStatusCode());
EntityUtils.consume(attachmentCode.getEntity());
}
// check if the file exists
ForumManager fm = ForumManager.getInstance();
VFSContainer container = fm.getMessageContainer(message.getForumKey(), message.getKey());
VFSItem uploadedFile = container.resolve("portrait64.jpg");
assertNotNull(uploadedFile);
assertTrue(uploadedFile instanceof VFSLeaf);
// check if the image is still an image
VFSLeaf uploadedImage = (VFSLeaf) uploadedFile;
InputStream uploadedStream = uploadedImage.getInputStream();
BufferedImage image = ImageIO.read(uploadedStream);
FileUtils.closeSafely(uploadedStream);
assertNotNull(image);
// check if the single page exists
VFSItem uploadedPage = container.resolve("singlepage64.html");
assertNotNull(uploadedPage);
assertTrue(uploadedPage instanceof VFSLeaf);
conn.shutdown();
}
use of org.olat.modules.fo.manager.ForumManager in project openolat by klemens.
the class ForumTest method testUploadAttachment.
@Test
public void testUploadAttachment() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id1.getName(), "A6B7C8"));
URI uri = getForumUriBuilder().path("posts").path(m1.getKey().toString()).queryParam("authorKey", id1.getKey()).queryParam("title", "New message with attachment ").queryParam("body", "A very interesting response in Thread-1 with an attachment").build();
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
MessageVO message = conn.parse(response, MessageVO.class);
assertNotNull(message);
// attachment
URL portraitUrl = CoursesElementsTest.class.getResource("portrait.jpg");
assertNotNull(portraitUrl);
File portrait = new File(portraitUrl.toURI());
// upload portrait
URI attachUri = getForumUriBuilder().path("posts").path(message.getKey().toString()).path("attachments").build();
HttpPost attachMethod = conn.createPost(attachUri, MediaType.APPLICATION_JSON);
conn.addMultipart(attachMethod, "portrait.jpg", portrait);
HttpResponse attachResponse = conn.execute(attachMethod);
assertEquals(200, attachResponse.getStatusLine().getStatusCode());
// check if the file exists
ForumManager fm = ForumManager.getInstance();
VFSContainer container = fm.getMessageContainer(message.getForumKey(), message.getKey());
VFSItem uploadedFile = container.resolve("portrait.jpg");
assertNotNull(uploadedFile);
assertTrue(uploadedFile instanceof VFSLeaf);
// check if the image is still an image
VFSLeaf uploadedImage = (VFSLeaf) uploadedFile;
InputStream uploadedStream = uploadedImage.getInputStream();
BufferedImage image = ImageIO.read(uploadedStream);
FileUtils.closeSafely(uploadedStream);
assertNotNull(image);
conn.shutdown();
}
use of org.olat.modules.fo.manager.ForumManager in project openolat by klemens.
the class FOCourseNodeIndexer method doIndexForum.
/**
* Index a forum in a course.
* @param parentResourceContext
* @param course
* @param courseNode
* @param indexWriter
* @throws IOException
*/
private void doIndexForum(SearchResourceContext parentResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
if (log.isDebug())
log.debug("Index Course Forum...");
ForumManager fom = ForumManager.getInstance();
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
Property forumKeyProperty = cpm.findCourseNodeProperty(courseNode, null, null, FOCourseNode.FORUM_KEY);
// Check if forum-property exist
if (forumKeyProperty != null) {
Long forumKey = forumKeyProperty.getLongValue();
Forum forum = fom.loadForum(forumKey);
parentResourceContext.setDocumentType(TYPE);
doIndexAllMessages(parentResourceContext, forum, indexWriter);
}
}
use of org.olat.modules.fo.manager.ForumManager in project openolat by klemens.
the class ForumNodeForumCallback method loadForum.
private Forum loadForum(CourseEnvironment courseEnv, Property prop) {
final ForumManager fom = CoreSpringFactory.getImpl(ForumManager.class);
Long forumKey = prop.getLongValue();
Forum forum = fom.loadForum(forumKey);
if (forum == null) {
throw new OLATRuntimeException(FOCourseNode.class, "Tried to load forum with key " + forumKey.longValue() + " in course " + courseEnv.getCourseResourceableId() + " for node " + getIdent() + " as defined in course node property but forum manager could not load forum.", null);
}
return forum;
}
Aggregations