Search in sources :

Example 21 with ForumThreadReply

use of fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply in project muikku by otavanopisto.

the class AcceptanceTestsRESTService method deleteDiscussion.

@DELETE
@Path("/discussiongroups/{GROUPID}/discussions/{DISCUSSIONID}")
@RESTPermit(handling = Handling.UNSECURED)
public Response deleteDiscussion(@PathParam("GROUPID") Long groupId, @PathParam("DISCUSSIONID") Long discussionId) {
    ForumAreaGroup group = forumController.findForumAreaGroup(groupId);
    if (group == null) {
        return Response.status(Status.NOT_FOUND).entity("Group not found").build();
    }
    ForumArea forumArea = forumController.getForumArea(discussionId);
    if (forumArea == null) {
        return Response.status(Status.NOT_FOUND).entity("Discussion not found").build();
    }
    List<ForumThread> threads = forumController.listForumThreads(forumArea, 0, Integer.MAX_VALUE, true);
    for (ForumThread thread : threads) {
        List<ForumThreadReply> replies = forumController.listForumThreadReplies(thread, 0, Integer.MAX_VALUE, true);
        for (ForumThreadReply reply : replies) {
            forumController.deleteReply(reply);
        }
        forumController.deleteThread(thread);
    }
    forumController.deleteArea(forumArea);
    return Response.noContent().build();
}
Also used : ForumAreaGroup(fi.otavanopisto.muikku.plugins.forum.model.ForumAreaGroup) ForumThread(fi.otavanopisto.muikku.plugins.forum.model.ForumThread) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) EnvironmentForumArea(fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) ForumThreadReply(fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Aggregations

ForumThreadReply (fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply)21 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)12 Path (javax.ws.rs.Path)12 ForumArea (fi.otavanopisto.muikku.plugins.forum.model.ForumArea)11 ForumThread (fi.otavanopisto.muikku.plugins.forum.model.ForumThread)11 WorkspaceForumArea (fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea)7 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)6 EnvironmentForumArea (fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea)6 EntityManager (javax.persistence.EntityManager)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 DELETE (javax.ws.rs.DELETE)4 GET (javax.ws.rs.GET)4 ForumAreaGroup (fi.otavanopisto.muikku.plugins.forum.model.ForumAreaGroup)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2