Search in sources :

Example 11 with CourseConfigVO

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

the class LecturesBlocksTest method addTeacherToLectureBlock.

@Test
public void addTeacherToLectureBlock() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
    Identity teacher = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-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()).path("teachers").path(teacher.getKey().toString()).build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    // check the response
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // check the database
    List<Identity> teachers = lectureService.getTeachers(block);
    Assert.assertTrue(teachers.contains(teacher));
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) 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) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 12 with CourseConfigVO

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

the class LecturesBlocksTest method getLecturesBlockConfiguration.

@Test
public void getLecturesBlockConfiguration() 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();
    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("configuration").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    RepositoryEntryLectureConfigurationVO configVo = conn.parse(response, RepositoryEntryLectureConfigurationVO.class);
    Assert.assertNotNull(configVo);
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) RepositoryEntryLectureConfigurationVO(org.olat.modules.lecture.restapi.RepositoryEntryLectureConfigurationVO) HttpGet(org.apache.http.client.methods.HttpGet) 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 13 with CourseConfigVO

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

the class LecturesBlocksTest method removeTeacherToLectureBlock.

@Test
public void removeTeacherToLectureBlock() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
    Identity teacher1 = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-2");
    Identity teacher2 = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-3");
    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();
    lectureService.addTeacher(block, teacher1);
    lectureService.addTeacher(block, teacher2);
    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("teachers").path(teacher1.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());
    EntityUtils.consume(response.getEntity());
    // check the database
    List<Identity> teachers = lectureService.getTeachers(block);
    Assert.assertEquals(1, teachers.size());
    Assert.assertFalse(teachers.contains(teacher1));
    Assert.assertTrue(teachers.contains(teacher2));
}
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 14 with CourseConfigVO

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

the class CourseCalendarTest method putCalendarEvents.

@Test
public void putCalendarEvents() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    Identity admin = BaseSecurityManager.getInstance().findIdentityByName("administrator");
    Assert.assertTrue(conn.login("administrator", "openolat"));
    CourseConfigVO config = new CourseConfigVO();
    config.setCalendar(Boolean.TRUE);
    ICourse course = CoursesWebService.createEmptyCourse(admin, "Course with calendar", "Course with calendar", config);
    dbInstance.commitAndCloseSession();
    // create an event
    EventVO event1 = new EventVO();
    Calendar cal = Calendar.getInstance();
    event1.setBegin(cal.getTime());
    cal.add(Calendar.HOUR_OF_DAY, 1);
    event1.setEnd(cal.getTime());
    String subject1 = UUID.randomUUID().toString();
    event1.setSubject(subject1);
    EventVO event2 = new EventVO();
    event2.setBegin(cal.getTime());
    cal.add(Calendar.HOUR_OF_DAY, 1);
    event2.setEnd(cal.getTime());
    String subject2 = UUID.randomUUID().toString();
    event2.setSubject(subject2);
    EventVO[] newEvents = new EventVO[2];
    newEvents[0] = event1;
    newEvents[1] = event2;
    URI eventUri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course.getResourceableId().toString()).path("calendar").path("events").build();
    HttpPut putEventMethod = conn.createPut(eventUri, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(putEventMethod, newEvents);
    HttpResponse putEventResponse = conn.execute(putEventMethod);
    assertEquals(200, putEventResponse.getStatusLine().getStatusCode());
    EntityUtils.consume(putEventResponse.getEntity());
    // check if the event is saved
    KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course);
    Collection<KalendarEvent> savedEvents = calendarWrapper.getKalendar().getEvents();
    boolean found1 = false;
    boolean found2 = false;
    for (KalendarEvent savedEvent : savedEvents) {
        if (subject1.equals(savedEvent.getSubject())) {
            found1 = true;
        } else if (subject2.equals(savedEvent.getSubject())) {
            found2 = true;
        }
    }
    Assert.assertTrue(found1);
    Assert.assertTrue(found2);
    conn.shutdown();
}
Also used : Calendar(java.util.Calendar) HttpResponse(org.apache.http.HttpResponse) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) Identity(org.olat.core.id.Identity) EventVO(org.olat.commons.calendar.restapi.EventVO) Test(org.junit.Test)

Example 15 with CourseConfigVO

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

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