use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class UserCoursesTest method testTeachedCourses.
@Test
public void testTeachedCourses() throws IOException, URISyntaxException {
// prepare a course with a tutor
Identity teacher = JunitTestHelper.createAndPersistIdentityAsUser("Course-teacher-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(teacher, "A course to teach", "A course to teach", null);
RepositoryEntry courseRe = repositoryManager.lookupRepositoryEntry(course, true);
repositoryManager.setAccess(courseRe, RepositoryEntry.ACC_OWNERS, true);
repositoryService.addRole(teacher, courseRe, GroupRoles.coach.name());
dbInstance.commitAndCloseSession();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login(teacher.getName(), JunitTestHelper.PWD));
// without paging
URI request = UriBuilder.fromUri(getContextURI()).path("/users").path(teacher.getKey().toString()).path("/courses/teached").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<CourseVO> courses = parseCourseArray(body);
Assert.assertNotNull(courses);
Assert.assertEquals(1, courses.size());
// with paging
URI pagedRequest = UriBuilder.fromUri(getContextURI()).path("/users").path(teacher.getKey().toString()).path("/courses/teached").queryParam("start", "0").queryParam("limit", "10").build();
HttpGet pagedMethod = conn.createGet(pagedRequest, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
HttpResponse pagedResponse = conn.execute(pagedMethod);
Assert.assertEquals(200, pagedResponse.getStatusLine().getStatusCode());
InputStream pagedBody = pagedResponse.getEntity().getContent();
CourseVOes pagedCourses = conn.parse(pagedBody, CourseVOes.class);
Assert.assertNotNull(pagedCourses);
Assert.assertEquals(1, pagedCourses.getTotalCount());
Assert.assertNotNull(pagedCourses.getCourses());
Assert.assertEquals(1, pagedCourses.getCourses().length);
conn.shutdown();
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class UserCoursesTest method testFavoritCourses.
@Test
public void testFavoritCourses() throws IOException, URISyntaxException {
// prepare a course with a tutor
Identity me = JunitTestHelper.createAndPersistIdentityAsUser("Course-teacher-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(me, "A course to teach", "A course to teach", null);
RepositoryEntry courseRe = repositoryManager.lookupRepositoryEntry(course, true);
repositoryManager.setAccess(courseRe, RepositoryEntry.ACC_USERS, false);
markManager.setMark(courseRe, me, null, "[RepositoryEntry:" + courseRe.getKey() + "]");
dbInstance.commitAndCloseSession();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login(me.getName(), JunitTestHelper.PWD));
// without paging
URI request = UriBuilder.fromUri(getContextURI()).path("/users").path(me.getKey().toString()).path("/courses/favorite").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<CourseVO> courses = parseCourseArray(body);
Assert.assertNotNull(courses);
Assert.assertEquals(1, courses.size());
// with paging
URI pagedRequest = UriBuilder.fromUri(getContextURI()).path("/users").path(me.getKey().toString()).path("/courses/favorite").queryParam("start", "0").queryParam("limit", "10").build();
HttpGet pagedMethod = conn.createGet(pagedRequest, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
HttpResponse pagedResponse = conn.execute(pagedMethod);
Assert.assertEquals(200, pagedResponse.getStatusLine().getStatusCode());
InputStream pagedBody = pagedResponse.getEntity().getContent();
CourseVOes pagedCourses = conn.parse(pagedBody, CourseVOes.class);
Assert.assertNotNull(pagedCourses);
Assert.assertEquals(1, pagedCourses.getTotalCount());
Assert.assertNotNull(pagedCourses.getCourses());
Assert.assertEquals(1, pagedCourses.getCourses().length);
conn.shutdown();
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class CourseRuntimeController method initToolbar.
@Override
protected void initToolbar(Dropdown toolsDropdown, Dropdown settingsDropdown) {
toolbarPanel.removeAllTools();
if (corrupted)
return;
ICourse course = CourseFactory.loadCourse(getRepositoryEntry());
UserCourseEnvironmentImpl uce = getUserCourseEnvironment();
if (!course.getCourseConfig().isToolbarEnabled() && !reSecurity.isEntryAdmin() && !reSecurity.isCourseCoach() && !reSecurity.isGroupCoach() && !hasCourseRight(CourseRights.RIGHT_COURSEEDITOR) && !hasCourseRight(CourseRights.RIGHT_MEMBERMANAGEMENT) && !hasCourseRight(CourseRights.RIGHT_GROUPMANAGEMENT) && !hasCourseRight(CourseRights.RIGHT_ARCHIVING) && !hasCourseRight(CourseRights.RIGHT_STATISTICS) && !hasCourseRight(CourseRights.RIGHT_DB) && !hasCourseRight(CourseRights.RIGHT_ASSESSMENT) && !hasCourseRight(CourseRights.RIGHT_ASSESSMENT_MODE)) {
toolbarPanel.setToolbarEnabled(false);
} else {
toolbarPanel.setToolbarEnabled(true);
}
if (!isAssessmentLock()) {
initTools(toolsDropdown, course, uce);
initSettingsTools(settingsDropdown);
initEditionTools(settingsDropdown);
initDeleteTools(settingsDropdown, true);
}
initToolsMyCourse(course, uce);
initGeneralTools(course);
if (getRunMainController() != null) {
getRunMainController().initToolbar();
}
setCourseClosedMessage(uce);
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class CourseRuntimeController method doOptions.
private void doOptions(UserRequest ureq) {
if (delayedClose == Delayed.options || requestForClose(ureq)) {
if (reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_COURSEEDITOR)) {
removeCustomCSS();
ICourse course = CourseFactory.loadCourse(getRepositoryEntry());
CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig().clone();
CourseOptionsController ctrl = new CourseOptionsController(ureq, getWindowControl(), getRepositoryEntry(), courseConfig, true);
optionsToolCtr = pushController(ureq, translate("command.options"), ctrl);
setActiveTool(optionsLink);
currentToolCtr = optionsToolCtr;
}
} else {
delayedClose = Delayed.options;
}
}
use of org.olat.course.ICourse in project OpenOLAT by OpenOLAT.
the class CourseRuntimeController method event.
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (layoutLink == source) {
doLayout(ureq);
} else if (optionsLink == source) {
doOptions(ureq);
} else if (assessmentModeLink == source) {
doAssessmentMode(ureq);
} else if (certificatesOptionsLink == source) {
doCertificatesOptions(ureq);
} else if (lifeCycleChangeLink == source) {
doLifeCycleChange(ureq);
} else if (reminderLink == source) {
doReminders(ureq);
} else if (lecturesAdminLink == source) {
doLecturesAdmin(ureq);
} else if (lecturesLink == source) {
doLectures(ureq);
} else if (archiverLink == source) {
doArchive(ureq);
} else if (folderLink == source) {
doCourseFolder(ureq);
} else if (areaLink == source) {
doCourseAreas(ureq);
} else if (dbLink == source) {
doDatabases(ureq);
} else if (courseStatisticLink == source) {
doCourseStatistics(ureq);
} else if (testStatisticLink == source) {
doAssessmentTestStatistics(ureq);
} else if (surveyStatisticLink == source) {
doAssessmentSurveyStatistics(ureq);
} else if (assessmentLink == source) {
doAssessmentTool(ureq);
} else if (calendarLink == source) {
launchCalendar(ureq);
} else if (chatLink == source) {
launchChat(ureq);
} else if (searchLink == source) {
launchCourseSearch(ureq);
} else if (efficiencyStatementsLink == source) {
doEfficiencyStatements(ureq);
} else if (noteLink == source) {
launchPersonalNotes(ureq);
} else if (openGlossaryLink == source) {
launchGlossary(ureq);
} else if (leaveLink == source) {
doConfirmLeave(ureq);
} else if (source instanceof Link && "group".equals(((Link) source).getCommand())) {
BusinessGroupRef ref = (BusinessGroupRef) ((Link) source).getUserObject();
launchGroup(ureq, ref.getKey());
} else if (source == toolbarPanel) {
if (event instanceof VetoPopEvent) {
delayedClose = Delayed.pop;
} else if (event instanceof PopEvent) {
processPopEvent(ureq, (PopEvent) event);
}
} else if (enableGlossaryLink == source) {
toggleGlossary(ureq);
}
// Update window title
if (source instanceof Link) {
Link link = (Link) source;
ICourse course = CourseFactory.loadCourse(getRepositoryEntry());
String newTitle = course.getCourseTitle() + " - " + link.getI18n();
getWindowControl().getWindowBackOffice().getWindow().setTitle(getTranslator(), newTitle);
}
super.event(ureq, source, event);
}
Aggregations