@Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int postId = Integer.parseInt(request.getParameter("post_id")); PostingTask post = service.getById(postId); SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat time = new SimpleDateFormat("HH:mm"); JSONObject json = new JSONObject(); { json.put("now", date.format(new Date())); json.put("date", date.format(post.getPostTime())); json.put("time", time.format(post.getPostTime())); Date deleteTime = post.getDeleteTime(); if (deleteTime == null) { Date now = new Date(post.getPostTime().getTime() + 60 * 60 * 1000); json.put("del_date", date.format(now)); json.put("del_time", time.format(now)); } else { json.put("del_date", date.format(deleteTime)); json.put("del_time", time.format(deleteTime)); } } response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().print(json.toString()); }
@Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); User user = (User) session.getAttribute("user"); int offset = Integer.parseInt(request.getParameter("iDisplayStart")); int limit = Integer.parseInt(request.getParameter("iDisplayLength")); Integer wallId = null; try { wallId = service.getById(Integer.parseInt(request.getParameter("postId"))).getWallId(); } catch (NumberFormatException ignored) { } List<PostingTask> posts = service.getByUserIdWithParameters( user.getId(), offset, limit, "POSTED", request.getParameter("sSearch"), request.getParameter("sSortDir_0"), wallId); int postCount = service.getCountAllByUserIdWithParameters( user.getId(), "POSTED", request.getParameter("sSearch"), wallId); JSONObject result = new JSONObject(); JSONArray array = new JSONArray(); posts = loadingStatistics(posts, user.getId()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm"); for (PostingTask post : posts) { try { JSONArray row = new JSONArray(); row.put( post.getPost().getMessage().length() > 45 ? post.getPost().getMessage().substring(0, 42) + "..." : post.getPost().getMessage()); row.put(post.getOwner().getName()); row.put(post.getFullId()); row.put(dateFormat.format(post.getPostTime())); PostingTaskImpl.Stats stats = post.getStats(); String data = stats.getLikes() + "|" + stats.getRePosts() + "|" + stats.getComments(); row.put(data); row.put(post.getPostId()); row.put(post.getId()); array.put(row); } catch (Exception e) { LOG.warn("Post id = " + post.getPostId() + " deleted."); service.delete(post.getId()); } } result.put("iTotalDisplayRecords", postCount); result.put("aaData", array); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().print(result.toString()); }