Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java,v diff -u -r1.41 -r1.42 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java 22 Nov 2005 20:38:06 -0000 1.41 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java 27 Nov 2005 16:08:45 -0000 1.42 @@ -150,6 +150,10 @@ public static final String MAP_DISABLED_QUESTIONS ="mapDisabledQuestions"; public static final String MAP_GENERAL_OPTIONS_CONTENT ="mapGeneralOptionsContent"; public static final String MAP_GENERAL_SELECTED_OPTIONS_CONTENT ="mapGeneralSelectedOptionsContent"; + public static final String MAP_STARTUP_GENERAL_OPTIONS_CONTENT ="mapStartupGeneralOptionsContent"; + public static final String MAP_STARTUP_GENERAL_SELECTED_OPTIONS_CONTENT ="mapStartupGeneralSelectedOptionsContent"; + public static final String MAP_STARTUP_GENERAL_OPTIONS_QUEID ="mapStartupGeneralOptionsQueId"; + public static final String MAP_GENERAL_CHECKED_OPTIONS_CONTENT ="mapGeneralCheckedOptionsContent"; public static final String MAP_LEARNER_QUESTIONS_CONTENT ="mapLearnerQuestionsContent"; public static final String MAP_LEARNER_CHECKED_OPTIONS_CONTENT ="mapLearnerCheckedOptionsContent"; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java,v diff -u -r1.27 -r1.28 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java 25 Nov 2005 12:02:19 -0000 1.27 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java 27 Nov 2005 16:08:44 -0000 1.28 @@ -74,10 +74,14 @@ public void removeMcQueContent(McQueContent mcQueContent) throws McApplicationException; + public McQueContent getMcQueContentByUID(Long uid) throws McApplicationException; + public void saveOrUpdateMcQueContent(McQueContent mcQueContent) throws McApplicationException; public void removeQuestionContentByMcUid(final Long mcContentUid) throws McApplicationException; + public McOptsContent getMcOptionsContentByUID(Long uid) throws McApplicationException; + public void cleanAllQuestionsSimple(final Long mcContentUid) throws McApplicationException; public void resetAllQuestions(final Long mcContentUid) throws McApplicationException; @@ -125,7 +129,7 @@ public McOptsContent getOptionContentByOptionText(final String option, final Long mcQueContentUid); public void updateMcOptionsContent(McOptsContent mcOptsContent) throws McApplicationException; - + public void deleteMcOptionsContent(McOptsContent mcOptsContent) throws McApplicationException; public void deleteMcOptionsContentByUID(Long uid) throws McApplicationException; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java,v diff -u -r1.30 -r1.31 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java 25 Nov 2005 12:02:19 -0000 1.30 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java 27 Nov 2005 16:08:44 -0000 1.31 @@ -187,6 +187,21 @@ } + public McQueContent getMcQueContentByUID(Long uid) throws McApplicationException + { + try + { + return mcQueContentDAO.getMcQueContentByUID(uid); + } + catch (DataAccessException e) + { + throw new McApplicationException("Exception occured when lams is getting mc que content by uid: " + + e.getMessage(), + e); + } + } + + public void saveOrUpdateMcQueContent(McQueContent mcQueContent) throws McApplicationException { try @@ -734,6 +749,21 @@ } } + + public McOptsContent getMcOptionsContentByUID(Long uid) throws McApplicationException + { + try + { + return getMcOptionsContentByUID(uid); + } + catch (DataAccessException e) + { + throw new McApplicationException("Exception occured when lams is getting opt content by uid" + + e.getMessage(),e); + } + } + + public void saveMcOptionsContent(McOptsContent mcOptsContent) throws McApplicationException { try Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java,v diff -u -r1.11 -r1.12 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java 25 Nov 2005 12:02:19 -0000 1.11 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java 27 Nov 2005 16:08:45 -0000 1.12 @@ -8,6 +8,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; @@ -17,7 +18,6 @@ import org.apache.log4j.Logger; import org.lamsfoundation.lams.tool.exception.ToolException; import org.lamsfoundation.lams.tool.mc.McAppConstants; -import org.lamsfoundation.lams.tool.mc.McApplicationException; import org.lamsfoundation.lams.tool.mc.McComparator; import org.lamsfoundation.lams.tool.mc.McContent; import org.lamsfoundation.lams.tool.mc.McOptsContent; @@ -373,7 +373,108 @@ return false; } + + public static Map rebuildStartupGeneralOptionsQueIdfromDB(HttpServletRequest request, Map mapQuestionsUidContent) + { + IMcService mcService =McUtils.getToolService(request); + Map map= new TreeMap(new McComparator()); + + Iterator itMap = mapQuestionsUidContent.entrySet().iterator(); + Long mapIndex=new Long(1); + while (itMap.hasNext()) { + Map.Entry pairs = (Map.Entry)itMap.next(); + logger.debug("using the pair: " + pairs.getKey() + " = " + pairs.getValue()); + String currentQuestionUid=pairs.getValue().toString(); + logger.debug("currentQuestionUid: " + currentQuestionUid); + List listQuestionOptions=mcService.findMcOptionsContentByQueId(new Long(currentQuestionUid)); + logger.debug("listQuestionOptions: " + listQuestionOptions); + Map mapQuestionOptions=generateOptionsQueIdMap(listQuestionOptions); + map.put(mapIndex.toString(),mapQuestionOptions); + mapIndex=new Long(mapIndex.longValue()+1); + } + return map; + } + + + public static Map rebuildStartupGeneralSelectedOptionsContentMapfromDB(HttpServletRequest request, Map mapQuestionsUidContent) + { + IMcService mcService =McUtils.getToolService(request); + Map mapStartupGeneralOptionsContent= new TreeMap(new McComparator()); + + Iterator itMap = mapQuestionsUidContent.entrySet().iterator(); + Long mapIndex=new Long(1); + while (itMap.hasNext()) { + Map.Entry pairs = (Map.Entry)itMap.next(); + logger.debug("using the pair: " + pairs.getKey() + " = " + pairs.getValue()); + String currentQuestionUid=pairs.getValue().toString(); + logger.debug("currentQuestionUid: " + currentQuestionUid); + List listQuestionOptions=mcService.getPersistedSelectedOptions(new Long(currentQuestionUid)); + logger.debug("listQuestionOptions: " + listQuestionOptions); + Map mapQuestionOptions=generateOptionsMap(listQuestionOptions); + mapStartupGeneralOptionsContent.put(mapIndex.toString(),mapQuestionOptions); + mapIndex=new Long(mapIndex.longValue()+1); + } + return mapStartupGeneralOptionsContent; + } + + public static Map rebuildStartupGeneralOptionsContentMapfromDB(HttpServletRequest request, Map mapQuestionsUidContent) + { + IMcService mcService =McUtils.getToolService(request); + Map mapStartupGeneralOptionsContent= new TreeMap(new McComparator()); + + Iterator itMap = mapQuestionsUidContent.entrySet().iterator(); + Long mapIndex=new Long(1); + while (itMap.hasNext()) { + Map.Entry pairs = (Map.Entry)itMap.next(); + logger.debug("using the pair: " + pairs.getKey() + " = " + pairs.getValue()); + String currentQuestionUid=pairs.getValue().toString(); + logger.debug("currentQuestionUid: " + currentQuestionUid); + List listQuestionOptions=mcService.findMcOptionsContentByQueId(new Long(currentQuestionUid)); + logger.debug("listQuestionOptions: " + listQuestionOptions); + Map mapQuestionOptions=generateOptionsMap(listQuestionOptions); + mapStartupGeneralOptionsContent.put(mapIndex.toString(),mapQuestionOptions); + mapIndex=new Long(mapIndex.longValue()+1); + } + return mapStartupGeneralOptionsContent; + } + + + public static Map generateOptionsMap(List listQuestionOptions) + { + Map mapOptsContent= new TreeMap(new McComparator()); + + Iterator listIterator=listQuestionOptions.iterator(); + Long mapIndex=new Long(1); + while (listIterator.hasNext()) + { + McOptsContent mcOptsContent=(McOptsContent)listIterator.next(); + logger.debug("mcOptsContent: " + mcOptsContent); + mapOptsContent.put(mapIndex.toString(),mcOptsContent.getMcQueOptionText()); + mapIndex=new Long(mapIndex.longValue()+1); + } + return mapOptsContent; + } + + + public static Map generateOptionsQueIdMap(List listQuestionOptions) + { + Map mapOptsContent= new TreeMap(new McComparator()); + + Iterator listIterator=listQuestionOptions.iterator(); + Long mapIndex=new Long(1); + while (listIterator.hasNext()) + { + McOptsContent mcOptsContent=(McOptsContent)listIterator.next(); + logger.debug("mcOptsContent: " + mcOptsContent); + mapOptsContent.put(mapIndex.toString(),mcOptsContent.getMcQueContentId().toString()); + mapIndex=new Long(mapIndex.longValue()+1); + } + return mapOptsContent; + } + + + public static Map rebuildQuestionMapfromDB(HttpServletRequest request, Long toolContentId) { Map mapQuestionsContent= new TreeMap(new McComparator()); @@ -553,6 +654,7 @@ */ public static void persistOptionsFinal(HttpServletRequest request, Map currentOptions, Map selectedOptions, McQueContent mcQueContent) { + logger.debug("doing persistOptionsFinal..."); IMcService mcService =McUtils.getToolService(request); logger.debug("passed currentOptions: " + currentOptions); logger.debug("passed selectedOptions: " + selectedOptions); @@ -602,6 +704,7 @@ */ public static void persistOptions(HttpServletRequest request, Map mapGeneralOptionsContent, Map mapGeneralSelectedOptionsContent, McQueContent mcQueContent, String questionIndex) { + logger.debug("doing persistOptions..."); IMcService mcService =McUtils.getToolService(request); logger.debug("passed questionIndex: " + questionIndex); @@ -642,7 +745,7 @@ */ public static McContent createContent(HttpServletRequest request, McAuthoringForm mcAuthoringForm) { - logger.debug("called createContent"); + logger.debug("doing createContent..."); IMcService mcService =McUtils.getToolService(request); /* the tool content id is passed from the container to the tool and placed into session in the McStarterAction */ @@ -811,7 +914,7 @@ public static void cleanupRedundantQuestions(HttpServletRequest request, List existingQuestions, Map mapQuestionsContent, McContent mcContent) { - logger.debug("will cleanupRedundantQuestions... "); + logger.debug("doing cleanupRedundantQuestions..."); IMcService mcService =McUtils.getToolService(request); /*remove ununsed question entries from the db */ @@ -856,6 +959,7 @@ public static void selectAndPersistQuestions(HttpServletRequest request, List existingQuestions, Map mapQuestionsContent, Map mapFeedbackIncorrect, Map mapFeedbackCorrect, McContent mcContent) { + logger.debug("doing selectAndPersistQuestions..."); IMcService mcService =McUtils.getToolService(request); Iterator itQuestionsMap = mapQuestionsContent.entrySet().iterator(); @@ -900,7 +1004,7 @@ public static void updateExistingQuestionContent(HttpServletRequest request, Map mapFeedbackIncorrect, Map mapFeedbackCorrect, McQueContent mcQueContent, String displayOrder) { - logger.debug("using updateExisitingQuestionContent: " + mcQueContent); + logger.debug("doing updateExistingQuestionContent..."); logger.debug("using displayOrder: " + displayOrder); Map mapWeights= (Map)request.getSession().getAttribute(MAP_WEIGHTS); @@ -929,7 +1033,354 @@ logger.debug("updated mcQueContent in the db: " + mcQueContent); } + + public static void removeRedundantOptionEntry(HttpServletRequest request, Map mapSGO, Map mapGO, Map options) + { + logger.debug("doing removeRedundantOptionEntry..."); + IMcService mcService =McUtils.getToolService(request); + Iterator itSGOMap = mapSGO.entrySet().iterator(); + boolean optionFound=false; + while (itSGOMap.hasNext()) + { + Map.Entry pairsSGO = (Map.Entry)itSGOMap.next(); + optionFound=false; + Iterator itGOMap = mapGO.entrySet().iterator(); + while (itGOMap.hasNext()) + { + Map.Entry pairsGO = (Map.Entry)itGOMap.next(); + if (pairsSGO.getValue().equals(pairsGO.getValue())) + { + logger.debug("equal option found: " + pairsGO.getValue()); + optionFound=true; + break; + } + } + + if (optionFound == false) + { + logger.debug("options optionFound is false: remove this option"); + int optionSize=options.size(); + logger.debug("optionSize:" + optionSize); + String mcQueContentUid=(String)options.get(new Integer(optionSize).toString()); + + logger.debug("mcQueContentUid: " + mcQueContentUid); + + String deletableOptionText=pairsSGO.getValue().toString(); + logger.debug("deletableOptionText: " + deletableOptionText); + + if (deletableOptionText != null && (!deletableOptionText.equals(""))) + { + McOptsContent mcOptsContent = mcService.getOptionContentByOptionText(deletableOptionText, new Long(mcQueContentUid)); + logger.debug("mcOptsContent: " + mcOptsContent); + mcService.removeMcOptionsContent(mcOptsContent); + logger.debug("removed mcOptsContent from db: " + mcOptsContent); + } + else + { + logger.debug("This should not happen: deletableOptionText is null.."); + } + } + } + } + + + public static void cleanupRedundantOptions(HttpServletRequest request, Map mapStartupGeneralOptionsContent, Map mapStartupGeneralSelectedOptionsContent, Map mapGeneralOptionsContent, Map mapGeneralSelectedOptionsContent, Map mapStartupGeneralOptionsQueId) + { + logger.debug("doing cleanupRedundantOptions..."); + logger.debug("starting cleanupRedundantOptions...:" + mapStartupGeneralOptionsContent); + logger.debug("using mapGeneralOptionsContent..: "+ mapGeneralOptionsContent); + IMcService mcService =McUtils.getToolService(request); + + Iterator itSGOMap = mapStartupGeneralOptionsContent.entrySet().iterator(); + int displayOrder=0; + boolean optionFound=false; + while (itSGOMap.hasNext()) + { + Map.Entry pairsSGO = (Map.Entry)itSGOMap.next(); + + optionFound=false; + Iterator itGOMap = mapGeneralOptionsContent.entrySet().iterator(); + while (itGOMap.hasNext()) + { + Map.Entry pairsGO = (Map.Entry)itGOMap.next(); + if (pairsSGO.getKey().equals(pairsGO.getKey())) + { + logger.debug("equal keys found: " + pairsSGO.getKey()); + Map mapSGO=(Map)pairsSGO.getValue(); + Map mapGO=(Map)pairsGO.getValue(); + logger.debug("mapSGO: " + mapSGO); + logger.debug("mapGO: " + mapGO); + + Map options=(Map)mapStartupGeneralOptionsQueId.get(pairsSGO.getKey()); + logger.debug("options: " + options); + removeRedundantOptionEntry(request, mapSGO, mapGO,options); + } + } + } + } + + public static void selectAndPersistOptions(HttpServletRequest request, Map mapStartupGeneralOptionsContent, Map mapStartupGeneralSelectedOptionsContent, + Map mapGeneralOptionsContent, Map mapGeneralSelectedOptionsContent, Map mapStartupGeneralOptionsQueId) + { + logger.debug("doing selectAndPersistOptions..."); + logger.debug("starting selectAndPersistOptions..: "+ mapStartupGeneralOptionsContent); + logger.debug("using mapGeneralOptionsContent..: "+ mapGeneralOptionsContent); + IMcService mcService =McUtils.getToolService(request); + + Iterator itSGOMap = mapStartupGeneralOptionsContent.entrySet().iterator(); + int displayOrder=0; + boolean optionFound=false; + while (itSGOMap.hasNext()) + { + Map.Entry pairsSGO = (Map.Entry)itSGOMap.next(); + + optionFound=false; + Iterator itGOMap = mapGeneralOptionsContent.entrySet().iterator(); + while (itGOMap.hasNext()) + { + Map.Entry pairsGO = (Map.Entry)itGOMap.next(); + if (pairsSGO.getKey().equals(pairsGO.getKey())) + { + + logger.debug("equal keys found: " + pairsSGO.getKey()); + String questionIndex=pairsSGO.getKey().toString(); + Map mapSGO=(Map)pairsSGO.getValue(); + Map mapGO=(Map)pairsGO.getValue(); + logger.debug("mapSGO: " + mapSGO); + logger.debug("mapGO: " + mapGO); + + Map options=(Map)mapStartupGeneralOptionsQueId.get(pairsSGO.getKey()); + logger.debug("options: " + options); + updateOrCreateOptions(request, mapSGO, mapGO,options, questionIndex, mapGeneralSelectedOptionsContent); + } + } + } + + logger.debug("will do writePendingOptions for the new questions.."); + writePendingOptions(request, mapGeneralOptionsContent, mapGeneralSelectedOptionsContent); + } + + + public static void updateOrCreateOptions(HttpServletRequest request, Map mapSGO, Map mapGO, Map options, String questionIndex, Map mapGeneralSelectedOptionsContent) + { + logger.debug("doing updateOrCreateOptions..."); + Iterator itOptionsGoMap = mapGO.entrySet().iterator(); + boolean optionContentFound=false; + while (itOptionsGoMap.hasNext()) + { + Map.Entry pairs = (Map.Entry)itOptionsGoMap.next(); + logger.debug("using the pair: " + pairs.getKey() + " = " + pairs.getValue()); + + optionContentFound = false; + Iterator itOptionsSGO = mapSGO.entrySet().iterator(); + while (itOptionsSGO.hasNext()) + { + Map.Entry pairsSGO = (Map.Entry)itOptionsSGO.next(); + if (pairsSGO.getValue().equals(pairs.getValue())) + { + optionContentFound = true; + break; + } + } + + if (optionContentFound == false) + { + String optionText=pairs.getValue().toString(); + logger.debug("optionContentFound is false and option is: " + optionText); + createOptionContent(request, options, optionText, questionIndex, mapGeneralSelectedOptionsContent); + } + } + } + + + public static void updateExistingOptionContent(HttpServletRequest request, Map options, String optionText) + { + logger.debug("doing updateExistingOptionContent..."); + IMcService mcService =McUtils.getToolService(request); + int optionSize=options.size(); + logger.debug("optionSize:" + optionSize); + String mcQueContentUid=(String)options.get(new Integer(optionSize).toString()); + logger.debug("mcQueContentUid: " + mcQueContentUid); + + McOptsContent mcOptsContent = mcService.getOptionContentByOptionText(optionText, new Long(mcQueContentUid)); + logger.debug("mcOptsContent: " + mcOptsContent); + mcService.removeMcOptionsContent(mcOptsContent); + logger.debug("removed mcOptsContent from db: " + mcOptsContent); + } + + + public static void writePendingOptions(HttpServletRequest request, Map mapGeneralOptionsContent, Map mapGeneralSelectedOptionsContent) + { + logger.debug("doing writePendingQuestions..."); + Iterator itGO = mapGeneralOptionsContent.entrySet().iterator(); + while (itGO.hasNext()) + { + Map.Entry pairsGO = (Map.Entry)itGO.next(); + Map pendingOptions=(Map) pairsGO.getValue(); + logger.debug("pendingOptions: " + pendingOptions); + writePendingOption(request, pairsGO.getKey().toString(), pendingOptions, mapGeneralSelectedOptionsContent); + } + } + + + public static void writePendingOption(HttpServletRequest request, String questionIndex, Map pendingOptions, Map mapGeneralSelectedOptionsContent) + { + logger.debug("doing writePendingOption..."); + logger.debug("questionIndex: " + questionIndex); + logger.debug("pendingOptions: " + pendingOptions); + IMcService mcService =McUtils.getToolService(request); + + Long toolContentId=(Long)request.getSession().getAttribute(TOOL_CONTENT_ID); + logger.debug("getting existing content with id:" + toolContentId); + McContent mcContent=mcService.retrieveMc(toolContentId); + logger.debug("existing mcContent:" + mcContent); + McQueContent mcQueContent=mcService.getQuestionContentByDisplayOrder(new Long(questionIndex), mcContent.getUid()); + logger.debug("exracted mcQueContent:" + mcQueContent); + + if (mcQueContent != null) + { + Long mcQueContentUid=mcQueContent.getUid(); + logger.debug("mcQueContentUid:" + mcQueContentUid); + + Iterator itPQ = pendingOptions.entrySet().iterator(); + boolean isOptionSelected=false; + while (itPQ.hasNext()) + { + Map.Entry pairsPQ = (Map.Entry)itPQ.next(); + String optionText=pairsPQ.getValue().toString() ; + logger.debug("optionText: " + optionText); + isOptionSelected=false; + isOptionSelected=isOptionSelected(mapGeneralSelectedOptionsContent, optionText, questionIndex); + logger.debug("isOptionSelected: " + isOptionSelected); + + McOptsContent mcOptsContent = mcService.getOptionContentByOptionText(optionText, mcQueContentUid); + logger.debug("mcOptsContent: " + mcOptsContent); + + if (mcOptsContent == null) + { + mcOptsContent = new McOptsContent(isOptionSelected, pairsPQ.getValue().toString(),mcQueContent , new TreeSet()); + logger.debug("created new mcOptsContent:" + mcOptsContent); + } + else + { + logger.debug("this option is already persisted mcQueContent, just look after isOptionSelected:" + mcQueContent); + mcOptsContent.setCorrectOption(isOptionSelected); + } + mcService.saveMcOptionsContent(mcOptsContent); + logger.debug("persisted mcQueContent: " + mcQueContent); + } + } + } + + + public static void createOptionContent(HttpServletRequest request, Map options, String optionText, + String questionIndex, Map mapGeneralSelectedOptionsContent) + { + IMcService mcService =McUtils.getToolService(request); + logger.debug("doing createOptionContent..."); + int optionSize=options.size(); + logger.debug("optionSize:" + optionSize); + logger.debug("optionText:" + optionText); + + String mcQueContentUid=(String)options.get(new Integer(optionSize).toString()); + logger.debug("mcQueContentUid: " + mcQueContentUid); + + boolean isOptionSelected=isOptionSelected(mapGeneralSelectedOptionsContent, optionText, questionIndex); + logger.debug("isOptionSelected: " + isOptionSelected); + + if (mcQueContentUid != null) + { + McQueContent mcQueContent= mcService.getMcQueContentByUID(new Long(mcQueContentUid)); + logger.debug("mcQueContent: " + mcQueContent); + + McOptsContent mcOptsContent = mcService.getOptionContentByOptionText(optionText, new Long(mcQueContentUid)); + if (mcOptsContent == null) + { + mcOptsContent = new McOptsContent(isOptionSelected, optionText,mcQueContent , new TreeSet()); + mcService.saveMcOptionsContent(mcOptsContent); + logger.debug("persisted mcQueContent: " + mcQueContent); + } + else + { + logger.debug("mcOptsContent already exists: " + mcQueContent); + } + } + else + { + Long toolContentId=(Long)request.getSession().getAttribute(TOOL_CONTENT_ID); + logger.debug("getting existing content with id:" + toolContentId); + McContent mcContent=mcService.retrieveMc(toolContentId); + logger.debug("existing mcContent:" + mcContent); + logger.debug("mcOptsContent is null, get the mcQueContent in an alternative way, use pendingOptionsKey: " + questionIndex); + McQueContent mcQueContent=mcService.getQuestionContentByDisplayOrder(new Long(questionIndex), mcContent.getUid()); + logger.debug("exracted mcQueContent:" + mcQueContent); + + if (mcQueContent != null) + { + McOptsContent mcOptsContent = new McOptsContent(isOptionSelected, optionText,mcQueContent , new TreeSet()); + mcService.saveMcOptionsContent(mcOptsContent); + logger.debug("persisted mcQueContent: " + mcQueContent); + } + } + } + + + public static boolean isOptionSelected(Map mapGeneralSelectedOptionsContent, String optionText, String questionIndex) + { + Iterator itGSOMap = mapGeneralSelectedOptionsContent.entrySet().iterator(); + logger.debug("questionIndex: " + questionIndex); + logger.debug("optionText: " + optionText); + while (itGSOMap.hasNext()) + { + Map.Entry pairs = (Map.Entry)itGSOMap.next(); + if (pairs.getKey().toString().equals(questionIndex)) + { + Map currentOptionsMap= (Map)pairs.getValue(); + logger.debug("currentOptionsMap: " + currentOptionsMap); + boolean isOptionSelectedInMap=isOptionSelectedInMap(optionText, currentOptionsMap); + logger.debug("isOptionSelectedInMap: " + isOptionSelectedInMap); + return isOptionSelectedInMap; + } + } + return false; + } + + + public static boolean isOptionSelectedInMap(String optionText, Map currentOptionsMap) + { + logger.debug("optionText: " + optionText); + Iterator itCOMap = currentOptionsMap.entrySet().iterator(); + while (itCOMap.hasNext()) + { + Map.Entry pairs = (Map.Entry)itCOMap.next(); + if (pairs.getValue().toString().equals(optionText)) + { + logger.debug("option text found in the map: " + optionText); + return true; + } + } + return false; + } + + + public static void createDefaultOptionContent(HttpServletRequest request, McQueContent mcQueContent) + { + logger.debug("doing createDefaultOptionContent..."); + IMcService mcService =McUtils.getToolService(request); + + String mcQueContentUid=mcQueContent.getUid().toString(); + logger.debug("mcQueContentUid:" + mcQueContentUid); + + if (mcQueContentUid != null) + { + McOptsContent mcOptsContent= new McOptsContent(true,"a sample answer", mcQueContent, new TreeSet()); + mcService.saveMcOptionsContent(mcOptsContent); + logger.debug("created a new mcOptsContent in the db: " + mcOptsContent); + } + } + + public static void createQuestionContent(HttpServletRequest request, Map mapQuestionsContent, Map mapFeedbackIncorrect, Map mapFeedbackCorrect, String question, McContent mcContent) { logger.debug("using createQuestionContent with question: " + question); @@ -1110,6 +1561,26 @@ } + + public static void refreshMaps(HttpServletRequest request, long toolContentId) + { + Map mapQuestionsUidContent=AuthoringUtil.rebuildQuestionUidMapfromDB(request, new Long(toolContentId)); + logger.debug("mapQuestionsUidContent:" + mapQuestionsUidContent); + + Map mapStartupGeneralOptionsContent=AuthoringUtil.rebuildStartupGeneralOptionsContentMapfromDB(request, mapQuestionsUidContent); + logger.debug("mapStartupGeneralOptionsContent:" + mapStartupGeneralOptionsContent); + request.getSession().setAttribute(MAP_STARTUP_GENERAL_OPTIONS_CONTENT, mapStartupGeneralOptionsContent); + + Map mapStartupGeneralSelectedOptionsContent=AuthoringUtil.rebuildStartupGeneralSelectedOptionsContentMapfromDB(request, mapQuestionsUidContent); + logger.debug("mapStartupGeneralSelectedOptionsContent:" + mapStartupGeneralSelectedOptionsContent); + request.getSession().setAttribute(MAP_STARTUP_GENERAL_SELECTED_OPTIONS_CONTENT, mapStartupGeneralSelectedOptionsContent); + + Map mapStartupGeneralOptionsQueId=AuthoringUtil.rebuildStartupGeneralOptionsQueIdfromDB(request, mapQuestionsUidContent); + logger.debug("mapStartupGeneralOptionsQueId:" + mapStartupGeneralOptionsQueId); + request.getSession().setAttribute(MAP_STARTUP_GENERAL_OPTIONS_QUEID, mapStartupGeneralOptionsQueId); + } + + public void simulatePropertyInspector_RunOffline(HttpServletRequest request) { IMcService mcService =McUtils.getToolService(request); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java,v diff -u -r1.68 -r1.69 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java 25 Nov 2005 12:02:19 -0000 1.68 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java 27 Nov 2005 16:08:44 -0000 1.69 @@ -692,6 +692,27 @@ logger.debug("MAP_SELECTED_OPTIONS set as empty list :" + mapSelectedOptions); } } + + logger.debug("final mapOptionsContent used is: " + mapOptionsContent); + if (mapOptionsContent.isEmpty()) + { + logger.debug("mapOptionsContent is empty"); + mapOptionsContent.put("1","sample answer 1"); + mapSelectedOptions = mapOptionsContent; + request.getSession().setAttribute(MAP_OPTIONS_CONTENT, mapOptionsContent); + request.getSession().setAttribute(MAP_SELECTED_OPTIONS, mapSelectedOptions); + + + mapGeneralOptionsContent=(Map)request.getSession().getAttribute(MAP_GENERAL_OPTIONS_CONTENT); + logger.debug("current mapGeneralOptionsContent:"+ mapGeneralOptionsContent); + mapGeneralOptionsContent.put(questionIndex,mapOptionsContent); + request.getSession().setAttribute(MAP_GENERAL_OPTIONS_CONTENT, mapGeneralOptionsContent); + + Map mapGeneralSelectedOptionsContent=mapGeneralOptionsContent; + request.getSession().setAttribute(MAP_GENERAL_SELECTED_OPTIONS_CONTENT, mapGeneralSelectedOptionsContent); + } + + request.getSession().setAttribute(EDIT_OPTIONS_MODE, new Integer(1)); logger.debug("resetting EDIT_OPTIONS_MODE to 1"); mcAuthoringForm.resetUserAction(); @@ -1168,7 +1189,6 @@ logger.debug("setting EDIT_OPTIONS_MODE to 0"); ActionMessages errors= new ActionMessages(); - Map mapQuestionsContent=AuthoringUtil.repopulateMap(request, "questionContent"); logger.debug("mapQuestionsContent before submit: " + mapQuestionsContent); request.getSession().setAttribute(MAP_QUESTIONS_CONTENT, mapQuestionsContent); @@ -1293,7 +1313,6 @@ } } - if ((mcAuthoringForm.getPassmark() != null) && (mcAuthoringForm.getPassmark().length() > 0)) { passmark= new Integer(mcAuthoringForm.getPassmark()).intValue(); @@ -1436,24 +1455,41 @@ Map mapFeedbackCorrect =(Map)request.getSession().getAttribute(MAP_FEEDBACK_CORRECT); logger.debug("Submit final MAP_FEEDBACK_CORRECT :" + mapFeedbackCorrect); - //AuthoringUtil.cleanupExistingQuestions(request, mcContent); - //logger.debug("post cleanupExistingQuestions"); + AuthoringUtil.refreshMaps(request, toolContentId.longValue()); + logger.debug("refreshed maps..."); logger.debug("start processing questions content..."); Long mcContentId =mcContent.getUid(); List existingQuestions = mcService.refreshQuestionContent(mcContentId); logger.debug("existingQuestions: " + existingQuestions); - logger.debug("will cleanupRedundantQuestions"); + logger.debug("will cleanupRedundantQuestions:"); + /* Removes only unused question entries from the db. It keeps the valid entries since they get updated. */ AuthoringUtil.cleanupRedundantQuestions(request, existingQuestions, mapQuestionsContent, mcContent); - logger.debug("existingQuestions: " + existingQuestions); logger.debug("calling selectAndPersistQuestions: " + existingQuestions); AuthoringUtil.selectAndPersistQuestions(request, existingQuestions, mapQuestionsContent, mapFeedbackIncorrect, mapFeedbackCorrect, mcContent); + logger.debug("finished processing questions content..."); - existingQuestions = mcService.refreshQuestionContent(mcContentId); - logger.debug("last set of existingQuestions: " + existingQuestions); + logger.debug("start processing options content..."); + Map mapStartupGeneralOptionsContent= (Map) request.getSession().getAttribute(MAP_STARTUP_GENERAL_OPTIONS_CONTENT); + logger.debug("mapStartupGeneralOptionsContent: " + mapStartupGeneralOptionsContent); + Map mapStartupGeneralSelectedOptionsContent=(Map)request.getSession().getAttribute(MAP_STARTUP_GENERAL_SELECTED_OPTIONS_CONTENT); + logger.debug("mapStartupGeneralSelectedOptionsContent: " + mapStartupGeneralSelectedOptionsContent); + Map mapStartupGeneralOptionsQueId=(Map) request.getSession().getAttribute(MAP_STARTUP_GENERAL_OPTIONS_QUEID); + logger.debug("mapStartupGeneralOptionsQueId: " + mapStartupGeneralOptionsQueId); + Map mapGeneralOptionsContent=(Map)request.getSession().getAttribute(MAP_GENERAL_OPTIONS_CONTENT); + logger.debug("mapGeneralOptionsContent: " + mapGeneralOptionsContent); + Map mapGeneralSelectedOptionsContent=(Map)request.getSession().getAttribute(MAP_GENERAL_SELECTED_OPTIONS_CONTENT); + logger.debug("mapGeneralSelectedOptionsContent: " + mapGeneralSelectedOptionsContent); + + logger.debug("calling cleanupRedundantOptions"); + AuthoringUtil.cleanupRedundantOptions(request, mapStartupGeneralOptionsContent, mapStartupGeneralSelectedOptionsContent, mapGeneralOptionsContent, mapGeneralSelectedOptionsContent, mapStartupGeneralOptionsQueId); + logger.debug("calling selectAndPersistOptions"); + AuthoringUtil.selectAndPersistOptions(request, mapStartupGeneralOptionsContent, mapStartupGeneralSelectedOptionsContent, mapGeneralOptionsContent, mapGeneralSelectedOptionsContent, mapStartupGeneralOptionsQueId); + + logger.debug("will do addUploadedFilesMetaData"); McUtils.addUploadedFilesMetaData(request,mcContent); logger.debug("done addUploadedFilesMetaData"); @@ -2277,5 +2313,7 @@ mcLearningForm.resetCommands(); return (mapping.findForward(LOAD_LEARNER)); } + + } \ No newline at end of file Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java,v diff -u -r1.26 -r1.27 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java 25 Nov 2005 12:02:19 -0000 1.26 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java 27 Nov 2005 16:08:44 -0000 1.27 @@ -432,17 +432,16 @@ McUtils.populateUploadedFilesData(request, mcContent); logger.debug("populated UploadedFilesData"); - - Map mapQuestionsContent=AuthoringUtil.rebuildQuestionMapfromDB(request, new Long(toolContentId)); - logger.debug("mapQuestionsContent:" + mapQuestionsContent); - - request.getSession().setAttribute(MAP_QUESTIONS_CONTENT, mapQuestionsContent); - logger.debug("starter initialized the existing Questions Map: " + request.getSession().getAttribute(MAP_QUESTIONS_CONTENT)); - - Map mapWeights=AuthoringUtil.rebuildWeightsMapfromDB(request, new Long(toolContentId)); - logger.debug("mapWeights:" + mapWeights); - request.getSession().setAttribute(MAP_WEIGHTS, mapWeights); - logger.debug("MAP_WEIGHTS:" + request.getSession().getAttribute(MAP_WEIGHTS)); + Map mapWeights= AuthoringUtil.rebuildWeightsMapfromDB(request, new Long(toolContentId)); + logger.debug("mapWeights: " + mapWeights); + request.getSession().setAttribute(MAP_WEIGHTS, mapWeights); + + Map mapQuestionsContent=AuthoringUtil.rebuildQuestionMapfromDB(request, new Long(toolContentId)); + logger.debug("mapQuestionsContent:" + mapQuestionsContent); + request.getSession().setAttribute(MAP_QUESTIONS_CONTENT, mapQuestionsContent); + logger.debug("starter initialized the existing Questions Map: " + request.getSession().getAttribute(MAP_QUESTIONS_CONTENT)); + + AuthoringUtil.refreshMaps(request, toolContentId); } @@ -600,6 +599,12 @@ Map mapGeneralSelectedOptionsContent= new TreeMap(new McComparator()); request.getSession().setAttribute(MAP_GENERAL_SELECTED_OPTIONS_CONTENT, mapGeneralSelectedOptionsContent); + Map mapStartupGeneralOptionsContent= new TreeMap(new McComparator()); + request.getSession().setAttribute(MAP_STARTUP_GENERAL_OPTIONS_CONTENT, mapStartupGeneralOptionsContent); + + Map mapStartupGeneralSelectedOptionsContent= new TreeMap(new McComparator()); + request.getSession().setAttribute(MAP_STARTUP_GENERAL_SELECTED_OPTIONS_CONTENT, mapStartupGeneralSelectedOptionsContent); + Map mapDisabledQuestions= new TreeMap(new McComparator()); request.getSession().setAttribute(MAP_DISABLED_QUESTIONS, mapDisabledQuestions);