Search in sources :

Example 1 with ForumMessage

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

the class WorkspaceForumRESTService method getWorkspaceForumStatistics.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/forumStatistics")
@RESTPermit(handling = Handling.INLINE)
public Response getWorkspaceForumStatistics(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @QueryParam("userIdentifier") String userId) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d could not be found", workspaceEntityId)).build();
    }
    SchoolDataIdentifier userIdentifier = null;
    if (StringUtils.isNotBlank(userId)) {
        userIdentifier = SchoolDataIdentifier.fromId(userId);
    }
    if (userIdentifier == null) {
        return Response.status(Status.NOT_IMPLEMENTED).entity("Listing forum statistics for all users is not implemented yet").build();
    }
    UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(userIdentifier);
    if (userEntity == null) {
        return Response.status(Status.BAD_REQUEST).entity("Invalid userIdentifier").build();
    }
    if (!sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_FINDWORKSPACE_USERSTATISTICS, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    Long messageCount = forumController.countUserEntityWorkspaceMessages(workspaceEntity, userEntity);
    ForumMessage latestMessage = forumController.findUserEntitysLatestWorkspaceMessage(workspaceEntity, userEntity);
    return Response.ok(new WorkspaceForumUserStatisticsRESTModel(messageCount, latestMessage != null ? latestMessage.getCreated() : null)).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ForumMessage(fi.otavanopisto.muikku.plugins.forum.model.ForumMessage) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 2 with ForumMessage

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

the class ForumMessageDAO method listByContributingUser.

public List<ForumMessage> listByContributingUser(UserEntity loggedUser) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<ForumMessage> criteria = criteriaBuilder.createQuery(ForumMessage.class);
    Root<ForumMessage> root = criteria.from(ForumMessage.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(ForumMessage_.creator), loggedUser.getId()), criteriaBuilder.equal(root.get(ForumMessage_.archived), Boolean.FALSE)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) ForumMessage(fi.otavanopisto.muikku.plugins.forum.model.ForumMessage)

Example 3 with ForumMessage

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

the class ForumMessageDAO method countByArea.

public Long countByArea(ForumArea area) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
    Root<ForumMessage> root = criteria.from(ForumMessage.class);
    criteria.select(criteriaBuilder.count(root));
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(ForumMessage_.forumArea), area), criteriaBuilder.equal(root.get(ForumMessage_.archived), Boolean.FALSE)));
    return entityManager.createQuery(criteria).getSingleResult();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) ForumMessage(fi.otavanopisto.muikku.plugins.forum.model.ForumMessage)

Example 4 with ForumMessage

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

the class ForumMessageDAO method findLatestMessageByArea.

public ForumMessage findLatestMessageByArea(ForumArea area) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<ForumMessage> criteria = criteriaBuilder.createQuery(ForumMessage.class);
    Root<ForumMessage> root = criteria.from(ForumMessage.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(ForumMessage_.forumArea), area), criteriaBuilder.equal(root.get(ForumMessage_.archived), Boolean.FALSE)));
    criteria.orderBy(criteriaBuilder.desc(root.get(ForumMessage_.created)));
    TypedQuery<ForumMessage> query = entityManager.createQuery(criteria);
    query.setMaxResults(1);
    return getSingleResult(query);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) ForumMessage(fi.otavanopisto.muikku.plugins.forum.model.ForumMessage)

Example 5 with ForumMessage

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

the class ForumMessageDAO method listByWorkspaceEntityAndCreatorOrderByCreated.

public List<ForumMessage> listByWorkspaceEntityAndCreatorOrderByCreated(Long workspaceEntityId, Long creatorId, int firstResult, int maxResults) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<ForumMessage> criteria = criteriaBuilder.createQuery(ForumMessage.class);
    Root<ForumMessage> root = criteria.from(ForumMessage.class);
    Root<WorkspaceForumArea> workspaceAreaJoin = criteria.from(WorkspaceForumArea.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(workspaceAreaJoin.get(WorkspaceForumArea_.workspace), workspaceEntityId), criteriaBuilder.equal(workspaceAreaJoin.get(WorkspaceForumArea_.id), root.get(ForumMessage_.forumArea)), criteriaBuilder.equal(root.get(ForumMessage_.creator), creatorId), criteriaBuilder.equal(root.get(ForumMessage_.archived), Boolean.FALSE)));
    criteria.orderBy(criteriaBuilder.desc(root.get(ForumMessage_.created)));
    TypedQuery<ForumMessage> query = entityManager.createQuery(criteria);
    query.setFirstResult(firstResult);
    query.setMaxResults(maxResults);
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) EntityManager(javax.persistence.EntityManager) ForumMessage(fi.otavanopisto.muikku.plugins.forum.model.ForumMessage)

Aggregations

ForumMessage (fi.otavanopisto.muikku.plugins.forum.model.ForumMessage)7 EntityManager (javax.persistence.EntityManager)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 WorkspaceForumArea (fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea)3 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1