/src/com/shroggle/presentation/forum/ShowThreadAction.java

https://github.com/shroggle/Shroggle · Java · 175 lines · 125 code · 36 blank · 14 comment · 14 complexity · 2414a68f496c5999e552647245fbb1d7 MD5 · raw file

  1. /*********************************************************************
  2. * *
  3. * Copyright (c) 2007-2011 by Web-Deva. *
  4. * All rights reserved. *
  5. * *
  6. * This computer program is protected by copyright law and *
  7. * international treaties. Unauthorized reproduction or distribution *
  8. * of this program, or any portion of it, may result in severe civil *
  9. * and criminal penalties, and will be prosecuted to the maximum *
  10. * extent possible under the law. *
  11. * *
  12. *********************************************************************/
  13. package com.shroggle.presentation.forum;
  14. import com.shroggle.entity.ForumThread;
  15. import com.shroggle.entity.Site;
  16. import com.shroggle.entity.User;
  17. import com.shroggle.entity.Widget;
  18. import com.shroggle.exception.CannotFindThreadException;
  19. import com.shroggle.logic.forum.ForumRightsManager;
  20. import com.shroggle.logic.site.AccessGroupManager;
  21. import com.shroggle.logic.user.UsersManager;
  22. import com.shroggle.presentation.Action;
  23. import com.shroggle.presentation.ActionUtil;
  24. import com.shroggle.util.ServiceLocator;
  25. import com.shroggle.util.context.SessionStorage;
  26. import com.shroggle.util.persistance.Persistance;
  27. import net.sourceforge.stripes.action.DefaultHandler;
  28. import net.sourceforge.stripes.action.ForwardResolution;
  29. import net.sourceforge.stripes.action.Resolution;
  30. import net.sourceforge.stripes.action.UrlBinding;
  31. @UrlBinding("/forum/showThread.action")
  32. public class ShowThreadAction extends Action {
  33. private SessionStorage sessionStorage = ServiceLocator.getSessionStorage();
  34. private Persistance persistance = ServiceLocator.getPersistance();
  35. //Initialized by true if user already voted for this thread(ForumThreadVotingService)
  36. public int threadId;
  37. public boolean alreadyVoted;
  38. private ForumThread forumThread;
  39. private boolean isPoll;
  40. public boolean isShowOnUserPages;
  41. private boolean createSubForumRight;
  42. private boolean createThreadRight;
  43. private boolean createPostRight;
  44. private boolean createPollRight;
  45. private boolean voteInPollRight;
  46. private boolean manageSubFroumsRight;
  47. private boolean managePostsRight;
  48. private boolean shouldShowRegisterLinks;
  49. public int widgetId;
  50. private Integer activePageVisitorId;
  51. private Integer loginedVisitorId;
  52. @DefaultHandler
  53. public Resolution execute() {
  54. activePageVisitorId = ActionUtil.getPageVisitorId(getContext().getRequest().getCookies());
  55. final User user = new UsersManager().getLoginedUser();
  56. loginedVisitorId = user != null ? user.getUserId() : null;
  57. forumThread = persistance.getForumThreadById(threadId);
  58. if (forumThread == null) {
  59. throw new CannotFindThreadException("Cannot find thread by Id=" + threadId);
  60. }
  61. final Widget widget = persistance.getWidget(widgetId);
  62. final Site site;
  63. if (widget != null) {
  64. site = widget.getSite();
  65. } else {
  66. site = persistance.getSite(forumThread.getSubForum().getForum().getSiteId());
  67. }
  68. if (forumThread == null) {
  69. throw new CannotFindThreadException("Cannot find thread with Id=" + threadId);
  70. }
  71. //Checking if user already voted in this thread
  72. String respondedntId = String.valueOf(user != null ? user.getUserId() : null);
  73. if (respondedntId.isEmpty() || respondedntId.equals("null")) {
  74. respondedntId = getContext().getRequest().getRemoteAddr();
  75. }
  76. if (persistance.getForumThreadVoteByRespondentIdAndThreadId(respondedntId, threadId) != null) {
  77. alreadyVoted = true;
  78. }
  79. createSubForumRight = AccessGroupManager.isUserFitsForAccessGroup(forumThread.getSubForum().getForum().getCreateSubForumRight(),
  80. user, site);
  81. createThreadRight = AccessGroupManager.isUserFitsForAccessGroup(forumThread.getSubForum().getForum().getCreateThreadRight(),
  82. user, site);
  83. createPostRight = AccessGroupManager.isUserFitsForAccessGroup(forumThread.getSubForum().getForum().getCreatePostRight(),
  84. user, site);
  85. createPollRight = AccessGroupManager.isUserFitsForAccessGroup(forumThread.getSubForum().getForum().getCreatePollRight(),
  86. user, site);
  87. voteInPollRight = AccessGroupManager.isUserFitsForAccessGroup(forumThread.getSubForum().getForum().getVoteInPollRight(),
  88. user, site);
  89. manageSubFroumsRight = AccessGroupManager.isUserFitsForAccessGroup(forumThread.getSubForum().getForum().getManageSubForumsRight(),
  90. user, site);
  91. managePostsRight = AccessGroupManager.isUserFitsForAccessGroup(forumThread.getSubForum().getForum().getManagePostsRight(),
  92. user, site);
  93. isPoll = forumThread.getPollQuestion() != null;
  94. shouldShowRegisterLinks = ForumRightsManager.isShouldShowRegisterLinks(user, forumThread.getSubForum().getForum());
  95. return new ForwardResolution("/forum/showThread.jsp");
  96. }
  97. public boolean isShouldShowRegisterLinks() {
  98. return shouldShowRegisterLinks;
  99. }
  100. public Integer getLoginedVisitorId() {
  101. return loginedVisitorId;
  102. }
  103. public void setLoginedVisitorId(int loginedVisitorId) {
  104. this.loginedVisitorId = loginedVisitorId;
  105. }
  106. public boolean isManageSubFroumsRight() {
  107. return manageSubFroumsRight;
  108. }
  109. public boolean isManagePostsRight() {
  110. return managePostsRight;
  111. }
  112. public boolean isCreateSubForumRight() {
  113. return createSubForumRight;
  114. }
  115. public boolean isCreateThreadRight() {
  116. return createThreadRight;
  117. }
  118. public boolean isCreatePostRight() {
  119. return createPostRight;
  120. }
  121. public boolean isCreatePollRight() {
  122. return createPollRight;
  123. }
  124. public boolean isVoteInPollRight() {
  125. return voteInPollRight;
  126. }
  127. public boolean isPoll() {
  128. return isPoll;
  129. }
  130. public ForumThread getForumThread() {
  131. return forumThread;
  132. }
  133. public Persistance getPersistance() {
  134. return persistance;
  135. }
  136. public Integer getActivePageVisitorId() {
  137. return activePageVisitorId;
  138. }
  139. }