use of org.olat.repository.RepositoryService in project openolat by klemens.
the class RepositoryEntriesResource method importFileResource.
private RepositoryEntry importFileResource(Identity identity, File fResource, String resourcename, String displayname, String softkey, int access) {
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryHandlerFactory handlerFactory = CoreSpringFactory.getImpl(RepositoryHandlerFactory.class);
try {
RepositoryHandler handler = null;
for (String type : handlerFactory.getSupportedTypes()) {
RepositoryHandler h = handlerFactory.getRepositoryHandler(type);
ResourceEvaluation eval = h.acceptImport(fResource, fResource.getName());
if (eval != null && eval.isValid()) {
handler = h;
break;
}
}
RepositoryEntry addedEntry = null;
if (handler != null) {
Locale locale = I18nModule.getDefaultLocale();
addedEntry = handler.importResource(identity, null, displayname, "", true, locale, fResource, fResource.getName());
if (StringHelper.containsNonWhitespace(resourcename)) {
addedEntry.setResourcename(resourcename);
}
if (StringHelper.containsNonWhitespace(softkey)) {
addedEntry.setSoftkey(softkey);
}
if (access < RepositoryEntry.ACC_OWNERS || access > RepositoryEntry.ACC_USERS_GUESTS) {
addedEntry.setAccess(RepositoryEntry.ACC_OWNERS);
} else {
addedEntry.setAccess(access);
}
addedEntry = repositoryService.update(addedEntry);
}
return addedEntry;
} catch (Exception e) {
log.error("Fail to import a resource", e);
throw new WebApplicationException(e);
}
}
use of org.olat.repository.RepositoryService in project openolat by klemens.
the class RepositoryEntryResource method deleteCourse.
/**
* Delete a resource by id
*
* @response.representation.200.doc The metadatas of the deleted resource
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found
* @param courseId The course resourceable's id
* @param request The HTTP request
* @return It returns the XML representation of the <code>Structure</code>
* object representing the course.
*/
@DELETE
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response deleteCourse(@PathParam("repoEntryKey") String repoEntryKey, @Context HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
if (re == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(re, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
UserRequest ureq = getUserRequest(request);
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
ErrorList errors = rs.deletePermanently(re, ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale());
if (errors.hasErrors()) {
return Response.serverError().status(500).build();
}
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_DELETE, 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 deleteCourse.
/**
* Delete a course by id.
*
* @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.
*/
@DELETE
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response deleteCourse(@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();
}
UserRequest ureq = getUserRequest(request);
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
ErrorList errors = rs.deletePermanently(re, ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale());
if (errors.hasErrors()) {
return Response.serverError().status(500).build();
}
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_DELETE, 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 getTutors.
/**
* Get all coaches 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 coaches
* @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("tutors")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getTutors(@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> coachList = repositoryService.getMembers(repositoryEntry, GroupRoles.coach.name());
int count = 0;
UserVO[] coaches = new UserVO[coachList.size()];
for (Identity coach : coachList) {
coaches[count++] = UserVOFactory.get(coach);
}
return Response.ok(coaches).build();
}
use of org.olat.repository.RepositoryService in project openolat by klemens.
the class ScoreAccountingHelper method loadUsers.
/**
* Load all users from all known learning groups into a list
*
* @param courseEnv
* @return The list of identities from this course
*/
public static List<Identity> loadUsers(CourseEnvironment courseEnv) {
CourseGroupManager gm = courseEnv.getCourseGroupManager();
List<BusinessGroup> groups = gm.getAllBusinessGroups();
BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
Set<Identity> userSet = new HashSet<>(businessGroupService.getMembers(groups, GroupRoles.participant.name()));
RepositoryEntry re = gm.getCourseEntry();
if (re != null) {
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
userSet.addAll(repositoryService.getMembers(re, GroupRoles.participant.name()));
}
List<Identity> assessedList = courseEnv.getCoursePropertyManager().getAllIdentitiesWithCourseAssessmentData(userSet);
if (!assessedList.isEmpty()) {
userSet.addAll(assessedList);
}
return new ArrayList<>(userSet);
}
Aggregations