use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class NotificationsTest method testGetCourseForumNotifications.
@Test
public void testGetCourseForumNotifications() throws IOException, URISyntaxException {
// create a course with a forum
Identity id = JunitTestHelper.createAndPersistIdentityAsAuthor("rest-not-6-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(id, "Course forum not", "Course forum with notification", null);
dbInstance.intermediateCommit();
// create the forum
CourseNodeConfiguration newNodeConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration("fo");
FOCourseNode forumNode = (FOCourseNode) newNodeConfig.getInstance();
forumNode.setShortTitle("Forum");
forumNode.setLearningObjectives("forum objectives");
forumNode.setNoAccessExplanation("You don't have access");
Forum courseForum = forumNode.loadOrCreateForum(course.getCourseEnvironment());
course.getEditorTreeModel().addCourseNode(forumNode, course.getRunStructure().getRootNode());
CourseFactory.publishCourse(course, RepositoryEntry.ACC_USERS, false, id, Locale.ENGLISH);
dbInstance.intermediateCommit();
// add message and publisher
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(course.getCourseEnvironment().getCourseGroupManager().getCourseResource(), true);
String businessPath = "[RepositoryEntry:" + re.getKey() + "][CourseNode:" + forumNode.getIdent() + "]";
SubscriptionContext forumSubContext = new SubscriptionContext("CourseModule", course.getResourceableId(), forumNode.getIdent());
PublisherData forumPdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), courseForum.getKey().toString(), businessPath);
notificationManager.subscribe(id, forumSubContext, forumPdata);
Message message = createMessage(id, courseForum);
notificationManager.markPublisherNews(forumSubContext, null, true);
dbInstance.commitAndCloseSession();
// get the notification
RestConnection conn = new RestConnection();
assertTrue(conn.login(id.getName(), "A6B7C8"));
UriBuilder request = UriBuilder.fromUri(getContextURI()).path("notifications");
HttpGet method = conn.createGet(request.build(), MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<SubscriptionInfoVO> infos = parseUserArray(response.getEntity().getContent());
Assert.assertNotNull(infos);
Assert.assertEquals(1, infos.size());
SubscriptionInfoVO infoVO = infos.get(0);
Assert.assertNotNull(infoVO.getItems());
Assert.assertEquals(1, infoVO.getItems().size());
SubscriptionListItemVO itemVO = infoVO.getItems().get(0);
Assert.assertNotNull(itemVO);
Assert.assertEquals(course.getResourceableId(), itemVO.getCourseKey());
Assert.assertEquals(forumNode.getIdent(), itemVO.getCourseNodeId());
Assert.assertEquals(message.getKey(), itemVO.getMessageKey());
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class NotificationsTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
if (!setup) {
userSubscriberId = JunitTestHelper.createAndPersistIdentityAsUser("rest-notifications-test-1");
userAndForumSubscriberId = JunitTestHelper.createAndPersistIdentityAsUser("rest-notifications-test-2");
JunitTestHelper.createAndPersistIdentityAsUser("rest-notifications-test-3");
SubscriptionContext subContext = UsersSubscriptionManager.getInstance().getNewUsersSubscriptionContext();
PublisherData publisherData = UsersSubscriptionManager.getInstance().getNewUsersPublisherData();
if (!notificationManager.isSubscribed(userSubscriberId, subContext)) {
notificationManager.subscribe(userSubscriberId, subContext, publisherData);
}
if (!notificationManager.isSubscribed(userAndForumSubscriberId, subContext)) {
notificationManager.subscribe(userAndForumSubscriberId, subContext, publisherData);
}
// create a forum
forum = ForumManager.getInstance().addAForum();
Message m1 = createMessage(userSubscriberId, forum);
Assert.assertNotNull(m1);
// subscribe
SubscriptionContext forumSubContext = new SubscriptionContext("NotificationRestCourse", forum.getKey(), "2387");
PublisherData forumPdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), forum.getKey().toString(), "");
if (!notificationManager.isSubscribed(userAndForumSubscriberId, forumSubContext)) {
notificationManager.subscribe(userAndForumSubscriberId, forumSubContext, forumPdata);
}
notificationManager.markPublisherNews(forumSubContext, userSubscriberId, true);
// generate one notification
String randomLogin = UUID.randomUUID().toString().replace("-", "");
JunitTestHelper.createAndPersistIdentityAsUser(randomLogin);
setup = true;
}
dbInstance.commitAndCloseSession();
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class MessageListController method doArchiveThread.
private void doArchiveThread(UserRequest ureq, Message currMsg) {
Message m = currMsg.getThreadtop();
Long topMessageId = (m == null) ? currMsg.getKey() : m.getKey();
VFSContainer forumContainer = forumManager.getForumContainer(forum.getKey());
ForumDownloadResource download = new ForumDownloadResource("Forum", forum, foCallback, topMessageId, forumContainer, getLocale());
ureq.getDispatchResult().setResultingMediaResource(download);
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class MessageListController method doExportForumItem.
private void doExportForumItem(UserRequest ureq, MessageView messageToMove) {
if (foCallback.mayEditMessageAsModerator()) {
StepRunnerCallback finish = new FinishCallback();
Translator trans = Util.createPackageTranslator(Step_1_SelectCourse.class, getLocale());
Step start = new Step_1_SelectCourse(ureq);
Message message = forumManager.getMessageById(messageToMove.getKey());
String wizardTitle = trans.translate("title.wizard.movethread", new String[] { message.getTitle() });
exportCtrl = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, wizardTitle, "o_sel_bulk_assessment_wizard");
StepsRunContext runContext = exportCtrl.getRunContext();
// can be threadtop message
runContext.put(SendMailStepForm.MESSAGE_TO_MOVE, message);
// starting thread
runContext.put(SendMailStepForm.START_THREADTOP, message.getThreadtop() == null ? message : message.getThreadtop());
// get start course
PropertyManager propertyManager = PropertyManager.getInstance();
Long forumResourceableId = forum.getResourceableId();
Property forumproperty = propertyManager.getPropertyByLongValue(forumResourceableId, FOCourseNode.FORUM_KEY);
if (forumproperty != null) {
Long resourcetypeId = forumproperty.getResourceTypeId();
String resourcetypeName = forumproperty.getResourceTypeName();
OLATResourceable olatResourceable = olatManager.findResourceable(resourcetypeId, resourcetypeName);
RepositoryEntry startCourse = repositoryManager.lookupRepositoryEntry(olatResourceable, false);
if (startCourse != null) {
runContext.put(SendMailStepForm.START_COURSE, startCourse);
}
}
listenTo(exportCtrl);
getWindowControl().pushAsModalDialog(exportCtrl.getInitialComponent());
} else {
showWarning("may.not.move.message");
}
}
use of org.olat.modules.fo.Message in project OpenOLAT by OpenOLAT.
the class MessageListController method doFinalizeMove.
private void doFinalizeMove(UserRequest ureq, MessageView messageToMove, Long parentMessageKey) {
if (foCallback.mayEditMessageAsModerator()) {
Message message = forumManager.getMessageById(messageToMove.getKey());
Message parentMessage = forumManager.getMessageById(parentMessageKey);
message = forumManager.moveMessage(message, parentMessage);
markRead(message);
// commit before sending event
DBFactory.getInstance().commit();
ThreadLocalUserActivityLogger.log(ForumLoggingAction.FORUM_MESSAGE_MOVE, getClass(), LoggingResourceable.wrap(message));
Long threadKey = parentMessage.getThreadtop() == null ? parentMessage.getKey() : parentMessage.getThreadtop().getKey();
fireEvent(ureq, new SelectMessageEvent(SelectMessageEvent.SELECT_THREAD, threadKey, message.getKey()));
} else {
showWarning("may.not.move.message");
}
}
Aggregations