Search in sources :

Example 1 with WorkspaceForumArea

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

the class WorkspaceForumAreaDAO method listByWorkspaceEntity.

public List<WorkspaceForumArea> listByWorkspaceEntity(WorkspaceEntity workspaceEntity) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<WorkspaceForumArea> criteria = criteriaBuilder.createQuery(WorkspaceForumArea.class);
    Root<WorkspaceForumArea> root = criteria.from(WorkspaceForumArea.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceForumArea_.workspace), workspaceEntity.getId()), criteriaBuilder.equal(root.get(WorkspaceForumArea_.archived), Boolean.FALSE)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) EntityManager(javax.persistence.EntityManager)

Example 2 with WorkspaceForumArea

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

the class WorkspaceForumRESTService method findThread.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas/{AREAID}/threads/{THREADID}")
@RESTPermit(handling = Handling.INLINE)
public Response findThread(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("AREAID") Long areaId, @PathParam("THREADID") Long threadId) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d not found", workspaceEntityId)).build();
    }
    ForumThread thread = forumController.getForumThread(threadId);
    if (thread == null) {
        return Response.status(Status.NOT_FOUND).entity("Forum thread not found").build();
    }
    ForumArea forumArea = thread.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 (sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_READ_WORKSPACE_MESSAGES, workspaceEntity)) {
        long numReplies = forumController.getThreadReplyCount(thread);
        ForumThreadRESTModel result = new ForumThreadRESTModel(thread.getId(), thread.getTitle(), thread.getMessage(), thread.getCreator(), thread.getCreated(), thread.getForumArea().getId(), thread.getSticky(), thread.getLocked(), thread.getUpdated(), numReplies, thread.getLastModified());
        return Response.ok(result).build();
    } else {
        return Response.status(Status.FORBIDDEN).build();
    }
}
Also used : WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ForumThread(fi.otavanopisto.muikku.plugins.forum.model.ForumThread) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 3 with WorkspaceForumArea

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

the class WorkspaceForumRESTService method findWorkspaceArea.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas/{AREAID}")
@RESTPermit(handling = Handling.INLINE)
public Response findWorkspaceArea(@Context Request request, @PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("AREAID") Long areaId) {
    ForumArea forumArea = forumController.getForumArea(areaId);
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d not found", workspaceEntityId)).build();
    }
    if (forumArea != null) {
        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_ACCESSWORKSPACEFORUMS, workspaceEntity)) {
            Long numThreads = forumController.getThreadCount(forumArea);
            EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(forumArea.getVersion()) + String.valueOf(numThreads)));
            ResponseBuilder builder = request.evaluatePreconditions(tag);
            if (builder != null) {
                return builder.build();
            }
            CacheControl cacheControl = new CacheControl();
            cacheControl.setMustRevalidate(true);
            ForumAreaRESTModel result = new ForumAreaRESTModel(forumArea.getId(), forumArea.getName(), forumArea.getDescription(), forumArea.getGroup() != null ? forumArea.getGroup().getId() : null, numThreads);
            return Response.ok(result).cacheControl(cacheControl).tag(tag).build();
        } else {
            return Response.status(Status.FORBIDDEN).build();
        }
    } else {
        return Response.status(Status.NOT_FOUND).build();
    }
}
Also used : WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) EntityTag(javax.ws.rs.core.EntityTag) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) CacheControl(javax.ws.rs.core.CacheControl) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 4 with WorkspaceForumArea

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

the class WorkspaceForumRESTService method archiveWorkspaceForumArea.

@DELETE
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas/{AREAID}")
@RESTPermit(handling = Handling.INLINE)
public Response archiveWorkspaceForumArea(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("AREAID") Long areaId) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d not found", workspaceEntityId)).build();
    }
    ForumArea forumArea = forumController.getForumArea(areaId);
    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, forumArea) || sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_DELETEWORKSPACEFORUM, workspaceEntity)) {
        forumController.archiveArea(forumArea);
    } else {
        return Response.status(Status.FORBIDDEN).build();
    }
    return Response.noContent().build();
}
Also used : WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 5 with WorkspaceForumArea

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

the class WorkspaceForumRESTService method listWorkspaceForumAreas.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas")
@RESTPermit(handling = Handling.INLINE)
public Response listWorkspaceForumAreas(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d not found", workspaceEntityId)).build();
    }
    if (!sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_LIST_WORKSPACE_FORUM, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    List<WorkspaceForumArea> workspaceForumAreas = forumController.listWorkspaceForumAreas(workspaceEntity);
    List<WorkspaceForumAreaRESTModel> result = new ArrayList<WorkspaceForumAreaRESTModel>();
    for (WorkspaceForumArea forum : workspaceForumAreas) {
        Long numThreads = forumController.getThreadCount(forum);
        result.add(new WorkspaceForumAreaRESTModel(forum.getId(), forum.getWorkspace(), forum.getName(), forum.getDescription(), forum.getGroup() != null ? forum.getGroup().getId() : null, numThreads));
    }
    return Response.ok(result).build();
}
Also used : WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

WorkspaceForumArea (fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea)26 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)17 ForumArea (fi.otavanopisto.muikku.plugins.forum.model.ForumArea)16 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)15 Path (javax.ws.rs.Path)15 ForumThread (fi.otavanopisto.muikku.plugins.forum.model.ForumThread)11 GET (javax.ws.rs.GET)6 ForumThreadReply (fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply)5 EntityManager (javax.persistence.EntityManager)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 ArrayList (java.util.ArrayList)4 ForumMessage (fi.otavanopisto.muikku.plugins.forum.model.ForumMessage)3 DELETE (javax.ws.rs.DELETE)3 POST (javax.ws.rs.POST)3 PUT (javax.ws.rs.PUT)3 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)2 EnvironmentForumArea (fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Permission (fi.otavanopisto.muikku.model.security.Permission)1