Search in sources :

Example 26 with CourseConfigVO

use of org.olat.restapi.support.vo.CourseConfigVO in project OpenOLAT by OpenOLAT.

the class CourseWebService method updateConfiguration.

/**
 * Update the course configuration
 * @response.representation.200.qname {http://www.example.com}courseConfigVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The metadatas of the created course
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSECONFIGVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found
 * @param courseId The course resourceable's id
 * @param calendar Enable/disable the calendar (value: true/false) (optional)
 * @param chat Enable/disable the chat (value: true/false) (optional)
 * @param cssLayoutRef Set the custom CSS file for the layout (optional)
 * @param efficencyStatement Enable/disable the efficencyStatement (value: true/false) (optional)
 * @param glossarySoftkey Set the glossary (optional)
 * @param sharedFolderSoftkey Set the shared folder (optional)
 * @param request The HTTP request
 * @return It returns the XML/Json representation of the <code>CourseConfig</code>
 *         object representing the course configuration.
 */
@POST
@Path("configuration")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updateConfiguration(@PathParam("courseId") Long courseId, @FormParam("calendar") Boolean calendar, @FormParam("chat") Boolean chat, @FormParam("cssLayoutRef") String cssLayoutRef, @FormParam("efficencyStatement") Boolean efficencyStatement, @FormParam("glossarySoftkey") String glossarySoftkey, @FormParam("sharedFolderSoftkey") String sharedFolderSoftkey, @Context HttpServletRequest request) {
    if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    ICourse editedCourse = CourseFactory.openCourseEditSession(courseId);
    // change course config
    CourseConfig courseConfig = editedCourse.getCourseEnvironment().getCourseConfig();
    if (calendar != null) {
        courseConfig.setCalendarEnabled(calendar.booleanValue());
    }
    if (chat != null) {
        courseConfig.setChatIsEnabled(chat.booleanValue());
    }
    if (StringHelper.containsNonWhitespace(cssLayoutRef)) {
        courseConfig.setCssLayoutRef(cssLayoutRef);
    }
    if (efficencyStatement != null) {
        courseConfig.setEfficencyStatementIsEnabled(efficencyStatement.booleanValue());
    }
    if (StringHelper.containsNonWhitespace(glossarySoftkey)) {
        courseConfig.setGlossarySoftKey(glossarySoftkey);
    }
    if (StringHelper.containsNonWhitespace(sharedFolderSoftkey)) {
        courseConfig.setSharedFolderSoftkey(sharedFolderSoftkey);
    }
    CourseFactory.setCourseConfig(editedCourse.getResourceableId(), courseConfig);
    CourseFactory.closeCourseEditSession(editedCourse.getResourceableId(), true);
    CourseConfigVO vo = ObjectFactory.getConfig(editedCourse);
    return Response.ok(vo).build();
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) ICourse(org.olat.course.ICourse) CourseConfig(org.olat.course.config.CourseConfig) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 27 with CourseConfigVO

use of org.olat.restapi.support.vo.CourseConfigVO in project OpenOLAT by OpenOLAT.

the class CoursesWebService method createEmptyCourse.

/**
 * Creates an empty course
 * @response.representation.200.qname {http://www.example.com}courseVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The metadatas of the created course
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param courseVo The course
 * @param request The HTTP request
 * @return It returns the newly created course
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createEmptyCourse(CourseVO courseVo, @Context HttpServletRequest request) {
    if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    UserRequest ureq = getUserRequest(request);
    CourseConfigVO configVO = new CourseConfigVO();
    ICourse course = createEmptyCourse(ureq.getIdentity(), courseVo.getTitle(), courseVo.getTitle(), courseVo.getTitle(), courseVo.getDescription(), courseVo.getSoftKey(), RepositoryEntry.ACC_OWNERS, false, courseVo.getAuthors(), courseVo.getLocation(), courseVo.getExternalId(), courseVo.getExternalRef(), courseVo.getManagedFlags(), configVO);
    CourseVO vo = ObjectFactory.get(course);
    return Response.ok(vo).build();
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) CourseVO(org.olat.restapi.support.vo.CourseVO) ICourse(org.olat.course.ICourse) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 28 with CourseConfigVO

use of org.olat.restapi.support.vo.CourseConfigVO in project OpenOLAT by OpenOLAT.

the class LecturesBlocksRootTest method getLecturesBlock_date.

@Test
public void getLecturesBlock_date() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-root-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence", "Course with absence", new CourseConfigVO());
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    LectureBlock block = createLectureBlock(entry);
    dbInstance.commit();
    lectureService.addTeacher(block, author);
    dbInstance.commit();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    String date = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss").format(new Date());
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("lectures").queryParam("date", date).build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    List<LectureBlockVO> voList = parseLectureBlockArray(response.getEntity().getContent());
    Assert.assertNotNull(voList);
    Assert.assertFalse(voList.isEmpty());
    LectureBlockVO lectureBlockVo = null;
    for (LectureBlockVO vo : voList) {
        if (vo.getKey().equals(block.getKey())) {
            lectureBlockVo = vo;
        }
    }
    Assert.assertNotNull(lectureBlockVo);
    Assert.assertEquals(block.getKey(), lectureBlockVo.getKey());
    Assert.assertEquals(entry.getKey(), lectureBlockVo.getRepoEntryKey());
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) LectureBlockVO(org.olat.modules.lecture.restapi.LectureBlockVO) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) URI(java.net.URI) Date(java.util.Date) CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) Identity(org.olat.core.id.Identity) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 29 with CourseConfigVO

use of org.olat.restapi.support.vo.CourseConfigVO in project OpenOLAT by OpenOLAT.

the class LecturesBlocksRootTest method getLecturesBlock.

@Test
public void getLecturesBlock() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-root-all");
    ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence", "Course with absence", new CourseConfigVO());
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    LectureBlock block = createLectureBlock(entry);
    dbInstance.commit();
    lectureService.addTeacher(block, author);
    dbInstance.commit();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("lectures").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    List<LectureBlockVO> voList = parseLectureBlockArray(response.getEntity().getContent());
    Assert.assertNotNull(voList);
    Assert.assertFalse(voList.isEmpty());
    LectureBlockVO lectureBlockVo = null;
    for (LectureBlockVO vo : voList) {
        if (vo.getKey().equals(block.getKey())) {
            lectureBlockVo = vo;
        }
    }
    Assert.assertNotNull(lectureBlockVo);
    Assert.assertEquals(block.getKey(), lectureBlockVo.getKey());
    Assert.assertEquals(entry.getKey(), lectureBlockVo.getRepoEntryKey());
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) HttpGet(org.apache.http.client.methods.HttpGet) LectureBlockVO(org.olat.modules.lecture.restapi.LectureBlockVO) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 30 with CourseConfigVO

use of org.olat.restapi.support.vo.CourseConfigVO in project OpenOLAT by OpenOLAT.

the class CourseTest method testGetCourseConfig.

@Test
public void testGetCourseConfig() throws IOException, URISyntaxException {
    assertTrue("Cannot login as administrator", conn.login("administrator", "openolat"));
    URI uri = conn.getContextURI().path("repo").path("courses").path(course1.getResourceableId().toString()).path("configuration").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CourseConfigVO courseConfig = conn.parse(response, CourseConfigVO.class);
    Assert.assertNotNull(courseConfig);
    Assert.assertNotNull(courseConfig.getCssLayoutRef());
    Assert.assertNotNull(courseConfig.getCalendar());
    Assert.assertNotNull(courseConfig.getChat());
    Assert.assertNotNull(courseConfig.getEfficencyStatement());
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Aggregations

CourseConfigVO (org.olat.restapi.support.vo.CourseConfigVO)44 ICourse (org.olat.course.ICourse)40 URI (java.net.URI)32 HttpResponse (org.apache.http.HttpResponse)32 Test (org.junit.Test)32 Identity (org.olat.core.id.Identity)32 RepositoryEntry (org.olat.repository.RepositoryEntry)30 LectureBlock (org.olat.modules.lecture.LectureBlock)24 HttpGet (org.apache.http.client.methods.HttpGet)14 LectureBlockVO (org.olat.modules.lecture.restapi.LectureBlockVO)14 Date (java.util.Date)10 HttpPut (org.apache.http.client.methods.HttpPut)10 Calendar (java.util.Calendar)6 Produces (javax.ws.rs.Produces)6 HttpDelete (org.apache.http.client.methods.HttpDelete)6 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)6 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)6 CourseConfig (org.olat.course.config.CourseConfig)6 Consumes (javax.ws.rs.Consumes)4 PUT (javax.ws.rs.PUT)4