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();
}
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();
}
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();
}
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);
}
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();
}
Aggregations