Search in sources :

Example 11 with ErrorList

use of org.olat.repository.ErrorList 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 12 with ErrorList

use of org.olat.repository.ErrorList 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)

Aggregations

ErrorList (org.olat.repository.ErrorList)12 RepositoryEntry (org.olat.repository.RepositoryEntry)10 DELETE (javax.ws.rs.DELETE)4 Produces (javax.ws.rs.Produces)4 UserRequest (org.olat.core.gui.UserRequest)4 Roles (org.olat.core.id.Roles)4 RepositoryService (org.olat.repository.RepositoryService)4 RestSecurityHelper.getUserRequest (org.olat.restapi.security.RestSecurityHelper.getUserRequest)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 GroupRoles (org.olat.basesecurity.GroupRoles)2 LicenseService (org.olat.core.commons.services.license.LicenseService)2 MarkManager (org.olat.core.commons.services.mark.MarkManager)2 Identity (org.olat.core.id.Identity)2 LectureService (org.olat.modules.lecture.LectureService)2 PortfolioService (org.olat.modules.portfolio.PortfolioService)2 EntryChangedEvent (org.olat.repository.controllers.EntryChangedEvent)2 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)2 OLATResource (org.olat.resource.OLATResource)2