use of org.olat.repository.RepositoryService in project openolat by klemens.
the class CourseAssessmentWebService method loadUsers.
private List<Identity> loadUsers(ICourse course) {
List<Identity> identities = new ArrayList<Identity>();
List<BusinessGroup> groups = course.getCourseEnvironment().getCourseGroupManager().getAllBusinessGroups();
Set<Long> check = new HashSet<Long>();
BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<Identity> participants = businessGroupService.getMembers(groups, GroupRoles.participant.name());
for (Identity participant : participants) {
if (!check.contains(participant.getKey())) {
identities.add(participant);
check.add(participant.getKey());
}
}
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(course, false);
if (re != null) {
List<Identity> ids = repositoryService.getMembers(re, GroupRoles.participant.name());
for (Identity id : ids) {
if (!check.contains(id.getKey())) {
identities.add(id);
check.add(id.getKey());
}
}
}
return identities;
}
use of org.olat.repository.RepositoryService in project openolat by klemens.
the class CourseWebService method getRepoFileById.
/**
* Export the course
* @response.representation.200.mediaType application/zip
* @response.representation.200.doc The course as a ZIP file
* @response.representation.401.doc Not authorized to export the course
* @response.representation.404.doc The course not found
* @return It returns the <code>CourseVO</code> object representing the course.
*/
@GET
@Path("file")
@Produces({ "application/zip", MediaType.APPLICATION_OCTET_STREAM })
public Response getRepoFileById(@Context HttpServletRequest request) {
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
if (re == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
RepositoryHandler typeToDownload = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
if (typeToDownload == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Identity identity = getIdentity(request);
boolean canDownload = re.getCanDownload() && typeToDownload.supportsDownload();
if (isAdmin(request) || RepositoryManager.getInstance().isOwnerOfRepositoryEntry(identity, re)) {
canDownload = true;
} else if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
if (!canDownload) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
OLATResource ores = OLATResourceManager.getInstance().findResourceable(re.getOlatResource());
if (ores == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
boolean isAlreadyLocked = typeToDownload.isLocked(ores);
LockResult lockResult = null;
try {
lockResult = typeToDownload.acquireLock(ores, identity);
if (lockResult == null || (lockResult != null && lockResult.isSuccess() && !isAlreadyLocked)) {
MediaResource mr = typeToDownload.getAsMediaResource(ores, false);
if (mr != null) {
rs.incrementDownloadCounter(re);
// success
return Response.ok(mr.getInputStream()).cacheControl(cc).build();
} else {
return Response.serverError().status(Status.NO_CONTENT).build();
}
} else {
return Response.serverError().status(Status.CONFLICT).build();
}
} finally {
if ((lockResult != null && lockResult.isSuccess() && !isAlreadyLocked)) {
typeToDownload.releaseLock(lockResult);
}
}
}
use of org.olat.repository.RepositoryService in project openolat by klemens.
the class CourseWebService method deleteCoursePermanently.
/**
* Change the status of a course by id. The possible status are:
* <ul>
* <li>closed</li>
* <li>unclosed</li>
* <li>unpublished</li>
* <li>deleted</li>
* <li>restored</li>
* </ul>
*
* @response.representation.200.doc The metadatas of the deleted course
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found
* @param request The HTTP request
* @return It returns the XML representation of the <code>Structure</code>
* object representing the course.
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("status")
public Response deleteCoursePermanently(@FormParam("newStatus") String newStatus, @Context HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (!isAuthorEditor(course, request) && !isInstitutionalResourceManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
if ("closed".equals(newStatus)) {
rs.closeRepositoryEntry(re);
log.audit("REST closing course: " + re.getDisplayname() + " [" + re.getKey() + "]");
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_CLOSE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
} else if ("unclosed".equals(newStatus)) {
rs.uncloseRepositoryEntry(re);
log.audit("REST unclosing course: " + re.getDisplayname() + " [" + re.getKey() + "]");
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_UPDATE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
} else if ("unpublished".equals(newStatus)) {
rs.unpublishRepositoryEntry(re);
log.audit("REST unpublishing course: " + re.getDisplayname() + " [" + re.getKey() + "]");
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_DEACTIVATE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
} else if ("deleted".equals(newStatus)) {
Identity identity = getIdentity(request);
rs.deleteSoftly(re, identity, true);
log.audit("REST deleting (soft) course: " + re.getDisplayname() + " [" + re.getKey() + "]");
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_TRASH, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
} else if ("restored".equals(newStatus)) {
rs.restoreRepositoryEntry(re);
log.audit("REST restoring course: " + re.getDisplayname() + " [" + re.getKey() + "]");
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_RESTORE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
}
return Response.ok().build();
}
use of org.olat.repository.RepositoryService in project openolat by klemens.
the class CourseWebService method getAuthors.
/**
* Get all owners and authors of the course
* @response.representation.200.qname {http://www.example.com}userVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The array of authors
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found
* @param httpRequest The HTTP request
* @return It returns an array of <code>UserVO</code>
*/
@GET
@Path("authors")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getAuthors(@Context HttpServletRequest httpRequest) {
if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
List<Identity> owners = repositoryService.getMembers(repositoryEntry, GroupRoles.owner.name());
int count = 0;
UserVO[] authors = new UserVO[owners.size()];
for (Identity owner : owners) {
authors[count++] = UserVOFactory.get(owner);
}
return Response.ok(authors).build();
}
use of org.olat.repository.RepositoryService in project openolat by klemens.
the class CourseWebService method getParticipants.
/**
* Get all participants of the course (don't follow the groups)
* @response.representation.200.qname {http://www.example.com}userVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The array of participants
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found
* @param httpRequest The HTTP request
* @return It returns an array of <code>UserVO</code>
*/
@GET
@Path("participants")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getParticipants(@Context HttpServletRequest httpRequest) {
if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
List<Identity> participantList = repositoryService.getMembers(repositoryEntry, GroupRoles.participant.name());
int count = 0;
UserVO[] participants = new UserVO[participantList.size()];
for (Identity participant : participantList) {
participants[count++] = UserVOFactory.get(participant);
}
return Response.ok(participants).build();
}
Aggregations