use of fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply in project muikku by otavanopisto.
the class ForumThreadReplyDAO method findLatestReplyByArea.
public ForumThreadReply findLatestReplyByArea(ForumArea area) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<ForumThreadReply> criteria = criteriaBuilder.createQuery(ForumThreadReply.class);
Root<ForumThreadReply> root = criteria.from(ForumThreadReply.class);
Join<ForumThreadReply, ForumThread> join = root.join(ForumThreadReply_.thread);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(join.get(ForumThread_.forumArea), area), criteriaBuilder.equal(root.get(ForumThreadReply_.archived), Boolean.FALSE)));
criteria.orderBy(criteriaBuilder.desc(root.get(ForumThreadReply_.created)));
TypedQuery<ForumThreadReply> query = entityManager.createQuery(criteria);
query.setMaxResults(1);
return getSingleResult(query);
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply in project muikku by otavanopisto.
the class ForumThreadReplyDAO method create.
public ForumThreadReply create(ForumArea forumArea, ForumThread thread, String message, Date created, UserEntity creator, Date lastModified, UserEntity lastModifier, Boolean deleted, Boolean archived, ForumThreadReply parentReply) {
ForumThreadReply reply = new ForumThreadReply();
reply.setForumArea(forumArea);
reply.setThread(thread);
reply.setMessage(message);
reply.setCreated(created);
reply.setCreator(creator.getId());
reply.setLastModified(lastModified);
reply.setLastModifier(lastModifier.getId());
reply.setDeleted(deleted);
reply.setArchived(archived);
reply.setParentReply(parentReply);
getEntityManager().persist(reply);
return reply;
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply in project muikku by otavanopisto.
the class ForumThreadReplyDAO method listByForumThread.
public List<ForumThreadReply> listByForumThread(ForumThread forumThread, Integer firstResult, Integer maxResults, boolean includeArchived) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<ForumThreadReply> criteria = criteriaBuilder.createQuery(ForumThreadReply.class);
Root<ForumThreadReply> root = criteria.from(ForumThreadReply.class);
Join<ForumThreadReply, ForumThreadReply> parent = root.join(ForumThreadReply_.parentReply, JoinType.LEFT);
criteria.select(root);
if (!includeArchived) {
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(ForumThreadReply_.thread), forumThread), criteriaBuilder.equal(root.get(ForumThreadReply_.archived), Boolean.FALSE)));
} else {
criteria.where(criteriaBuilder.equal(root.get(ForumThreadReply_.thread), forumThread));
}
criteria.orderBy(criteriaBuilder.asc(criteriaBuilder.coalesce(parent.get(ForumThreadReply_.created), root.get(ForumThreadReply_.created))), criteriaBuilder.asc(root.get(ForumThreadReply_.created)));
TypedQuery<ForumThreadReply> query = entityManager.createQuery(criteria);
if (firstResult != null) {
query.setFirstResult(firstResult);
}
if (maxResults != null) {
query.setMaxResults(maxResults);
}
return query.getResultList();
}
use of fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply in project muikku by otavanopisto.
the class ForumRESTService method createReply.
@POST
@Path("/areas/{AREAID}/threads/{THREADID}/replies")
@RESTPermit(handling = Handling.INLINE)
public Response createReply(@PathParam("AREAID") Long areaId, @PathParam("THREADID") Long threadId, ForumThreadReplyRESTModel newReply) {
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 EnvironmentForumArea)) {
logger.severe(String.format("Trying to post thread reply for to non environment area (%d) from environment endpoint", forumArea.getId()));
return Response.status(Status.BAD_REQUEST).build();
}
if (sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_WRITE_ENVIRONMENT_MESSAGES)) {
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 archiveMessage.
public void archiveMessage(ForumMessage message) {
forumMessageDAO.archive(message);
if (message instanceof ForumThreadReply) {
ForumThreadReply reply = (ForumThreadReply) message;
ForumThreadReply latestReply = getLatestReply(reply.getThread());
if (latestReply != null)
forumThreadDAO.updateThreadUpdated(reply.getThread(), latestReply.getCreated());
else
forumThreadDAO.updateThreadUpdated(reply.getThread(), reply.getThread().getCreated());
}
}
Aggregations