Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java =================================================================== diff -u -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f -rdd67faab130f90be03ee1067cfecbdc550f8342b --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java (.../McAppConstants.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java (.../McAppConstants.java) (revision dd67faab130f90be03ee1067cfecbdc550f8342b) @@ -157,7 +157,6 @@ public static final String PASSMARK = "passMark"; public static final String VIEW_ANSWERS = "viewAnswers"; public static final String SHOW_AUTHORING_TABS = "showAuthoringTabs"; - public static final String REQUEST_BY_STARTER = "requestByStarter"; public static final String ON = "ON"; public static final String OFF = "OFF"; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueUsr.java =================================================================== diff -u -rb3ab9dedd256ee8c388d395b33b12486730b2f2c -rdd67faab130f90be03ee1067cfecbdc550f8342b --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueUsr.java (.../McQueUsr.java) (revision b3ab9dedd256ee8c388d395b33b12486730b2f2c) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueUsr.java (.../McQueUsr.java) (revision dd67faab130f90be03ee1067cfecbdc550f8342b) @@ -51,7 +51,7 @@ private boolean responseFinalised; - //please pay attention this is *sessionUid* and not sessionId (this is due to Ozgur gave wrongly name to this field) + //please pay attention this is *sessionUid* and not sessionId (this is due to Ozgur gave wrong name to this field) private Long mcSessionId; /** nullable persistent field */ Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java =================================================================== diff -u -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f -rdd67faab130f90be03ee1067cfecbdc550f8342b --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java (.../McLearningAction.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java (.../McLearningAction.java) (revision dd67faab130f90be03ee1067cfecbdc550f8342b) @@ -41,6 +41,7 @@ import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.ActionRedirect; import org.apache.tomcat.util.json.JSONException; import org.apache.tomcat.util.json.JSONObject; import org.lamsfoundation.lams.learning.web.util.LearningWebUtil; @@ -205,10 +206,6 @@ return mapping.findForward(McAppConstants.LEARNING_STARTER); } - McQueUsr mcQueUsr = mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); - mcQueUsr.setResponseFinalised(true); - mcService.updateMcQueUsr(mcQueUsr); - response.sendRedirect(nextUrl); return null; @@ -319,21 +316,31 @@ request.getSession().setAttribute(httpSessionID, sessionMap); HttpSession ss = SessionManager.getSession(); - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - String userID = user.getUserID().toString(); - McQueUsr mcQueUsr = mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); + UserDTO userDto = (UserDTO) ss.getAttribute(AttributeNames.USER); + String userID = userDto.getUserID().toString(); + McQueUsr user = mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); + + //prohibit users from submitting answers after response is finalized but Resubmit button is not pressed (e.g. using 2 browsers) + if (user.isResponseFinalised()) { + ActionRedirect redirect = new ActionRedirect(mapping.findForwardConfig("viewAnswersRedirect")); + redirect.addParameter(AttributeNames.PARAM_TOOL_SESSION_ID, toolSessionID); + redirect.addParameter(MODE, "learner"); + redirect.addParameter("httpSessionID", httpSessionID); + return redirect; + } // Have to work out in advance if passed so that we can store it against the attempts - boolean passed = mcQueUsr.isMarkPassed(learnerMark); + boolean passed = user.isMarkPassed(learnerMark); mcGeneralLearnerFlowDTO.setUserOverPassMark(new Boolean(passed).toString()); mcGeneralLearnerFlowDTO.setPassMarkApplicable(new Boolean(mcContent.getPassMark() != null).toString()); - McLearningAction.saveUserAttempt(mcQueUsr, selectedQuestionAndCandidateAnswersDTO); + McLearningAction.saveUserAttempt(user, selectedQuestionAndCandidateAnswersDTO); - Integer numberOfAttempts = mcQueUsr.getNumberOfAttempts() + 1; - mcQueUsr.setNumberOfAttempts(numberOfAttempts); - mcQueUsr.setLastAttemptTotalMark(learnerMark); - mcService.updateMcQueUsr(mcQueUsr); + Integer numberOfAttempts = user.getNumberOfAttempts() + 1; + user.setNumberOfAttempts(numberOfAttempts); + user.setLastAttemptTotalMark(learnerMark); + user.setResponseFinalised(true); + mcService.updateMcQueUsr(user); mcGeneralLearnerFlowDTO.setDisplayAnswers(new Boolean(mcContent.isDisplayAnswers()).toString()); @@ -354,7 +361,7 @@ //String reflectionSubject = McUtils.replaceNewLines(mcContent.getReflectionSubject()); mcGeneralLearnerFlowDTO.setReflectionSubject(mcContent.getReflectionSubject()); - mcGeneralLearnerFlowDTO.setLatestAttemptMark(mcQueUsr.getLastAttemptTotalMark()); + mcGeneralLearnerFlowDTO.setLatestAttemptMark(user.getLastAttemptTotalMark()); request.setAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); @@ -388,6 +395,15 @@ String httpSessionID = mcLearningForm.getHttpSessionID(); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + //prohibit users from submitting answers after response is finalized but Resubmit button is not pressed (e.g. using 2 browsers) + if (user.isResponseFinalised()) { + ActionRedirect redirect = new ActionRedirect(mapping.findForwardConfig("viewAnswersRedirect")); + redirect.addParameter(AttributeNames.PARAM_TOOL_SESSION_ID, toolSessionID); + redirect.addParameter(MODE, "learner"); + redirect.addParameter("httpSessionID", httpSessionID); + return redirect; + } + //parse learner input List learnerInput = McLearningAction.parseLearnerAnswers(mcLearningForm, request); sessionMap.put(McAppConstants.QUESTION_AND_CANDIDATE_ANSWERS_KEY, learnerInput); @@ -431,11 +447,17 @@ } /** - * prepareViewAnswersData + * allows the learner to view their answer history + * + * @param request + * @param form + * @param mapping + * @return ActionForward */ - public void prepareViewAnswersData(ActionMapping mapping, McLearningForm mcLearningForm, - HttpServletRequest request, ServletContext servletContext) { - + public ActionForward viewAnswers(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + McLearningForm mcLearningForm = (McLearningForm) form; + // may have to get service from the form - if class has been created by starter action, rather than by struts if (mcService == null) { if (getServlet() != null) { @@ -580,21 +602,8 @@ request.setAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); - LearningWebUtil.putActivityPositionInRequestByToolSessionId(new Long(toolSessionID), request, servletContext); - } + LearningWebUtil.putActivityPositionInRequestByToolSessionId(new Long(toolSessionID), request, getServlet().getServletContext()); - /** - * allows the learner to view their answer history - * - * @param request - * @param form - * @param mapping - * @return ActionForward - */ - public ActionForward viewAnswers(ActionMapping mapping, McLearningForm mcLearningForm, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - prepareViewAnswersData(mapping, mcLearningForm, request, getServlet().getServletContext()); return mapping.findForward(McAppConstants.VIEW_ANSWERS); } @@ -611,6 +620,10 @@ McContent mcContent = mcService.getMcContent(new Long(toolContentId)); McQueUsr mcQueUsr = getCurrentUser(toolSessionID); + //in order to track whether redo button is pressed store this info + mcQueUsr.setResponseFinalised(false); + mcService.updateMcQueUsr(mcQueUsr); + //clear sessionMap String httpSessionID = mcLearningForm.getHttpSessionID(); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); @@ -795,6 +808,11 @@ UserDTO userDto = (UserDTO) ss.getAttribute(AttributeNames.USER); String userID = userDto.getUserID().toString(); McQueUsr user = mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); + + //prohibit users from autosaving answers after response is finalized but Resubmit button is not pressed (e.g. using 2 browsers) + if (user.isResponseFinalised()) { + return null; + } List learnerInput = McLearningAction.parseLearnerAnswers(mcLearningForm, request); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java =================================================================== diff -u -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f -rdd67faab130f90be03ee1067cfecbdc550f8342b --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java (.../McLearningStarterAction.java) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java (.../McLearningStarterAction.java) (revision dd67faab130f90be03ee1067cfecbdc550f8342b) @@ -42,6 +42,7 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; +import org.apache.struts.action.ActionRedirect; import org.lamsfoundation.lams.notebook.model.NotebookEntry; import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants; import org.lamsfoundation.lams.tool.ToolAccessMode; @@ -247,30 +248,15 @@ sessionMap.put(ATTR_CONTENT, mcContent); request.setAttribute("sessionMapID", sessionMap.getSessionID()); - if (mode.equals("teacher")) { - - /* LEARNER_PROGRESS for jsp */ - mcLearningForm.setLearnerProgress(new Boolean(true).toString()); - mcLearningForm.setLearnerProgressUserId(user.getQueUsrId().toString()); - - LearningUtil.saveFormRequestData(request, mcLearningForm, true); - - request.setAttribute(McAppConstants.REQUEST_BY_STARTER, new Boolean(true).toString()); + /* user has already submitted response once OR it's a monitor - go to viewAnswers page. */ + if (user.isResponseFinalised() || mode.equals("teacher")) { - McLearningAction mcLearningAction = new McLearningAction(); - mcLearningAction.setServlet(servlet); - return mcLearningAction.viewAnswers(mapping, mcLearningForm, request, response); + ActionRedirect redirect = new ActionRedirect(mapping.findForwardConfig("viewAnswersRedirect")); + redirect.addParameter(AttributeNames.PARAM_TOOL_SESSION_ID, toolSessionID); + redirect.addParameter(MODE, mode); + redirect.addParameter("httpSessionID", sessionMap.getSessionID()); + return redirect; } - - request.setAttribute(McAppConstants.MC_LEARNER_STARTER_DTO, mcLearnerStarterDTO); - - /* user has already submitted response once - go to viewAnswers page. */ - if (user.getNumberOfAttempts() > 0) { - McLearningAction mcLearningAction = new McLearningAction(); - request.setAttribute(McAppConstants.REQUEST_BY_STARTER, (Boolean.TRUE).toString()); - mcLearningAction.prepareViewAnswersData(mapping, mcLearningForm, request, getServlet().getServletContext()); - return mapping.findForward(McAppConstants.VIEW_ANSWERS); - } request.setAttribute(McAppConstants.MC_LEARNER_STARTER_DTO, mcLearnerStarterDTO); return (mapping.findForward(McAppConstants.LOAD_LEARNER)); Index: lams_tool_lamc/web/WEB-INF/struts-config.xml =================================================================== diff -u -r9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f -rdd67faab130f90be03ee1067cfecbdc550f8342b --- lams_tool_lamc/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 9db7a5bb39fecf9a0f1ae5cf2a9f701d2aa1532f) +++ lams_tool_lamc/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision dd67faab130f90be03ee1067cfecbdc550f8342b) @@ -158,9 +158,9 @@ /> - - - - +