Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McQueContent.java =================================================================== diff -u -r2dbeea64b0b9925ebfcc5b10ced841ad134a0f38 -r7178c958439c0def43ca0f2e33515c76b4d6d051 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McQueContent.java (.../McQueContent.java) (revision 2dbeea64b0b9925ebfcc5b10ced841ad134a0f38) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McQueContent.java (.../McQueContent.java) (revision 7178c958439c0def43ca0f2e33515c76b4d6d051) @@ -24,6 +24,7 @@ import java.io.Serializable; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -96,7 +97,19 @@ this.mcOptionsContents = mcOptionsContents; } + public McQueContent(String question, Integer displayOrder, Integer weight, boolean disabled, String feedbackIncorrect, String feedbackCorrect, McContent mcContent, Set mcUsrAttempts, Set mcOptionsContents) { + this.question = question; + this.displayOrder = displayOrder; + this.weight = weight; + this.disabled = disabled; + this.feedbackIncorrect = feedbackIncorrect; + this.feedbackCorrect = feedbackCorrect; + this.mcContent=mcContent; + this.mcUsrAttempts = mcUsrAttempts; + this.mcOptionsContents = mcOptionsContents; + } + public McQueContent(String question, Integer displayOrder, Integer weight, String feedbackCorrect, String feedbackIncorrect, boolean disabled, McContent mcContent, Set mcUsrAttempts, Set mcOptionsContents) { this.question = question; this.displayOrder = displayOrder; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcQueContentDAO.java =================================================================== diff -u -r735c5db341aaba22874662bf7e44ec91a24424c7 -r7178c958439c0def43ca0f2e33515c76b4d6d051 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcQueContentDAO.java (.../IMcQueContentDAO.java) (revision 735c5db341aaba22874662bf7e44ec91a24424c7) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcQueContentDAO.java (.../IMcQueContentDAO.java) (revision 7178c958439c0def43ca0f2e33515c76b4d6d051) @@ -45,6 +45,8 @@ public List refreshQuestionContent(final Long mcContentId); public void cleanAllQuestions(final Long mcContentUid); + + public void cleanAllQuestionsSimple(final Long mcContentUid); public void resetAllQuestions(final Long mcContentUid); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McQueContentDAO.java =================================================================== diff -u -r2535250d78ca2298cbdc24c1bb1bb9a87d9a234c -r7178c958439c0def43ca0f2e33515c76b4d6d051 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McQueContentDAO.java (.../McQueContentDAO.java) (revision 2535250d78ca2298cbdc24c1bb1bb9a87d9a234c) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McQueContentDAO.java (.../McQueContentDAO.java) (revision 7178c958439c0def43ca0f2e33515c76b4d6d051) @@ -47,6 +47,8 @@ private static final String LOAD_QUESTION_CONTENT_BY_CONTENT_ID = "from mcQueContent in class McQueContent where mcQueContent.mcContentId=:mcContentId order by mcQueContent.displayOrder"; + private static final String CLEAN_QUESTION_CONTENT_BY_CONTENT_ID_SIMPLE = "from mcQueContent in class McQueContent where mcQueContent.mcContentId=:mcContentId"; + private static final String CLEAN_QUESTION_CONTENT_BY_CONTENT_ID = "from mcQueContent in class McQueContent where mcQueContent.mcContentId=:mcContentId and mcQueContent.disabled=true"; private static final String REFRESH_QUESTION_CONTENT = "from mcQueContent in class McQueContent where mcQueContent.mcContentId=:mcContentId and mcQueContent.disabled=false"; @@ -171,6 +173,25 @@ } } + public void cleanAllQuestionsSimple(final Long mcContentUid) + { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(CLEAN_QUESTION_CONTENT_BY_CONTENT_ID_SIMPLE) + .setLong("mcContentId", mcContentUid.longValue()) + .list(); + + if(list != null && list.size() > 0){ + logger.debug("will iterate the list of McQueContent"); + Iterator listIterator=list.iterator(); + while (listIterator.hasNext()) + { + McQueContent mcQueContent=(McQueContent)listIterator.next(); + this.getSession().setFlushMode(FlushMode.AUTO); + logger.debug("deleting mcQueContent: " + mcQueContent); + templ.delete(mcQueContent); + } + } + } public void saveMcQueContent(McQueContent mcQueContent) Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java =================================================================== diff -u -r7018cf59202a9562124f6ea36ea1b2a95f5897bb -r7178c958439c0def43ca0f2e33515c76b4d6d051 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java (.../IMcService.java) (revision 7018cf59202a9562124f6ea36ea1b2a95f5897bb) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java (.../IMcService.java) (revision 7178c958439c0def43ca0f2e33515c76b4d6d051) @@ -39,7 +39,6 @@ import org.lamsfoundation.lams.tool.mc.McQueContent; import org.lamsfoundation.lams.tool.mc.McQueUsr; import org.lamsfoundation.lams.tool.mc.McSession; -import org.lamsfoundation.lams.tool.mc.McUploadedFile; import org.lamsfoundation.lams.tool.mc.McUsrAttempt; import org.lamsfoundation.lams.usermanagement.User; @@ -78,6 +77,8 @@ public void removeQuestionContentByMcUid(final Long mcContentUid) throws McApplicationException; + public void cleanAllQuestionsSimple(final Long mcContentUid) throws McApplicationException; + public void resetAllQuestions(final Long mcContentUid) throws McApplicationException; public void cleanAllQuestions(final Long mcContentUid) throws McApplicationException; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java =================================================================== diff -u -r7018cf59202a9562124f6ea36ea1b2a95f5897bb -r7178c958439c0def43ca0f2e33515c76b4d6d051 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java (.../McServicePOJO.java) (revision 7018cf59202a9562124f6ea36ea1b2a95f5897bb) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java (.../McServicePOJO.java) (revision 7178c958439c0def43ca0f2e33515c76b4d6d051) @@ -334,7 +334,21 @@ e); } } + + public void cleanAllQuestionsSimple(final Long mcContentId) throws McApplicationException + { + try + { + mcQueContentDAO.cleanAllQuestionsSimple(mcContentId); + } + catch (DataAccessException e) + { + throw new McApplicationException("Exception occured when lams is cleaning mc question content by mcContentId : " + + e.getMessage(), + e); + } + } public List getAllQuestionEntries(final Long uid) throws McApplicationException { Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java =================================================================== diff -u -rf37e902802cd59114b62435f47e9106df830496d -r7178c958439c0def43ca0f2e33515c76b4d6d051 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java (.../McAction.java) (revision f37e902802cd59114b62435f47e9106df830496d) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java (.../McAction.java) (revision 7178c958439c0def43ca0f2e33515c76b4d6d051) @@ -413,6 +413,10 @@ request.setAttribute(USER_ACTION, userAction); logger.debug("userAction:" + userAction); + Map mapWeights= repopulateMap(request, "questionWeight"); + request.getSession().setAttribute(MAP_WEIGHTS, mapWeights); + System.out.print("MAP_WEIGHTS:" + request.getSession().getAttribute(MAP_WEIGHTS)); + Map mapQuestionsContent=repopulateMap(request, "questionContent"); logger.debug("mapQuestionsContent after shrinking: " + mapQuestionsContent); logger.debug("mapQuestionsContent size after shrinking: " + mapQuestionsContent.size()); @@ -1473,20 +1477,24 @@ mapQuestionsContent=(Map) request.getSession().getAttribute(MAP_QUESTIONS_CONTENT); logger.debug("Submit final MAP_QUESTIONS_CONTENT :" + mapQuestionsContent); - - Map mapGeneralOptionsContent=(Map)request.getSession().getAttribute(MAP_GENERAL_OPTIONS_CONTENT); - logger.debug("Submit final MAP_GENERAL_OPTIONS_CONTENT :" + mapGeneralOptionsContent); - - Map mapGeneralSelectedOptionsContent=(Map)request.getSession().getAttribute(MAP_GENERAL_SELECTED_OPTIONS_CONTENT); - logger.debug("Submit final MAP_GENERAL_SELECTED_OPTIONS_CONTENT :" + mapGeneralSelectedOptionsContent); Map mapFeedbackIncorrect =(Map)request.getSession().getAttribute(MAP_FEEDBACK_INCORRECT); logger.debug("Submit final MAP_FEEDBACK_INCORRECT :" + mapFeedbackIncorrect); Map mapFeedbackCorrect =(Map)request.getSession().getAttribute(MAP_FEEDBACK_CORRECT); logger.debug("Submit final MAP_FEEDBACK_CORRECT :" + mapFeedbackCorrect); + + cleanupExistingQuestions(request, mcContent); + logger.debug("post cleanupExistingQuestions"); + + + persistQuestions(request, mapQuestionsContent, mapFeedbackIncorrect, mapFeedbackCorrect, mcContent); + logger.debug("post persistQuestions"); + + + + - /* Map mapWeights=repopulateCurrentWeightsMap(request, "questionWeight"); logger.debug("final mapWeights :" + mapWeights); @@ -1535,13 +1543,11 @@ //logger.debug("all questions cleaned for :" + mcContent.getUid()); - -/* logger.debug("will do addUploadedFilesMetaData"); McUtils.addUploadedFilesMetaData(request,mcContent); logger.debug("done addUploadedFilesMetaData"); -*/ + errors.clear(); errors.add(Globals.ERROR_KEY,new ActionMessage("submit.successful")); @@ -1674,8 +1680,163 @@ mcAuthoringForm.resetUserAction(); return (mapping.findForward(LOAD_FILE_CONTENT)); } + + protected void cleanupExistingQuestions(HttpServletRequest request, McContent mcContent) + { + IMcService mcService =McUtils.getToolService(request); + logger.debug("remove questions by mcQueContent uid : " + mcContent.getUid()); + mcService.cleanAllQuestionsSimple(mcContent.getUid()); + } + protected void persistQuestions(HttpServletRequest request, Map mapQuestionsContent, Map mapFeedbackIncorrect, Map mapFeedbackCorrect, McContent mcContent) + { + IMcService mcService =McUtils.getToolService(request); + logger.debug("mapQuestionsContent to be persisted :" + mapQuestionsContent); + logger.debug("mapFeedbackIncorrect :" + mapFeedbackIncorrect); + logger.debug("mapFeedbackCorrect :" + mapFeedbackCorrect); + + + Map mapGeneralOptionsContent=(Map)request.getSession().getAttribute(MAP_GENERAL_OPTIONS_CONTENT); + logger.debug("final MAP_GENERAL_OPTIONS_CONTENT :" + mapGeneralOptionsContent); + + Map mapGeneralSelectedOptionsContent=(Map)request.getSession().getAttribute(MAP_GENERAL_SELECTED_OPTIONS_CONTENT); + logger.debug("final MAP_GENERAL_SELECTED_OPTIONS_CONTENT :" + mapGeneralSelectedOptionsContent); + + Map mapWeights= repopulateMap(request, "questionWeight"); + request.getSession().setAttribute(MAP_WEIGHTS, mapWeights); + System.out.print("MAP_WEIGHTS:" + request.getSession().getAttribute(MAP_WEIGHTS)); + + + Iterator itQuestionsMap = mapQuestionsContent.entrySet().iterator(); + while (itQuestionsMap.hasNext()) { + Map.Entry pairs = (Map.Entry)itQuestionsMap.next(); + logger.debug("using the pair: " + pairs.getKey() + " = " + pairs.getValue()); + if ((pairs.getValue() != null) && (!pairs.getValue().equals(""))) + { + 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); + Integer currentWeight= new Integer(mapWeights.get(pairs.getKey()).toString()); + logger.debug("currentWeight:" + currentWeight); + */ + + String currentFeedbackIncorrect=(String)mapFeedbackIncorrect.get(pairs.getKey()); + logger.debug("currentFeedbackIncorrect: " + currentFeedbackIncorrect); + if (currentFeedbackIncorrect == null) currentFeedbackIncorrect=""; + + String currentFeedbackCorrect=(String)mapFeedbackCorrect.get(pairs.getKey()); + logger.debug("currentFeedbackCorrect: " + currentFeedbackCorrect); + if (currentFeedbackCorrect == null) currentFeedbackCorrect=""; + + String currentWeight=(String) mapWeights.get(pairs.getKey().toString()); + logger.debug("currentWeight: " + currentWeight); + + McQueContent mcQueContent= new McQueContent(pairs.getValue().toString(), + new Integer(pairs.getKey().toString()), + new Integer(currentWeight), + false, + currentFeedbackIncorrect, + currentFeedbackCorrect, + mcContent, + new HashSet(), + new HashSet() + ); + mcService.createMcQue(mcQueContent); + logger.debug("persisted mcQueContent: " + mcQueContent); + + logger.debug("remove existing options for mcQueContent : " + mcQueContent.getUid()); + mcService.removeMcOptionsContentByQueId(mcQueContent.getUid()); + logger.debug("removed all mcOptionsContents for mcQueContentId :" + mcQueContent.getUid()); + + + if (mcQueContent != null) + { + logger.debug("pre persistOptions for: " + mcQueContent); + logger.debug("sending :" + pairs.getKey().toString()); + persistOptions(request, mapGeneralOptionsContent, mapGeneralSelectedOptionsContent, mcQueContent, pairs.getKey().toString()); + logger.debug("post persistOptions"); + } + } + } + + } + + + protected void persistOptions(HttpServletRequest request, Map mapGeneralOptionsContent, Map mapGeneralSelectedOptionsContent, McQueContent mcQueContent, String questionIndex) + { + IMcService mcService =McUtils.getToolService(request); + + logger.debug("passed questionIndex: " + questionIndex); + + Iterator itOptionsMap = mapGeneralOptionsContent.entrySet().iterator(); + while (itOptionsMap.hasNext()) { + Map.Entry pairs = (Map.Entry)itOptionsMap.next(); + logger.debug("checking the general options pair: " + pairs.getKey() + " = " + pairs.getValue()); + if ((pairs.getValue() != null) && (!pairs.getValue().equals(""))) + { + Iterator itSelectedOptionsMap = mapGeneralSelectedOptionsContent.entrySet().iterator(); + while (itSelectedOptionsMap.hasNext()) + { + Map.Entry selectedPairs = (Map.Entry)itSelectedOptionsMap.next(); + logger.debug("checking the general selected options pair: " + selectedPairs.getKey() + " = " + selectedPairs.getValue()); + + logger.debug("dubuging: " + pairs.getKey() + "---" + questionIndex); + if (pairs.getKey().equals(selectedPairs.getKey()) && questionIndex.equals(pairs.getKey())) + { + logger.debug("using updated equal question: " + pairs.getKey()); + Map currentOptions=(Map) pairs.getValue(); + Map selectedOptions=(Map) selectedPairs.getValue(); + + persistOptionsFinal(request, currentOptions,selectedOptions,mcQueContent); + } + } + } + } + } + + + protected void persistOptionsFinal(HttpServletRequest request, Map currentOptions, Map selectedOptions, McQueContent mcQueContent) + { + IMcService mcService =McUtils.getToolService(request); + + logger.debug("passed currentOptions: " + currentOptions); + logger.debug("passed selectedOptions: " + selectedOptions); + + Iterator itCurrentOptions = currentOptions.entrySet().iterator(); + + + boolean selected=false; + while (itCurrentOptions.hasNext()) + { + Map.Entry pairs = (Map.Entry)itCurrentOptions.next(); + logger.debug("checking the current options pair: " + pairs.getKey() + " = " + pairs.getValue()); + + selected=false; + Iterator itSelectedOptions = selectedOptions.entrySet().iterator(); + while (itSelectedOptions.hasNext()) + { + Map.Entry selectedPairs = (Map.Entry)itSelectedOptions.next(); + logger.debug("checking the selected options pair: " + selectedPairs.getKey() + " = " + selectedPairs.getValue()); + selected=false; + if (pairs.getValue().equals(selectedPairs.getValue())) + { + selected=true; + logger.debug("set selected to true for: " + pairs.getValue()); + break; + } + } + + logger.debug("pre-persist mcOptionsContent: " + pairs.getValue() + " " + selected); + logger.debug("pre-persist mcOptionsContent, using mcQueContent: " + mcQueContent); + McOptsContent mcOptionsContent= new McOptsContent(selected,pairs.getValue().toString() , mcQueContent, new HashSet()); + logger.debug("created mcOptionsContent: " + mcOptionsContent); + mcService.saveMcOptionsContent(mcOptionsContent); + logger.debug("persisted the answer: " + pairs.getValue().toString()); + } + } + protected McContent createContent(HttpServletRequest request, McAuthoringForm mcAuthoringForm) { IMcService mcService =McUtils.getToolService(request);