use of fi.otavanopisto.muikku.plugins.forum.model.ForumThread in project muikku by otavanopisto.
the class ForumThreadDAO method listLatestOrdered.
public List<ForumThread> listLatestOrdered(List<ForumArea> forumAreas, int firstResult, int maxResults) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<ForumThread> criteria = criteriaBuilder.createQuery(ForumThread.class);
Root<ForumThread> root = criteria.from(ForumThread.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(root.get(ForumThread_.forumArea).in(forumAreas), criteriaBuilder.equal(root.get(ForumThread_.archived), Boolean.FALSE)));
criteria.orderBy(criteriaBuilder.desc(root.get(ForumThread_.sticky)), criteriaBuilder.desc(root.get(ForumThread_.updated)));
TypedQuery<ForumThread> query = entityManager.createQuery(criteria);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
return query.getResultList();
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumThread in project muikku by otavanopisto.
the class ForumThreadDAO method listByForumArea.
public List<ForumThread> listByForumArea(ForumArea forumArea) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<ForumThread> criteria = criteriaBuilder.createQuery(ForumThread.class);
Root<ForumThread> root = criteria.from(ForumThread.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(ForumThread_.forumArea), forumArea), criteriaBuilder.equal(root.get(ForumThread_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumThread in project muikku by otavanopisto.
the class ForumThreadDAO method listByForumAreaOrdered.
public List<ForumThread> listByForumAreaOrdered(ForumArea forumArea, int firstResult, int maxResults, boolean includeArchived) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<ForumThread> criteria = criteriaBuilder.createQuery(ForumThread.class);
Root<ForumThread> root = criteria.from(ForumThread.class);
criteria.select(root);
if (!includeArchived) {
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(ForumThread_.forumArea), forumArea), criteriaBuilder.equal(root.get(ForumThread_.archived), Boolean.FALSE)));
} else {
criteria.where(criteriaBuilder.equal(root.get(ForumThread_.forumArea), forumArea));
}
criteria.orderBy(criteriaBuilder.desc(root.get(ForumThread_.sticky)), criteriaBuilder.desc(root.get(ForumThread_.updated)));
TypedQuery<ForumThread> query = entityManager.createQuery(criteria);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
return query.getResultList();
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumThread 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();
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumThread in project muikku by otavanopisto.
the class AcceptanceTestsRESTService method deleteDiscussionThread.
@DELETE
@Path("/discussiongroups/{GROUPID}/discussions/{DISCUSSIONID}/threads/{ID}")
@RESTPermit(handling = Handling.UNSECURED)
public Response deleteDiscussionThread(@PathParam("GROUPID") Long groupId, @PathParam("DISCUSSIONID") Long discussionId, @PathParam("ID") Long id) {
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();
}
ForumThread thread = forumController.getForumThread(id);
if (thread == null) {
return Response.status(Status.NOT_FOUND).entity("Thread not found").build();
}
forumController.deleteThread(thread);
return Response.noContent().build();
}
Aggregations