Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java =================================================================== diff -u -rb648e82f0ebdc0178aec9d47c90209b4816c0584 -r8a3b509ec4fab06d5f29dee76fa6ba2f852a0abe --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (.../LearningAction.java) (revision b648e82f0ebdc0178aec9d47c90209b4816c0584) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (.../LearningAction.java) (revision 8a3b509ec4fab06d5f29dee76fa6ba2f852a0abe) @@ -24,9 +24,11 @@ import org.lamsfoundation.lams.tool.exception.ToolException; import org.lamsfoundation.lams.tool.forum.dto.MessageDTO; import org.lamsfoundation.lams.tool.forum.persistence.Attachment; +import org.lamsfoundation.lams.tool.forum.persistence.Forum; import org.lamsfoundation.lams.tool.forum.persistence.ForumException; import org.lamsfoundation.lams.tool.forum.persistence.ForumToolSession; import org.lamsfoundation.lams.tool.forum.persistence.ForumUser; +import org.lamsfoundation.lams.tool.forum.persistence.ForumUserDao; import org.lamsfoundation.lams.tool.forum.persistence.Message; import org.lamsfoundation.lams.tool.forum.persistence.PersistenceException; import org.lamsfoundation.lams.tool.forum.service.ForumServiceProxy; @@ -41,155 +43,184 @@ import org.springframework.web.context.support.WebApplicationContextUtils; /** - * User: conradb - * Date: 24/06/2005 - * Time: 10:54:09 + * User: conradb Date: 24/06/2005 Time: 10:54:09 */ public class LearningAction extends Action { - private static Logger log = Logger.getLogger(LearningAction.class); - private static final boolean MODE_OPTIONAL = false; + private static Logger log = Logger.getLogger(LearningAction.class); + + private static final boolean MODE_OPTIONAL = false; + private IForumService forumService; + public final ActionForward execute(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + String param = mapping.getParameter(); + // --------------Forum Level ------------------ + if (param.equals("viewForum")) { + return viewForm(mapping, form, request, response); + } + if (param.equals("newTopic")) { + return newTopic(mapping, form, request, response); + } + if (param.equals("finish")) { + return finish(mapping, form, request, response); + } - public final ActionForward execute(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) throws Exception { - String param = mapping.getParameter(); - //--------------Forum Level ------------------ - if (param.equals("viewForum")) { - return viewForm(mapping, form, request, response); - } - if (param.equals("newTopic")) { - return newTopic(mapping, form, request, response); - } - if (param.equals("finish")) { - return finish(mapping, form, request, response); - } - - //--------------Topic Level ------------------ - if (param.equals("viewTopic")) { - return viewTopic(mapping, form, request, response); - } - if (param.equals("createTopic")) { - return createTopic(mapping, form, request, response); - } - if (param.equals("newReplyTopic")) { - return newReplyTopic(mapping, form, request, response); - } - if (param.equals("replyTopic")) { - return replyTopic(mapping, form, request, response); - } - if (param.equals("editTopic")) { - return editTopic(mapping, form, request, response); - } - if (param.equals("updateTopic")) { - return updateTopic(mapping, form, request, response); - } - if (param.equals("deleteAttachment")) { - return deleteAttachment(mapping, form, request, response); - } - + // --------------Topic Level ------------------ + if (param.equals("viewTopic")) { + return viewTopic(mapping, form, request, response); + } + if (param.equals("createTopic")) { + return createTopic(mapping, form, request, response); + } + if (param.equals("newReplyTopic")) { + return newReplyTopic(mapping, form, request, response); + } + if (param.equals("replyTopic")) { + return replyTopic(mapping, form, request, response); + } + if (param.equals("editTopic")) { + return editTopic(mapping, form, request, response); + } + if (param.equals("updateTopic")) { + return updateTopic(mapping, form, request, response); + } + if (param.equals("updateMessageHideFlag")) { + return updateMessageHideFlag(mapping, form, request, response); + } + if (param.equals("deleteAttachment")) { + return deleteAttachment(mapping, form, request, response); + } + return mapping.findForward("error"); - } - //========================================================================================== - // Forum level methods - //========================================================================================== - /** - * Display root topics of a forum. This page will be the initial page of Learner page. - * - */ - private ActionForward viewForm(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - //set the mode into http session + } + + // ========================================================================================== + // Forum level methods + // ========================================================================================== + /** + * Display root topics of a forum. This page will be the initial page of + * Learner page. + * + */ + private ActionForward viewForm(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + // set the mode into http session ToolAccessMode mode = null; - try{ - mode = WebUtil.readToolAccessModeParam(request, AttributeNames.PARAM_MODE,MODE_OPTIONAL); - request.getSession().setAttribute(AttributeNames.ATTR_MODE, mode); - }catch(Exception exp){ - //check wether it already existed in Session - mode = (ToolAccessMode) request.getSession().getAttribute(AttributeNames.ATTR_MODE); + try { + mode = WebUtil.readToolAccessModeParam(request, + AttributeNames.PARAM_MODE, MODE_OPTIONAL); + request.getSession().setAttribute(AttributeNames.ATTR_MODE, mode); + } catch (Exception exp) { + // check wether it already existed in Session + mode = (ToolAccessMode) request.getSession().getAttribute( + AttributeNames.ATTR_MODE); } - if(mode == null){ + if (mode == null) { throw new ForumException("Mode is required."); } - - //get sessionId from HttpServletRequest - String sessionIdStr = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + + // get sessionId from HttpServletRequest + String sessionIdStr = request + .getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); Long sessionId; - if(StringUtils.isEmpty(sessionIdStr)) - //if SessionID in request is empty, then try to get it from session. This happens when client "refresh" - //page after create a new topic - sessionId = (Long) request.getSession().getAttribute(AttributeNames.PARAM_TOOL_SESSION_ID); + if (StringUtils.isEmpty(sessionIdStr)) + // if SessionID in request is empty, then try to get it from + // session. This happens when client "refresh" + // page after create a new topic + sessionId = (Long) request.getSession().getAttribute( + AttributeNames.PARAM_TOOL_SESSION_ID); else sessionId = new Long(Long.parseLong(sessionIdStr)); - //cache this sessionId into HttpSession - request.getSession().setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, sessionId); - - //Try to get ForumID according to sessionId + // cache this sessionId into HttpSession + request.getSession().setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, + sessionId); + + // Try to get ForumID according to sessionId forumService = getForumManager(); - ForumToolSession session = forumService.getSessionBySessionId(sessionId); - if(session == null || session.getForum() == null){ - log.error("Failed on getting session by given sessionID:" + sessionId); + ForumToolSession session = forumService + .getSessionBySessionId(sessionId); + if (session == null || session.getForum() == null) { + log.error("Failed on getting session by given sessionID:" + + sessionId); return mapping.findForward("error"); } Long forumId = session.getForum().getUid(); Boolean allowEdit = new Boolean(session.getForum().isAllowEdit()); - Boolean allowRichEditor = new Boolean(session.getForum().isAllowRichEditor()); + Boolean allowRichEditor = new Boolean(session.getForum() + .isAllowRichEditor()); int allowNumber = session.getForum().getLimitedChar(); request.getSession().setAttribute(ForumConstants.FORUM_ID, forumId); request.getSession().setAttribute(ForumConstants.ALLOW_EDIT, allowEdit); - request.getSession().setAttribute(ForumConstants.ALLOW_RICH_EDITOR, allowRichEditor); - request.getSession().setAttribute(ForumConstants.LIMITED_CHARS, new Integer(allowNumber)); + request.getSession().setAttribute(ForumConstants.ALLOW_RICH_EDITOR, + allowRichEditor); + request.getSession().setAttribute(ForumConstants.LIMITED_CHARS, + new Integer(allowNumber)); boolean lock = session.getForum().getLockWhenFinished(); - lock = lock && (session.getStatus() == ForumConstants.SESSION_STATUS_FINISHED ? true:false); - request.getSession().setAttribute(ForumConstants.FINISHEDLOCK,new Boolean(lock)); + lock = lock + && (session.getStatus() == ForumConstants.SESSION_STATUS_FINISHED ? true + : false); + request.getSession().setAttribute(ForumConstants.FINISHEDLOCK, + new Boolean(lock)); - //get all root topic to display on init page + // get all root topic to display on init page List rootTopics = forumService.getRootTopics(sessionId); - request.setAttribute(ForumConstants.AUTHORING_TOPICS_LIST,rootTopics); + request.setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, rootTopics); return mapping.findForward("success"); } + /** * Display empty page for a new topic in forum + * * @param mapping * @param form * @param request * @param response * @return */ - private ActionForward newTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { + private ActionForward newTopic(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { return mapping.findForward("success"); } + /** - * Learner click "finish" button in forum page, this method will turn on session status flag for this learner. + * Learner click "finish" button in forum page, this method will turn on + * session status flag for this learner. + * * @param mapping * @param form * @param request * @param response * @return */ - private ActionForward finish(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - Long sessionId = (Long) request.getSession().getAttribute(AttributeNames.PARAM_TOOL_SESSION_ID); - ToolAccessMode mode = (ToolAccessMode) request.getSession().getAttribute(AttributeNames.ATTR_MODE); + private ActionForward finish(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + Long sessionId = (Long) request.getSession().getAttribute( + AttributeNames.PARAM_TOOL_SESSION_ID); + ToolAccessMode mode = (ToolAccessMode) request.getSession() + .getAttribute(AttributeNames.ATTR_MODE); if (mode == ToolAccessMode.LEARNER) { - //get sessionId from HttpServletRequest + // get sessionId from HttpServletRequest forumService = getForumManager(); - ForumToolSession session = forumService.getSessionBySessionId(sessionId); + ForumToolSession session = forumService + .getSessionBySessionId(sessionId); session.setStatus(ForumConstants.SESSION_STATUS_FINISHED); forumService.updateSession(session); - - ToolSessionManager sessionMgrService = ForumServiceProxy.getToolSessionManager(getServlet().getServletContext()); - //get back login user DTO - //get session from shared session. + ToolSessionManager sessionMgrService = ForumServiceProxy + .getToolSessionManager(getServlet().getServletContext()); + + // get back login user DTO + // get session from shared session. HttpSession ss = SessionManager.getSession(); UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); Long userID = new Long(user.getUserID().longValue()); String nextActivityUrl; try { - nextActivityUrl = sessionMgrService.leaveToolSession(sessionId, userID); + nextActivityUrl = sessionMgrService.leaveToolSession(sessionId, + userID); response.sendRedirect(nextActivityUrl); } catch (DataMissingException e) { throw new ForumException(e); @@ -199,46 +230,46 @@ throw new ForumException(e); } return null; - - + } - //get all root topic to display on init page + // get all root topic to display on init page List rootTopics = forumService.getRootTopics(sessionId); - request.setAttribute(ForumConstants.AUTHORING_TOPICS_LIST,rootTopics); - + request.setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, rootTopics); + return mapping.findForward("success"); } - //========================================================================================== - // Topic level methods - //========================================================================================== - + // ========================================================================================== + // Topic level methods + // ========================================================================================== + /** - * Display read-only page for a special topic. Topic will arrange by Tree structure. + * Display read-only page for a special topic. Topic will arrange by Tree + * structure. * * @param mapping * @param form * @param request * @param response * @return */ - private ActionForward viewTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - Long topicId = new Long(WebUtil.readLongParam(request,"topicId")); - + private ActionForward viewTopic(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + Long topicId = new Long(WebUtil.readLongParam(request, "topicId")); + forumService = getForumManager(); - //get root topic list + // get root topic list List msgDtoList = forumService.getTopicThread(topicId); - + setAuthorMark(msgDtoList); - - request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD,msgDtoList); + + request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD, msgDtoList); return mapping.findForward("success"); - + } /** - * Create a new root topic. + * Create a new root topic. * * @param mapping * @param form @@ -249,11 +280,12 @@ * @throws ServletException * @throws PersistenceException */ - public ActionForward createTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException, PersistenceException { - + public ActionForward createTopic(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException, PersistenceException { + MessageForm messageForm = (MessageForm) form; - + Message message = messageForm.getMessage(); message.setIsAuthored(false); message.setCreated(new Date()); @@ -263,57 +295,64 @@ message.setCreatedBy(forumUser); message.setModifiedBy(forumUser); setAttachment(messageForm, message); - - //save message into database + + // save message into database forumService = getForumManager(); - Long forumId = (Long) request.getSession().getAttribute(ForumConstants.FORUM_ID); - Long sessionId = (Long) request.getSession().getAttribute(AttributeNames.PARAM_TOOL_SESSION_ID); - forumService.createRootTopic(forumId,sessionId,message); - - //echo back current root topic to fourm init page + Long forumId = (Long) request.getSession().getAttribute( + ForumConstants.FORUM_ID); + Long sessionId = (Long) request.getSession().getAttribute( + AttributeNames.PARAM_TOOL_SESSION_ID); + forumService.createRootTopic(forumId, sessionId, message); + + // echo back current root topic to fourm init page List rootTopics = forumService.getRootTopics(sessionId); - request.setAttribute(ForumConstants.AUTHORING_TOPICS_LIST,rootTopics); + request.setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, rootTopics); return mapping.findForward("success"); } + /** - * Dipslay replay topic page. Message form subject will include parent topics same subject. + * Dipslay replay topic page. Message form subject will include parent + * topics same subject. * * @param mapping * @param form * @param request * @param response * @return */ - private ActionForward newReplyTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - Long parentId = new Long(WebUtil.readLongParam(request,"parentId")); - - //get parent topic, it can decide default subject of reply. - MessageDTO topic = getTopic(parentId); - - if(topic != null && topic.getMessage() != null){ - //echo back current topic subject to web page - MessageForm msgForm = (MessageForm)form; - msgForm.getMessage().setSubject("Re:"+topic.getMessage().getSubject()); - } - - //cache this parentId in order to create reply - request.getSession().setAttribute("parentId",parentId); + private ActionForward newReplyTopic(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + Long parentId = new Long(WebUtil.readLongParam(request, "parentId")); + + // get parent topic, it can decide default subject of reply. + MessageDTO topic = getTopic(parentId); + + if (topic != null && topic.getMessage() != null) { + // echo back current topic subject to web page + MessageForm msgForm = (MessageForm) form; + msgForm.getMessage().setSubject( + "Re:" + topic.getMessage().getSubject()); + } + + // cache this parentId in order to create reply + request.getSession().setAttribute("parentId", parentId); return mapping.findForward("success"); } + /** - * Create a replayed topic for a parent topic. + * Create a replayed topic for a parent topic. * * @param mapping * @param form * @param request * @param response * @return */ - private ActionForward replyTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { + private ActionForward replyTopic(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { Long parentId = (Long) request.getSession().getAttribute("parentId"); - Long sessionId = (Long) request.getSession().getAttribute(AttributeNames.PARAM_TOOL_SESSION_ID); + Long sessionId = (Long) request.getSession().getAttribute( + AttributeNames.PARAM_TOOL_SESSION_ID); MessageForm messageForm = (MessageForm) form; Message message = messageForm.getMessage(); message.setIsAuthored(false); @@ -324,20 +363,21 @@ message.setCreatedBy(forumUser); message.setModifiedBy(forumUser); setAttachment(messageForm, message); - - //save message into database + + // save message into database forumService = getForumManager(); - forumService.replyTopic(parentId,sessionId,message); - - //echo back this topic thread into page + forumService.replyTopic(parentId, sessionId, message); + + // echo back this topic thread into page forumService = getForumManager(); Long rootTopicId = forumService.getRootTopicId(parentId); List msgDtoList = forumService.getTopicThread(rootTopicId); setAuthorMark(msgDtoList); - request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD,msgDtoList); - + request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD, msgDtoList); + return mapping.findForward("success"); } + /** * Display a editable form for a special topic in order to update it. * @@ -348,171 +388,236 @@ * @return * @throws PersistenceException */ - public ActionForward editTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws PersistenceException { - Long topicId = new Long(WebUtil.readLongParam(request,"topicId")); - - MessageDTO topic = getTopic(topicId); - //echo current topic content to web page - if(topic != null){ - MessageForm msgForm = (MessageForm)form; - msgForm.setMessage(topic.getMessage()); - request.setAttribute(ForumConstants.AUTHORING_TOPIC,topic); - } - - //cache this topicId in order to create reply - request.getSession().setAttribute("topicId",topicId); - return mapping.findForward("success"); - } - /** - * Update a topic. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws PersistenceException - */ - public ActionForward updateTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws PersistenceException { - //get value from HttpSession + public ActionForward editTopic(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) + throws PersistenceException { + Long topicId = new Long(WebUtil.readLongParam(request, "topicId")); + + MessageDTO topic = getTopic(topicId); + // echo current topic content to web page + if (topic != null) { + MessageForm msgForm = (MessageForm) form; + msgForm.setMessage(topic.getMessage()); + request.setAttribute(ForumConstants.AUTHORING_TOPIC, topic); + } + + // cache this topicId in order to create reply + request.getSession().setAttribute("topicId", topicId); + return mapping.findForward("success"); + } + + /** + * Update a topic. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws PersistenceException + */ + public ActionForward updateTopic(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) + throws PersistenceException { + // get value from HttpSession Long topicId = (Long) request.getSession().getAttribute("topicId"); forumService = getForumManager(); - + MessageForm messageForm = (MessageForm) form; Message message = messageForm.getMessage(); - //get PO from database and sync with Form + // get PO from database and sync with Form Message messagePO = forumService.getMessage(topicId); messagePO.setSubject(message.getSubject()); messagePO.setBody(message.getBody()); messagePO.setUpdated(new Date()); messagePO.setModifiedBy(getCurrentUser(request)); setAttachment(messageForm, messagePO); - - //save message into database + + // save message into database forumService.updateTopic(messagePO); - //echo back this topic thread into page + // echo back this topic thread into page forumService = getForumManager(); Long rootTopicId = forumService.getRootTopicId(topicId); List msgDtoList = forumService.getTopicThread(rootTopicId); setAuthorMark(msgDtoList); - request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD,msgDtoList); + request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD, msgDtoList); + + return mapping.findForward("success"); + } + + /** + * Sets the visibility of a message by updating the hide flag for a message + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + public ActionForward updateMessageHideFlag(ActionMapping mapping, + ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + Long msgId = new Long(WebUtil.readLongParam(request, "msgId")); + Boolean hideFlag = new Boolean(WebUtil.readBooleanParam(request, "hideFlag")); + forumService = getForumManager(); + + // check if the user has permission to hide posts. + Long sessionId = (Long) request.getSession().getAttribute( + AttributeNames.PARAM_TOOL_SESSION_ID); + ForumToolSession toolSession = forumService + .getSessionBySessionId(sessionId); + + Forum forum = toolSession.getForum(); + ForumUser currentUser = getCurrentUser(request); + ForumUser forumCreatedBy = forum.getCreatedBy(); + + if (currentUser.getUserId().equals(forumCreatedBy.getUserId())) { + forumService.updateMessageHideFlag(msgId, hideFlag.booleanValue()); + } else { + log.info(currentUser + "does not have permission to hide/show postings in forum: " + forum.getUid()); + log.info("Forum created by :" + forumCreatedBy.getUid() + ", Current User is: " + currentUser.getUid()); + } + + + // echo back this topic thread into page + forumService = getForumManager(); + Long rootTopicId = forumService.getRootTopicId(msgId); + List msgDtoList = forumService.getTopicThread(rootTopicId); + setAuthorMark(msgDtoList); + request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD, msgDtoList); + return mapping.findForward("success"); - } + } - /** - * Only delete the attachemnt file for current topic. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws PersistenceException - */ - public ActionForward deleteAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request, + /** + * Only delete the attachemnt file for current topic. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws PersistenceException + */ + public ActionForward deleteAttachment(ActionMapping mapping, + ActionForm form, HttpServletRequest request, HttpServletResponse response) throws PersistenceException { - //get value from HttpSession - Long topicId = (Long) request.getSession().getAttribute("topicId"); - Long versionID = new Long(WebUtil.readLongParam(request,"versionID")); - Long uuID = new Long(WebUtil.readLongParam(request,"uuid")); + // get value from HttpSession + Long topicId = (Long) request.getSession().getAttribute("topicId"); + Long versionID = new Long(WebUtil.readLongParam(request, "versionID")); + Long uuID = new Long(WebUtil.readLongParam(request, "uuid")); forumService = getForumManager(); - forumService.deleteFromRepository(uuID,versionID); -// get value from HttpSession + forumService.deleteFromRepository(uuID, versionID); + // get value from HttpSession Message messagePO = forumService.getMessage(topicId); messagePO.setUpdated(new Date()); messagePO.setModifiedBy(getCurrentUser(request)); messagePO.setAttachments(null); - //save message into database + // save message into database forumService.updateTopic(messagePO); - - return mapping.findForward("success"); - } - //========================================================================================== + return mapping.findForward("success"); + } + + // ========================================================================================== // Utility methods - //========================================================================================== + // ========================================================================================== /** - * If this topic is created by current login user, then set Author mark true. + * If this topic is created by current login user, then set Author mark + * true. * * @param msgDtoList */ private void setAuthorMark(List msgDtoList) { - //set current user to web page, so that can display "edit" button correct. Only author alow to edit. + // set current user to web page, so that can display "edit" button + // correct. Only author alow to edit. HttpSession ss = SessionManager.getSession(); - //get back login user DTO + // get back login user DTO UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); Long currUserId = new Long(user.getUserID().intValue()); Iterator iter = msgDtoList.iterator(); - while(iter.hasNext()){ + while (iter.hasNext()) { MessageDTO dto = (MessageDTO) iter.next(); - if(dto.getMessage().getCreatedBy() != null - && currUserId.equals(dto.getMessage().getCreatedBy().getUserId())) + if (dto.getMessage().getCreatedBy() != null + && currUserId.equals(dto.getMessage().getCreatedBy() + .getUserId())) dto.setAuthor(true); else dto.setAuthor(false); } } + /** * @param topicId * @return */ private MessageDTO getTopic(Long topicId) { - //get Topic content according to TopicID + // get Topic content according to TopicID forumService = getForumManager(); - MessageDTO topic = MessageDTO.getMessageDTO(forumService.getMessage(topicId)); + MessageDTO topic = MessageDTO.getMessageDTO(forumService + .getMessage(topicId)); return topic; } - + /** - * Get login user information from system level session. Check it whether it exists in database or not, and save it - * if it does not exists. Return an instance of PO of ForumUser. - * @param request - * @return - * Current user instance + * Get login user information from system level session. Check it whether it + * exists in database or not, and save it if it does not exists. Return an + * instance of PO of ForumUser. + * + * @param request + * @return Current user instance */ private ForumUser getCurrentUser(HttpServletRequest request) { -// get login user (author) + // get login user (author) HttpSession ss = SessionManager.getSession(); - //get back login user DTO + // get back login user DTO UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - //check whether this user exist or not - Long sessionId = (Long) request.getSession().getAttribute(AttributeNames.PARAM_TOOL_SESSION_ID); - ForumUser forumUser = forumService.getUserByUserAndSession(new Long(user.getUserID().intValue()),sessionId); - if(forumUser == null){ - //if user not exist, create new one in database - ForumToolSession session = forumService.getSessionBySessionId(sessionId); - forumUser = new ForumUser(user,session); + // check whether this user exist or not + Long sessionId = (Long) request.getSession().getAttribute( + AttributeNames.PARAM_TOOL_SESSION_ID); + ForumUser forumUser = forumService.getUserByUserAndSession(new Long( + user.getUserID().intValue()), sessionId); + if (forumUser == null) { + // if user not exist, create new one in database + ForumToolSession session = forumService + .getSessionBySessionId(sessionId); + forumUser = new ForumUser(user, session); forumService.createUser(forumUser); } return forumUser; } + /** * Get Forum Service. * * @return */ - private IForumService getForumManager() { - if ( forumService == null ) { - WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); - forumService = (IForumService) wac.getBean(ForumConstants.FORUM_SERVICE); - } - return forumService; - } + private IForumService getForumManager() { + if (forumService == null) { + WebApplicationContext wac = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet() + .getServletContext()); + forumService = (IForumService) wac + .getBean(ForumConstants.FORUM_SERVICE); + } + return forumService; + } + /** * @param messageForm * @param message */ private void setAttachment(MessageForm messageForm, Message message) { - if(messageForm.getAttachmentFile() != null - && !StringUtils.isEmpty(messageForm.getAttachmentFile().getFileName())){ + if (messageForm.getAttachmentFile() != null + && !StringUtils.isEmpty(messageForm.getAttachmentFile() + .getFileName())) { forumService = getForumManager(); - Attachment att = forumService.uploadAttachment(messageForm.getAttachmentFile()); - //only allow one attachment, so replace whatever + Attachment att = forumService.uploadAttachment(messageForm + .getAttachmentFile()); + // only allow one attachment, so replace whatever Set attSet = attSet = new HashSet(); attSet.add(att); message.setAttachments(attSet); Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/MonitoringAction.java =================================================================== diff -u -r462b4216c86cb13aa7207f1ebaaa85e5e667e0ae -r8a3b509ec4fab06d5f29dee76fa6ba2f852a0abe --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/MonitoringAction.java (.../MonitoringAction.java) (revision 462b4216c86cb13aa7207f1ebaaa85e5e667e0ae) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/MonitoringAction.java (.../MonitoringAction.java) (revision 8a3b509ec4fab06d5f29dee76fa6ba2f852a0abe) @@ -46,6 +46,7 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; +import org.lamsfoundation.lams.tool.ToolAccessMode; import org.lamsfoundation.lams.tool.forum.dto.MessageDTO; import org.lamsfoundation.lams.tool.forum.dto.SessionDTO; import org.lamsfoundation.lams.tool.forum.persistence.Forum; @@ -55,132 +56,118 @@ import org.lamsfoundation.lams.tool.forum.persistence.Message; import org.lamsfoundation.lams.tool.forum.service.IForumService; import org.lamsfoundation.lams.tool.forum.util.ForumConstants; +import org.lamsfoundation.lams.tool.forum.util.ForumWebUtils; import org.lamsfoundation.lams.tool.forum.web.forms.ForumForm; import org.lamsfoundation.lams.tool.forum.web.forms.MarkForm; +import org.lamsfoundation.lams.tool.forum.web.forms.MonitorForm; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; public class MonitoringAction extends Action { - private static Logger log = Logger.getLogger(MonitoringAction.class); + private static Logger log = Logger.getLogger(MonitoringAction.class); + private IForumService forumService; - - public final ActionForward execute(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) throws Exception { - String param = mapping.getParameter(); - - if (param.equals("listContentUsers")) { - return listContentUsers(mapping,form, request, response); - } - //***************** Marks Functions ******************** - if (param.equals("viewAllMarks")) { - return viewAllMarks(mapping,form, request, response); - } - if (param.equals("releaseMarks")) { - return releaseMarks(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); - } - - //***************** Activity and Instructions ******************** - if (param.equals("viewActivity")) { - return viewActivity(mapping,form, request, response); - } - if (param.equals("editActivity")) { - return editActivity(mapping,form, request, response); - } - if (param.equals("updateActivity")) { - return updateActivity(mapping,form, request, response); - } - if (param.equals("viewInstructions")) { - return viewInstructions(mapping,form, request, response); - } - //***************** Statistic ******************** - if (param.equals("statistic")) { - return statistic(mapping,form, request, response); - } - //***************** Miscellaneous ******************** - if (param.equals("viewTopic")) { - return viewTopic(mapping,form, request, response); - } - return mapping.findForward("error"); - } + public final ActionForward execute(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) + throws Exception { + String param = mapping.getParameter(); + if (param.equals("listContentUsers")) { + return listContentUsers(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); + } - /** - * The initial method for monitoring. List all users according to given Content ID. - * - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - private ActionForward listContentUsers(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - Long contentID =new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_CONTENT_ID)); - request.getSession().setAttribute(AttributeNames.PARAM_TOOL_CONTENT_ID,contentID); - - //get content ID from URL - return userList(mapping, request); + // ***************** Activity and Instructions ******************** + if (param.equals("viewActivity")) { + return viewActivity(mapping, form, request, response); + } + if (param.equals("editActivity")) { + return editActivity(mapping, form, request, response); + } + if (param.equals("updateActivity")) { + return updateActivity(mapping, form, request, response); + } + if (param.equals("viewInstructions")) { + return viewInstructions(mapping, form, request, response); + } + // ***************** Statistic ******************** + if (param.equals("statistic")) { + return statistic(mapping, form, request, response); + } + + // ***************** Miscellaneous ******************** + if (param.equals("viewTopic")) { + return viewTopic(mapping, form, request, response); + } + return mapping.findForward("error"); } - /** - * View all user marks for a special Session ID + * The initial method for monitoring. List all users according to given + * Content ID. + * * @param mapping * @param form * @param request * @param response * @return */ - private ActionForward viewAllMarks(ActionMapping mapping, ActionForm form, HttpServletRequest request, + private ActionForward listContentUsers(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); + Long toolContentID = new Long(WebUtil.readLongParam(request, + AttributeNames.PARAM_TOOL_CONTENT_ID)); + request.getSession().setAttribute(AttributeNames.PARAM_TOOL_CONTENT_ID, + toolContentID); - Map topicsByUser = getTopicsSortedByAuthor(topicList); - request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID,sessionID); - request.setAttribute("report",topicsByUser); - return mapping.findForward("success"); + request.getSession().setAttribute(AttributeNames.PARAM_MODE, ToolAccessMode.TEACHER); + + return userList(mapping, request); } /** - * Release marks for all users in a special Session. + * View all user marks for a special Session ID * * @param mapping * @param form * @param request * @param response * @return */ - private ActionForward releaseMarks(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { + private ActionForward viewAllMarks(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { - - Long sessionID =new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_SESSION_ID)); - //get service then update report table + Long sessionID = new Long(WebUtil.readLongParam(request, + AttributeNames.PARAM_TOOL_SESSION_ID)); forumService = getForumService(); - forumService.releaseMarksForSession(sessionID); - - //echo back message to web page - return userList(mapping,request); + List topicList = forumService.getAllTopicsFromSession(sessionID); + + Map topicsByUser = getTopicsSortedByAuthor(topicList); + request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, sessionID); + request.setAttribute("report", topicsByUser); + + return mapping.findForward("success"); } + /** * Download marks for all users in a speical session. * @@ -190,159 +177,177 @@ * @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)); + 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 + // construct Excel file format and download ActionMessages errors = new ActionMessages(); try { - //create an empty excel file + // create an empty excel file HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Marks"); - sheet.setColumnWidth((short)0,(short)5000); - HSSFRow row=null; + sheet.setColumnWidth((short) 0, (short) 5000); + HSSFRow row = null; HSSFCell cell; - Iterator iter = getTopicsSortedByAuthor(topicList).values().iterator(); - Iterator dtoIter; + Iterator iter = getTopicsSortedByAuthor(topicList).values() + .iterator(); + Iterator dtoIter; boolean first = true; int idx = 0; int fileCount = 0; - while(iter.hasNext()){ + while (iter.hasNext()) { List list = (List) iter.next(); dtoIter = list.iterator(); first = true; - - while(dtoIter.hasNext()){ + + while (dtoIter.hasNext()) { MessageDTO dto = (MessageDTO) dtoIter.next(); - if(first){ + if (first) { first = false; row = sheet.createRow(0); cell = row.createCell((short) idx); cell.setCellValue("Subject"); - sheet.setColumnWidth((short)idx,(short)8000); + sheet.setColumnWidth((short) idx, (short) 8000); ++idx; - + cell = row.createCell((short) idx); cell.setCellValue("Author"); - sheet.setColumnWidth((short)idx,(short)8000); + sheet.setColumnWidth((short) idx, (short) 8000); ++idx; - + cell = row.createCell((short) idx); cell.setCellValue("Date"); - sheet.setColumnWidth((short)idx,(short)8000); + sheet.setColumnWidth((short) idx, (short) 8000); ++idx; - + cell = row.createCell((short) idx); cell.setCellValue("Marks"); - sheet.setColumnWidth((short)idx,(short)8000); + sheet.setColumnWidth((short) idx, (short) 8000); ++idx; - + cell = row.createCell((short) idx); cell.setCellValue("Comments"); - sheet.setColumnWidth((short)idx,(short)8000); + sheet.setColumnWidth((short) idx, (short) 8000); ++idx; } ++fileCount; idx = 0; row = sheet.createRow(fileCount); cell = row.createCell((short) idx++); cell.setCellValue(dto.getMessage().getSubject()); - + cell = row.createCell((short) idx++); cell.setCellValue(dto.getAuthor()); - + cell = row.createCell((short) idx++); - cell.setCellValue(DateFormat.getInstance().format(dto.getMessage().getCreated())); - + cell.setCellValue(DateFormat.getInstance().format( + dto.getMessage().getCreated())); + cell = row.createCell((short) idx++); - - if(dto.getMessage() != null && dto.getMessage().getReport() != null + + if (dto.getMessage() != null + && dto.getMessage().getReport() != null && dto.getMessage().getReport().getMark() != null) - cell.setCellValue(dto.getMessage().getReport().getMark().doubleValue()); + cell.setCellValue(dto.getMessage().getReport() + .getMark().doubleValue()); else cell.setCellValue(""); - + cell = row.createCell((short) idx++); - if(dto.getMessage() != null && dto.getMessage().getReport() != null) - cell.setCellValue(dto.getMessage().getReport().getComment()); + 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"; + // 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); + response.setHeader("Content-Disposition", header); byte[] data = bos.toByteArray(); - response.getOutputStream().write(data,0,data.length); + response.getOutputStream().write(data, 0, data.length); response.getOutputStream().flush(); } catch (IOException e) { log.error(e); - errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("monitoring.download.error",e.toString())); + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( + "monitoring.download.error", e.toString())); } - if(!errors.isEmpty()){ - saveErrors(request,errors); - request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID,sessionID); + if (!errors.isEmpty()) { + saveErrors(request, errors); + request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, + sessionID); return mapping.getInputForward(); } - - + return null; } + /** * 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)); - + 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)); + forumService = getForumService(); - List messageList = forumService.getMessagesByUserUid(userUid,sessionId); + List messageList = forumService + .getMessagesByUserUid(userUid, sessionId); ForumUser user = forumService.getUser(userUid); - //each back to web page - request.setAttribute("topicList",messageList); - request.setAttribute("user",user); - request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID,sessionId); + // each back to web page + request.setAttribute("topicList", messageList); + request.setAttribute("user", user); + request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, sessionId); return mapping.findForward("success"); } + /** * 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) { - Long userUid = new Long(WebUtil.readLongParam(request,ForumConstants.USER_UID)); - Long messageId = new Long(WebUtil.readLongParam(request,ForumConstants.MESSAGE_UID)); - Long sessionId = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_SESSION_ID)); - - //get Message and User from database + private ActionForward editMark(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + Long userUid = new Long(WebUtil.readLongParam(request, + ForumConstants.USER_UID)); + Long messageId = new Long(WebUtil.readLongParam(request, + ForumConstants.MESSAGE_UID)); + Long sessionId = new Long(WebUtil.readLongParam(request, + AttributeNames.PARAM_TOOL_SESSION_ID)); + + // get Message and User from database forumService = getForumService(); - Message msg = forumService.getMessage(messageId); + Message msg = forumService.getMessage(messageId); ForumUser user = forumService.getUser(userUid); - - //echo back to web page + + // echo back to web page MarkForm markForm = (MarkForm) form; - if(msg.getReport() != null ){ - if(msg.getReport().getMark() != null) + if (msg.getReport() != null) { + if (msg.getReport().getMark() != null) markForm.setMark(msg.getReport().getMark().toString()); else markForm.setMark(""); @@ -353,226 +358,274 @@ markForm.setSessionId(sessionId); return mapping.findForward("success"); } + /** * 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) { - Long messageId = new Long(WebUtil.readLongParam(request,ForumConstants.MESSAGE_UID)); - Long userUid = new Long(WebUtil.readLongParam(request,ForumConstants.USER_UID)); - Long sessionId = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_SESSION_ID)); - + private ActionForward updateMark(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + Long messageId = new Long(WebUtil.readLongParam(request, + ForumConstants.MESSAGE_UID)); + Long userUid = new Long(WebUtil.readLongParam(request, + ForumConstants.USER_UID)); + Long sessionId = new Long(WebUtil.readLongParam(request, + AttributeNames.PARAM_TOOL_SESSION_ID)); + forumService = getForumService(); - Message msg = forumService.getMessage(messageId); - - //save it into database + Message msg = forumService.getMessage(messageId); + + // save it into database MarkForm markForm = (MarkForm) form; forumService = getForumService(); ForumReport report = msg.getReport(); - if(report == null){ + if (report == null) { report = new ForumReport(); msg.setReport(report); } report.setMark(new Float(Float.parseFloat(markForm.getMark()))); report.setComment(markForm.getComment()); forumService.updateTopic(msg); - - //echo back to web page + + // echo back to web page forumService = getForumService(); - List messageList = forumService.getMessagesByUserUid(userUid,sessionId); + List messageList = forumService + .getMessagesByUserUid(userUid, sessionId); ForumUser user = forumService.getUser(userUid); - request.setAttribute("topicList",messageList); - request.setAttribute("user",user); - request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID,sessionId); + request.setAttribute("topicList", messageList); + request.setAttribute("user", user); + request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, sessionId); 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 contentId =(Long) request.getSession().getAttribute(AttributeNames.PARAM_TOOL_CONTENT_ID); + private ActionForward viewActivity(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + Long contentId = (Long) request.getSession().getAttribute( + AttributeNames.PARAM_TOOL_CONTENT_ID); forumService = getForumService(); Forum forum = forumService.getForumByContentId(contentId); - //if can not find out forum, echo back error message - if(forum == null){ + // 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); + 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(); - - request.setAttribute("title",title); - request.setAttribute("instruction",instruction); + + request.setAttribute("title", title); + request.setAttribute("instruction", instruction); return mapping.findForward("success"); } + /** - * Show edit page for a content activity. + * Show edit page for a content activity. + * * @param mapping * @param form * @param request * @param response * @return */ - private ActionForward editActivity(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - Long contentId =(Long) request.getSession().getAttribute(AttributeNames.PARAM_TOOL_CONTENT_ID); + private ActionForward editActivity(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + MonitorForm monitorForm = (MonitorForm) form; + + Long toolContentId = (Long) request.getSession().getAttribute( + AttributeNames.PARAM_TOOL_CONTENT_ID); forumService = getForumService(); - Forum forum = forumService.getForumByContentId(contentId); - //if can not find out forum, echo back error message - if(forum == null){ + 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); - //echo back to screen + errors.add("activity.globel", new ActionMessage( + "error.fail.get.forum")); + this.addErrors(request, errors); + log.error("Forum is null"); return mapping.getInputForward(); } - String title = forum.getTitle(); String instruction = forum.getInstructions(); - request.setAttribute("title",title); - request.setAttribute("instruction",instruction); + request.setAttribute("title", title); + request.setAttribute("instruction", instruction); + + if (ForumWebUtils.isForumEditable(forum)) { + request.setAttribute(ForumConstants.PAGE_EDITABLE, "true"); + log.debug("Forum is editable"); + + // set up the request parameters to append to the URL + Map map = new HashMap(); + map.put(AttributeNames.PARAM_TOOL_CONTENT_ID, toolContentId); + monitorForm.setParametersToAppend(map); + } else { + request.setAttribute(ForumConstants.PAGE_EDITABLE, "false"); + log.debug("Forum is not editable"); + } return mapping.findForward("success"); } + /** * Update activity for a content. + * * @param mapping * @param form * @param request * @param response * @return */ - private ActionForward updateActivity(ActionMapping mapping, ActionForm form, HttpServletRequest request, + private ActionForward updateActivity(ActionMapping mapping, + ActionForm form, HttpServletRequest request, HttpServletResponse response) { - Long contentId =(Long) request.getSession().getAttribute(AttributeNames.PARAM_TOOL_CONTENT_ID); + Long contentId = (Long) request.getSession().getAttribute( + AttributeNames.PARAM_TOOL_CONTENT_ID); String title = request.getParameter("title"); String instruction = request.getParameter("instruction"); - + forumService = getForumService(); Forum forum = forumService.getForumByContentId(contentId); - //if can not find out forum, echo back error message + // if can not find out forum, echo back error message ActionErrors errors = new ActionErrors(); - if(forum == null){ - errors.add("activity.globel", new ActionMessage("error.fail.get.forum")); + if (forum == null) { + errors.add("activity.globel", new ActionMessage( + "error.fail.get.forum")); } - if(StringUtils.isEmpty(title)){ - errors.add("activity.title", new ActionMessage("error.title.empty")); + if (StringUtils.isEmpty(title)) { + errors.add("activity.title", new ActionMessage( + "error.title.empty")); } - //echo back to screen - request.setAttribute("title",title); - request.setAttribute("instruction",instruction); - if(!errors.isEmpty()){ - this.addErrors(request,errors); + // echo back to screen + request.setAttribute("title", title); + request.setAttribute("instruction", instruction); + if (!errors.isEmpty()) { + this.addErrors(request, errors); return mapping.getInputForward(); } forum.setTitle(title); forum.setInstructions(instruction); forumService.updateForum(forum); - + return mapping.findForward("success"); } + /** * View instruction inforamtion for a content. + * * @param mapping * @param form * @param request * @param response * @return */ - private ActionForward viewInstructions(ActionMapping mapping, ActionForm form, HttpServletRequest request, + private ActionForward viewInstructions(ActionMapping mapping, + ActionForm form, HttpServletRequest request, HttpServletResponse response) { - Long contentId =(Long) request.getSession().getAttribute(AttributeNames.PARAM_TOOL_CONTENT_ID); - + Long contentId = (Long) request.getSession().getAttribute( + AttributeNames.PARAM_TOOL_CONTENT_ID); + forumService = getForumService(); Forum forum = forumService.getForumByContentId(contentId); - //if can not find out forum, echo back error message - if(forum == null){ + // 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); + errors.add("instruction.globel", new ActionMessage( + "error.fail.get.forum")); + this.addErrors(request, errors); return mapping.getInputForward(); } - + ForumForm forumForm = new ForumForm(); forumForm.setForum(forum); - - request.setAttribute("forumBean",forumForm); + + request.setAttribute("forumBean", forumForm); return mapping.findForward("success"); } + /** * 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 contentID = (Long) request.getSession().getAttribute(AttributeNames.PARAM_TOOL_CONTENT_ID); - + private ActionForward statistic(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + Long contentID = (Long) request.getSession().getAttribute( + AttributeNames.PARAM_TOOL_CONTENT_ID); + forumService = getForumService(); Map sessionTopicsMap = new HashMap(); Map sessionAvaMarkMap = new HashMap(); Map sessionTotalMsgMap = new HashMap(); - + List sessList = forumService.getSessionsByContentId(contentID); Iterator sessIter = sessList.iterator(); - while(sessIter.hasNext()){ + 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();){ + 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 + // 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++){ + for (msgNum = 0; threadIter.hasNext(); msgNum++) { MessageDTO dto = (MessageDTO) threadIter.next(); - if(dto.getMark() != null) + if (dto.getMark() != null) msgMarkSum += dto.getMark().floatValue(); - } - //summary to total mark + } + // summary to total mark totalMsgMarkSum += msgMarkSum; - //set average mark to topic message DTO for display use - msgDto.setMark(getAverageFormat(msgMarkSum/(float)msgNum)); + // set average mark to topic message DTO for display use + msgDto.setMark(getAverageFormat(msgMarkSum / (float) msgNum)); totalMsg += msgNum; } - - float averMark = totalMsg == 0 ? 0: (totalMsgMarkSum/(float)totalMsg); - + + float averMark = totalMsg == 0 ? 0 + : (totalMsgMarkSum / (float) totalMsg); + SessionDTO sessionDto = new SessionDTO(); sessionDto.setSessionID(session.getSessionId()); sessionDto.setSessionName(session.getSessionName()); - - sessionTopicsMap.put(sessionDto,topicList); - sessionAvaMarkMap.put(session.getSessionId(),getAverageFormat(averMark)); - sessionTotalMsgMap.put(session.getSessionId(),new Integer(totalMsg)); + + sessionTopicsMap.put(sessionDto, topicList); + sessionAvaMarkMap.put(session.getSessionId(), + getAverageFormat(averMark)); + sessionTotalMsgMap.put(session.getSessionId(), + new Integer(totalMsg)); } - request.setAttribute("topicList",sessionTopicsMap); - request.setAttribute("markAverage",sessionAvaMarkMap); - request.setAttribute("totalMessage",sessionTotalMsgMap); + request.setAttribute("topicList", sessionTopicsMap); + request.setAttribute("markAverage", sessionAvaMarkMap); + request.setAttribute("totalMessage", sessionTotalMsgMap); return mapping.findForward("success"); } + /** * View topic subject, content and attachement. * @@ -582,62 +635,71 @@ * @param response * @return */ - private ActionForward viewTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - - Long msgUid = new Long(WebUtil.readLongParam(request,ForumConstants.MESSAGE_UID)); - - forumService = getForumService(); - Message topic = forumService.getMessage(msgUid); - - request.setAttribute(ForumConstants.AUTHORING_TOPIC,MessageDTO.getMessageDTO(topic)); - return mapping.findForward("success"); + private ActionForward viewTopic(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) { + + Long msgUid = new Long(WebUtil.readLongParam(request, + ForumConstants.MESSAGE_UID)); + + forumService = getForumService(); + Message topic = forumService.getMessage(msgUid); + + request.setAttribute(ForumConstants.AUTHORING_TOPIC, MessageDTO + .getMessageDTO(topic)); + return mapping.findForward("success"); } - //========================================================================================== + // ========================================================================================== // Utility methods - //========================================================================================== + // ========================================================================================== /** * Show all users in a ToolContentID. + * * @param mapping * @param request * @return */ - private ActionForward userList(ActionMapping mapping, HttpServletRequest request) { - Long contentID =(Long) request.getSession().getAttribute(AttributeNames.PARAM_TOOL_CONTENT_ID); - + private ActionForward userList(ActionMapping mapping, + HttpServletRequest request) { + Long contentID = (Long) request.getSession().getAttribute( + AttributeNames.PARAM_TOOL_CONTENT_ID); + forumService = getForumService(); - List sessionsList = forumService.getSessionsByContentId(contentID); + List sessionsList = forumService.getSessionsByContentId(contentID); - Map sessionUserMap = new HashMap(); - //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(); - sessionDto.setSessionID(fts.getSessionId()); - sessionDto.setSessionName(fts.getSessionName()); - List userList = forumService.getUsersBySessionId(fts.getSessionId()); - sessionUserMap.put(sessionDto, userList); - } - - //request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID,sessionID); - request.setAttribute("sessionUserMap",sessionUserMap); + Map sessionUsersMap = new HashMap(); + // 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(); + sessionDto.setSessionID(fts.getSessionId()); + sessionDto.setSessionName(fts.getSessionName()); + List userList = forumService + .getUsersBySessionId(fts.getSessionId()); + sessionUsersMap.put(sessionDto, userList); + } + + // request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID,sessionID); + request.setAttribute("sessionUserMap", sessionUsersMap); return mapping.findForward("success"); } + /** * 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; - } - + private IForumService getForumService() { + if (forumService == null) { + WebApplicationContext wac = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet() + .getServletContext()); + forumService = (IForumService) wac + .getBean(ForumConstants.FORUM_SERVICE); + } + return forumService; + } /** * @param topicList @@ -646,20 +708,23 @@ private Map getTopicsSortedByAuthor(List topicList) { Map topicsByUser = new HashMap(); Iterator iter = topicList.iterator(); - while(iter.hasNext()){ + while (iter.hasNext()) { MessageDTO dto = (MessageDTO) iter.next(); dto.getMessage().getReport(); - List list = (List) topicsByUser.get(dto.getMessage().getCreatedBy()); - if(list == null){ + List list = (List) topicsByUser + .get(dto.getMessage().getCreatedBy()); + if (list == null) { list = new ArrayList(); - topicsByUser.put(dto.getMessage().getCreatedBy(),list); + topicsByUser.put(dto.getMessage().getCreatedBy(), list); } list.add(dto); } return topicsByUser; } + /** * Get formatted average mark. + * * @param aver * @return */