use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.
the class UserCoursesWebService method getFavoritCourses.
/**
* Retrieves the list of my favorite courses.
* @response.representation.200.qname {http://www.example.com}courseVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The courses
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEVOes}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param start The first result
* @param limit Max result
* @param httpRequest The HTTP request
* @param request The REST request
* @return The list of my favorite courses
*/
@GET
@Path("favorite")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getFavoritCourses(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest, @Context Request request) {
List<String> courseType = Collections.singletonList("CourseModule");
RepositoryManager rm = RepositoryManager.getInstance();
if (MediaTypeVariants.isPaged(httpRequest, request)) {
List<RepositoryEntry> repoEntries = rm.getFavoritLearningResourcesAsTeacher(identity, courseType, start, limit, RepositoryEntryOrder.nameAsc);
int totalCount;
if (repoEntries.size() < limit) {
totalCount = repoEntries.size();
} else {
totalCount = rm.countFavoritLearningResourcesAsTeacher(identity, courseType);
}
CourseVO[] vos = toCourseVo(repoEntries);
CourseVOes voes = new CourseVOes();
voes.setCourses(vos);
voes.setTotalCount(totalCount);
return Response.ok(voes).build();
} else {
List<RepositoryEntry> repoEntries = rm.getFavoritLearningResourcesAsTeacher(identity, courseType, 0, -1, RepositoryEntryOrder.nameAsc);
CourseVO[] vos = toCourseVo(repoEntries);
return Response.ok(vos).build();
}
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CourseWebService method publishCourse.
/**
* Publish the 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
* @response.representation.404.doc The course not found
* @param locale The course locale
* @param request The HTTP request
* @return It returns the metadatas of the published course.
*/
@POST
@Path("publish")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response publishCourse(@QueryParam("locale") Locale locale, @QueryParam("access") Integer access, @QueryParam("membersOnly") Boolean membersOnly, @Context HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
UserRequest ureq = getUserRequest(request);
if (!isAuthorEditor(course, request) && !isInstitutionalResourceManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
int newAccess = access == null ? RepositoryEntry.ACC_USERS : access.intValue();
boolean members = membersOnly == null ? false : membersOnly.booleanValue();
CourseFactory.publishCourse(course, newAccess, members, ureq.getIdentity(), locale);
CourseVO vo = ObjectFactory.get(course);
return Response.ok(vo).build();
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CoursesWebService method importCourse.
/**
* Imports a course from a course archive zip file
* @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 imported 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 ownerUsername set the owner of the imported course to the user of this username.
* @param request The HTTP request
* @return It returns the imported course
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response importCourse(@QueryParam("ownerUsername") String ownerUsername, @Context HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
UserRequest ureq = RestSecurityHelper.getUserRequest(request);
Identity identity = null;
// Set the owner of the imported course to the user defined in the parameter
if (ownerUsername != null && !ownerUsername.isEmpty() && isAuthor(request)) {
identity = BaseSecurityManager.getInstance().findIdentityByName(ownerUsername);
if (identity == null) {
return Response.serverError().status(Status.BAD_REQUEST).build();
}
}
if (identity == null) {
identity = ureq.getIdentity();
}
MultipartReader partsReader = null;
try {
partsReader = new MultipartReader(request);
File tmpFile = partsReader.getFile();
long length = tmpFile.length();
if (length > 0) {
Long accessRaw = partsReader.getLongValue("access");
int access = accessRaw != null ? accessRaw.intValue() : RepositoryEntry.ACC_OWNERS;
String membersOnlyRaw = partsReader.getValue("membersOnly");
boolean membersonly = "true".equals(membersOnlyRaw);
String softKey = partsReader.getValue("softkey");
String displayName = partsReader.getValue("displayname");
ICourse course = importCourse(ureq, identity, tmpFile, displayName, softKey, access, membersonly);
CourseVO vo = ObjectFactory.get(course);
return Response.ok(vo).build();
}
return Response.serverError().status(Status.NO_CONTENT).build();
} catch (Exception e) {
log.error("Error while importing a file", e);
} finally {
MultipartReader.closeQuietly(partsReader);
}
CourseVO vo = null;
return Response.ok(vo).build();
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CoursesWebService method getCourseList.
/**
* Get all courses viewable by the authenticated user
* @response.representation.200.qname {http://www.example.com}courseVO
* @response.representation.200.mediaType application/xml, application/json, application/json;pagingspec=1.0
* @response.representation.200.doc List of visible courses
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEVOes}
* @param start
* @param limit
* @param externalId Search with an external ID
* @param externalRef Search with an external reference
* @param managed (true / false) Search only managed / not managed groups
* @param httpRequest The HTTP request
* @param request The REST request
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseList(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @QueryParam("managed") Boolean managed, @QueryParam("externalId") String externalId, @QueryParam("externalRef") String externalRef, @QueryParam("repositoryEntryKey") String repositoryEntryKey, @Context HttpServletRequest httpRequest, @Context Request request) {
RepositoryManager rm = RepositoryManager.getInstance();
Roles roles = getRoles(httpRequest);
Identity identity = getIdentity(httpRequest);
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles, CourseModule.getCourseTypeName());
params.setManaged(managed);
if (StringHelper.containsNonWhitespace(externalId)) {
params.setExternalId(externalId);
}
if (StringHelper.containsNonWhitespace(externalRef)) {
params.setExternalRef(externalRef);
}
if (StringHelper.containsNonWhitespace(repositoryEntryKey) && StringHelper.isLong(repositoryEntryKey)) {
try {
params.setRepositoryEntryKeys(Collections.singletonList(new Long(repositoryEntryKey)));
} catch (NumberFormatException e) {
log.error("Cannot parse the following repository entry key: " + repositoryEntryKey);
}
}
if (MediaTypeVariants.isPaged(httpRequest, request)) {
int totalCount = rm.countGenericANDQueryWithRolesRestriction(params);
List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, start, limit, true);
CourseVO[] vos = toCourseVo(repoEntries);
CourseVOes voes = new CourseVOes();
voes.setCourses(vos);
voes.setTotalCount(totalCount);
return Response.ok(voes).build();
} else {
List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, 0, -1, false);
CourseVO[] vos = toCourseVo(repoEntries);
return Response.ok(vos).build();
}
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CoursesWebService method toCourseVo.
public static CourseVO[] toCourseVo(List<RepositoryEntry> repoEntries) {
List<CourseVO> voList = new ArrayList<CourseVO>();
int count = 0;
for (RepositoryEntry repoEntry : repoEntries) {
try {
ICourse course = loadCourse(repoEntry.getOlatResource().getResourceableId());
voList.add(ObjectFactory.get(repoEntry, course));
if (count % 33 == 0) {
DBFactory.getInstance().commitAndCloseSession();
}
} catch (Exception e) {
log.error("Cannot load the course with this repository entry: " + repoEntry, e);
}
}
CourseVO[] vos = new CourseVO[voList.size()];
voList.toArray(vos);
return vos;
}
Aggregations