Search in sources :

Example 71 with RepositoryService

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);
    }
}
Also used : ResourceEvaluation(org.olat.fileresource.types.ResourceEvaluation) Locale(java.util.Locale) WebApplicationException(javax.ws.rs.WebApplicationException) RepositoryHandlerFactory(org.olat.repository.handlers.RepositoryHandlerFactory) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) RepositoryEntry(org.olat.repository.RepositoryEntry) WebApplicationException(javax.ws.rs.WebApplicationException) RepositoryService(org.olat.repository.RepositoryService)

Example 72 with RepositoryService

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();
}
Also used : ErrorList(org.olat.repository.ErrorList) RepositoryEntry(org.olat.repository.RepositoryEntry) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) RepositoryService(org.olat.repository.RepositoryService) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 73 with RepositoryService

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();
}
Also used : ErrorList(org.olat.repository.ErrorList) RepositoryEntry(org.olat.repository.RepositoryEntry) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) RepositoryService(org.olat.repository.RepositoryService) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 74 with RepositoryService

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();
}
Also used : UserVO(org.olat.user.restapi.UserVO) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RepositoryService(org.olat.repository.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 75 with RepositoryService

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);
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupService(org.olat.group.BusinessGroupService) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) RepositoryService(org.olat.repository.RepositoryService)

Aggregations

RepositoryService (org.olat.repository.RepositoryService)76 RepositoryEntry (org.olat.repository.RepositoryEntry)72 OLATResource (org.olat.resource.OLATResource)32 Identity (org.olat.core.id.Identity)20 Produces (javax.ws.rs.Produces)18 Path (javax.ws.rs.Path)16 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)14 File (java.io.File)12 OLATResourceable (org.olat.core.id.OLATResourceable)12 GET (javax.ws.rs.GET)10 UserRequest (org.olat.core.gui.UserRequest)8 WindowControl (org.olat.core.gui.control.WindowControl)8 ICourse (org.olat.course.ICourse)8 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)8 UserVO (org.olat.user.restapi.UserVO)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Before (org.junit.Before)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 GlossaryResource (org.olat.fileresource.types.GlossaryResource)6