Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java =================================================================== diff -u -r0f3f4e592b6337d5777631acfbd92d90a6211826 -rdcb4bb59e05ab9fc05be18355abc22d8d5a675e9 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java (.../McUtils.java) (revision 0f3f4e592b6337d5777631acfbd92d90a6211826) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java (.../McUtils.java) (revision dcb4bb59e05ab9fc05be18355abc22d8d5a675e9) @@ -21,8 +21,6 @@ import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; import org.lamsfoundation.lams.tool.mc.pojos.McSession; import org.lamsfoundation.lams.tool.mc.service.IMcService; -import org.lamsfoundation.lams.tool.mc.web.AuthoringUtil; -import org.lamsfoundation.lams.tool.mc.web.LearningUtil; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.web.session.SessionManager; @@ -511,20 +509,11 @@ } - /** - * cleanUpSession(HttpServletRequest request) - * @param request - */ - public static void cleanUpSession(HttpServletRequest request) - { - LearningUtil.cleanUpLearningSession(request); - AuthoringUtil.cleanupAuthoringSession(request); - //MonitoringUtil.cleanupAuthoringSession(request); - } + /** - * the only attributes kept are TOOL_SESSION and TOOL_CONTENT_ID + * the only attributes kept are TOOL_SESSION and TOOL_CONTENT_ID and CURRENT_MONITORED_TOOL_SESSION * cleanUpSessionAbsolute(HttpServletRequest request) * @param request */ @@ -676,7 +665,6 @@ request.getSession().removeAttribute(MONITORED_CONTENT_ID); request.getSession().removeAttribute(EDITACTIVITY_EDITMODE); request.getSession().removeAttribute(FORM_INDEX); - request.getSession().removeAttribute(CURRENT_MONITORED_TOOL_SESSION); request.getSession().removeAttribute(SELECTION_CASE); request.getSession().removeAttribute(LIST_MONITORED_ANSWERS_CONTAINER_DTO); request.getSession().removeAttribute(QUESTION_LISTING_MODE); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java =================================================================== diff -u -r2b6abf25dfd33a6c8b0dba91267a444d7bf5d7e8 -rdcb4bb59e05ab9fc05be18355abc22d8d5a675e9 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision 2b6abf25dfd33a6c8b0dba91267a444d7bf5d7e8) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision dcb4bb59e05ab9fc05be18355abc22d8d5a675e9) @@ -2592,6 +2592,7 @@ } } + /** * removeRedundantOnlineFileItems(HttpServletRequest request, McContent mcContent) Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java =================================================================== diff -u -ra7071889ce5b336ce1adbbc1c5219c64d12143cd -rdcb4bb59e05ab9fc05be18355abc22d8d5a675e9 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java (.../LearningUtil.java) (revision a7071889ce5b336ce1adbbc1c5219c64d12143cd) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java (.../LearningUtil.java) (revision dcb4bb59e05ab9fc05be18355abc22d8d5a675e9) @@ -39,6 +39,7 @@ * * @param request * @param form + * @param questionIndex */ public static void selectOptionsCheckBox(HttpServletRequest request,McLearningForm mcLearningForm, String questionIndex) { @@ -756,7 +757,7 @@ if (displayOrder != 0) { /* add the question to the questions Map in the displayOrder*/ - mapQuestionsContent.put(new Integer(displayOrder).toString(),mcQueContent.getQuestion()); + mapQuestionsContent.put(new Integer(displayOrder).toString(),mcQueContent.getQuestion() + " of weight: " + mcQueContent.getWeight().toString() + "%"); } /* prepare the first question's candidate answers for presentation*/ @@ -775,7 +776,92 @@ } return mapQuestionsContent; } + + public static int getLearnerMarkAtLeast(Integer passMark, Map mapQuestionWeights) + { + logger.debug("passMark:" + passMark); + logger.debug("mapQuestionWeights:" + mapQuestionWeights); + + if ((passMark == null) || (passMark.intValue() == 0)) + { + logger.debug("no passMark.."); + return 0; + } + else if ((passMark != null) && (passMark.intValue() != 0)) + { + int minimumQuestionCountToPass=calculateMinimumQuestionCountToPass(passMark, mapQuestionWeights); + logger.debug("minimumQuestionCountToPass: " + minimumQuestionCountToPass); + return minimumQuestionCountToPass; + } + return 0; + } + + + public static int calculateMinimumQuestionCountToPass(Integer passMark, Map mapQuestionWeights) + { + logger.debug("passMark: " + passMark); + logger.debug("original mapQuestionWeights: " + mapQuestionWeights); + + int minimumQuestionCount=0; + int totalHighestWeights=0; + while (totalHighestWeights <= passMark.intValue()) + { + int highestWeight=getHighestWeight(mapQuestionWeights); + totalHighestWeights=totalHighestWeights + highestWeight; + logger.debug("totalHighestWeights: " + totalHighestWeights); + mapQuestionWeights=rebuildWeightsMapExcludeHighestWeight(mapQuestionWeights, highestWeight); + logger.debug("mapQuestionWeights: " + mapQuestionWeights); + ++minimumQuestionCount; + } + logger.debug("returning minimumQuestionCount: " + minimumQuestionCount); + return minimumQuestionCount; + } + + + public static int getHighestWeight(Map mapQuestionWeights) + { + Iterator itMap = mapQuestionWeights.entrySet().iterator(); + int highestWeight=0; + while (itMap.hasNext()) + { + Map.Entry pair = (Map.Entry)itMap.next(); + String weight=pair.getValue().toString(); + int intWeight=new Integer(weight).intValue(); + + if (intWeight > highestWeight) + highestWeight= intWeight; + } + return highestWeight; + } + + + public static Map rebuildWeightsMapExcludeHighestWeight(Map mapQuestionWeights, int highestWeight) + { + Map mapWeightsExcludeHighestWeight= new TreeMap(new McComparator()); + + Iterator itMap = mapQuestionWeights.entrySet().iterator(); + Long mapIndex=new Long(1); + while (itMap.hasNext()) + { + Map.Entry pair = (Map.Entry)itMap.next(); + String weight=pair.getValue().toString(); + int intWeight=new Integer(weight).intValue(); + if (intWeight != highestWeight) + { + mapWeightsExcludeHighestWeight.put(mapIndex.toString(),weight); + mapIndex=new Long(mapIndex.longValue()+1); + } + else + { + logger.debug("excluding highest weight from the reconstructed map: " + intWeight); + } + } + logger.debug("returning mapWeightsExcludeHighestWeight: " + mapWeightsExcludeHighestWeight); + return mapWeightsExcludeHighestWeight; + } + + /** * removes Learning session attributes * cleanUpLearningSession(HttpServletRequest request) Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java =================================================================== diff -u -r9995a2c37bd1ca5cafa9e41d6d30a8872bba0a80 -rdcb4bb59e05ab9fc05be18355abc22d8d5a675e9 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java (.../McLearningAction.java) (revision 9995a2c37bd1ca5cafa9e41d6d30a8872bba0a80) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java (.../McLearningAction.java) (revision dcb4bb59e05ab9fc05be18355abc22d8d5a675e9) @@ -369,6 +369,7 @@ int mark=LearningUtil.getMark(mapLeanerAssessmentResults); logger.debug("mark: " + mark); + request.getSession().setAttribute(LEARNER_MARK, new Integer(mark).toString()); Map mapQuestionWeights =(Map) request.getSession().getAttribute(MAP_QUESTION_WEIGHTS); logger.debug("mapQuestionWeights: " + mapQuestionWeights); @@ -416,12 +417,16 @@ int intHighestAttemptOrder=new Integer(highestAttemptOrder).intValue()+ 1 ; logger.debug("updated highestAttemptOrder:" + intHighestAttemptOrder); request.getSession().setAttribute(LEARNER_LAST_ATTEMPT_ORDER, new Integer(intHighestAttemptOrder).toString()); + + int learnerMarkAtLeast=LearningUtil.getLearnerMarkAtLeast(passMark,mapQuestionWeights); + logger.debug("learnerMarkAtLeast:" + learnerMarkAtLeast); + request.getSession().setAttribute(LEARNER_MARK_ATLEAST, new Integer(learnerMarkAtLeast).toString()); mcLearningForm.resetCommands(); return (mapping.findForward(INDIVIDUAL_REPORT)); } + - /** * takes the learner to the next set of questions * continueOptionsCombined(ActionMapping mapping, @@ -748,7 +753,6 @@ } - /** * redoQuestions(HttpServletRequest request, McLearningForm mcLearningForm, ActionMapping mapping) * Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java =================================================================== diff -u -r0f3f4e592b6337d5777631acfbd92d90a6211826 -rdcb4bb59e05ab9fc05be18355abc22d8d5a675e9 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java (.../McLearningStarterAction.java) (revision 0f3f4e592b6337d5777631acfbd92d90a6211826) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java (.../McLearningStarterAction.java) (revision dcb4bb59e05ab9fc05be18355abc22d8d5a675e9) @@ -123,6 +123,14 @@ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, McApplicationException { + /* + * By now, the passed tool session id MUST exist in the db through the calling of: + * public void createToolSession(Long toolSessionId, Long toolContentId) by the container. + * + * + * make sure this session exists in tool's session table by now. + */ + McUtils.cleanUpSessionAbsolute(request); Map mapQuestionsContent= new TreeMap(new McComparator()); @@ -209,32 +217,6 @@ } /*till here*/ - - /* - * By now, the passed tool session id MUST exist in the db through the calling of: - * public void createToolSession(Long toolSessionId, Long toolContentId) by the container. - * - * - * make sure this session exists in tool's session table by now. - */ -/* - if (!McUtils.existsSession(toolSessionID, request)) - { - logger.debug("tool session does not exist" + toolSessionID); - Long currentToolContentId= new Long(9876); - logger.debug("simulating container behaviour: calling createToolSession with toolSessionId : " + - toolSessionID + " and toolContentId: " + currentToolContentId); - try - { - mcService.createToolSession(toolSessionID, currentToolContentId); - logger.debug("simulated container behaviour."); - } - catch(ToolException e) - { - logger.debug("we should never come here."); - } - } -*/ /* * by now, we made sure that the passed tool session id exists in the db as a new record @@ -436,11 +418,24 @@ String learningMode=(String) request.getSession().getAttribute(LEARNING_MODE); logger.debug("users learning mode is: " + learningMode); - + /*if the user's session id AND user id exists in the tool tables go to redo questions.*/ if ((mcQueUsr != null) && learningMode.equals("learner")) { - logger.debug("the learner has already responsed to this content, just generate a read-only report. Use redo questions for this."); - return (mapping.findForward(REDO_QUESTIONS)); + Long sessionUid=mcQueUsr.getMcSessionId(); + logger.debug("users sessionUid: " + sessionUid); + McSession mcUserSession= mcService.getMcSessionByUID(sessionUid); + logger.debug("mcUserSession: " + mcUserSession); + String userSessionId=mcUserSession.getMcSessionId().toString(); + logger.debug("userSessionId: " + userSessionId); + Long toolSessionId=(Long)request.getSession().getAttribute(TOOL_SESSION_ID); + logger.debug("current toolSessionId: " + toolSessionId); + if (toolSessionId.toString().equals(userSessionId)) + { + logger.debug("the user's session id AND user id exists in the tool tables go to redo questions. " + toolSessionId + " mcQueUsr: " + + mcQueUsr + " user id: " + mcQueUsr.getQueUsrId()); + logger.debug("the learner has already responsed to this content, just generate a read-only report. Use redo questions for this."); + return (mapping.findForward(REDO_QUESTIONS)); + } } else if (learningMode.equals("teacher")) { Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringAction.java =================================================================== diff -u -r0f3f4e592b6337d5777631acfbd92d90a6211826 -rdcb4bb59e05ab9fc05be18355abc22d8d5a675e9 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringAction.java (.../McMonitoringAction.java) (revision 0f3f4e592b6337d5777631acfbd92d90a6211826) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringAction.java (.../McMonitoringAction.java) (revision dcb4bb59e05ab9fc05be18355abc22d8d5a675e9) @@ -331,7 +331,12 @@ HttpServletResponse response) throws IOException, ServletException { - logger.debug("dispatching getSummary..."); + McMonitoringStarterAction mcMonitoringStarter= new McMonitoringStarterAction(); + logger.debug("init monitoring data"); + boolean initData=mcMonitoringStarter.initialiseMonitoringData(mapping, form, request, response); + logger.debug("monitoring data initialised.."); + + logger.debug("dispatching getSummary..."+ request); McMonitoringForm mcMonitoringForm = (McMonitoringForm) form; IMcService mcService =McUtils.getToolService(request); if (mcService == null) @@ -369,9 +374,15 @@ HttpServletResponse response) throws IOException, ServletException { - logger.debug("dispatching getInstructions..."); + logger.debug("dispatching getInstructions..." + request); + McMonitoringStarterAction mcMonitoringStarter= new McMonitoringStarterAction(); + logger.debug("init monitoring data"); + boolean initData=mcMonitoringStarter.initialiseMonitoringData(mapping, form, request, response); + logger.debug("monitoring data initialised.."); + McMonitoringForm mcMonitoringForm = (McMonitoringForm) form; IMcService mcService =McUtils.getToolService(request); + logger.debug("mcService: " + mcService); if (mcService == null) { @@ -384,6 +395,7 @@ request.setAttribute(CURRENT_MONITORING_TAB, "instructions"); return (mapping.findForward(LOAD_MONITORING)); } + /** * switches to Stats tab of the Monitoring url @@ -407,7 +419,12 @@ HttpServletResponse response) throws IOException, ServletException { - logger.debug("dispatching getStats..."); + McMonitoringStarterAction mcMonitoringStarter= new McMonitoringStarterAction(); + logger.debug("init monitoring data"); + boolean initData=mcMonitoringStarter.initialiseMonitoringData(mapping, form, request, response); + logger.debug("monitoring data initialised.."); + + logger.debug("dispatching getStats..." + request); McMonitoringForm mcMonitoringForm = (McMonitoringForm) form; IMcService mcService =McUtils.getToolService(request); if (mcService == null) @@ -511,7 +528,7 @@ HttpServletResponse response) throws IOException, ServletException { - logger.debug("dispatching proxy editOptions..."); + logger.debug("dispatching proxy editOptions..." + request); request.setAttribute(SOURCE_MC_STARTER, "monitoring"); logger.debug("SOURCE_MC_STARTER: monitoring"); @@ -544,7 +561,7 @@ HttpServletResponse response) throws IOException, ServletException { - logger.debug("dispatching proxy addOption..."); + logger.debug("dispatching proxy addOption..."+ request); request.setAttribute(SOURCE_MC_STARTER, "monitoring"); logger.debug("SOURCE_MC_STARTER: monitoring"); @@ -576,7 +593,7 @@ HttpServletResponse response) throws IOException, ServletException { - logger.debug("dispatching proxy removeOption..."); + logger.debug("dispatching proxy removeOption..." + request); request.setAttribute(SOURCE_MC_STARTER, "monitoring"); logger.debug("SOURCE_MC_STARTER: monitoring"); @@ -610,7 +627,7 @@ HttpServletResponse response) throws IOException, ServletException { - logger.debug("dispatching proxy moveQuestionDown..."); + logger.debug("dispatching proxy moveQuestionDown..." + request); request.setAttribute(SOURCE_MC_STARTER, "monitoring"); logger.debug("SOURCE_MC_STARTER: monitoring"); @@ -643,7 +660,7 @@ HttpServletResponse response) throws IOException, ServletException { - logger.debug("dispatching proxy moveQuestionUp..."); + logger.debug("dispatching proxy moveQuestionUp..." + request); request.setAttribute(SOURCE_MC_STARTER, "monitoring"); logger.debug("SOURCE_MC_STARTER: monitoring"); @@ -709,7 +726,7 @@ ServletException { - logger.debug("dispatching proxy submitQuestions..."); + logger.debug("dispatching proxy submitQuestions..." + request); request.setAttribute(SOURCE_MC_STARTER, "monitoring"); logger.debug("SOURCE_MC_STARTER: monitoring"); @@ -747,7 +764,7 @@ ServletException { - logger.debug("dispatching proxy deleteOfflineFile..."); + logger.debug("dispatching proxy deleteOfflineFile..." + request); request.setAttribute(SOURCE_MC_STARTER, "monitoring"); logger.debug("SOURCE_MC_STARTER: monitoring"); @@ -816,7 +833,7 @@ ServletException, RepositoryCheckedException { - logger.debug("dispatching proxy deleteOnlineFile..."); + logger.debug("dispatching proxy deleteOnlineFile..." + request); request.setAttribute(SOURCE_MC_STARTER, "monitoring"); logger.debug("SOURCE_MC_STARTER: monitoring"); @@ -851,7 +868,7 @@ ServletException, RepositoryCheckedException { - logger.debug("dispatching proxy submitOnlineFiles..."); + logger.debug("dispatching proxy submitOnlineFiles..." + request); request.setAttribute(SOURCE_MC_STARTER, "monitoring"); logger.debug("SOURCE_MC_STARTER: monitoring"); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringStarterAction.java =================================================================== diff -u -r0f3f4e592b6337d5777631acfbd92d90a6211826 -rdcb4bb59e05ab9fc05be18355abc22d8d5a675e9 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringStarterAction.java (.../McMonitoringStarterAction.java) (revision 0f3f4e592b6337d5777631acfbd92d90a6211826) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McMonitoringStarterAction.java (.../McMonitoringStarterAction.java) (revision dcb4bb59e05ab9fc05be18355abc22d8d5a675e9) @@ -76,27 +76,55 @@ static Logger logger = Logger.getLogger(McMonitoringStarterAction.class.getName()); public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException, McApplicationException { - + throws IOException, ServletException, McApplicationException + { McUtils.cleanUpSessionAbsolute(request); + + ActionForward validateParameters=validateParameters(request, mapping); + logger.debug("validateParamaters: " + validateParameters); + if (validateParameters != null) + { + return validateParameters; + } - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - logger.debug("retrieving mcService from proxy: " + mcService); - request.getSession().setAttribute(TOOL_SERVICE, mcService); + boolean initData=initialiseMonitoringData(mapping, form, request, response); + logger.debug("initData: " + initData); + if (initData == false) + return (mapping.findForward(ERROR_LIST)); + + return (mapping.findForward(LOAD_MONITORING)); + } + + /** + * initialises monitoring data mainly for jsp purposes + * initialiseMonitoringData(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + * + * @param mapping + * @param form + * @param request + * @param response + * @return boolean + */ + public boolean initialiseMonitoringData(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + { + IMcService mcService = (IMcService)request.getSession().getAttribute(TOOL_SERVICE); + logger.debug("mcService: " + mcService); + if (mcService == null) + { + logger.debug("will retrieve mcService"); + mcService = McServiceProxy.getMcService(getServlet().getServletContext()); + logger.debug("retrieving mcService from cache: " + mcService); + } + + request.getSession().setAttribute(TOOL_SERVICE, mcService); McMonitoringForm mcMonitoringForm = (McMonitoringForm) form; /* * persist time zone information to session scope. */ McUtils.persistTimeZone(request); - ActionForward validateParameters=validateParameters(request, mapping); - logger.debug("validateParamaters: " + validateParameters); - if (validateParameters != null) - { - return validateParameters; - } - + /* we have made sure TOOL_CONTENT_ID is passed */ Long toolContentId =(Long) request.getSession().getAttribute(TOOL_CONTENT_ID); logger.debug("toolContentId: " + toolContentId); @@ -108,7 +136,7 @@ { persistError(request, "error.content.doesNotExist"); McUtils.cleanUpSessionAbsolute(request); - return (mapping.findForward(ERROR_LIST)); + return false; } Map summaryToolSessions=MonitoringUtil.populateToolSessions(request, mcContent); @@ -186,13 +214,18 @@ request.getSession().setAttribute(LOWEST_MARK, new Integer(lowestMark).toString()); request.getSession().setAttribute(AVERAGE_MARK, new Integer(averageMark).toString()); /* ends here. */ - - - logger.debug("forwarding to: " + LOAD_MONITORING); - return (mapping.findForward(LOAD_MONITORING)); + return true; } + - + /** + * validates request paramaters based on tool contract + * validateParameters(HttpServletRequest request, ActionMapping mapping) + * + * @param request + * @param mapping + * @return ActionForward + */ protected ActionForward validateParameters(HttpServletRequest request, ActionMapping mapping) { logger.debug("start validating monitoring parameters..."); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java =================================================================== diff -u -r3971dc9408da1bacd6012b197165c66eca01778b -rdcb4bb59e05ab9fc05be18355abc22d8d5a675e9 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java (.../MonitoringUtil.java) (revision 3971dc9408da1bacd6012b197165c66eca01778b) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java (.../MonitoringUtil.java) (revision dcb4bb59e05ab9fc05be18355abc22d8d5a675e9) @@ -172,7 +172,6 @@ logger.debug("total attempt count: " + listMarks.size()); return listMarks.size(); } - /**