use of org.olat.course.ICourse 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.course.ICourse in project OpenOLAT by OpenOLAT.
the class NotificationsTest method testGetCourseFolderNotifications.
@Test
public void testGetCourseFolderNotifications() throws IOException, URISyntaxException {
// create a course with a forum
Identity id = JunitTestHelper.createAndPersistIdentityAsAuthor("rest-not-7-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(id, "Course folder not", "Course with folder and notification", null);
dbInstance.intermediateCommit();
// create the folder
CourseNodeConfiguration newNodeConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration("bc");
BCCourseNode folderNode = (BCCourseNode) newNodeConfig.getInstance();
folderNode.setShortTitle("Folder");
folderNode.setLearningObjectives("folder objectives");
folderNode.setNoAccessExplanation("You don't have access");
String relPath = BCCourseNode.getFoldernodePathRelToFolderBase(course.getCourseEnvironment(), folderNode);
VFSContainer folder = BCCourseNode.getNodeFolderContainer(folderNode, course.getCourseEnvironment());
course.getEditorTreeModel().addCourseNode(folderNode, 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:" + folderNode.getIdent() + "]";
SubscriptionContext folderSubContext = new SubscriptionContext("CourseModule", course.getResourceableId(), folderNode.getIdent());
PublisherData folderPdata = new PublisherData("FolderModule", relPath, businessPath);
notificationManager.subscribe(id, folderSubContext, folderPdata);
String filename = addFile(folder);
notificationManager.markPublisherNews(folderSubContext, 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(folderNode.getIdent(), itemVO.getCourseNodeId());
Assert.assertEquals("/" + filename, itemVO.getPath());
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class CalendarTest method startup.
@Before
public void startup() {
if (id1 == null) {
id1 = JunitTestHelper.createAndPersistIdentityAsUser("cal-1-" + UUID.randomUUID().toString());
}
if (id2 == null) {
id2 = JunitTestHelper.createAndPersistIdentityAsUser("cal-2-" + UUID.randomUUID().toString());
}
if (course1 == null) {
// create a course with a calendar
CourseConfigVO config = new CourseConfigVO();
config.setCalendar(Boolean.TRUE);
course1 = CoursesWebService.createEmptyCourse(id1, "Cal course", "Cal course", config);
dbInstance.commit();
ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
Assert.assertTrue(courseConfig.isCalendarEnabled());
KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course);
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 10; i++) {
Date begin = cal.getTime();
cal.add(Calendar.HOUR_OF_DAY, 1);
Date end = cal.getTime();
KalendarEvent event = new KalendarEvent(UUID.randomUUID().toString(), null, "Unit test " + i, begin, end);
calendarManager.addEventTo(calendarWrapper.getKalendar(), event);
cal.add(Calendar.DATE, 1);
}
cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -1);
Date begin2 = cal.getTime();
cal.add(Calendar.HOUR_OF_DAY, 1);
Date end2 = cal.getTime();
KalendarEvent event2 = new KalendarEvent(UUID.randomUUID().toString(), null, "Unit test 2", begin2, end2);
calendarManager.addEventTo(calendarWrapper.getKalendar(), event2);
RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course1, false);
entry = repositoryManager.setAccess(entry, RepositoryEntry.ACC_USERS, false);
repositoryService.addRole(id1, entry, GroupRoles.participant.name());
dbInstance.commit();
}
if (course2 == null) {
// create a course with a calendar
CourseConfigVO config = new CourseConfigVO();
config.setCalendar(Boolean.TRUE);
course2 = CoursesWebService.createEmptyCourse(id2, "Cal course - 2", "Cal course - 2", config);
dbInstance.commit();
KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course2);
Assert.assertNotNull(calendarWrapper);
RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course2, false);
entry = repositoryManager.setAccess(entry, RepositoryEntry.ACC_USERS, false);
dbInstance.commit();
}
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class ForumCourseNodeWebService method getForumContent.
@Path("{nodeId}/forum")
public ForumWebService getForumContent(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest request) {
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
} else if (!CourseWebService.isCourseAccessible(course, false, request)) {
throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
}
CourseNode courseNode = course.getRunStructure().getNode(nodeId);
if (courseNode == null || !(courseNode instanceof FOCourseNode)) {
throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
}
UserRequest ureq = getUserRequest(request);
CourseTreeVisitor courseVisitor = new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment());
if (courseVisitor.isAccessible(courseNode, new VisibleTreeFilter())) {
FOCourseNode forumNode = (FOCourseNode) courseNode;
Forum forum = forumNode.loadOrCreateForum(course.getCourseEnvironment());
return new ForumWebService(forum);
} else {
throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
}
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class ForumCourseNodeWebService method getForums.
/**
* Retrieves metadata of the published course node
* @response.representation.200.qname {http://www.example.com}forumVOes
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The course node metadatas
* @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVOes}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or parentNode not found
* @param courseId The course resourceable's id
* @param httpRequest The HTTP request
* @return The persisted structure element (fully populated)
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getForums(@PathParam("courseId") Long courseId, @Context HttpServletRequest httpRequest) {
final ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!CourseWebService.isCourseAccessible(course, false, httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
UserRequest ureq = getUserRequest(httpRequest);
final Set<Long> subcribedForums = new HashSet<Long>();
NotificationsManager man = NotificationsManager.getInstance();
List<String> notiTypes = Collections.singletonList("Forum");
List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
for (Subscriber sub : subs) {
Long forumKey = Long.parseLong(sub.getPublisher().getData());
subcribedForums.add(forumKey);
}
final List<ForumVO> forumVOs = new ArrayList<ForumVO>();
new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment()).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof FOCourseNode) {
FOCourseNode forumNode = (FOCourseNode) node;
ForumVO forum = createForumVO(course, forumNode, subcribedForums);
forumVOs.add(forum);
}
}
}, new VisibleTreeFilter());
ForumVOes voes = new ForumVOes();
voes.setForums(forumVOs.toArray(new ForumVO[forumVOs.size()]));
voes.setTotalCount(forumVOs.size());
return Response.ok(voes).build();
}
Aggregations