use of fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply in project muikku by otavanopisto.
the class WorkspaceForumRESTService method listReplies.
@GET
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas/{AREAID}/threads/{THREADID}/replies")
@RESTPermit(handling = Handling.INLINE)
public Response listReplies(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("AREAID") Long areaId, @PathParam("THREADID") Long threadId, @QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("10") Integer maxResults) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d not found", workspaceEntityId)).build();
}
try {
ForumArea forumArea = forumController.getForumArea(areaId);
if (forumArea == null) {
return Response.status(Status.NOT_FOUND).entity("Forum area not found").build();
}
ForumThread forumThread = forumController.getForumThread(threadId);
if (forumThread == null) {
return Response.status(Status.NOT_FOUND).entity("Forum thread not found").build();
}
if (!(forumArea instanceof WorkspaceForumArea)) {
logger.severe(String.format("Trying to access forum %d via incorrect REST endpoint", forumArea.getId()));
return Response.status(Status.NOT_FOUND).build();
}
if (!workspaceEntity.getId().equals(((WorkspaceForumArea) forumArea).getWorkspace())) {
return Response.status(Status.NOT_FOUND).entity(String.format("WorkspaceForumArea %d does not belong to workspace entity %d", forumArea.getId(), workspaceEntity.getId())).build();
}
if (sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_READ_WORKSPACE_MESSAGES, workspaceEntity)) {
if (!forumArea.getId().equals(forumThread.getForumArea().getId())) {
return Response.status(Status.NOT_FOUND).entity("Forum thread not found from the specified area").build();
}
List<ForumThreadReply> replies = forumController.listForumThreadReplies(forumThread, firstResult, maxResults);
return Response.ok(createRestModel(replies.toArray(new ForumThreadReply[0]))).build();
} else
return Response.status(Status.FORBIDDEN).build();
} catch (Exception e) {
logger.log(Level.SEVERE, "Listing forum thread replies failed", e);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply in project muikku by otavanopisto.
the class WorkspaceForumRESTService method updateReply.
@PUT
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas/{AREAID}/threads/{THREADID}/replies/{REPLYID}")
@RESTPermit(handling = Handling.INLINE)
public Response updateReply(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("AREAID") Long areaId, @PathParam("THREADID") Long threadId, @PathParam("REPLYID") Long replyId, ForumThreadReplyRESTModel reply) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d not found", workspaceEntityId)).build();
}
try {
ForumArea forumArea = forumController.getForumArea(areaId);
if (forumArea == null) {
return Response.status(Status.NOT_FOUND).entity("Forum area not found").build();
}
ForumThread forumThread = forumController.getForumThread(threadId);
if (forumThread == null) {
return Response.status(Status.NOT_FOUND).entity("Forum thread not found").build();
}
if (!forumArea.getId().equals(forumThread.getForumArea().getId())) {
return Response.status(Status.NOT_FOUND).entity("Forum thread not found from the specified area").build();
}
ForumThreadReply threadReply = forumController.getForumThreadReply(replyId);
if (threadReply == null) {
return Response.status(Status.NOT_FOUND).entity("Forum thread reply not found").build();
}
if (!threadReply.getThread().getId().equals(forumThread.getId())) {
return Response.status(Status.NOT_FOUND).entity("Forum thread reply not found from the specified thread").build();
}
if (!reply.getId().equals(replyId)) {
return Response.status(Status.BAD_REQUEST).build();
}
if (!(forumArea instanceof WorkspaceForumArea)) {
logger.severe(String.format("Trying to access forum %d via incorrect REST endpoint", forumArea.getId()));
return Response.status(Status.NOT_FOUND).build();
}
if (!workspaceEntity.getId().equals(((WorkspaceForumArea) forumArea).getWorkspace())) {
return Response.status(Status.NOT_FOUND).entity(String.format("WorkspaceForumArea %d does not belong to workspace entity %d", forumArea.getId(), workspaceEntity.getId())).build();
}
if (sessionController.hasPermission(MuikkuPermissions.OWNER, threadReply) || sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_EDIT_WORKSPACE_MESSAGES, workspaceEntity)) {
forumController.updateForumThreadReply(threadReply, reply.getMessage());
return Response.ok(createRestModel(threadReply)).build();
} else {
return Response.status(Status.FORBIDDEN).build();
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Finding forum thread reply failed", e);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply in project muikku by otavanopisto.
the class WorkspaceForumRESTService method archiveReply.
@DELETE
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas/{AREAID}/threads/{THREADID}/replies/{REPLYID}")
@RESTPermit(handling = Handling.INLINE)
public Response archiveReply(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("AREAID") Long areaId, @PathParam("THREADID") Long threadId, @PathParam("REPLYID") Long replyId, @DefaultValue("false") @QueryParam("permanent") Boolean permanent) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d not found", workspaceEntityId)).build();
}
ForumThreadReply reply = forumController.getForumThreadReply(replyId);
ForumArea forumArea = reply.getForumArea();
if (!(forumArea instanceof WorkspaceForumArea)) {
logger.severe(String.format("Trying to access forum %d via incorrect REST endpoint", forumArea.getId()));
return Response.status(Status.NOT_FOUND).build();
}
if (!workspaceEntity.getId().equals(((WorkspaceForumArea) forumArea).getWorkspace())) {
return Response.status(Status.NOT_FOUND).entity(String.format("WorkspaceForumArea %d does not belong to workspace entity %d", forumArea.getId(), workspaceEntity.getId())).build();
}
if (!permanent) {
if (sessionController.hasPermission(MuikkuPermissions.OWNER, reply) || sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_DELETE_WORKSPACE_MESSAGES, workspaceEntity)) {
forumController.updateReplyDeleted(reply, true);
return Response.noContent().build();
}
} else {
if (sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_DELETE_WORKSPACE_MESSAGES, workspaceEntity)) {
forumController.archiveReply(reply);
return Response.noContent().build();
}
}
return Response.status(Status.FORBIDDEN).build();
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply in project muikku by otavanopisto.
the class WorkspaceForumRESTService method createReply.
@POST
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas/{AREAID}/threads/{THREADID}/replies")
@RESTPermit(handling = Handling.INLINE)
public Response createReply(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("AREAID") Long areaId, @PathParam("THREADID") Long threadId, ForumThreadReplyRESTModel newReply) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d not found", workspaceEntityId)).build();
}
try {
ForumArea forumArea = forumController.getForumArea(areaId);
if (forumArea == null) {
return Response.status(Status.NOT_FOUND).entity("Forum area not found").build();
}
ForumThread forumThread = forumController.getForumThread(threadId);
if (forumThread == null) {
return Response.status(Status.NOT_FOUND).entity("Forum thread not found").build();
}
if (!forumArea.getId().equals(forumThread.getForumArea().getId())) {
return Response.status(Status.NOT_FOUND).entity("Forum thread not found from the specified area").build();
}
if (forumThread.getLocked()) {
return Response.status(Status.BAD_REQUEST).entity("Forum thread is locked").build();
}
if (!(forumArea instanceof WorkspaceForumArea)) {
logger.severe(String.format("Trying to access forum %d via incorrect REST endpoint", forumArea.getId()));
return Response.status(Status.NOT_FOUND).build();
}
if (!workspaceEntity.getId().equals(((WorkspaceForumArea) forumArea).getWorkspace())) {
return Response.status(Status.NOT_FOUND).entity(String.format("WorkspaceForumArea %d does not belong to workspace entity %d", forumArea.getId(), workspaceEntity.getId())).build();
}
if (sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_WRITE_WORKSPACE_MESSAGES, workspaceEntity)) {
ForumThreadReply parentReply = null;
if (newReply.getParentReplyId() != null) {
parentReply = forumController.getForumThreadReply(newReply.getParentReplyId());
if (parentReply == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid parent reply id").build();
}
if (!Objects.equals(parentReply.getThread().getId(), threadId)) {
return Response.status(Status.BAD_REQUEST).entity("Parent reply is in wrong thread").build();
}
}
return Response.ok(createRestModel(forumController.createForumThreadReply(forumThread, newReply.getMessage(), parentReply))).build();
} else {
return Response.status(Status.FORBIDDEN).build();
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to create new forum thread reply", e);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply in project muikku by otavanopisto.
the class ForumController method archiveThread.
public void archiveThread(ForumThread thread) {
List<ForumThreadReply> replies = forumThreadReplyDAO.listByForumThread(thread);
for (ForumThreadReply reply : replies) {
forumThreadReplyDAO.updateArchived(reply, true);
}
forumThreadDAO.updateArchived(thread, true);
}
Aggregations