Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java =================================================================== diff -u -r284785a0cc2d61ac8a129a69888b3442141904ab -r259d377ac126220dbeed3feedc9096d1f441b4a1 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java (.../McAppConstants.java) (revision 284785a0cc2d61ac8a129a69888b3442141904ab) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java (.../McAppConstants.java) (revision 259d377ac126220dbeed3feedc9096d1f441b4a1) @@ -112,8 +112,11 @@ public static final String MAP_QUESTIONS_CONTENT ="mapQuestionsContent"; public static final String MAP_OPTIONS_CONTENT ="mapOptionsContent"; public static final String MAP_DEFAULTOPTIONS_CONTENT ="mapDefaultOptionsContent"; + public static final String MAP_DISABLED_QUESTIONS ="mapDisabledQuestions"; + public static final String SELECTED_QUESTION_CONTENT_UID ="selectedQuestionContentUid"; public static final String SELECTED_QUESTION ="selectedQuestion"; + public static final String SELECTED_QUESTION_INDEX ="selectedQuestionIndex"; public static final String MAP_QUESTION_CONTENT ="mapQuestionContent"; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McResources.properties =================================================================== diff -u -r8742c4d01b2ac066988448e0c64d76998d5f4f5b -r259d377ac126220dbeed3feedc9096d1f441b4a1 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McResources.properties (.../McResources.properties) (revision 8742c4d01b2ac066988448e0c64d76998d5f4f5b) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McResources.properties (.../McResources.properties) (revision 259d377ac126220dbeed3feedc9096d1f441b4a1) @@ -51,6 +51,8 @@ error.defaultquestion.empty =The first question can not be empty. submit.successful =The content has been created successfully. +error.question.addNotAllowed.thisScreen = The question texts can not be modified in this screen once they have options attached to them. Please use the "Options" button to edit question texts. + error.content.locked =The content has been locked since it is being used by one mor more learners. The modification of the content is not allowed. error.content.inUse =The modification of the content is not allowed since one or more students has attempted the activity. error.content.beingModified =The content creation is not allowed since the same content is being modified. Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McQueContentDAO.java =================================================================== diff -u -r8742c4d01b2ac066988448e0c64d76998d5f4f5b -r259d377ac126220dbeed3feedc9096d1f441b4a1 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McQueContentDAO.java (.../McQueContentDAO.java) (revision 8742c4d01b2ac066988448e0c64d76998d5f4f5b) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McQueContentDAO.java (.../McQueContentDAO.java) (revision 259d377ac126220dbeed3feedc9096d1f441b4a1) @@ -25,11 +25,8 @@ import org.apache.log4j.Logger; import org.hibernate.FlushMode; -import org.hibernate.HibernateException; -import org.hibernate.Session; import org.lamsfoundation.lams.tool.mc.McQueContent; import org.lamsfoundation.lams.tool.mc.dao.IMcQueContentDAO; -import org.springframework.orm.hibernate3.HibernateCallback; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java =================================================================== diff -u -r8742c4d01b2ac066988448e0c64d76998d5f4f5b -r259d377ac126220dbeed3feedc9096d1f441b4a1 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java (.../IMcService.java) (revision 8742c4d01b2ac066988448e0c64d76998d5f4f5b) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java (.../IMcService.java) (revision 259d377ac126220dbeed3feedc9096d1f441b4a1) @@ -73,6 +73,8 @@ public void removeMcQueContent(McQueContent mcQueContent) throws McApplicationException; + public void saveOrUpdateMcQueContent(McQueContent mcQueContent) throws McApplicationException; + public void removeMcOptionsContentByQueId(Long mcQueContentId) throws McApplicationException; public void removeMcOptionsContent(McOptsContent mcOptsContent); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java =================================================================== diff -u -r8742c4d01b2ac066988448e0c64d76998d5f4f5b -r259d377ac126220dbeed3feedc9096d1f441b4a1 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java (.../McServicePOJO.java) (revision 8742c4d01b2ac066988448e0c64d76998d5f4f5b) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java (.../McServicePOJO.java) (revision 259d377ac126220dbeed3feedc9096d1f441b4a1) @@ -180,6 +180,22 @@ e); } } + + + public void saveOrUpdateMcQueContent(McQueContent mcQueContent) throws McApplicationException + { + try + { + mcQueContentDAO.saveOrUpdateMcQueContent(mcQueContent); + } + catch (DataAccessException e) + { + throw new McApplicationException("Exception occured when lams is updating mc que content: " + + e.getMessage(), + e); + } + } + public void createMcSession(McSession mcSession) throws McApplicationException { Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java =================================================================== diff -u -r8742c4d01b2ac066988448e0c64d76998d5f4f5b -r259d377ac126220dbeed3feedc9096d1f441b4a1 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java (.../McAction.java) (revision 8742c4d01b2ac066988448e0c64d76998d5f4f5b) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java (.../McAction.java) (revision 259d377ac126220dbeed3feedc9096d1f441b4a1) @@ -229,22 +229,31 @@ IMcService mcService =McUtils.getToolService(request); logger.debug("mcService:" + mcService); + String userAction=null; if (mcAuthoringForm.getAddQuestion() != null) { userAction="addQuestion"; request.setAttribute(USER_ACTION, userAction); logger.debug("userAction:" + userAction); - /*Map mapQuestionsContent=(Map) request.getSession().getAttribute(MAP_QUESTIONS_CONTENT); - logger.debug("mapQuestionsContent: " + mapQuestionsContent); - */ - - Map mapQuestionsContent=repopulateMap(request, "questionContent"); + Map mapQuestionsContent=repopulateMap(request, "questionContent"); logger.debug("mapQuestionsContent after shrinking: " + mapQuestionsContent); - logger.debug("mapQuestionsContent size after shrinking: " + mapQuestionsContent.size()); + logger.debug("addQuestion action is not allowed."); + logger.debug("mapQuestionsContent size after shrinking: " + mapQuestionsContent.size()); - addQuestion(request, mcAuthoringForm, mapQuestionsContent, true); + if (verifyAddQuestion(request) == false) + { + ActionMessages errors= new ActionMessages(); + errors.add(Globals.ERROR_KEY,new ActionMessage("error.question.addNotAllowed.thisScreen")); + logger.debug("error.question.addNotAllowed.thisScreeto ActionMessages"); + saveErrors(request,errors); + mcAuthoringForm.resetUserAction(); + logger.debug("return to LOAD_QUESTIONS to fix error."); + return (mapping.findForward(LOAD_QUESTIONS)); + } + + addQuestion(request, mcAuthoringForm, mapQuestionsContent, true); logger.debug("after addQuestion"); mcAuthoringForm.resetUserAction(); @@ -256,12 +265,7 @@ request.setAttribute(USER_ACTION, userAction); logger.debug("userAction:" + userAction); - /* - Map mapQuestionsContent=(Map) request.getSession().getAttribute(MAP_QUESTIONS_CONTENT); - logger.debug("mapQuestionsContent: " + mapQuestionsContent); - */ - - Map mapQuestionsContent=repopulateMap(request, "questionContent"); + Map mapQuestionsContent=repopulateMap(request, "questionContent"); logger.debug("mapQuestionsContent after shrinking: " + mapQuestionsContent); logger.debug("mapQuestionsContent size after shrinking: " + mapQuestionsContent.size()); @@ -304,6 +308,28 @@ request.getSession().setAttribute(MAP_QUESTIONS_CONTENT, mapQuestionsContent); logger.debug("updated Questions Map: " + request.getSession().getAttribute(MAP_QUESTIONS_CONTENT)); } + + Map mapDisabledQuestions=(Map) request.getSession().getAttribute(MAP_DISABLED_QUESTIONS); + logger.debug("mapDisabledQuestions" + mapDisabledQuestions); + logger.debug("attempt removing deletableQuestionEntry from mapDisabledQuestions: " + mapDisabledQuestions); + + Iterator itMap = mapDisabledQuestions.entrySet().iterator(); + while (itMap.hasNext()) { + Map.Entry pairs = (Map.Entry)itMap.next(); + logger.debug("the pair: " + pairs.getKey() + " = " + pairs.getValue()); + if ((pairs.getValue() != null) && (!pairs.getValue().equals(""))) + { + if (pairs.getValue().equals(deletableQuestionEntry)) + { + logger.debug("deletableQuestionEntry found in mapDisabledQuestions: " + deletableQuestionEntry); + mapDisabledQuestions.remove(pairs.getKey()); + logger.debug("removed deletableQuestionEntry from mapDisabledQuestions"); + request.getSession().setAttribute(MAP_DISABLED_QUESTIONS, mapDisabledQuestions); + logger.debug("updated MAP_DISABLED_QUESTIONS: " + request.getSession().getAttribute(MAP_DISABLED_QUESTIONS)); + } + } + } + mcAuthoringForm.resetUserAction(); return (mapping.findForward(LOAD_QUESTIONS)); } @@ -313,18 +339,25 @@ request.setAttribute(USER_ACTION, userAction); logger.debug("userAction:" + userAction); - /* - Map mapQuestionsContent=(Map) request.getSession().getAttribute(MAP_QUESTIONS_CONTENT); - logger.debug("mapQuestionsContent: " + mapQuestionsContent); - */ - - Map mapQuestionsContent=repopulateMap(request, "questionContent"); + if (verifyAddQuestion(request) == false) + { + ActionMessages errors= new ActionMessages(); + errors.add(Globals.ERROR_KEY,new ActionMessage("error.question.addNotAllowed.thisScreen")); + logger.debug("error.question.addNotAllowed.thisScreeto ActionMessages"); + saveErrors(request,errors); + mcAuthoringForm.resetUserAction(); + logger.debug("return to LOAD_QUESTIONS to fix error."); + return (mapping.findForward(LOAD_QUESTIONS)); + } + + Map mapQuestionsContent=repopulateMap(request, "questionContent"); logger.debug("mapQuestionsContent after shrinking: " + mapQuestionsContent); logger.debug("mapQuestionsContent size after shrinking: " + mapQuestionsContent.size()); request.getSession().setAttribute(MAP_QUESTIONS_CONTENT, mapQuestionsContent); String questionIndex =mcAuthoringForm.getQuestionIndex(); logger.debug("questionIndex:" + questionIndex); + String editableQuestionEntry=(String)mapQuestionsContent.get(questionIndex); logger.debug("editableQuestionEntry:" + editableQuestionEntry); @@ -339,6 +372,7 @@ return (mapping.findForward(LOAD_QUESTIONS)); } + Long toolContentId=(Long)request.getSession().getAttribute(TOOL_CONTENT_ID); logger.debug("toolContentId:" + toolContentId); @@ -358,13 +392,29 @@ McQueContent mcQueContent =mcService.getQuestionContentByQuestionText(editableQuestionEntry, mcContent.getUid()); logger.debug("mcQueContent:" + mcQueContent); + if (mcQueContent == null) + { + logger.debug("convenience add mcQueContent"); + mcQueContent= new McQueContent(editableQuestionEntry, + new Integer(questionIndex), + mcContent, + new HashSet(), + new HashSet() + ); + mcService.createMcQue(mcQueContent); + logger.debug("persisted convenience mcQueContent: " + mcQueContent); + } + request.getSession().setAttribute(SELECTED_QUESTION, mcQueContent.getQuestion()); logger.debug("SELECTED_QUESTION:" + request.getSession().getAttribute(SELECTED_QUESTION)); request.getSession().setAttribute(SELECTED_QUESTION_CONTENT_UID, mcQueContent.getUid() ); logger.debug("SELECTED_QUESTION_CONTENT_UID:" + request.getSession().getAttribute(SELECTED_QUESTION_CONTENT_UID)); + request.getSession().setAttribute(SELECTED_QUESTION_INDEX, questionIndex); + logger.debug("SELECTED_QUESTION_INDEX:" + request.getSession().getAttribute(SELECTED_QUESTION_INDEX)); + Map mapOptionsContent= new TreeMap(new McComparator()); logger.debug("initialized mapOptionsContent:" + mapOptionsContent); @@ -416,12 +466,7 @@ request.setAttribute(USER_ACTION, userAction); logger.debug("userAction:" + userAction); - /* - Map mapOptionsContent=(Map) request.getSession().getAttribute(MAP_OPTIONS_CONTENT); - logger.debug("mapOptionsContent: " + mapOptionsContent); - */ - - Map mapOptionsContent=repopulateMap(request,"optionContent"); + Map mapOptionsContent=repopulateMap(request,"optionContent"); logger.debug("mapOptionsContent after shrinking: " + mapOptionsContent); logger.debug("mapOptionsContent size after shrinking: " + mapOptionsContent.size()); @@ -470,12 +515,7 @@ String optionIndex =mcAuthoringForm.getOptionIndex(); logger.debug("optionIndex:" + optionIndex); - /* - Map mapOptionsContent=(Map) request.getSession().getAttribute(MAP_QUESTIONS_CONTENT); - logger.debug("mapQuestionsContent: " + mapOptionsContent); - */ - - Map mapOptionsContent=repopulateMap(request, "optionContent"); + Map mapOptionsContent=repopulateMap(request, "optionContent"); logger.debug("mapOptionsContent after shrinking: " + mapOptionsContent); logger.debug("mapOptionsContent size after shrinking: " + mapOptionsContent.size()); @@ -515,7 +555,64 @@ request.setAttribute(USER_ACTION, userAction); logger.debug("userAction:" + userAction); - mcAuthoringForm.resetUserAction(); + /** make the particular question content in the main page disabled for user access*/ + Long selectedQuestionContentUid=(Long) request.getSession().getAttribute(SELECTED_QUESTION_CONTENT_UID); + logger.debug("selectedQuestionContentUid:" + selectedQuestionContentUid); + + McQueContent mcQueContent = mcService.retrieveMcQueContentByUID(selectedQuestionContentUid); + logger.debug("mcQueContent:" + mcQueContent); + mcQueContent.setDisabled(true); + logger.debug("made the question content disabled"); + mcService.saveOrUpdateMcQueContent(mcQueContent); + logger.debug("mcQueContent updated with disabled"); + + + Map mapDisabledQuestions=(Map) request.getSession().getAttribute(MAP_DISABLED_QUESTIONS); + logger.debug("mapDisabledQuestions" + mapDisabledQuestions); + + String selectedQuestionIndex=(String) request.getSession().getAttribute(SELECTED_QUESTION_INDEX); + logger.debug("SELECTED_QUESTION_INDEX:" + selectedQuestionIndex); + + String selectedQuestion=(String) request.getSession().getAttribute(SELECTED_QUESTION); + logger.debug("SELECTED_QUESTION:" + selectedQuestion); + + mapDisabledQuestions.put(selectedQuestionIndex, selectedQuestion); + logger.debug("mapDisabledQuestions:" + mapDisabledQuestions); + + request.getSession().setAttribute(MAP_DISABLED_QUESTIONS, mapDisabledQuestions); + logger.debug("MAP_DISABLED_QUESTIONS:" + mapDisabledQuestions); + + + + /** parse all the options and persist them */ + Map mapOptionsContent=repopulateMap(request,"optionContent"); + logger.debug("mapOptionsContent after shrinking: " + mapOptionsContent); + logger.debug("mapOptionsContent size after shrinking: " + mapOptionsContent.size()); + request.getSession().setAttribute(MAP_OPTIONS_CONTENT, mapOptionsContent); + logger.debug("Options Map: " + request.getSession().getAttribute(MAP_OPTIONS_CONTENT)); + + mcService.removeMcOptionsContentByQueId(selectedQuestionContentUid); + logger.debug("removed all mcOptionsContents for mcQueContentId :" + selectedQuestionContentUid); + + if (mcQueContent != null) + { + /** iterate the options Map and persist the options into the DB*/ + Iterator itOptionsMap = mapOptionsContent.entrySet().iterator(); + while (itOptionsMap.hasNext()) { + Map.Entry pairs = (Map.Entry)itOptionsMap.next(); + logger.debug("adding the pair: " + pairs.getKey() + " = " + pairs.getValue()); + if ((pairs.getValue() != null) && (!pairs.getValue().equals(""))) + { + McOptsContent mcOptionsContent= new McOptsContent(false,pairs.getValue().toString() , mcQueContent, new HashSet()); + logger.debug("created mcOptionsContent: " + mcOptionsContent); + mcService.saveMcOptionsContent(mcOptionsContent); + logger.debug("persisted the answer: " + pairs.getValue().toString()); + } + } + } + logger.debug("doneOptions persists all the options"); + + mcAuthoringForm.resetUserAction(); return (mapping.findForward(LOAD_QUESTIONS)); } @@ -767,6 +864,7 @@ { logger.debug("checking existing question text: " + pairs.getValue().toString() + " and mcContent uid():" + mcContent.getUid()); McQueContent mcQueContent=mcService.getQuestionContentByQuestionText(pairs.getValue().toString(), mcContent.getUid()); + logger.debug("mcQueContent: " + mcQueContent); if (mcQueContent == null) { @@ -779,12 +877,51 @@ mcService.createMcQue(mcQueContent); logger.debug("persisted mcQueContent: " + mcQueContent); } + else + { + logger.debug("is mcQueContent disabled: " + mcQueContent.isDisabled()); + } } } } + protected boolean verifyAddQuestion(HttpServletRequest request) + { + logger.debug("will verify addQuestion"); + Map mapDisabledQuestions=(Map) request.getSession().getAttribute(MAP_DISABLED_QUESTIONS); + logger.debug("MAP_DISABLED_QUESTIONS:" + mapDisabledQuestions); + + String parameterType="questionContent"; + + Iterator itQuestionsMap = mapDisabledQuestions.entrySet().iterator(); + + while (itQuestionsMap.hasNext()) { + Map.Entry pairs = (Map.Entry)itQuestionsMap.next(); + + for (long i=1; i <= MAX_QUESTION_COUNT ; i++) + { + String candidateQuestionEntry =request.getParameter(parameterType + i); + //logger.debug("is it the same questionIndex?: " + new Long(i).toString() + " *** " + i); + + if (new Long(i).toString().equalsIgnoreCase(pairs.getKey().toString())) + { + logger.debug( i + " is a disabled question: " + candidateQuestionEntry + " *** " + pairs.getValue().toString()); + + if (!(candidateQuestionEntry.equals(pairs.getValue().toString()))) + { + logger.debug(candidateQuestionEntry + " " + i); + logger.debug("give a warning, the action is not allowed."); + return false; + } + } + } + } + return true; + } + + /** * persists error messages to request scope Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java =================================================================== diff -u -r4336aafba788b801aa78c2dc27f8d07a2f932be7 -r259d377ac126220dbeed3feedc9096d1f441b4a1 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java (.../McStarterAction.java) (revision 4336aafba788b801aa78c2dc27f8d07a2f932be7) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java (.../McStarterAction.java) (revision 259d377ac126220dbeed3feedc9096d1f441b4a1) @@ -109,6 +109,9 @@ Map mapOptionsContent= new TreeMap(new McComparator()); Map mapDefaultOptionsContent= new TreeMap(new McComparator()); + Map mapDisabledQuestions= new TreeMap(new McComparator()); + request.getSession().setAttribute(MAP_DISABLED_QUESTIONS, mapDisabledQuestions); + McAuthoringForm mcAuthoringForm = (McAuthoringForm) form; mcAuthoringForm.resetRadioBoxes(); Index: lams_tool_lamc/web/authoringMaincontent.jsp =================================================================== diff -u -rb261a00d2159e4a3b753a6637fe2891e24819595 -r259d377ac126220dbeed3feedc9096d1f441b4a1 --- lams_tool_lamc/web/authoringMaincontent.jsp (.../authoringMaincontent.jsp) (revision b261a00d2159e4a3b753a6637fe2891e24819595) +++ lams_tool_lamc/web/authoringMaincontent.jsp (.../authoringMaincontent.jsp) (revision 259d377ac126220dbeed3feedc9096d1f441b4a1) @@ -121,49 +121,52 @@ - - - : - - " value="" - size="50" maxlength="255"> - - - - - - - - - - - - - - - - - : - - " value="" - size="50" maxlength="255"> - - - - - - - - - - - - - + + + + : + + " value="" + size="50" maxlength="255" > + + + + + + + + + + + + + + + + + + : + + " value="" + size="50" maxlength="255" > + + + + + + + + + + + + + +