use of org.olat.restapi.support.vo.CourseConfigVO in project openolat by klemens.
the class LecturesBlocksTest method getLecturesBlock_repository.
/**
* Get the list of lecture block through the repository entry.
*
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void getLecturesBlock_repository() 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();
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").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.assertEquals(1, voList.size());
LectureBlockVO blockVo = voList.get(0);
Assert.assertEquals(block.getKey(), blockVo.getKey());
Assert.assertEquals(entry.getKey(), blockVo.getRepoEntryKey());
}
use of org.olat.restapi.support.vo.CourseConfigVO in project openolat by klemens.
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));
}
use of org.olat.restapi.support.vo.CourseConfigVO in project openolat by klemens.
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();
}
use of org.olat.restapi.support.vo.CourseConfigVO in project openolat by klemens.
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();
}
use of org.olat.restapi.support.vo.CourseConfigVO in project openolat by klemens.
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;
}
Aggregations