Search in sources :

Example 1 with CourseConfigVO

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

the class CourseCalendarTest method setUp.

/**
 * SetUp is called before each test.
 */
@Before
public void setUp() throws Exception {
    super.setUp();
    try {
        // create course and persist as OLATResourceImpl
        auth1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-course-cal-one");
        CourseConfigVO config = new CourseConfigVO();
        config.setCalendar(Boolean.TRUE);
        course1 = CoursesWebService.createEmptyCourse(auth1, "course calendar", "course with calendar for REST API testing", config);
        dbInstance.commit();
        ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
        Assert.assertTrue(course.getCourseConfig().isCalendarEnabled());
        CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
        KalendarRenderWrapper calendarWrapper = calManager.getCourseCalendar(course);
        Calendar cal = Calendar.getInstance();
        for (int i = 0; i < 2; i++) {
            Date begin = cal.getTime();
            cal.add(Calendar.HOUR_OF_DAY, 1);
            Date end = cal.getTime();
            String eventId = UUID.randomUUID().toString();
            KalendarEvent event = new KalendarEvent(eventId, null, "Unit test " + i, begin, end);
            calManager.addEventTo(calendarWrapper.getKalendar(), event);
            cal.add(Calendar.DATE, 1);
        }
    } catch (Exception e) {
        log.error("Exception in setUp(): " + e);
    }
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) CalendarManager(org.olat.commons.calendar.CalendarManager) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Before(org.junit.Before)

Example 2 with CourseConfigVO

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

the class CalendarTest method startup.

@Before
public void startup() {
    if (id1 == null) {
        id1 = JunitTestHelper.createAndPersistIdentityAsUser("cal-1-" + UUID.randomUUID().toString());
    }
    if (id2 == null) {
        id2 = JunitTestHelper.createAndPersistIdentityAsUser("cal-2-" + UUID.randomUUID().toString());
    }
    if (course1 == null) {
        // create a course with a calendar
        CourseConfigVO config = new CourseConfigVO();
        config.setCalendar(Boolean.TRUE);
        course1 = CoursesWebService.createEmptyCourse(id1, "Cal course", "Cal course", config);
        dbInstance.commit();
        ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
        CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
        Assert.assertTrue(courseConfig.isCalendarEnabled());
        KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course);
        Calendar cal = Calendar.getInstance();
        for (int i = 0; i < 10; i++) {
            Date begin = cal.getTime();
            cal.add(Calendar.HOUR_OF_DAY, 1);
            Date end = cal.getTime();
            KalendarEvent event = new KalendarEvent(UUID.randomUUID().toString(), null, "Unit test " + i, begin, end);
            calendarManager.addEventTo(calendarWrapper.getKalendar(), event);
            cal.add(Calendar.DATE, 1);
        }
        cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, -1);
        Date begin2 = cal.getTime();
        cal.add(Calendar.HOUR_OF_DAY, 1);
        Date end2 = cal.getTime();
        KalendarEvent event2 = new KalendarEvent(UUID.randomUUID().toString(), null, "Unit test 2", begin2, end2);
        calendarManager.addEventTo(calendarWrapper.getKalendar(), event2);
        RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course1, false);
        entry = repositoryManager.setAccess(entry, RepositoryEntry.ACC_USERS, false);
        repositoryService.addRole(id1, entry, GroupRoles.participant.name());
        dbInstance.commit();
    }
    if (course2 == null) {
        // create a course with a calendar
        CourseConfigVO config = new CourseConfigVO();
        config.setCalendar(Boolean.TRUE);
        course2 = CoursesWebService.createEmptyCourse(id2, "Cal course - 2", "Cal course - 2", config);
        dbInstance.commit();
        KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course2);
        Assert.assertNotNull(calendarWrapper);
        RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course2, false);
        entry = repositoryManager.setAccess(entry, RepositoryEntry.ACC_USERS, false);
        dbInstance.commit();
    }
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Date(java.util.Date) CourseConfig(org.olat.course.config.CourseConfig) Before(org.junit.Before)

Example 3 with CourseConfigVO

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

the class CoursesWebService method createEmptyCourse.

/**
 * Creates an empty course, or a copy from a course if the parameter copyFrom is set.
 * @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 shortTitle The short title
 * @param title The title
 * @param sharedFolderSoftKey The repository entry key of a shared folder (optional)
 * @param copyFrom The course primary key key to make a copy from (optional)
 * @param initialAuthor The primary key of the initial author (optional)
 * @param noAuthor True to create a course without the author
 * @param request The HTTP request
 * @return It returns the id of the newly created Course
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createEmptyCourse(@QueryParam("shortTitle") String shortTitle, @QueryParam("title") String title, @QueryParam("displayName") String displayName, @QueryParam("description") String description, @QueryParam("softKey") String softKey, @QueryParam("access") Integer access, @QueryParam("membersOnly") Boolean membersOnly, @QueryParam("externalId") String externalId, @QueryParam("externalRef") String externalRef, @QueryParam("authors") String authors, @QueryParam("location") String location, @QueryParam("managedFlags") String managedFlags, @QueryParam("sharedFolderSoftKey") String sharedFolderSoftKey, @QueryParam("copyFrom") Long copyFrom, @QueryParam("initialAuthor") Long initialAuthor, @QueryParam("setAuthor") @DefaultValue("true") Boolean setAuthor, @Context HttpServletRequest request) {
    if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    CourseConfigVO configVO = new CourseConfigVO();
    configVO.setSharedFolderSoftKey(sharedFolderSoftKey);
    int accessInt = (access == null ? RepositoryEntry.ACC_OWNERS : access.intValue());
    boolean membersOnlyBool = (membersOnly == null ? false : membersOnly.booleanValue());
    if (!StringHelper.containsNonWhitespace(displayName)) {
        displayName = shortTitle;
    }
    ICourse course;
    UserRequest ureq = getUserRequest(request);
    Identity id = null;
    if (setAuthor != null && setAuthor.booleanValue()) {
        if (initialAuthor != null) {
            id = getIdentity(initialAuthor);
        }
        if (id == null) {
            id = ureq.getIdentity();
        }
    }
    if (copyFrom != null) {
        course = copyCourse(copyFrom, ureq, id, shortTitle, title, displayName, description, softKey, accessInt, membersOnlyBool, authors, location, externalId, externalRef, managedFlags, configVO);
    } else {
        course = createEmptyCourse(id, shortTitle, title, displayName, description, softKey, accessInt, membersOnlyBool, authors, location, externalId, externalRef, managedFlags, configVO);
    }
    if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    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) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 4 with CourseConfigVO

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

the class ObjectFactory method getConfig.

public static CourseConfigVO getConfig(ICourse course) {
    CourseConfigVO vo = new CourseConfigVO();
    CourseConfig config = course.getCourseEnvironment().getCourseConfig();
    vo.setCalendar(new Boolean(config.isCalendarEnabled()));
    vo.setChat(new Boolean(config.isChatEnabled()));
    vo.setCssLayoutRef(config.getCssLayoutRef());
    vo.setEfficencyStatement(new Boolean(config.isEfficencyStatementEnabled()));
    vo.setGlossarySoftkey(config.getGlossarySoftKey());
    vo.setSharedFolderSoftKey(config.getSharedFolderSoftkey());
    return vo;
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) CourseConfig(org.olat.course.config.CourseConfig)

Example 5 with CourseConfigVO

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

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)

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