Search in sources :

Example 96 with ICourse

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();
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseVOes(org.olat.restapi.support.vo.CourseVOes) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 97 with ICourse

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();
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseVOes(org.olat.restapi.support.vo.CourseVOes) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 98 with ICourse

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);
}
Also used : UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) ICourse(org.olat.course.ICourse)

Example 99 with ICourse

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;
    }
}
Also used : CourseOptionsController(org.olat.course.config.ui.CourseOptionsController) ICourse(org.olat.course.ICourse) CourseConfig(org.olat.course.config.CourseConfig)

Example 100 with ICourse

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);
}
Also used : BusinessGroupRef(org.olat.group.BusinessGroupRef) VetoPopEvent(org.olat.core.gui.components.stack.VetoPopEvent) PopEvent(org.olat.core.gui.components.stack.PopEvent) ICourse(org.olat.course.ICourse) VetoPopEvent(org.olat.core.gui.components.stack.VetoPopEvent) Link(org.olat.core.gui.components.link.Link)

Aggregations

ICourse (org.olat.course.ICourse)674 Identity (org.olat.core.id.Identity)262 RepositoryEntry (org.olat.repository.RepositoryEntry)246 CourseNode (org.olat.course.nodes.CourseNode)182 Test (org.junit.Test)158 ArrayList (java.util.ArrayList)102 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)90 Date (java.util.Date)84 URI (java.net.URI)76 HttpResponse (org.apache.http.HttpResponse)76 OLATResource (org.olat.resource.OLATResource)64 File (java.io.File)62 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)52 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)52 Produces (javax.ws.rs.Produces)48 Roles (org.olat.core.id.Roles)44 Path (javax.ws.rs.Path)42 UserRequest (org.olat.core.gui.UserRequest)42 INode (org.olat.core.util.nodes.INode)40 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)40