private String postComment( String projectId, String entityId, String text, String name, String email) { if (projectId == null) throw new RuntimeException("projectId == null"); if (Str.isBlank(text)) throw new RuntimeException("Comment is empty."); Project project = projectDao.getById(projectId); AEntity entity = daoService.getById(entityId); Comment comment = commentDao.postComment(entity, "<nowiki>" + text + "</nowiki>", name, email, true); String message = "New comment posted"; if (!Str.isBlank(name)) message += " by " + name; subscriptionService.notifySubscribers(entity, message, project, email); project.updateHomepage(entity, true); String reference = ((ReferenceSupport) entity).getReference(); String label = ((LabelSupport) entity).getLabel(); ProjectEvent event = projectEventDao.postEvent( project, comment.getAuthorName() + " commented on " + reference + " " + label, entity); if (Str.isEmail(email)) subscriptionService.subscribe(email, entity); transactionService.commit(); webApplication.sendToConversationsByProject(project, event); return "<h2>Comment posted</h2><p>Thank you for your comment! It will be visible in a few minutes.</p><p>Back to <strong>" + KunagiUtl.createExternalRelativeHtmlAnchor(entity) + "</strong>.</p>"; }
@Test public void shouldSaveCollection() { // when commentDao.save(asList(aComment("1"), aComment("2"))); // then verify(template).bulkIndex(any()); }
@Test public void shouldSave() { // when commentDao.save(aComment("1")); // then verify(template).index(isA(IndexQuery.class)); }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); HttpSession session = request.getSession(); UserInfo user = (UserInfo) session.getAttribute("userinfo"); int uid = user.getU_id(); BlogDao bDao = new BlogDao(); // set number of blogs per page int showPageNum = 4; // 每页个数 int currPage = 1; if (request.getParameter("p") != null) currPage = Integer.parseInt(request.getParameter("p")); ArrayList<Blog> CollectBlogList = bDao.getCollectBlog(uid, showPageNum, currPage); long counts = bDao.getAllCollectBlogSum(uid); int totalPages = (int) counts / showPageNum + ((counts % showPageNum) > 0 ? 1 : 0); // get comments CommentDao cDao = new CommentDao(); for (Blog b : CollectBlogList) { ArrayList<Comment> CommentList = cDao.getAllCommentsByBid(b.getBid()); b.setCommentList(CommentList); b.setContentLink(); for (Comment c : CommentList) { c.setContentLink(); } } // put into DataMap Map<String, Object> root = new HashMap<>(); root.put("account", user.getU_account()); root.put("p", currPage); root.put("totalPages", totalPages); root.put("CollectBlogList", CollectBlogList); Template template = cfg.getTemplate("CollectBlog.ftl"); Writer out = response.getWriter(); try { template.process(root, out); } catch (TemplateException e) { WeiboLogger.exception(e); } }
@SuppressWarnings("unchecked") @Test public void shouldGet() { // given FacetedPage page = mock(FacetedPage.class); given(template.queryForPage(isA(SearchQuery.class), isA(Class.class))).willReturn(page); // when commentDao.get(0, 10); // then verify(template).queryForPage(isA(SearchQuery.class), isA(Class.class)); }
@Override public Page processRequest(HttpServletRequest request) { Page result = this; if ("new".equals(request.getParameter("action"))) { Member member = (Member) request.getSession().getAttribute("user"); result = new TopicEdit(this, new Topic(member)); } else if ("previous".equals(request.getParameter("action"))) { if (page > 1) { page--; } } else if ("next".equals(request.getParameter("action"))) { if (page < getNumberOfPages()) { page++; } } else if (isAction("edit")) { long id = Long.parseLong(request.getParameter("actionValue")); result = new TopicEdit(this, dao.find(id)); } else if (isAction("remove")) { long topicId = Long.parseLong(request.getParameter("actionValue")); Topic topic = dao.find(topicId); CommentDao commentDao = new CommentDao(); for (Comment comment : topic.getComments()) { commentDao.remove(comment); } dao.remove(topicId); } return result; }
@Before public void setup() { commentDao.indexName = "rs"; }
public Set<Comment> getComments() { return commentDao.getCommentsByParent(this); }