Search in sources :

Example 41 with CourseConfigVO

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

the class LecturesBlocksTest method removeRepositoryEntryDefaultGroupToLectureBlock.

@Test
public void removeRepositoryEntryDefaultGroupToLectureBlock() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence config", "Course with absence configuration", new CourseConfigVO());
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    LectureBlock block = createLectureBlock(entry);
    Group defGroup = repositoryService.getDefaultGroup(entry);
    lectureService.save(block, Collections.singletonList(defGroup));
    dbInstance.commit();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(entry.getKey().toString()).path("lectureblocks").path(block.getKey().toString()).path("participants").path("repositoryentry").build();
    HttpDelete method = conn.createDelete(uri, MediaType.APPLICATION_JSON);
    HttpResponse response = conn.execute(method);
    // check the response
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // check the database
    List<Group> groups = lectureService.getLectureBlockToGroups(block);
    Assert.assertNotNull(groups);
    Assert.assertEquals(0, groups.size());
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) Group(org.olat.basesecurity.Group) HttpDelete(org.apache.http.client.methods.HttpDelete) 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 42 with CourseConfigVO

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

the class LecturesBlocksTest method putLecturesBlock_autoclosed.

/**
 * Check that the done and autoclosed status are set.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void putLecturesBlock_autoclosed() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence", "Course with absence", new CourseConfigVO());
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    dbInstance.commit();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    String externalId = UUID.randomUUID().toString();
    LectureBlockVO lectureBlockVo = new LectureBlockVO();
    lectureBlockVo.setTitle("A block to close");
    lectureBlockVo.setDescription("A description");
    lectureBlockVo.setManagedFlagsString("all");
    lectureBlockVo.setPlannedLectures(4);
    lectureBlockVo.setExternalId(externalId);
    lectureBlockVo.setStartDate(new Date());
    lectureBlockVo.setEndDate(new Date());
    lectureBlockVo.setStatus("done");
    lectureBlockVo.setRollCallStatus("autoclosed");
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(entry.getKey().toString()).path("lectureblocks").build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, lectureBlockVo);
    HttpResponse response = conn.execute(method);
    // check the response
    Assertions.assertThat(response.getStatusLine().getStatusCode()).isIn(200, 201);
    LectureBlockVO blockVo = conn.parse(response.getEntity().getContent(), LectureBlockVO.class);
    Assert.assertNotNull(blockVo);
    // check the database
    LectureBlock dbBlock = lectureService.getLectureBlock(new LectureBlockRefImpl(blockVo.getKey()));
    Assert.assertNotNull(dbBlock);
    Assert.assertEquals("A block to close", dbBlock.getTitle());
    Assert.assertEquals("A description", dbBlock.getDescription());
    Assert.assertEquals("all", dbBlock.getManagedFlagsString());
    Assert.assertEquals(4, dbBlock.getPlannedLecturesNumber());
    Assert.assertEquals(externalId, dbBlock.getExternalId());
    Assert.assertNotNull(dbBlock.getStartDate());
    Assert.assertNotNull(dbBlock.getEndDate());
    Assert.assertEquals(LectureBlockStatus.done, dbBlock.getStatus());
    Assert.assertEquals(LectureRollCallStatus.autoclosed, dbBlock.getRollCallStatus());
}
Also used : 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) HttpPut(org.apache.http.client.methods.HttpPut) CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRefImpl(org.olat.modules.lecture.model.LectureBlockRefImpl) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 43 with CourseConfigVO

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

the class LecturesBlocksTest method deleteLectureBlock.

@Test
public void deleteLectureBlock() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence config", "Course with absence configuration", new CourseConfigVO());
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    LectureBlock block = createLectureBlock(entry);
    dbInstance.commit();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(entry.getKey().toString()).path("lectureblocks").path(block.getKey().toString()).build();
    HttpDelete method = conn.createDelete(uri, MediaType.APPLICATION_JSON);
    HttpResponse response = conn.execute(method);
    // check the response
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    LectureBlock deletedBlock = lectureService.getLectureBlock(block);
    Assert.assertNull(deletedBlock);
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) HttpDelete(org.apache.http.client.methods.HttpDelete) 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 44 with CourseConfigVO

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

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)

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