Search in sources :

Example 26 with RepositoryService

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;
}
Also used : 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)

Example 27 with RepositoryService

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);
        }
    }
}
Also used : LockResult(org.olat.core.util.coordinate.LockResult) OLATResource(org.olat.resource.OLATResource) MediaResource(org.olat.core.gui.media.MediaResource) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) 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 28 with RepositoryService

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();
}
Also used : 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) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 29 with RepositoryService

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();
}
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 30 with RepositoryService

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();
}
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)

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