Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/MonitoringAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/MonitoringAction.java,v diff -u -r1.39 -r1.39.6.1 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/MonitoringAction.java 17 Sep 2008 02:28:50 -0000 1.39 +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/MonitoringAction.java 22 Apr 2009 07:35:59 -0000 1.39.6.1 @@ -81,812 +81,800 @@ public class MonitoringAction extends Action { - private static Logger log = Logger.getLogger(MonitoringAction.class); + private static Logger log = Logger.getLogger(MonitoringAction.class); - private IForumService forumService; + private IForumService forumService; - private class SessionDTOComparator implements Comparator { - public int compare(SessionDTO o1, SessionDTO o2) { - if (o1 != null && o2 != null) { - return o1.getSessionName().compareTo(o2.getSessionName()); - } - else if (o1 != null) { - return 1; - } - else { - return -1; - } - } + private class SessionDTOComparator implements Comparator { + public int compare(SessionDTO o1, SessionDTO o2) { + if (o1 != null && o2 != null) { + return o1.getSessionName().compareTo(o2.getSessionName()); + } else if (o1 != null) { + return 1; + } else { + return -1; + } } + } - private class ForumUserComparator implements Comparator { - public int compare(ForumUser o1, ForumUser o2) { - if (o1 != null && o2 != null) { - return o1.getLoginName().compareTo(o2.getLoginName()); - } - else if (o1 != null) { - return 1; - } - else { - return -1; - } - } + private class ForumUserComparator implements Comparator { + public int compare(ForumUser o1, ForumUser o2) { + if (o1 != null && o2 != null) { + return o1.getLoginName().compareTo(o2.getLoginName()); + } else if (o1 != null) { + return 1; + } else { + return -1; + } } + } - private class UserDTOComparator implements Comparator { - public int compare(UserDTO o1, UserDTO o2) { - if (o1 != null && o2 != null) { - return o1.getLoginName().compareTo(o2.getLoginName()); - } - else if (o1 != null) { - return 1; - } - else { - return -1; - } - } + private class UserDTOComparator implements Comparator { + public int compare(UserDTO o1, UserDTO o2) { + if (o1 != null && o2 != null) { + return o1.getLoginName().compareTo(o2.getLoginName()); + } else if (o1 != null) { + return 1; + } else { + return -1; + } } + } - /** - * Action method entry. - */ - @Override - public final ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws Exception { - String param = mapping.getParameter(); + /** + * Action method entry. + */ + @Override + public final ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + String param = mapping.getParameter(); - if (param.equals("init")) { - return init(mapping, form, request, response); - } - //refresh statistic page by Ajax call. - if (param.equals("statistic")) { - return statistic(mapping, form, request, response); - } - // ***************** Marks Functions ******************** - if (param.equals("viewAllMarks")) { - return viewAllMarks(mapping, form, request, response); - } - if (param.equals("downloadMarks")) { - return downloadMarks(mapping, form, request, response); - } - if (param.equals("viewUserMark")) { - return viewUserMark(mapping, form, request, response); - } - if (param.equals("editMark")) { - return editMark(mapping, form, request, response); - } - if (param.equals("updateMark")) { - return updateMark(mapping, form, request, response); - } + if (param.equals("init")) { + return init(mapping, form, request, response); + } + //refresh statistic page by Ajax call. + if (param.equals("statistic")) { + return statistic(mapping, form, request, response); + } + // ***************** Marks Functions ******************** + if (param.equals("viewAllMarks")) { + return viewAllMarks(mapping, form, request, response); + } + if (param.equals("downloadMarks")) { + return downloadMarks(mapping, form, request, response); + } + if (param.equals("viewUserMark")) { + return viewUserMark(mapping, form, request, response); + } + if (param.equals("editMark")) { + return editMark(mapping, form, request, response); + } + if (param.equals("updateMark")) { + return updateMark(mapping, form, request, response); + } - if (param.equals("releaseMark")) { - return releaseMark(mapping, form, request, response); - } + if (param.equals("releaseMark")) { + return releaseMark(mapping, form, request, response); + } - // ***************** Miscellaneous ******************** - if (param.equals("viewTopic")) { - return viewTopic(mapping, form, request, response); - } - if (param.equals("viewTopicTree")) { - return viewTopicTree(mapping, form, request, response); - } + // ***************** Miscellaneous ******************** + if (param.equals("viewTopic")) { + return viewTopic(mapping, form, request, response); + } + if (param.equals("viewTopicTree")) { + return viewTopicTree(mapping, form, request, response); + } - if (param.equals("viewReflection")) { - return viewReflection(mapping, form, request, response); - } - - return mapping.findForward("error"); + if (param.equals("viewReflection")) { + return viewReflection(mapping, form, request, response); } - /** - * The initial method for monitoring - */ - private ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { + return mapping.findForward("error"); + } - // perform the actions for all the tabs. - doTabs(mapping, form, request, response); + /** + * The initial method for monitoring + */ + private ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { - return mapping.findForward("load"); - } + // perform the actions for all the tabs. + doTabs(mapping, form, request, response); - private ActionForward doTabs(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - //set back tool content ID - String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, contentFolderID); + return mapping.findForward("load"); + } - Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); - request.setAttribute(AttributeNames.PARAM_TOOL_CONTENT_ID, toolContentID); + private ActionForward doTabs(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + //set back tool content ID + String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); + request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, contentFolderID); - request.setAttribute("initialTabId", WebUtil.readLongParam(request, AttributeNames.PARAM_CURRENT_TAB, true)); + Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); + request.setAttribute(AttributeNames.PARAM_TOOL_CONTENT_ID, toolContentID); - this.summary(mapping, form, request, response); - this.viewInstructions(mapping, form, request, response); - this.viewActivity(mapping, form, request, response, toolContentID); - this.statistic(mapping, form, request, response); - return mapping.findForward("load"); - } + request.setAttribute("initialTabId", WebUtil.readLongParam(request, AttributeNames.PARAM_CURRENT_TAB, true)); - /** - * The initial method for monitoring. List all users according to given - * Content ID. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward summary(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); + this.summary(mapping, form, request, response); + this.viewInstructions(mapping, form, request, response); + this.viewActivity(mapping, form, request, response, toolContentID); + this.statistic(mapping, form, request, response); + return mapping.findForward("load"); + } - forumService = getForumService(); - List sessionsList = forumService.getSessionsByContentId(toolContentID); + /** + * The initial method for monitoring. List all users according to given + * Content ID. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward summary(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); - // A forum clone required for listing the advanced options LDEV-1662 - Forum forumClone = null; + forumService = getForumService(); + List sessionsList = forumService.getSessionsByContentId(toolContentID); - Map sessionUsersMap = new TreeMap(this.new SessionDTOComparator()); - // build a map with all users in the submitFilesSessionList - Iterator it = sessionsList.iterator(); - while (it.hasNext()) { - SessionDTO sessionDto = new SessionDTO(); - ForumToolSession fts = (ForumToolSession) it.next(); - boolean hasReflection = fts.getForum().isReflectOnActivity(); + // A forum clone required for listing the advanced options LDEV-1662 + Forum forumClone = null; - if (forumClone == null) { - forumClone = (Forum) fts.getForum().clone(); - request.setAttribute("forum", forumClone); - } + Map sessionUsersMap = new TreeMap(this.new SessionDTOComparator()); + // build a map with all users in the submitFilesSessionList + Iterator it = sessionsList.iterator(); + while (it.hasNext()) { + SessionDTO sessionDto = new SessionDTO(); + ForumToolSession fts = (ForumToolSession) it.next(); + boolean hasReflection = fts.getForum().isReflectOnActivity(); - sessionDto.setSessionID(fts.getSessionId()); - sessionDto.setSessionName(fts.getSessionName()); - List userList = forumService.getUsersBySessionId(fts.getSessionId()); + if (forumClone == null) { + forumClone = (Forum) fts.getForum().clone(); + request.setAttribute("forum", forumClone); + } - //sort and create DTO list - List topicList = forumService.getAllTopicsFromSession(fts.getSessionId()); - Map topicsByUser = getTopicsSortedByAuthor(topicList); + sessionDto.setSessionID(fts.getSessionId()); + sessionDto.setSessionName(fts.getSessionName()); + List userList = forumService.getUsersBySessionId(fts.getSessionId()); - Set dtoList = new TreeSet(this.new UserDTOComparator()); - Iterator iter = userList.iterator(); - while (iter.hasNext()) { - ForumUser user = (ForumUser) iter.next(); - UserDTO userDTO = new UserDTO(user); - userDTO.setHasRefection(hasReflection); + //sort and create DTO list + List topicList = forumService.getAllTopicsFromSession(fts.getSessionId()); + Map topicsByUser = getTopicsSortedByAuthor(topicList); - userDTO.setAnyPostsMarked(false); - userDTO.setNoOfPosts(0); + Set dtoList = new TreeSet(this.new UserDTOComparator()); + Iterator iter = userList.iterator(); + while (iter.hasNext()) { + ForumUser user = (ForumUser) iter.next(); + UserDTO userDTO = new UserDTO(user); + userDTO.setHasRefection(hasReflection); - List messages = (List) topicsByUser.get(user); - if (messages != null && messages.size() > 0) { - userDTO.setNoOfPosts(messages.size()); - for (MessageDTO message : messages) { - if (message.getMark() != null) { - userDTO.setAnyPostsMarked(true); - break; - } - } - } - dtoList.add(userDTO); - } + userDTO.setAnyPostsMarked(false); + userDTO.setNoOfPosts(0); - sessionUsersMap.put(sessionDto, dtoList); + List messages = (List) topicsByUser.get(user); + if (messages != null && messages.size() > 0) { + userDTO.setNoOfPosts(messages.size()); + for (MessageDTO message : messages) { + if (message.getMark() != null) { + userDTO.setAnyPostsMarked(true); + break; + } + } } + dtoList.add(userDTO); + } - // request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID,sessionID); - request.setAttribute("sessionUserMap", sessionUsersMap); - return mapping.findForward("success"); - + sessionUsersMap.put(sessionDto, dtoList); } - /** - * Download marks for all users in a speical session. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward downloadMarks(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - Long sessionID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID)); - forumService = getForumService(); - List topicList = forumService.getAllTopicsFromSession(sessionID); - // construct Excel file format and download - ActionMessages errors = new ActionMessages(); - try { - // create an empty excel file - HSSFWorkbook wb = new HSSFWorkbook(); + // request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID,sessionID); + request.setAttribute("sessionUserMap", sessionUsersMap); + return mapping.findForward("success"); - HSSFSheet sheet = wb.createSheet("Marks"); - sheet.setColumnWidth((short) 0, (short) 5000); - HSSFRow row = null; - HSSFCell cell; - Iterator iter = getTopicsSortedByAuthor(topicList).values().iterator(); - Iterator dtoIter; - boolean first = true; - int idx = 0; - int fileCount = 0; - while (iter.hasNext()) { - List list = (List) iter.next(); - dtoIter = list.iterator(); - first = true; + } - while (dtoIter.hasNext()) { - MessageDTO dto = (MessageDTO) dtoIter.next(); - if (first) { - first = false; - row = sheet.createRow(0); - cell = row.createCell((short) idx); - cell.setEncoding(HSSFCell.ENCODING_UTF_16); - cell.setCellValue(getMessageService().getMessage("lable.topic.title.subject")); - sheet.setColumnWidth((short) idx, (short) 8000); - ++idx; + /** + * Download marks for all users in a speical session. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward downloadMarks(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + Long sessionID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID)); + forumService = getForumService(); + List topicList = forumService.getAllTopicsFromSession(sessionID); + // construct Excel file format and download + ActionMessages errors = new ActionMessages(); + try { + // create an empty excel file + HSSFWorkbook wb = new HSSFWorkbook(); - cell = row.createCell((short) idx); - cell.setEncoding(HSSFCell.ENCODING_UTF_16); - cell.setCellValue(getMessageService().getMessage("lable.topic.title.author")); - sheet.setColumnWidth((short) idx, (short) 8000); - ++idx; + HSSFSheet sheet = wb.createSheet("Marks"); + sheet.setColumnWidth((short) 0, (short) 5000); + HSSFRow row = null; + HSSFCell cell; + Iterator iter = getTopicsSortedByAuthor(topicList).values().iterator(); + Iterator dtoIter; + boolean first = true; + int idx = 0; + int fileCount = 0; + while (iter.hasNext()) { + List list = (List) iter.next(); + dtoIter = list.iterator(); + first = true; - cell = row.createCell((short) idx); - cell.setEncoding(HSSFCell.ENCODING_UTF_16); - cell.setCellValue(getMessageService().getMessage("label.download.marks.heading.date")); - sheet.setColumnWidth((short) idx, (short) 8000); - ++idx; + while (dtoIter.hasNext()) { + MessageDTO dto = (MessageDTO) dtoIter.next(); + if (first) { + first = false; + row = sheet.createRow(0); + cell = row.createCell((short) idx); + cell.setEncoding(HSSFCell.ENCODING_UTF_16); + cell.setCellValue(getMessageService().getMessage("lable.topic.title.subject")); + sheet.setColumnWidth((short) idx, (short) 8000); + ++idx; - cell = row.createCell((short) idx); - cell.setEncoding(HSSFCell.ENCODING_UTF_16); - cell.setCellValue(getMessageService().getMessage("label.download.marks.heading.marks")); - sheet.setColumnWidth((short) idx, (short) 8000); - ++idx; + cell = row.createCell((short) idx); + cell.setEncoding(HSSFCell.ENCODING_UTF_16); + cell.setCellValue(getMessageService().getMessage("lable.topic.title.author")); + sheet.setColumnWidth((short) idx, (short) 8000); + ++idx; - cell = row.createCell((short) idx); - cell.setEncoding(HSSFCell.ENCODING_UTF_16); - cell.setCellValue(getMessageService().getMessage("label.download.marks.heading.comments")); - sheet.setColumnWidth((short) idx, (short) 8000); - ++idx; - } - ++fileCount; - idx = 0; - row = sheet.createRow(fileCount); - cell = row.createCell((short) idx++); - cell.setEncoding(HSSFCell.ENCODING_UTF_16); - cell.setCellValue(dto.getMessage().getSubject()); + cell = row.createCell((short) idx); + cell.setEncoding(HSSFCell.ENCODING_UTF_16); + cell.setCellValue(getMessageService().getMessage("label.download.marks.heading.date")); + sheet.setColumnWidth((short) idx, (short) 8000); + ++idx; - cell = row.createCell((short) idx++); - cell.setEncoding(HSSFCell.ENCODING_UTF_16); - cell.setCellValue(dto.getAuthor()); + cell = row.createCell((short) idx); + cell.setEncoding(HSSFCell.ENCODING_UTF_16); + cell.setCellValue(getMessageService().getMessage("label.download.marks.heading.marks")); + sheet.setColumnWidth((short) idx, (short) 8000); + ++idx; - cell = row.createCell((short) idx++); - cell.setEncoding(HSSFCell.ENCODING_UTF_16); - cell.setCellValue(DateFormat.getInstance().format(dto.getMessage().getCreated())); + cell = row.createCell((short) idx); + cell.setEncoding(HSSFCell.ENCODING_UTF_16); + cell.setCellValue(getMessageService().getMessage("label.download.marks.heading.comments")); + sheet.setColumnWidth((short) idx, (short) 8000); + ++idx; + } + ++fileCount; + idx = 0; + row = sheet.createRow(fileCount); + cell = row.createCell((short) idx++); + cell.setEncoding(HSSFCell.ENCODING_UTF_16); + cell.setCellValue(dto.getMessage().getSubject()); - cell = row.createCell((short) idx++); - cell.setEncoding(HSSFCell.ENCODING_UTF_16); + cell = row.createCell((short) idx++); + cell.setEncoding(HSSFCell.ENCODING_UTF_16); + cell.setCellValue(dto.getAuthor()); - if (dto.getMessage() != null && dto.getMessage().getReport() != null - && dto.getMessage().getReport().getMark() != null) { - cell.setCellValue(NumberUtil.formatLocalisedNumber(dto.getMessage().getReport().getMark(), request - .getLocale(), 2)); - } - else { - cell.setCellValue(""); - } + cell = row.createCell((short) idx++); + cell.setEncoding(HSSFCell.ENCODING_UTF_16); + cell.setCellValue(DateFormat.getInstance().format(dto.getMessage().getCreated())); - cell = row.createCell((short) idx++); - cell.setEncoding(HSSFCell.ENCODING_UTF_16); - if (dto.getMessage() != null && dto.getMessage().getReport() != null) { - cell.setCellValue(dto.getMessage().getReport().getComment()); - } - else { - cell.setCellValue(""); - } - } - } - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - wb.write(bos); - // construct download file response header - String fileName = "marks" + sessionID + ".xls"; - String mineType = "application/vnd.ms-excel"; - String header = "attachment; filename=\"" + fileName + "\";"; - response.setContentType(mineType); - response.setHeader("Content-Disposition", header); + cell = row.createCell((short) idx++); + cell.setEncoding(HSSFCell.ENCODING_UTF_16); - byte[] data = bos.toByteArray(); - response.getOutputStream().write(data, 0, data.length); - response.getOutputStream().flush(); - } - catch (IOException e) { - MonitoringAction.log.error(e); - errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("monitoring.download.error", e.toString())); - } + if (dto.getMessage() != null && dto.getMessage().getReport() != null + && dto.getMessage().getReport().getMark() != null) { + cell.setCellValue(NumberUtil.formatLocalisedNumber(dto.getMessage().getReport().getMark(), + request.getLocale(), 2)); + } else { + cell.setCellValue(""); + } - if (!errors.isEmpty()) { - saveErrors(request, errors); - request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, sessionID); - return mapping.getInputForward(); + cell = row.createCell((short) idx++); + cell.setEncoding(HSSFCell.ENCODING_UTF_16); + if (dto.getMessage() != null && dto.getMessage().getReport() != null) { + cell.setCellValue(dto.getMessage().getReport().getComment()); + } else { + cell.setCellValue(""); + } } + } + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + wb.write(bos); + // construct download file response header + String fileName = "marks" + sessionID + ".xls"; + String mineType = "application/vnd.ms-excel"; + String header = "attachment; filename=\"" + fileName + "\";"; + response.setContentType(mineType); + response.setHeader("Content-Disposition", header); - return null; + byte[] data = bos.toByteArray(); + response.getOutputStream().write(data, 0, data.length); + response.getOutputStream().flush(); + } catch (IOException e) { + MonitoringAction.log.error(e); + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("monitoring.download.error", e.toString())); } - /** - * View activity for content. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward viewActivity(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response, Long toolContentID) { + if (!errors.isEmpty()) { + saveErrors(request, errors); + request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, sessionID); + return mapping.getInputForward(); + } - forumService = getForumService(); - Forum forum = forumService.getForumByContentId(toolContentID); - // if can not find out forum, echo back error message - if (forum == null) { - ActionErrors errors = new ActionErrors(); - errors.add("activity.globel", new ActionMessage("error.fail.get.forum")); - this.addErrors(request, errors); - return mapping.getInputForward(); - } - String title = forum.getTitle(); - String instruction = forum.getInstructions(); + return null; + } - boolean isForumEditable = ForumWebUtils.isForumEditable(forum); - request.setAttribute(ForumConstants.PAGE_EDITABLE, new Boolean(isForumEditable)); - request.setAttribute("title", title); - request.setAttribute("instruction", instruction); - return mapping.findForward("success"); + /** + * View activity for content. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward viewActivity(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response, Long toolContentID) { + + forumService = getForumService(); + Forum forum = forumService.getForumByContentId(toolContentID); + // if can not find out forum, echo back error message + if (forum == null) { + ActionErrors errors = new ActionErrors(); + errors.add("activity.globel", new ActionMessage("error.fail.get.forum")); + this.addErrors(request, errors); + return mapping.getInputForward(); } + String title = forum.getTitle(); + String instruction = forum.getInstructions(); - /** - * View instruction information for a content. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward viewInstructions(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); + boolean isForumEditable = ForumWebUtils.isForumEditable(forum); + request.setAttribute(ForumConstants.PAGE_EDITABLE, new Boolean(isForumEditable)); + request.setAttribute("title", title); + request.setAttribute("instruction", instruction); + return mapping.findForward("success"); + } - forumService = getForumService(); - Forum forum = forumService.getForumByContentId(toolContentID); - // if can not find out forum, echo back error message - if (forum == null) { - ActionErrors errors = new ActionErrors(); - errors.add("instruction.globel", new ActionMessage("error.fail.get.forum")); - this.addErrors(request, errors); - return mapping.getInputForward(); - } + /** + * View instruction information for a content. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward viewInstructions(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); - ForumForm forumForm = new ForumForm(); - forumForm.setForum(forum); - - request.setAttribute("forumBean", forumForm); - return mapping.findForward("success"); + forumService = getForumService(); + Forum forum = forumService.getForumByContentId(toolContentID); + // if can not find out forum, echo back error message + if (forum == null) { + ActionErrors errors = new ActionErrors(); + errors.add("instruction.globel", new ActionMessage("error.fail.get.forum")); + this.addErrors(request, errors); + return mapping.getInputForward(); } - /** - * Show statisitc page for a session. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward statistic(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); + ForumForm forumForm = new ForumForm(); + forumForm.setForum(forum); - forumService = getForumService(); - Map sessionTopicsMap = new TreeMap>(this.new SessionDTOComparator()); - Map sessionAvaMarkMap = new HashMap(); - Map sessionTotalMsgMap = new HashMap(); + request.setAttribute("forumBean", forumForm); + return mapping.findForward("success"); + } - List sessList = forumService.getSessionsByContentId(toolContentID); - Iterator sessIter = sessList.iterator(); - while (sessIter.hasNext()) { - ForumToolSession session = (ForumToolSession) sessIter.next(); - List topicList = forumService.getRootTopics(session.getSessionId()); - Iterator iter = topicList.iterator(); - int totalMsg = 0; - int msgNum; - float totalMsgMarkSum = 0; - float msgMarkSum = 0; - for (; iter.hasNext();) { - MessageDTO msgDto = (MessageDTO) iter.next(); - // get all message under this topic - List topicThread = forumService.getTopicThread(msgDto.getMessage().getUid()); - // loop all message under this topic - msgMarkSum = 0; - Iterator threadIter = topicThread.iterator(); - for (msgNum = 0; threadIter.hasNext(); msgNum++) { - MessageDTO dto = (MessageDTO) threadIter.next(); - if (dto.getMark() != null) { - msgMarkSum += dto.getMark().floatValue(); - } - } - // summary to total mark - totalMsgMarkSum += msgMarkSum; - // set average mark to topic message DTO for display use - msgDto.setMark(msgMarkSum / msgNum); - totalMsg += msgNum; - } + /** + * Show statisitc page for a session. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward statistic(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); - float averMark = totalMsg == 0 ? 0 : totalMsgMarkSum / totalMsg; + forumService = getForumService(); + Map sessionTopicsMap = new TreeMap>(this.new SessionDTOComparator()); + Map sessionAvaMarkMap = new HashMap(); + Map sessionTotalMsgMap = new HashMap(); - SessionDTO sessionDto = new SessionDTO(); - sessionDto.setSessionID(session.getSessionId()); - sessionDto.setSessionName(session.getSessionName()); - - sessionTopicsMap.put(sessionDto, topicList); - sessionAvaMarkMap.put(session.getSessionId(), averMark); - sessionTotalMsgMap.put(session.getSessionId(), new Integer(totalMsg)); + List sessList = forumService.getSessionsByContentId(toolContentID); + Iterator sessIter = sessList.iterator(); + while (sessIter.hasNext()) { + ForumToolSession session = (ForumToolSession) sessIter.next(); + List topicList = forumService.getRootTopics(session.getSessionId()); + Iterator iter = topicList.iterator(); + int totalMsg = 0; + int msgNum; + float totalMsgMarkSum = 0; + float msgMarkSum = 0; + for (; iter.hasNext();) { + MessageDTO msgDto = (MessageDTO) iter.next(); + // get all message under this topic + List topicThread = forumService.getTopicThread(msgDto.getMessage().getUid()); + // loop all message under this topic + msgMarkSum = 0; + Iterator threadIter = topicThread.iterator(); + for (msgNum = 0; threadIter.hasNext(); msgNum++) { + MessageDTO dto = (MessageDTO) threadIter.next(); + if (dto.getMark() != null) { + msgMarkSum += dto.getMark().floatValue(); + } } - request.setAttribute("topicList", sessionTopicsMap); - request.setAttribute("markAverage", sessionAvaMarkMap); - request.setAttribute("totalMessage", sessionTotalMsgMap); - return mapping.findForward("success"); - } + // summary to total mark + totalMsgMarkSum += msgMarkSum; + // set average mark to topic message DTO for display use + msgDto.setMark(msgMarkSum / msgNum); + totalMsg += msgNum; + } - /** - * View all messages under one topic. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward viewTopicTree(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { + float averMark = totalMsg == 0 ? 0 : totalMsgMarkSum / totalMsg; - Long rootTopicId = WebUtil.readLongParam(request, ForumConstants.ATTR_TOPIC_ID); - forumService = getForumService(); - // get root topic list - List msgDtoList = forumService.getTopicThread(rootTopicId); - request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD, msgDtoList); + SessionDTO sessionDto = new SessionDTO(); + sessionDto.setSessionID(session.getSessionId()); + sessionDto.setSessionName(session.getSessionName()); - return mapping.findForward("success"); + sessionTopicsMap.put(sessionDto, topicList); + sessionAvaMarkMap.put(session.getSessionId(), averMark); + sessionTotalMsgMap.put(session.getSessionId(), new Integer(totalMsg)); } + request.setAttribute("topicList", sessionTopicsMap); + request.setAttribute("markAverage", sessionAvaMarkMap); + request.setAttribute("totalMessage", sessionTotalMsgMap); + return mapping.findForward("success"); + } - private ActionForward viewReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { + /** + * View all messages under one topic. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward viewTopicTree(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { - Long uid = WebUtil.readLongParam(request, ForumConstants.ATTR_USER_UID); - Long sessionID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID); + Long rootTopicId = WebUtil.readLongParam(request, ForumConstants.ATTR_TOPIC_ID); + forumService = getForumService(); + // get root topic list + List msgDtoList = forumService.getTopicThread(rootTopicId); + request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD, msgDtoList); - ForumUser user = forumService.getUser(uid); - NotebookEntry notebookEntry = forumService.getEntry(sessionID, CoreNotebookConstants.NOTEBOOK_TOOL, - ForumConstants.TOOL_SIGNATURE, user.getUserId().intValue()); + return mapping.findForward("success"); + } - ForumToolSession session = forumService.getSessionBySessionId(sessionID); + private ActionForward viewReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { - UserDTO userDTO = new UserDTO(user); - if (notebookEntry == null) { - userDTO.setFinishReflection(false); - userDTO.setReflect(null); - } - else { - userDTO.setFinishReflection(true); - userDTO.setReflect(notebookEntry.getEntry()); - } - userDTO.setReflectInstrctions(session.getForum().getReflectInstructions()); + Long uid = WebUtil.readLongParam(request, ForumConstants.ATTR_USER_UID); + Long sessionID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID); - request.setAttribute("userDTO", userDTO); - return mapping.findForward("success"); - } + ForumUser user = forumService.getUser(uid); + NotebookEntry notebookEntry = forumService.getEntry(sessionID, CoreNotebookConstants.NOTEBOOK_TOOL, + ForumConstants.TOOL_SIGNATURE, user.getUserId().intValue()); - /** - * View topic subject, content and attachement. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward viewTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { + ForumToolSession session = forumService.getSessionBySessionId(sessionID); - Long msgUid = new Long(WebUtil.readLongParam(request, ForumConstants.ATTR_TOPIC_ID)); + UserDTO userDTO = new UserDTO(user); + if (notebookEntry == null) { + userDTO.setFinishReflection(false); + userDTO.setReflect(null); + } else { + userDTO.setFinishReflection(true); + userDTO.setReflect(notebookEntry.getEntry()); + } + userDTO.setReflectInstrctions(session.getForum().getReflectInstructions()); - forumService = getForumService(); - Message topic = forumService.getMessage(msgUid); + request.setAttribute("userDTO", userDTO); + return mapping.findForward("success"); + } - request.setAttribute(ForumConstants.AUTHORING_TOPIC, MessageDTO.getMessageDTO(topic)); - return mapping.findForward("success"); - } + /** + * View topic subject, content and attachement. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward viewTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { - private ActionForward releaseMark(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - //get service then update report table - forumService = getForumService(); - Long sessionID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID)); - forumService.releaseMarksForSession(sessionID); + Long msgUid = new Long(WebUtil.readLongParam(request, ForumConstants.ATTR_TOPIC_ID)); - try { - response.setContentType("text/html;charset=utf-8"); - PrintWriter out = response.getWriter(); - ForumToolSession session = forumService.getSessionBySessionId(sessionID); - String sessionName = ""; - if (session != null) { - sessionName = session.getSessionName(); - } - out.write(getMessageService().getMessage("msg.mark.released", new String[] { sessionName })); - out.flush(); + forumService = getForumService(); + Message topic = forumService.getMessage(msgUid); - } - catch (IOException e) { - } - return null; - } + request.setAttribute(ForumConstants.AUTHORING_TOPIC, MessageDTO.getMessageDTO(topic)); + return mapping.findForward("success"); + } - // ========================================================================================== - // View and update marks methods - // ========================================================================================== + private ActionForward releaseMark(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + //get service then update report table + forumService = getForumService(); + Long sessionID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID)); + forumService.releaseMarksForSession(sessionID); - /** - * View all user marks for a special Session ID - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward viewAllMarks(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - //only one param for session scope marks - Long sessionID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID)); + try { + response.setContentType("text/html;charset=utf-8"); + PrintWriter out = response.getWriter(); + ForumToolSession session = forumService.getSessionBySessionId(sessionID); + String sessionName = ""; + if (session != null) { + sessionName = session.getSessionName(); + } + out.write(getMessageService().getMessage("msg.mark.released", new String[] { sessionName })); + out.flush(); - //create sessionMap - SessionMap sessionMap = new SessionMap(); - request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); - sessionMap.put(AttributeNames.PARAM_TOOL_SESSION_ID, sessionID); - sessionMap.put(ForumConstants.PARAM_UPDATE_MODE, ForumConstants.MARK_UPDATE_FROM_SESSION); + } catch (IOException e) { + } + return null; + } - request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); + // ========================================================================================== + // View and update marks methods + // ========================================================================================== - //get tool session scope topics - forumService = getForumService(); - List topicList = forumService.getAllTopicsFromSession(sessionID); + /** + * View all user marks for a special Session ID + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward viewAllMarks(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + //only one param for session scope marks + Long sessionID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID)); - Map topicsByUser = getTopicsSortedByAuthor(topicList); - request.setAttribute(ForumConstants.ATTR_REPORT, topicsByUser); - return mapping.findForward("success"); - } + //create sessionMap + SessionMap sessionMap = new SessionMap(); + request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); + sessionMap.put(AttributeNames.PARAM_TOOL_SESSION_ID, sessionID); + sessionMap.put(ForumConstants.PARAM_UPDATE_MODE, ForumConstants.MARK_UPDATE_FROM_SESSION); - /** - * View a special user's mark - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward viewUserMark(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - Long userUid = new Long(WebUtil.readLongParam(request, ForumConstants.USER_UID)); - Long sessionId = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID)); + request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); - //create sessionMap - SessionMap sessionMap = new SessionMap(); - request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); + //get tool session scope topics + forumService = getForumService(); + List topicList = forumService.getAllTopicsFromSession(sessionID); - sessionMap.put(AttributeNames.PARAM_TOOL_SESSION_ID, sessionId); - sessionMap.put(ForumConstants.PARAM_UPDATE_MODE, ForumConstants.MARK_UPDATE_FROM_USER); + Map topicsByUser = getTopicsSortedByAuthor(topicList); + request.setAttribute(ForumConstants.ATTR_REPORT, topicsByUser); + return mapping.findForward("success"); + } - request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); - //get this user's all topics - forumService = getForumService(); - List messageList = forumService.getMessagesByUserUid(userUid, sessionId); - ForumUser user = forumService.getUser(userUid); + /** + * View a special user's mark + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward viewUserMark(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + Long userUid = new Long(WebUtil.readLongParam(request, ForumConstants.USER_UID)); + Long sessionId = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID)); - // each back to web page - Map> report = new TreeMap(this.new ForumUserComparator()); - report.put(user, messageList); - request.setAttribute(ForumConstants.ATTR_REPORT, report); + //create sessionMap + SessionMap sessionMap = new SessionMap(); + request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); - return mapping.findForward("success"); - } + sessionMap.put(AttributeNames.PARAM_TOOL_SESSION_ID, sessionId); + sessionMap.put(ForumConstants.PARAM_UPDATE_MODE, ForumConstants.MARK_UPDATE_FROM_USER); - /** - * Edit a special user's mark. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward editMark(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - MarkForm markForm = (MarkForm) form; - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(markForm.getSessionMapID()); - String updateMode = (String) sessionMap.get(ForumConstants.PARAM_UPDATE_MODE); - //view forum mode - if (StringUtils.isBlank(updateMode)) { - sessionMap.put(ForumConstants.PARAM_UPDATE_MODE, ForumConstants.MARK_UPDATE_FROM_FORUM); - sessionMap.put(ForumConstants.ATTR_ROOT_TOPIC_UID, markForm.getTopicID()); - } + request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); + //get this user's all topics + forumService = getForumService(); + List messageList = forumService.getMessagesByUserUid(userUid, sessionId); + ForumUser user = forumService.getUser(userUid); - // get Message and User from database - forumService = getForumService(); - Message msg = forumService.getMessage(markForm.getTopicID()); - ForumUser user = msg.getCreatedBy(); + // each back to web page + Map> report = new TreeMap(this.new ForumUserComparator()); + report.put(user, messageList); + request.setAttribute(ForumConstants.ATTR_REPORT, report); - // echo back to web page - if (msg.getReport() != null) { - if (msg.getReport().getMark() != null) { - markForm.setMark(NumberUtil.formatLocalisedNumber(msg.getReport().getMark(), request.getLocale(), 2)); - } - else { - markForm.setMark(""); - } - markForm.setComment(msg.getReport().getComment()); - } + return mapping.findForward("success"); + } - // each back to web page - request.setAttribute(ForumConstants.ATTR_TOPIC, MessageDTO.getMessageDTO(msg)); - request.setAttribute(ForumConstants.ATTR_USER, user); + /** + * Edit a special user's mark. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward editMark(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + MarkForm markForm = (MarkForm) form; + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(markForm.getSessionMapID()); + String updateMode = (String) sessionMap.get(ForumConstants.PARAM_UPDATE_MODE); + //view forum mode + if (StringUtils.isBlank(updateMode)) { + sessionMap.put(ForumConstants.PARAM_UPDATE_MODE, ForumConstants.MARK_UPDATE_FROM_FORUM); + sessionMap.put(ForumConstants.ATTR_ROOT_TOPIC_UID, markForm.getTopicID()); + } - // Should we show the reflection or not? We shouldn't show it when the View Forum screen is accessed - // from the Monitoring Summary screen, but we should when accessed from the Learner Progress screen. - // Need to constantly past this value on, rather than hiding just the once, as the View Forum - // screen has a refresh button. Need to pass it through the view topic screen and dependent screens - // as it has a link from the view topic screen back to View Forum screen. - boolean hideReflection = WebUtil.readBooleanParam(request, ForumConstants.ATTR_HIDE_REFLECTION, false); - sessionMap.put(ForumConstants.ATTR_HIDE_REFLECTION, hideReflection); + // get Message and User from database + forumService = getForumService(); + Message msg = forumService.getMessage(markForm.getTopicID()); + ForumUser user = msg.getCreatedBy(); - return mapping.findForward("success"); + // echo back to web page + if (msg.getReport() != null) { + if (msg.getReport().getMark() != null) { + markForm.setMark(NumberUtil.formatLocalisedNumber(msg.getReport().getMark(), request.getLocale(), 2)); + } else { + markForm.setMark(""); + } + markForm.setComment(msg.getReport().getComment()); } - /** - * Update mark for a special user - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward updateMark(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - MarkForm markForm = (MarkForm) form; + // each back to web page + request.setAttribute(ForumConstants.ATTR_TOPIC, MessageDTO.getMessageDTO(msg)); + request.setAttribute(ForumConstants.ATTR_USER, user); - request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, markForm.getSessionMapID()); - String markStr = markForm.getMark(); - Float mark = null; - ActionMessages errors = new ActionMessages(); - if (StringUtils.isBlank(markStr)) { - ActionMessage error = new ActionMessage("error.valueReqd"); - errors.add("report.mark", error); - } - else { - try { - mark = NumberUtil.getLocalisedFloat(markStr, request.getLocale()); - } - catch (Exception e) { - ActionMessage error = new ActionMessage("error.mark.invalid.number"); - errors.add("report.mark", error); - } - } + // Should we show the reflection or not? We shouldn't show it when the View Forum screen is accessed + // from the Monitoring Summary screen, but we should when accessed from the Learner Progress screen. + // Need to constantly past this value on, rather than hiding just the once, as the View Forum + // screen has a refresh button. Need to pass it through the view topic screen and dependent screens + // as it has a link from the view topic screen back to View Forum screen. + boolean hideReflection = WebUtil.readBooleanParam(request, ForumConstants.ATTR_HIDE_REFLECTION, false); + sessionMap.put(ForumConstants.ATTR_HIDE_REFLECTION, hideReflection); - forumService = getForumService(); - // echo back to web page - Message msg = forumService.getMessage(markForm.getTopicID()); - ForumUser user = msg.getCreatedBy(); + return mapping.findForward("success"); + } - request.setAttribute(ForumConstants.ATTR_USER, user); - if (!errors.isEmpty()) { - // each back to web page - request.setAttribute(ForumConstants.ATTR_TOPIC, MessageDTO.getMessageDTO(msg)); - saveErrors(request, errors); - return mapping.getInputForward(); - } + /** + * Update mark for a special user + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward updateMark(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + MarkForm markForm = (MarkForm) form; - //update message report + request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, markForm.getSessionMapID()); + String markStr = markForm.getMark(); + Float mark = null; + ActionMessages errors = new ActionMessages(); + if (StringUtils.isBlank(markStr)) { + ActionMessage error = new ActionMessage("error.valueReqd"); + errors.add("report.mark", error); + } else { + try { + mark = NumberUtil.getLocalisedFloat(markStr, request.getLocale()); + } catch (Exception e) { + ActionMessage error = new ActionMessage("error.mark.invalid.number"); + errors.add("report.mark", error); + } + } - forumService = getForumService(); - ForumReport report = msg.getReport(); - if (report == null) { - report = new ForumReport(); - msg.setReport(report); - } + forumService = getForumService(); + // echo back to web page + Message msg = forumService.getMessage(markForm.getTopicID()); + ForumUser user = msg.getCreatedBy(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(markForm.getSessionMapID()); - Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); - String updateMode = (String) sessionMap.get(ForumConstants.PARAM_UPDATE_MODE); + request.setAttribute(ForumConstants.ATTR_USER, user); + if (!errors.isEmpty()) { + // each back to web page + request.setAttribute(ForumConstants.ATTR_TOPIC, MessageDTO.getMessageDTO(msg)); + saveErrors(request, errors); + return mapping.getInputForward(); + } - //only session has been released mark, the data of mark release will have value. - ForumToolSession toolSession = forumService.getSessionBySessionId(sessionId); - if (toolSession.isMarkReleased()) { - report.setDateMarksReleased(new Date()); - } + //update message report - report.setMark(mark); - report.setComment(markForm.getComment()); - forumService.updateTopic(msg); + forumService = getForumService(); + ForumReport report = msg.getReport(); + if (report == null) { + report = new ForumReport(); + msg.setReport(report); + } - //echo back to topic list page: it depends which screen is come from: view special user mark, or view all user marks. - if (StringUtils.equals(updateMode, ForumConstants.MARK_UPDATE_FROM_SESSION)) { - List topicList = forumService.getAllTopicsFromSession(sessionId); - Map topicsByUser = getTopicsSortedByAuthor(topicList); - request.setAttribute(ForumConstants.ATTR_REPORT, topicsByUser); - //listMark or listAllMark. - return mapping.findForward("success"); - } - else if (StringUtils.equals(updateMode, ForumConstants.MARK_UPDATE_FROM_USER)) { - List messageList = forumService.getMessagesByUserUid(user.getUid(), sessionId); - Map> topicMap = new TreeMap(this.new ForumUserComparator()); - topicMap.put(user, messageList); - request.setAttribute(ForumConstants.ATTR_REPORT, topicMap); - //listMark or listAllMark. - return mapping.findForward("success"); - } - else { //mark from view forum - return mapping.findForward("viewTopic"); - } + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(markForm.getSessionMapID()); + Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); + String updateMode = (String) sessionMap.get(ForumConstants.PARAM_UPDATE_MODE); + //only session has been released mark, the data of mark release will have value. + ForumToolSession toolSession = forumService.getSessionBySessionId(sessionId); + if (toolSession.isMarkReleased()) { + report.setDateMarksReleased(new Date()); } - // ========================================================================================== - // Utility methods - // ========================================================================================== + report.setMark(mark); + report.setComment(markForm.getComment()); + forumService.updateTopic(msg); - /** - * Get Forum Service. - * - * @return - */ - private IForumService getForumService() { - if (forumService == null) { - WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() - .getServletContext()); - forumService = (IForumService) wac.getBean(ForumConstants.FORUM_SERVICE); - } - return forumService; + //echo back to topic list page: it depends which screen is come from: view special user mark, or view all user marks. + if (StringUtils.equals(updateMode, ForumConstants.MARK_UPDATE_FROM_SESSION)) { + List topicList = forumService.getAllTopicsFromSession(sessionId); + Map topicsByUser = getTopicsSortedByAuthor(topicList); + request.setAttribute(ForumConstants.ATTR_REPORT, topicsByUser); + //listMark or listAllMark. + return mapping.findForward("success"); + } else if (StringUtils.equals(updateMode, ForumConstants.MARK_UPDATE_FROM_USER)) { + List messageList = forumService.getMessagesByUserUid(user.getUid(), sessionId); + Map> topicMap = new TreeMap(this.new ForumUserComparator()); + topicMap.put(user, messageList); + request.setAttribute(ForumConstants.ATTR_REPORT, topicMap); + //listMark or listAllMark. + return mapping.findForward("success"); + } else { //mark from view forum + return mapping.findForward("viewTopic"); } - /** - * @param topicList - * @return - */ - private Map getTopicsSortedByAuthor(List topicList) { - Map> topicsByUser = new TreeMap(this.new ForumUserComparator()); - Iterator iter = topicList.iterator(); - forumService = getForumService(); - while (iter.hasNext()) { - MessageDTO dto = (MessageDTO) iter.next(); - if (dto.getMessage().getIsAuthored()) { - continue; - } - dto.getMessage().getReport(); - ForumUser user = (ForumUser) dto.getMessage().getCreatedBy().clone(); - List list = topicsByUser.get(user); - if (list == null) { - list = new ArrayList(); - topicsByUser.put(user, list); - } - list.add(dto); - } - return topicsByUser; + } + + // ========================================================================================== + // Utility methods + // ========================================================================================== + + /** + * Get Forum Service. + * + * @return + */ + private IForumService getForumService() { + if (forumService == null) { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + forumService = (IForumService) wac.getBean(ForumConstants.FORUM_SERVICE); } + return forumService; + } - /** - * Return ResourceService bean. - */ - private MessageService getMessageService() { - WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); - return (MessageService) wac.getBean("forumMessageService"); + /** + * @param topicList + * @return + */ + private Map getTopicsSortedByAuthor(List topicList) { + Map> topicsByUser = new TreeMap(this.new ForumUserComparator()); + Iterator iter = topicList.iterator(); + forumService = getForumService(); + while (iter.hasNext()) { + MessageDTO dto = (MessageDTO) iter.next(); + if (dto.getMessage().getIsAuthored()) { + continue; + } + dto.getMessage().getReport(); + ForumUser user = (ForumUser) dto.getMessage().getCreatedBy().clone(); + List list = topicsByUser.get(user); + if (list == null) { + list = new ArrayList(); + topicsByUser.put(user, list); + } + list.add(dto); } + return topicsByUser; + } + + /** + * Return ResourceService bean. + */ + private MessageService getMessageService() { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + return (MessageService) wac.getBean("forumMessageService"); + } }