Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java,v diff -u -r1.50 -r1.51 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java 14 Feb 2008 00:03:43 -0000 1.50 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java 18 Nov 2008 04:24:11 -0000 1.51 @@ -22,17 +22,13 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc.web; -import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; -import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; @@ -44,7 +40,6 @@ import org.lamsfoundation.lams.tool.mc.McGeneralLearnerFlowDTO; import org.lamsfoundation.lams.tool.mc.McLearnerAnswersDTO; import org.lamsfoundation.lams.tool.mc.McRandomizedListsDTO; -import org.lamsfoundation.lams.tool.mc.McStringComparator; import org.lamsfoundation.lams.tool.mc.McUtils; import org.lamsfoundation.lams.tool.mc.pojos.McContent; import org.lamsfoundation.lams.tool.mc.pojos.McOptsContent; @@ -56,82 +51,81 @@ /** * - * Keeps all operations needed for Authoring mode. + * Keeps all operations needed for Authoring mode. + * * @author Ozgur Demirtas - * + * */ public class LearningUtil implements McAppConstants { - static Logger logger = Logger.getLogger(LearningUtil.class.getName()); - - /** - * void saveFormRequestData(HttpServletRequest request, McLearningForm mcLearningForm, boolean prepareViewAnswersDataMode) - * - * @param request - * @param mcLearningForm - * @param prepareViewAnswersDataMode - */ - public static void saveFormRequestData(HttpServletRequest request, McLearningForm mcLearningForm, boolean prepareViewAnswersDataMode) - { - logger.debug("starting saveFormRequestData:"); - - String httpSessionID=request.getParameter("httpSessionID"); - logger.debug("httpSessionID: " + httpSessionID); - mcLearningForm.setHttpSessionID(httpSessionID); - - String userID=request.getParameter("userID"); - logger.debug("userID: " + userID); - mcLearningForm.setUserID(userID); - - String passMarkApplicable=request.getParameter("passMarkApplicable"); - logger.debug("passMarkApplicable: " + passMarkApplicable); - mcLearningForm.setPassMarkApplicable(passMarkApplicable); - - String userOverPassMark=request.getParameter("userOverPassMark"); - logger.debug("userOverPassMark: " + userOverPassMark); - mcLearningForm.setUserOverPassMark(userOverPassMark); - - if (prepareViewAnswersDataMode == false) - { - String learnerProgress=request.getParameter("learnerProgress"); - logger.debug("learnerProgress: " + learnerProgress); - mcLearningForm.setLearnerProgress(learnerProgress); - logger.debug("form is populated with learnerProgress"); - String learnerProgressUserId=request.getParameter("learnerProgressUserId"); - logger.debug("learnerProgressUserId: " + learnerProgressUserId); - mcLearningForm.setLearnerProgressUserId(learnerProgressUserId); + static Logger logger = Logger.getLogger(LearningUtil.class.getName()); - } - - String questionListingMode=request.getParameter("questionListingMode"); - logger.debug("questionListingMode: " + questionListingMode); - mcLearningForm.setQuestionListingMode(questionListingMode); + /** + * void saveFormRequestData(HttpServletRequest request, McLearningForm mcLearningForm, boolean + * prepareViewAnswersDataMode) + * + * @param request + * @param mcLearningForm + * @param prepareViewAnswersDataMode + */ + public static void saveFormRequestData(HttpServletRequest request, McLearningForm mcLearningForm, + boolean prepareViewAnswersDataMode) { + LearningUtil.logger.debug("starting saveFormRequestData:"); + String httpSessionID = request.getParameter("httpSessionID"); + LearningUtil.logger.debug("httpSessionID: " + httpSessionID); + mcLearningForm.setHttpSessionID(httpSessionID); - logger.debug("ending saveFormRequestData:"); + String userID = request.getParameter("userID"); + LearningUtil.logger.debug("userID: " + userID); + mcLearningForm.setUserID(userID); + + String passMarkApplicable = request.getParameter("passMarkApplicable"); + LearningUtil.logger.debug("passMarkApplicable: " + passMarkApplicable); + mcLearningForm.setPassMarkApplicable(passMarkApplicable); + + String userOverPassMark = request.getParameter("userOverPassMark"); + LearningUtil.logger.debug("userOverPassMark: " + userOverPassMark); + mcLearningForm.setUserOverPassMark(userOverPassMark); + + if (prepareViewAnswersDataMode == false) { + String learnerProgress = request.getParameter("learnerProgress"); + LearningUtil.logger.debug("learnerProgress: " + learnerProgress); + mcLearningForm.setLearnerProgress(learnerProgress); + LearningUtil.logger.debug("form is populated with learnerProgress"); + String learnerProgressUserId = request.getParameter("learnerProgressUserId"); + LearningUtil.logger.debug("learnerProgressUserId: " + learnerProgressUserId); + mcLearningForm.setLearnerProgressUserId(learnerProgressUserId); + } - - /** A question is correct if the number of correct options and the number of checked options is the same, - * plus all the checked options appears in the correct options list. + + String questionListingMode = request.getParameter("questionListingMode"); + LearningUtil.logger.debug("questionListingMode: " + questionListingMode); + mcLearningForm.setQuestionListingMode(questionListingMode); + + LearningUtil.logger.debug("ending saveFormRequestData:"); + } + + /** + * A question is correct if the number of correct options and the number of checked options is the same, plus all + * the checked options appears in the correct options list. * * @param mapGeneralCorrectOptions * @param checkedOptionsUIDs * @return */ - public static boolean isQuestionCorrect(Collection correctOptions, Collection checkedOptionIds) { + public static boolean isQuestionCorrect(Collection correctOptions, List checkedOptionIds) { - if ( logger.isDebugEnabled() ) { - logger.debug("performing isQuestionCorrect correctOptions: " + correctOptions + " checkedOptionIds: " + checkedOptionIds); - } - - if ( correctOptions.size() == checkedOptionIds.size() ) { - for ( McOptsContent mcOptsContent : correctOptions ) { - String optionId = mcOptsContent.getUid().toString(); - if ( !checkedOptionIds.contains(optionId) ) - return false; - } - return true; - } - return false; + if (LearningUtil.logger.isDebugEnabled()) { + LearningUtil.logger.debug("performing isQuestionCorrect correctOptions: " + correctOptions + + " checkedOptionIds: " + checkedOptionIds); + } + for (McOptsContent mcOptsContent : correctOptions) { + String optionId = mcOptsContent.getUid().toString(); + if (!optionId.equals(checkedOptionIds.get(checkedOptionIds.size() - 1))) { + return false; + } + } + return true; } /** @@ -142,48 +136,39 @@ * @param toolSessionId * @return */ - public static McQueUsr getUser(HttpServletRequest request, IMcService mcService, String toolSessionId) - { - logger.debug("getUser:: " + toolSessionId); - Long queUsrId=McUtils.getUserId(); - - McSession mcSession=mcService.retrieveMcSession(new Long(toolSessionId)); - logger.debug("retrieving mcSession: " + mcSession); - McQueUsr mcQueUsr=mcService.getMcUserBySession(queUsrId, mcSession.getUid()); - logger.debug("retrieving mcQueUsr: " + mcQueUsr); - return mcQueUsr; - } - - + public static McQueUsr getUser(HttpServletRequest request, IMcService mcService, String toolSessionId) { + LearningUtil.logger.debug("getUser:: " + toolSessionId); + Long queUsrId = McUtils.getUserId(); + + McSession mcSession = mcService.retrieveMcSession(new Long(toolSessionId)); + LearningUtil.logger.debug("retrieving mcSession: " + mcSession); + McQueUsr mcQueUsr = mcService.getMcUserBySession(queUsrId, mcSession.getUid()); + LearningUtil.logger.debug("retrieving mcQueUsr: " + mcQueUsr); + return mcQueUsr; + } + /** - * creates the user in the db - * createUser(HttpServletRequest request) + * creates the user in the db createUser(HttpServletRequest request) * * @param request */ - public static McQueUsr createUser(HttpServletRequest request, IMcService mcService, Long toolSessionId) - { - logger.debug("createUser: using toolSessionId: " + toolSessionId); - Long queUsrId=McUtils.getUserId(); - String username=McUtils.getUserName(); - String fullname=McUtils.getUserFullName(); - - McSession mcSession=mcService.retrieveMcSession(toolSessionId); - McQueUsr mcQueUsr= new McQueUsr(queUsrId, - username, - fullname, - mcSession, - new TreeSet()); - mcService.createMcQueUsr(mcQueUsr); - logger.debug("created mcQueUsr in the db: " + mcQueUsr); - return mcQueUsr; - } + public static McQueUsr createUser(HttpServletRequest request, IMcService mcService, Long toolSessionId) { + LearningUtil.logger.debug("createUser: using toolSessionId: " + toolSessionId); + Long queUsrId = McUtils.getUserId(); + String username = McUtils.getUserName(); + String fullname = McUtils.getUserFullName(); - + McSession mcSession = mcService.retrieveMcSession(toolSessionId); + McQueUsr mcQueUsr = new McQueUsr(queUsrId, username, fullname, mcSession, new TreeSet()); + mcService.createMcQueUsr(mcQueUsr); + LearningUtil.logger.debug("created mcQueUsr in the db: " + mcQueUsr); + return mcQueUsr; + } + /** - * createLearnerAttempt(HttpServletRequest request, McQueUsr mcQueUsr, List selectedQuestionAndCandidateAnswersDTO, - Integer totalMark, boolean passed, int highestAttemptOrder, Map mapLeanerAssessmentResults, IMcService mcService) - + * createLearnerAttempt(HttpServletRequest request, McQueUsr mcQueUsr, List selectedQuestionAndCandidateAnswersDTO, + * Integer totalMark, boolean passed, int highestAttemptOrder, Map mapLeanerAssessmentResults, IMcService mcService) + * * @param request * @param mcQueUsr * @param selectedQuestionAndCandidateAnswersDTO @@ -193,42 +178,34 @@ * @param mapLeanerAssessmentResults * @param mcService */ - public static void createLearnerAttempt(HttpServletRequest request, McQueUsr mcQueUsr, List selectedQuestionAndCandidateAnswersDTO, - boolean passed, Integer highestAttemptOrder, Map mapLeanerAssessmentResults, IMcService mcService) - { - logger.debug("starting createLearnerAttempt: "); - Date attemptTime=McUtils.getGMTDateTime(); - - Iterator itSelectedMap = selectedQuestionAndCandidateAnswersDTO.iterator(); - while (itSelectedMap.hasNext()) - { - McLearnerAnswersDTO mcLearnerAnswersDTO=(McLearnerAnswersDTO)itSelectedMap.next(); - - if ( logger.isDebugEnabled() ) { - logger.debug("mcLearnerAnswersDTO: " + mcLearnerAnswersDTO); - } - - McQueContent mcQueContent=mcService.findMcQuestionContentByUid(mcLearnerAnswersDTO.getQuestionUid()); - - createIndividualOptions(request, - mcLearnerAnswersDTO.getCandidateAnswers(), - mcQueContent, mcQueUsr, - attemptTime, - mcLearnerAnswersDTO.getMark(), - passed, - highestAttemptOrder, - mcLearnerAnswersDTO.getAttemptCorrect(), - mcService); - } - - } + public static void createLearnerAttempt(HttpServletRequest request, McQueUsr mcQueUsr, + List selectedQuestionAndCandidateAnswersDTO, boolean passed, Integer highestAttemptOrder, + Map mapLeanerAssessmentResults, IMcService mcService) { + LearningUtil.logger.debug("starting createLearnerAttempt: "); + Date attemptTime = McUtils.getGMTDateTime(); - + Iterator itSelectedMap = selectedQuestionAndCandidateAnswersDTO.iterator(); + while (itSelectedMap.hasNext()) { + McLearnerAnswersDTO mcLearnerAnswersDTO = (McLearnerAnswersDTO) itSelectedMap.next(); + + if (LearningUtil.logger.isDebugEnabled()) { + LearningUtil.logger.debug("mcLearnerAnswersDTO: " + mcLearnerAnswersDTO); + } + + McQueContent mcQueContent = mcService.findMcQuestionContentByUid(mcLearnerAnswersDTO.getQuestionUid()); + + createIndividualOptions(request, mcLearnerAnswersDTO.getCandidateAnswers(), mcQueContent, mcQueUsr, + attemptTime, mcLearnerAnswersDTO.getMark(), passed, highestAttemptOrder, mcLearnerAnswersDTO + .getAttemptCorrect(), mcService); + } + + } + /** * - * createIndividualOptions(HttpServletRequest request, Map candidateAnswers, McQueContent mcQueContent, - McQueUsr mcQueUsr, Date attempTime, String timeZone, int mark, boolean passed, Integer highestAttemptOrder, String isAttemptCorrect, - IMcService mcService) + * createIndividualOptions(HttpServletRequest request, Map candidateAnswers, McQueContent mcQueContent, McQueUsr + * mcQueUsr, Date attempTime, String timeZone, int mark, boolean passed, Integer highestAttemptOrder, String + * isAttemptCorrect, IMcService mcService) * * @param request * @param candidateAnswers @@ -241,40 +218,37 @@ * @param isAttemptCorrect * @param mcService */ - public static void createIndividualOptions(HttpServletRequest request, Map candidateAnswers, McQueContent mcQueContent, - McQueUsr mcQueUsr, Date attemptTime, int mark, boolean passed, Integer highestAttemptOrder, String isAttemptCorrect, - IMcService mcService) - { - logger.debug("starting createIndividualOptions"); - Integer IntegerMark= new Integer(mark); - - logger.debug("createIndividualOptions-> isAttemptCorrect: " + isAttemptCorrect); - logger.debug("mcQueContent: " + mcQueContent); - logger.debug("candidateAnswers: " + candidateAnswers); - logger.debug("highestAttemptOrder used : " + highestAttemptOrder); - - - if (mcQueContent != null) - { - if (candidateAnswers != null) - { - Iterator itCheckedMap = candidateAnswers.entrySet().iterator(); - while (itCheckedMap.hasNext()) - { - Map.Entry checkedPairs = (Map.Entry)itCheckedMap.next(); - McOptsContent mcOptsContent= mcService.getOptionContentByOptionText(checkedPairs.getValue().toString(), mcQueContent.getUid()); - logger.debug("mcOptsContent: " + mcOptsContent); - if (mcOptsContent != null) - { - McUsrAttempt mcUsrAttempt=new McUsrAttempt(attemptTime, mcQueContent, mcQueUsr, mcOptsContent, IntegerMark, passed, highestAttemptOrder, new Boolean(isAttemptCorrect).booleanValue()); - mcService.createMcUsrAttempt(mcUsrAttempt); - logger.debug("created mcUsrAttempt in the db :" + mcUsrAttempt); - } - } - } - } + public static void createIndividualOptions(HttpServletRequest request, Map candidateAnswers, + McQueContent mcQueContent, McQueUsr mcQueUsr, Date attemptTime, int mark, boolean passed, + Integer highestAttemptOrder, String isAttemptCorrect, IMcService mcService) { + LearningUtil.logger.debug("starting createIndividualOptions"); + Integer IntegerMark = new Integer(mark); + + LearningUtil.logger.debug("createIndividualOptions-> isAttemptCorrect: " + isAttemptCorrect); + LearningUtil.logger.debug("mcQueContent: " + mcQueContent); + LearningUtil.logger.debug("candidateAnswers: " + candidateAnswers); + LearningUtil.logger.debug("highestAttemptOrder used : " + highestAttemptOrder); + + if (mcQueContent != null) { + if (candidateAnswers != null) { + Iterator itCheckedMap = candidateAnswers.entrySet().iterator(); + while (itCheckedMap.hasNext()) { + Map.Entry checkedPairs = (Map.Entry) itCheckedMap.next(); + McOptsContent mcOptsContent = mcService.getOptionContentByOptionText(checkedPairs.getValue() + .toString(), mcQueContent.getUid()); + LearningUtil.logger.debug("mcOptsContent: " + mcOptsContent); + if (mcOptsContent != null) { + McUsrAttempt mcUsrAttempt = new McUsrAttempt(attemptTime, mcQueContent, mcQueUsr, + mcOptsContent, IntegerMark, passed, highestAttemptOrder, new Boolean(isAttemptCorrect) + .booleanValue()); + mcService.createMcUsrAttempt(mcUsrAttempt); + LearningUtil.logger.debug("created mcUsrAttempt in the db :" + mcUsrAttempt); + } + } + } + } } - + /** * Map buildMarksMap(HttpServletRequest request, Long toolContentId, IMcService mcService) * @@ -283,138 +257,122 @@ * @param mcService * @return */ - public static Map buildMarksMap(HttpServletRequest request, Long toolContentId, IMcService mcService) - { - logger.debug("starting buildMarksMap : " + toolContentId); - Map mapMarks= new TreeMap(new McComparator()); - McContent mcContent=mcService.retrieveMc(toolContentId); - logger.debug("mcContent : " + mcContent); - - List questionsContent=mcService.refreshQuestionContent(mcContent.getUid()); - logger.debug("questionsContent : " + questionsContent); - - Iterator listIterator=questionsContent.iterator(); - Long mapIndex=new Long(1); - while (listIterator.hasNext()) - { - McQueContent mcQueContent=(McQueContent)listIterator.next(); - logger.debug("mcQueContent : " + mcQueContent); - mapMarks.put(mapIndex.toString(),mcQueContent.getMark().toString()); - mapIndex=new Long(mapIndex.longValue()+1); - } - logger.debug("mapMarks : " + mapMarks); - return mapMarks; - } + public static Map buildMarksMap(HttpServletRequest request, Long toolContentId, IMcService mcService) { + LearningUtil.logger.debug("starting buildMarksMap : " + toolContentId); + Map mapMarks = new TreeMap(new McComparator()); + McContent mcContent = mcService.retrieveMc(toolContentId); + LearningUtil.logger.debug("mcContent : " + mcContent); - + List questionsContent = mcService.refreshQuestionContent(mcContent.getUid()); + LearningUtil.logger.debug("questionsContent : " + questionsContent); + Iterator listIterator = questionsContent.iterator(); + Long mapIndex = new Long(1); + while (listIterator.hasNext()) { + McQueContent mcQueContent = (McQueContent) listIterator.next(); + LearningUtil.logger.debug("mcQueContent : " + mcQueContent); + mapMarks.put(mapIndex.toString(), mcQueContent.getMark().toString()); + mapIndex = new Long(mapIndex.longValue() + 1); + } + LearningUtil.logger.debug("mapMarks : " + mapMarks); + return mapMarks; + } + /** * McGeneralLearnerFlowDTO buildMcGeneralLearnerFlowDTO(McContent mcContent) * * @param mcContent * @return */ - public static McGeneralLearnerFlowDTO buildMcGeneralLearnerFlowDTO(McContent mcContent) - { - logger.debug("starting buildMcGeneralLearnerFlowDTO: " + mcContent); - McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO =new McGeneralLearnerFlowDTO(); - mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); - mcGeneralLearnerFlowDTO.setActivityTitle(mcContent.getTitle()); - mcGeneralLearnerFlowDTO.setActivityInstructions(mcContent.getInstructions()); - mcGeneralLearnerFlowDTO.setPassMark(mcContent.getPassMark()); - mcGeneralLearnerFlowDTO.setReportTitleLearner("Report"); - mcGeneralLearnerFlowDTO.setLearnerProgress(new Boolean(false).toString()); - - if (mcContent.isQuestionsSequenced()) - mcGeneralLearnerFlowDTO.setQuestionListingMode(QUESTION_LISTING_MODE_SEQUENTIAL); - else - mcGeneralLearnerFlowDTO.setQuestionListingMode(QUESTION_LISTING_MODE_COMBINED); - - - logger.debug("continue buildMcGeneralLearnerFlowDTO: " + mcContent); - mcGeneralLearnerFlowDTO.setTotalQuestionCount(new Integer(mcContent.getMcQueContents().size())); - logger.debug("final mcGeneralLearnerFlowDTO: " + mcGeneralLearnerFlowDTO); - return mcGeneralLearnerFlowDTO; + public static McGeneralLearnerFlowDTO buildMcGeneralLearnerFlowDTO(McContent mcContent) { + LearningUtil.logger.debug("starting buildMcGeneralLearnerFlowDTO: " + mcContent); + McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO = new McGeneralLearnerFlowDTO(); + mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); + mcGeneralLearnerFlowDTO.setActivityTitle(mcContent.getTitle()); + mcGeneralLearnerFlowDTO.setActivityInstructions(mcContent.getInstructions()); + mcGeneralLearnerFlowDTO.setPassMark(mcContent.getPassMark()); + mcGeneralLearnerFlowDTO.setReportTitleLearner("Report"); + mcGeneralLearnerFlowDTO.setLearnerProgress(new Boolean(false).toString()); + + if (mcContent.isQuestionsSequenced()) { + mcGeneralLearnerFlowDTO.setQuestionListingMode(McAppConstants.QUESTION_LISTING_MODE_SEQUENTIAL); + } else { + mcGeneralLearnerFlowDTO.setQuestionListingMode(McAppConstants.QUESTION_LISTING_MODE_COMBINED); + } + + LearningUtil.logger.debug("continue buildMcGeneralLearnerFlowDTO: " + mcContent); + mcGeneralLearnerFlowDTO.setTotalQuestionCount(new Integer(mcContent.getMcQueContents().size())); + LearningUtil.logger.debug("final mcGeneralLearnerFlowDTO: " + mcGeneralLearnerFlowDTO); + return mcGeneralLearnerFlowDTO; } - - - public static McRandomizedListsDTO randomizeList(List listCandidateAnswers, List listCandidateAnswerUids) - { - logger.debug("starting randomizeList: " + listCandidateAnswers); - logger.debug("using listCandidateAnswerUids: " + listCandidateAnswerUids); - - McRandomizedListsDTO mcRandomizedListsDTO= new McRandomizedListsDTO(); - - int caCount=listCandidateAnswers.size(); - logger.debug("caCount: " + caCount); - Random generator = new Random(); - - boolean listNotComplete=true; - int randomInt=0; - - List randomList= new LinkedList(); - List randomUidList= new LinkedList(); - while (listNotComplete) - { - randomInt = generator.nextInt(caCount); - logger.debug("randomInt: " + randomInt); - - String ca=(String)listCandidateAnswers.get(randomInt); - logger.debug("ca: " + ca); - - String caUid=(String)listCandidateAnswerUids.get(randomInt); - - - if (!isEntryStored(ca, randomList)) - { - logger.debug("adding ca, since it is a new candidate, ca: " + ca); - randomList.add(ca); - randomUidList.add(caUid); - - logger.debug("randomList size: " + randomList.size()); - if (randomList.size() == listCandidateAnswers.size()) - { - logger.debug("the list is populated completely, randomList: " + randomList); - listNotComplete =false; - } - } - } - - listCandidateAnswerUids=randomUidList; - logger.debug("modified listCandidateAnswerUids as: " + listCandidateAnswerUids); - - mcRandomizedListsDTO.setListCandidateAnswers(randomList); - mcRandomizedListsDTO.setListCandidateAnswerUids(listCandidateAnswerUids); - - logger.debug("returning mcRandomizedListsDTO: " + mcRandomizedListsDTO); - return mcRandomizedListsDTO; + public static McRandomizedListsDTO randomizeList(List listCandidateAnswers, List listCandidateAnswerUids) { + LearningUtil.logger.debug("starting randomizeList: " + listCandidateAnswers); + LearningUtil.logger.debug("using listCandidateAnswerUids: " + listCandidateAnswerUids); + + McRandomizedListsDTO mcRandomizedListsDTO = new McRandomizedListsDTO(); + + int caCount = listCandidateAnswers.size(); + LearningUtil.logger.debug("caCount: " + caCount); + + Random generator = new Random(); + + boolean listNotComplete = true; + int randomInt = 0; + + List randomList = new LinkedList(); + List randomUidList = new LinkedList(); + while (listNotComplete) { + randomInt = generator.nextInt(caCount); + LearningUtil.logger.debug("randomInt: " + randomInt); + + String ca = (String) listCandidateAnswers.get(randomInt); + LearningUtil.logger.debug("ca: " + ca); + + String caUid = (String) listCandidateAnswerUids.get(randomInt); + + if (!isEntryStored(ca, randomList)) { + LearningUtil.logger.debug("adding ca, since it is a new candidate, ca: " + ca); + randomList.add(ca); + randomUidList.add(caUid); + + LearningUtil.logger.debug("randomList size: " + randomList.size()); + if (randomList.size() == listCandidateAnswers.size()) { + LearningUtil.logger.debug("the list is populated completely, randomList: " + randomList); + listNotComplete = false; + } + } + } + + listCandidateAnswerUids = randomUidList; + LearningUtil.logger.debug("modified listCandidateAnswerUids as: " + listCandidateAnswerUids); + + mcRandomizedListsDTO.setListCandidateAnswers(randomList); + mcRandomizedListsDTO.setListCandidateAnswerUids(listCandidateAnswerUids); + + LearningUtil.logger.debug("returning mcRandomizedListsDTO: " + mcRandomizedListsDTO); + return mcRandomizedListsDTO; } - - - public static boolean isEntryStored(String ca, List randomList) - { - logger.debug("isEntryStored, randomList: " + randomList); - logger.debug("isEntryStored, ca: " + ca); - - Iterator randomListIterator=randomList.iterator(); - - while (randomListIterator.hasNext()) - { - String caStored=(String)randomListIterator.next(); - logger.debug("caStored: " + caStored); - - if (caStored.equals(ca)) - { - logger.debug("this ca already is stored: " + ca); - return true; - } - } - - return false; + + public static boolean isEntryStored(String ca, List randomList) { + LearningUtil.logger.debug("isEntryStored, randomList: " + randomList); + LearningUtil.logger.debug("isEntryStored, ca: " + ca); + + Iterator randomListIterator = randomList.iterator(); + + while (randomListIterator.hasNext()) { + String caStored = (String) randomListIterator.next(); + LearningUtil.logger.debug("caStored: " + caStored); + + if (caStored.equals(ca)) { + LearningUtil.logger.debug("this ca already is stored: " + ca); + return true; + } + } + + return false; } - - + /** * List buildQuestionAndCandidateAnswersDTO(HttpServletRequest request, McContent mcContent, IMcService mcService) * @@ -423,184 +381,191 @@ * @param mcService * @return */ - public static List buildQuestionAndCandidateAnswersDTO(HttpServletRequest request, McContent mcContent, boolean randomize, - IMcService mcService) - { - List questionAndCandidateAnswersList= new LinkedList(); - List listQuestionEntries=mcService.getAllQuestionEntries(mcContent.getUid()); - - Iterator listQuestionEntriesIterator=listQuestionEntries.iterator(); - while (listQuestionEntriesIterator.hasNext()) - { - McQueContent mcQueContent=(McQueContent)listQuestionEntriesIterator.next(); - McLearnerAnswersDTO mcLearnerAnswersDTO= new McLearnerAnswersDTO(); - List listCandidateAnswers=mcService.findMcOptionNamesByQueId(mcQueContent.getUid()); - List listCandidateAnswerUids=mcService.findMcOptionUidsByQueId(mcQueContent.getUid()); - if (randomize) - { - //listCandidateAnswers=randomizeList(listCandidateAnswers, listCandidateAnswerUids); - McRandomizedListsDTO mcRandomizedListsDTO=randomizeList(listCandidateAnswers, listCandidateAnswerUids); - listCandidateAnswers=mcRandomizedListsDTO.getListCandidateAnswers(); - listCandidateAnswerUids=mcRandomizedListsDTO.getListCandidateAnswerUids(); - } - Map mapCandidateAnswers=convertToStringMap(listCandidateAnswers); - Map mapCandidateAnswerUids=convertToStringMap(listCandidateAnswerUids); - - String question=mcQueContent.getQuestion(); - - mcLearnerAnswersDTO.setQuestion(question); - mcLearnerAnswersDTO.setDisplayOrder(mcQueContent.getDisplayOrder().toString()); - mcLearnerAnswersDTO.setQuestionUid(mcQueContent.getUid()); - - mcLearnerAnswersDTO.setMark(mcQueContent.getMark()); - mcLearnerAnswersDTO.setCandidateAnswerUids(mapCandidateAnswerUids); - mcLearnerAnswersDTO.setCandidateAnswers(mapCandidateAnswers); - - questionAndCandidateAnswersList.add(mcLearnerAnswersDTO); - } - - if ( logger.isDebugEnabled() ) { - logger.debug("buildQuestionAndCandidateAnswersDTO: mcContent uid "+mcContent.getUid()+" randomize "+randomize - + "final questionAndCandidateAnswersList: " + questionAndCandidateAnswersList); - } - - return questionAndCandidateAnswersList; + public static List buildQuestionAndCandidateAnswersDTO(HttpServletRequest request, + McContent mcContent, boolean randomize, IMcService mcService) { + List questionAndCandidateAnswersList = new LinkedList(); + List listQuestionEntries = mcService.getAllQuestionEntries(mcContent.getUid()); + + Iterator listQuestionEntriesIterator = listQuestionEntries.iterator(); + while (listQuestionEntriesIterator.hasNext()) { + McQueContent mcQueContent = (McQueContent) listQuestionEntriesIterator.next(); + McLearnerAnswersDTO mcLearnerAnswersDTO = new McLearnerAnswersDTO(); + List listCandidateAnswers = mcService.findMcOptionNamesByQueId(mcQueContent.getUid()); + List listCandidateAnswerUids = mcService.findMcOptionUidsByQueId(mcQueContent.getUid()); + if (randomize) { + // listCandidateAnswers=randomizeList(listCandidateAnswers, listCandidateAnswerUids); + McRandomizedListsDTO mcRandomizedListsDTO = randomizeList(listCandidateAnswers, listCandidateAnswerUids); + listCandidateAnswers = mcRandomizedListsDTO.getListCandidateAnswers(); + listCandidateAnswerUids = mcRandomizedListsDTO.getListCandidateAnswerUids(); + } + Map mapCandidateAnswers = convertToStringMap(listCandidateAnswers); + Map mapCandidateAnswerUids = convertToStringMap(listCandidateAnswerUids); + + String question = mcQueContent.getQuestion(); + + mcLearnerAnswersDTO.setQuestion(question); + mcLearnerAnswersDTO.setDisplayOrder(mcQueContent.getDisplayOrder().toString()); + mcLearnerAnswersDTO.setQuestionUid(mcQueContent.getUid()); + + mcLearnerAnswersDTO.setMark(mcQueContent.getMark()); + mcLearnerAnswersDTO.setCandidateAnswerUids(mapCandidateAnswerUids); + mcLearnerAnswersDTO.setCandidateAnswers(mapCandidateAnswers); + + questionAndCandidateAnswersList.add(mcLearnerAnswersDTO); + } + + if (LearningUtil.logger.isDebugEnabled()) { + LearningUtil.logger.debug("buildQuestionAndCandidateAnswersDTO: mcContent uid " + mcContent.getUid() + + " randomize " + randomize + "final questionAndCandidateAnswersList: " + + questionAndCandidateAnswersList); + } + + return questionAndCandidateAnswersList; } - - + /** * Map convertToStringMap(List list) * * @param list * @return */ - public static Map convertToStringMap(List list) - { - logger.debug("using convertToStringMap: " + list); - Map map= new TreeMap(new McComparator()); - - Iterator listIterator=list.iterator(); - Long mapIndex=new Long(1); - - while (listIterator.hasNext()) - { - String data=(String)listIterator.next(); - map.put(mapIndex.toString(), data); - mapIndex=new Long(mapIndex.longValue()+1); - } - return map; + public static Map convertToStringMap(List list) { + LearningUtil.logger.debug("using convertToStringMap: " + list); + Map map = new TreeMap(new McComparator()); + + Iterator listIterator = list.iterator(); + Long mapIndex = new Long(1); + + while (listIterator.hasNext()) { + String data = (String) listIterator.next(); + map.put(mapIndex.toString(), data); + mapIndex = new Long(mapIndex.longValue() + 1); } + return map; + } - - /** Gets the various maps used by jsps to display a learner's attempts. - * @return Map[mapFinalAnswersIsContent, mapFinalAnswersContent, mapQueAttempts, mapQueCorrectAttempts, mapQueIncorrectAttempts, mapMarks] */ - public static Map[] getAttemptMapsForUser(int intTotalQuestionCount, Long toolContentUID, boolean allowRetries, IMcService mcService, McQueUsr mcQueUsr) { - - Map mapFinalAnswersIsContent= new TreeMap(new McComparator()); - Map mapFinalAnswersContent= new TreeMap(new McComparator()); - - // mapQueAttempts: key is the question display order, the value is the mapAttempOrderAttempts map. - // mapAttemptOrderAttempts: key is the attempt order, the value is the mapAttempt map. - // mapAttemptMap: key is an artificial ordering, the value is the actual value for the question - // at the moment, there will only be one attempt for each question of each learner in a tool session - // so mapAttemptMap will only have one value. - // The mapQueCorrectAttempts and mapQueIncorrectAttempts work in a similar way - Map mapQueAttempts= new TreeMap(new McComparator()); - Map mapQueCorrectAttempts= new TreeMap(new McComparator()); - Map mapQueIncorrectAttempts= new TreeMap(new McComparator()); - - for (int i=1; i<= intTotalQuestionCount; i++) - { - logger.debug("doing question with display order: " + i); - McQueContent mcQueContent=mcService.getQuestionContentByDisplayOrder(new Long(i), toolContentUID); - logger.debug("mcQueContent uid: " + mcQueContent.getUid()); - - McUsrAttempt mcUsrAttemptFinal = null; - - List userAttempts = mcService.getAllAttemptsForAUserForOneQuestionContentOrderByAttempt(mcQueUsr.getUid(), mcQueContent.getUid()); - Iterator userAttemptsIter = userAttempts.iterator(); + /** + * Gets the various maps used by jsps to display a learner's attempts. + * + * @return Map[mapFinalAnswersIsContent, mapFinalAnswersContent, mapQueAttempts, mapQueCorrectAttempts, + * mapQueIncorrectAttempts, mapMarks] + */ + public static Map[] getAttemptMapsForUser(int intTotalQuestionCount, Long toolContentUID, boolean allowRetries, + IMcService mcService, McQueUsr mcQueUsr) { - Map mapAttemptOrderAttempts= new TreeMap(new McComparator()); - Map mapAttemptOrderCorrectAttempts= new TreeMap(new McComparator()); - Map mapAttemptOrderIncorrectAttempts= new TreeMap(new McComparator()); + Map mapFinalAnswersIsContent = new TreeMap(new McComparator()); + Map mapFinalAnswersContent = new TreeMap(new McComparator()); - while ( userAttemptsIter.hasNext() ) { - McUsrAttempt mcUsrAttempt = (McUsrAttempt) userAttemptsIter.next(); - - if ( mcUsrAttemptFinal == null || mcUsrAttempt.getAttemptOrder().compareTo(mcUsrAttemptFinal.getAttemptOrder()) > 0) - mcUsrAttemptFinal = mcUsrAttempt; + // mapQueAttempts: key is the question display order, the value is the mapAttempOrderAttempts map. + // mapAttemptOrderAttempts: key is the attempt order, the value is the mapAttempt map. + // mapAttemptMap: key is an artificial ordering, the value is the actual value for the question + // at the moment, there will only be one attempt for each question of each learner in a tool session + // so mapAttemptMap will only have one value. + // The mapQueCorrectAttempts and mapQueIncorrectAttempts work in a similar way + Map mapQueAttempts = new TreeMap(new McComparator()); + Map mapQueCorrectAttempts = new TreeMap(new McComparator()); + Map mapQueIncorrectAttempts = new TreeMap(new McComparator()); - addToAttemptMaps(mapAttemptOrderAttempts, mapAttemptOrderCorrectAttempts, mapAttemptOrderIncorrectAttempts, mcUsrAttempt); - } + for (int i = 1; i <= intTotalQuestionCount; i++) { + LearningUtil.logger.debug("doing question with display order: " + i); + McQueContent mcQueContent = mcService.getQuestionContentByDisplayOrder(new Long(i), toolContentUID); + LearningUtil.logger.debug("mcQueContent uid: " + mcQueContent.getUid()); - String questionDisplayOrderString = new Integer(i).toString(); + McUsrAttempt mcUsrAttemptFinal = null; - Integer mark = null; - if ( mcUsrAttemptFinal != null ) { - mapFinalAnswersIsContent.put(questionDisplayOrderString, new Boolean(mcUsrAttemptFinal.isAttemptCorrect()).toString()); - mapFinalAnswersContent.put(questionDisplayOrderString, mcUsrAttemptFinal.getMcOptionsContent().getMcQueOptionText().toString()); - } - if (mapAttemptOrderAttempts.size() > 0) { - mapQueAttempts.put(questionDisplayOrderString, mapAttemptOrderAttempts); - } - if (mapAttemptOrderCorrectAttempts.size() > 0) { - mapQueCorrectAttempts.put(questionDisplayOrderString, mapAttemptOrderCorrectAttempts); - } - if (mapAttemptOrderIncorrectAttempts.size() > 0) { - mapQueIncorrectAttempts.put(questionDisplayOrderString, mapAttemptOrderIncorrectAttempts); - } + List userAttempts = mcService.getAllAttemptsForAUserForOneQuestionContentOrderByAttempt(mcQueUsr.getUid(), + mcQueContent.getUid()); + Iterator userAttemptsIter = userAttempts.iterator(); + + Map mapAttemptOrderAttempts = new TreeMap(new McComparator()); + Map mapAttemptOrderCorrectAttempts = new TreeMap(new McComparator()); + Map mapAttemptOrderIncorrectAttempts = new TreeMap(new McComparator()); + + while (userAttemptsIter.hasNext()) { + McUsrAttempt mcUsrAttempt = (McUsrAttempt) userAttemptsIter.next(); + + if (mcUsrAttemptFinal == null + || mcUsrAttempt.getAttemptOrder().compareTo(mcUsrAttemptFinal.getAttemptOrder()) > 0) { + mcUsrAttemptFinal = mcUsrAttempt; } - - if ( logger.isDebugEnabled() ) { - logger.debug("final mapFinalAnswersContent is: " + mapFinalAnswersContent); - logger.debug("final mapFinalAnswersIsContent is: " + mapFinalAnswersIsContent); - logger.debug("final mapQueAttempts is: " + mapQueAttempts); - logger.debug("final mapQueCorrectAttempts is: " + mapQueCorrectAttempts); - logger.debug("final mapQueIncorrectAttempts is: " + mapQueIncorrectAttempts); - } - - return new Map[] {mapFinalAnswersIsContent, mapFinalAnswersContent, mapQueAttempts, mapQueCorrectAttempts, mapQueIncorrectAttempts}; + + addToAttemptMaps(mapAttemptOrderAttempts, mapAttemptOrderCorrectAttempts, + mapAttemptOrderIncorrectAttempts, mcUsrAttempt); + } + + String questionDisplayOrderString = new Integer(i).toString(); + + Integer mark = null; + if (mcUsrAttemptFinal != null) { + mapFinalAnswersIsContent.put(questionDisplayOrderString, new Boolean(mcUsrAttemptFinal + .isAttemptCorrect()).toString()); + mapFinalAnswersContent.put(questionDisplayOrderString, mcUsrAttemptFinal.getMcOptionsContent() + .getMcQueOptionText().toString()); + } + if (mapAttemptOrderAttempts.size() > 0) { + mapQueAttempts.put(questionDisplayOrderString, mapAttemptOrderAttempts); + } + if (mapAttemptOrderCorrectAttempts.size() > 0) { + mapQueCorrectAttempts.put(questionDisplayOrderString, mapAttemptOrderCorrectAttempts); + } + if (mapAttemptOrderIncorrectAttempts.size() > 0) { + mapQueIncorrectAttempts.put(questionDisplayOrderString, mapAttemptOrderIncorrectAttempts); + } + } + + if (LearningUtil.logger.isDebugEnabled()) { + LearningUtil.logger.debug("final mapFinalAnswersContent is: " + mapFinalAnswersContent); + LearningUtil.logger.debug("final mapFinalAnswersIsContent is: " + mapFinalAnswersIsContent); + LearningUtil.logger.debug("final mapQueAttempts is: " + mapQueAttempts); + LearningUtil.logger.debug("final mapQueCorrectAttempts is: " + mapQueCorrectAttempts); + LearningUtil.logger.debug("final mapQueIncorrectAttempts is: " + mapQueIncorrectAttempts); + } + + return new Map[] { mapFinalAnswersIsContent, mapFinalAnswersContent, mapQueAttempts, mapQueCorrectAttempts, + mapQueIncorrectAttempts }; } - - private static void addToAttemptMaps(Map mapAttemptOrderAttempts, Map mapAttemptOrderCorrectAttempts, Map mapAttemptOrderIncorrectAttempts, McUsrAttempt mcUsrAttempt) { - String attemptOrderString = mcUsrAttempt.getAttemptOrder().toString(); - - Map attemptMap = (Map) mapAttemptOrderAttempts.get(attemptOrderString); - Map correctAttemptMap = (Map) mapAttemptOrderCorrectAttempts.get(attemptOrderString); - Map incorrectAttemptMap = (Map) mapAttemptOrderIncorrectAttempts.get(attemptOrderString); - - if ( attemptMap == null ) { - attemptMap = new TreeMap(new McComparator()); - mapAttemptOrderAttempts.put(attemptOrderString, attemptMap); - - correctAttemptMap = new TreeMap(new McComparator()); - mapAttemptOrderCorrectAttempts.put(attemptOrderString, correctAttemptMap); - incorrectAttemptMap = new TreeMap(new McComparator()); - mapAttemptOrderIncorrectAttempts.put(attemptOrderString, incorrectAttemptMap); - } + private static void addToAttemptMaps(Map mapAttemptOrderAttempts, Map mapAttemptOrderCorrectAttempts, + Map mapAttemptOrderIncorrectAttempts, McUsrAttempt mcUsrAttempt) { + String attemptOrderString = mcUsrAttempt.getAttemptOrder().toString(); - int mapSize = attemptMap.size(); - String mapIndex = (new Integer(mapSize+1)).toString(); - attemptMap.put(mapIndex, mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); - if ( mcUsrAttempt.isAttemptCorrect() ) - correctAttemptMap.put(mapIndex, mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); - else - incorrectAttemptMap.put(mapIndex, mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); + Map attemptMap = (Map) mapAttemptOrderAttempts.get(attemptOrderString); + Map correctAttemptMap = (Map) mapAttemptOrderCorrectAttempts.get(attemptOrderString); + Map incorrectAttemptMap = (Map) mapAttemptOrderIncorrectAttempts.get(attemptOrderString); + if (attemptMap == null) { + attemptMap = new TreeMap(new McComparator()); + mapAttemptOrderAttempts.put(attemptOrderString, attemptMap); + + correctAttemptMap = new TreeMap(new McComparator()); + mapAttemptOrderCorrectAttempts.put(attemptOrderString, correctAttemptMap); + + incorrectAttemptMap = new TreeMap(new McComparator()); + mapAttemptOrderIncorrectAttempts.put(attemptOrderString, incorrectAttemptMap); + } + + int mapSize = attemptMap.size(); + String mapIndex = (new Integer(mapSize + 1)).toString(); + attemptMap.put(mapIndex, mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); + if (mcUsrAttempt.isAttemptCorrect()) { + correctAttemptMap.put(mapIndex, mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); + } else { + incorrectAttemptMap.put(mapIndex, mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); + } + } - /** Should we show the marks for each question - we show the marks if any of the questions - * have a mark > 1. + /** + * Should we show the marks for each question - we show the marks if any of the questions have a mark > 1. */ public static Boolean isShowMarksOnQuestion(List listQuestionAndCandidateAnswersDTO) { - Iterator iter = listQuestionAndCandidateAnswersDTO.iterator(); - while (iter.hasNext()) { - McLearnerAnswersDTO elem = (McLearnerAnswersDTO) iter.next(); - if ( elem.getMark().intValue() > 1 ) { - return Boolean.TRUE; - } - } - return Boolean.FALSE; + Iterator iter = listQuestionAndCandidateAnswersDTO.iterator(); + while (iter.hasNext()) { + McLearnerAnswersDTO elem = (McLearnerAnswersDTO) iter.next(); + if (elem.getMark().intValue() > 1) { + return Boolean.TRUE; + } + } + return Boolean.FALSE; } - } +} Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java,v diff -u -r1.69 -r1.70 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java 14 May 2008 02:46:33 -0000 1.69 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java 18 Nov 2008 04:24:11 -0000 1.70 @@ -71,142 +71,141 @@ import org.lamsfoundation.lams.web.util.SessionMap; /** - * * @author Ozgur Demirtas + * * * - *

Action class that controls the logic of tool behavior.

+ * @author Ozgur Demirtas * - *

Note that Struts action class only has the responsibility to navigate - * page flow. All database operation should go to service layer and data - * transformation from domain model to struts form bean should go to form - * bean class. This ensure clean and maintainable code. + *

+ * Action class that controls the logic of tool behavior. *

* - * SystemException is thrown whenever an known error condition is - * identified. No system exception error handling code should appear in the - * Struts action class as all of them are handled in + *

+ * Note that Struts action class only has the responsibility to navigate page flow. All database operation should go to + * service layer and data transformation from domain model to struts form bean should go to form bean class. This ensure + * clean and maintainable code. + *

+ * + * SystemException is thrown whenever an known error condition is identified. No system exception error + * handling code should appear in the Struts action class as all of them are handled in * CustomStrutsExceptionHandler. * - - - - - - - + + + - + - + - + - + - + - - - * -*/ -public class McLearningAction extends LamsDispatchAction implements McAppConstants -{ - static Logger logger = Logger.getLogger(McLearningAction.class.getName()); - - /** - *

Default struts dispatch method.

+ + + + + +
+ * + */ +public class McLearningAction extends LamsDispatchAction implements McAppConstants { + static Logger logger = Logger.getLogger(McLearningAction.class.getName()); + + /** + *

+ * Default struts dispatch method. + *

* - *

It is assuming that progress engine should pass in the tool access - * mode and the tool session id as http parameters.

+ *

+ * It is assuming that progress engine should pass in the tool access mode and the tool session id as http + * parameters. + *

* - * @param mapping An ActionMapping class that will be used by the Action class to tell - * the ActionServlet where to send the end-user. - * - * @param form The ActionForm class that will contain any data submitted - * by the end-user via a form. - * @param request A standard Servlet HttpServletRequest class. - * @param response A standard Servlet HttpServletResponse class. - * @return An ActionForward class that will be returned to the ActionServlet indicating where - * the user is to go next. + * @param mapping + * An ActionMapping class that will be used by the Action class to tell the ActionServlet where to + * send the end-user. + * + * @param form + * The ActionForm class that will contain any data submitted by the end-user via a form. + * @param request + * A standard Servlet HttpServletRequest class. + * @param response + * A standard Servlet HttpServletResponse class. + * @return An ActionForward class that will be returned to the ActionServlet indicating where the user is to go + * next. * @throws IOException * @throws ServletException - * @throws McApplicationException the known runtime exception + * @throws McApplicationException + * the known runtime exception * - * unspecified(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - - * main content/question content management and workflow logic - * - * if the passed toolContentId exists in the db, we need to get the relevant data into the Map - * if not, create the default Map - */ - public ActionForward unspecified(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - McLearningForm mcLearningForm = (McLearningForm) form; - LearningUtil.saveFormRequestData(request, mcLearningForm, false); - return null; + * unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + * throws IOException, ServletException + * + * main content/question content management and workflow logic + * + * if the passed toolContentId exists in the db, we need to get the relevant data into the Map if not, create the + * default Map + */ + @Override + public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + McLearningForm mcLearningForm = (McLearningForm) form; + LearningUtil.saveFormRequestData(request, mcLearningForm, false); + return null; } - - /** - *displayMc(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - * + * displayMc(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + * throws IOException, ServletException + * * responds to learner activity in learner mode. - * + * * @param mapping * @param form * @param request @@ -215,116 +214,90 @@ * @throws IOException * @throws ServletException */ - public ActionForward displayMc(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - McLearningForm mcLearningForm = (McLearningForm) form; - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - mcLearningForm.setToolSessionID(toolSessionID); - - McSession mcSession=mcService.retrieveMcSession(new Long(toolSessionID)); - logger.debug("retrieving mcSession: " + mcSession); - - String toolContentId=mcSession.getMcContent().getMcContentId().toString(); - logger.debug("toolContentId: " + toolContentId); - mcLearningForm.setToolContentID(toolContentId); - - logger.debug("mcLearningForm nextQuestionSelected : " + mcLearningForm.getNextQuestionSelected()); - - if ((mcLearningForm.getNextQuestionSelected() != null) && - (!mcLearningForm.getNextQuestionSelected().equals(""))) - { - logger.debug("processing getNextQuestionSelected..."); - LearningUtil.saveFormRequestData(request, mcLearningForm, false); - mcLearningForm.resetParameters(); - setContentInUse(request, toolContentId, mcService); - return getNextOptions(mapping, form, request, response); - } - - - if (mcLearningForm.getContinueOptionsCombined() != null) - { - logger.debug("processing getContinueOptionsCombined..."); - LearningUtil.saveFormRequestData(request, mcLearningForm, false); - setContentInUse(request, toolContentId, mcService); - return continueOptionsCombined(mapping, form, request, response); - } - else if (mcLearningForm.getNextOptions() != null) - { - logger.debug("processing getNextOptions..."); - LearningUtil.saveFormRequestData(request, mcLearningForm, false); - setContentInUse(request, toolContentId, mcService); - return getNextOptions(mapping, form, request, response); - } - else if (mcLearningForm.getRedoQuestions() != null) - { - logger.debug("processing getRedoQuestions..."); - LearningUtil.saveFormRequestData(request, mcLearningForm, false); - setContentInUse(request, toolContentId, mcService); - return redoQuestions(mapping, form, request, response); - } - else if (mcLearningForm.getRedoQuestionsOk() != null) - { - logger.debug("processing getRedoQuestionsOk..."); - LearningUtil.saveFormRequestData(request, mcLearningForm, false); - setContentInUse(request, toolContentId, mcService); - logger.debug("requested redoQuestionsOk, user is sure to redo the questions."); - return redoQuestions(request, mcLearningForm, mapping); - } - else if (mcLearningForm.getViewAnswers() != null) - { - logger.debug("processing getViewAnswers..."); - LearningUtil.saveFormRequestData(request, mcLearningForm, false); - setContentInUse(request, toolContentId, mcService); - mcLearningForm.setLearnerProgress(new Boolean(false).toString()); - return viewAnswers(mapping, mcLearningForm, request, response); - } - else if (mcLearningForm.getViewSummary() != null) - { - logger.debug("processing getViewSummary..."); - LearningUtil.saveFormRequestData(request, mcLearningForm, false); - setContentInUse(request, toolContentId, mcService); - return viewSummary(mapping, form, request, response); - } - else if (mcLearningForm.getSubmitReflection() != null) - { - logger.debug("processing getSubmitReflection..."); - LearningUtil.saveFormRequestData(request, mcLearningForm, false); - setContentInUse(request, toolContentId, mcService); - return submitReflection(mapping, form, request, response); - } - else if (mcLearningForm.getForwardtoReflection() != null) - { - logger.debug("processing getForwardtoReflection..."); - LearningUtil.saveFormRequestData(request, mcLearningForm, false); - setContentInUse(request, toolContentId, mcService); - return forwardtoReflection(mapping, form, request, response); - } - else if (mcLearningForm.getLearnerFinished() != null) - { - logger.debug("processing getLearnerFinished..."); - LearningUtil.saveFormRequestData(request, mcLearningForm, false); - setContentInUse(request, toolContentId, mcService); - return endLearning(mapping, form, request, response); - } - - return (mapping.findForward(LOAD_LEARNER)); - } + public ActionForward displayMc(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + McLearningForm mcLearningForm = (McLearningForm) form; + IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - + String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + McLearningAction.logger.debug("toolSessionID: " + toolSessionID); + mcLearningForm.setToolSessionID(toolSessionID); + + McSession mcSession = mcService.retrieveMcSession(new Long(toolSessionID)); + McLearningAction.logger.debug("retrieving mcSession: " + mcSession); + + String toolContentId = mcSession.getMcContent().getMcContentId().toString(); + McLearningAction.logger.debug("toolContentId: " + toolContentId); + mcLearningForm.setToolContentID(toolContentId); + + McLearningAction.logger.debug("mcLearningForm nextQuestionSelected : " + + mcLearningForm.getNextQuestionSelected()); + + if (mcLearningForm.getNextQuestionSelected() != null && !mcLearningForm.getNextQuestionSelected().equals("")) { + McLearningAction.logger.debug("processing getNextQuestionSelected..."); + LearningUtil.saveFormRequestData(request, mcLearningForm, false); + mcLearningForm.resetParameters(); + setContentInUse(request, toolContentId, mcService); + return getNextOptions(mapping, form, request, response); + } + + if (mcLearningForm.getContinueOptionsCombined() != null) { + McLearningAction.logger.debug("processing getContinueOptionsCombined..."); + LearningUtil.saveFormRequestData(request, mcLearningForm, false); + setContentInUse(request, toolContentId, mcService); + return continueOptionsCombined(mapping, form, request, response); + } else if (mcLearningForm.getNextOptions() != null) { + McLearningAction.logger.debug("processing getNextOptions..."); + LearningUtil.saveFormRequestData(request, mcLearningForm, false); + setContentInUse(request, toolContentId, mcService); + return getNextOptions(mapping, form, request, response); + } else if (mcLearningForm.getRedoQuestions() != null) { + McLearningAction.logger.debug("processing getRedoQuestions..."); + LearningUtil.saveFormRequestData(request, mcLearningForm, false); + setContentInUse(request, toolContentId, mcService); + return redoQuestions(mapping, form, request, response); + } else if (mcLearningForm.getRedoQuestionsOk() != null) { + McLearningAction.logger.debug("processing getRedoQuestionsOk..."); + LearningUtil.saveFormRequestData(request, mcLearningForm, false); + setContentInUse(request, toolContentId, mcService); + McLearningAction.logger.debug("requested redoQuestionsOk, user is sure to redo the questions."); + return redoQuestions(request, mcLearningForm, mapping); + } else if (mcLearningForm.getViewAnswers() != null) { + McLearningAction.logger.debug("processing getViewAnswers..."); + LearningUtil.saveFormRequestData(request, mcLearningForm, false); + setContentInUse(request, toolContentId, mcService); + mcLearningForm.setLearnerProgress(new Boolean(false).toString()); + return viewAnswers(mapping, mcLearningForm, request, response); + } else if (mcLearningForm.getViewSummary() != null) { + McLearningAction.logger.debug("processing getViewSummary..."); + LearningUtil.saveFormRequestData(request, mcLearningForm, false); + setContentInUse(request, toolContentId, mcService); + return viewSummary(mapping, form, request, response); + } else if (mcLearningForm.getSubmitReflection() != null) { + McLearningAction.logger.debug("processing getSubmitReflection..."); + LearningUtil.saveFormRequestData(request, mcLearningForm, false); + setContentInUse(request, toolContentId, mcService); + return submitReflection(mapping, form, request, response); + } else if (mcLearningForm.getForwardtoReflection() != null) { + McLearningAction.logger.debug("processing getForwardtoReflection..."); + LearningUtil.saveFormRequestData(request, mcLearningForm, false); + setContentInUse(request, toolContentId, mcService); + return forwardtoReflection(mapping, form, request, response); + } else if (mcLearningForm.getLearnerFinished() != null) { + McLearningAction.logger.debug("processing getLearnerFinished..."); + LearningUtil.saveFormRequestData(request, mcLearningForm, false); + setContentInUse(request, toolContentId, mcService); + return endLearning(mapping, form, request, response); + } + + return mapping.findForward(McAppConstants.LOAD_LEARNER); + } + /** - * ActionForward endLearning(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) - + * ActionForward endLearning(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse + * response) * + * * @param mapping * @param form * @param request @@ -333,142 +306,120 @@ * @throws IOException * @throws ServletException */ - public ActionForward endLearning(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - logger.debug("dispatching endLearning "); - McLearningForm mcLearningForm = (McLearningForm) form; - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - mcLearningForm.setToolSessionID(toolSessionID); - - McSession mcSession=mcService.retrieveMcSession(new Long(toolSessionID)); - logger.debug("retrieving mcSession: " + mcSession); - - String toolContentId=mcSession.getMcContent().getMcContentId().toString(); - logger.debug("toolContentId: " + toolContentId); - mcLearningForm.setToolContentID(toolContentId); - - logger.debug("mcLearningForm nextQuestionSelected : " + mcLearningForm.getNextQuestionSelected()); - - LearningUtil.saveFormRequestData(request, mcLearningForm, false); - logger.debug("requested learner finished, the learner should be directed to next activity."); - - logger.debug("toolSessionID: " + toolSessionID); - - String userID = ""; - HttpSession ss = SessionManager.getSession(); - logger.debug("ss: " + ss); - - if (ss != null) - { - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - if ((user != null) && (user.getUserID() != null)) - { - userID = user.getUserID().toString(); - logger.debug("retrieved userId: " + userID); - } - } - - logger.debug("attempting to leave/complete session with toolSessionId:" + toolSessionID + " and userID:"+userID); - - McUtils.cleanUpSessionAbsolute(request); - - String nextUrl=null; - try - { - nextUrl=mcService.leaveToolSession(new Long(toolSessionID), new Long(userID)); - logger.debug("nextUrl: "+ nextUrl); - } - catch (DataMissingException e) - { - logger.debug("failure getting nextUrl: "+ e); - return (mapping.findForward(LEARNING_STARTER)); - } - catch (ToolException e) - { - logger.debug("failure getting nextUrl: "+ e); - return (mapping.findForward(LEARNING_STARTER)); - } - catch (Exception e) - { - logger.debug("unknown exception getting nextUrl: "+ e); - return (mapping.findForward(LEARNING_STARTER)); - } - - logger.debug("success getting nextUrl: "+ nextUrl); - - McQueUsr mcQueUsr=mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); - logger.debug("mcQueUsr:" + mcQueUsr); - - - - /* it is possible that mcQueUsr can be null if the content is set as runoffline and reflection is on*/ - if (mcQueUsr == null) - { - logger.debug("attempt creating user record since it must exist for the runOffline + reflection screens"); - - UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); - logger.debug("retrieving toolUser: " + toolUser); - logger.debug("retrieving toolUser userId: " + toolUser.getUserID()); - logger.debug("retrieving toolUser username: " + toolUser.getLogin()); + public ActionForward endLearning(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + McLearningAction.logger.debug("dispatching endLearning "); + McLearningForm mcLearningForm = (McLearningForm) form; + IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - String userName=toolUser.getLogin(); - String fullName= toolUser.getFirstName() + " " + toolUser.getLastName(); - logger.debug("retrieving toolUser fullname: " + fullName); - - Long userId=new Long(toolUser.getUserID().longValue()); - logger.debug("userId: " + userId); - logger.debug("retrieving toolUser fullname: " + fullName); - - mcQueUsr= new McQueUsr(userId, - userName, - fullName, - mcSession, - new TreeSet()); - mcService.createMcQueUsr(mcQueUsr); - logger.debug("createMcQueUsr - mcQueUsr: " + mcQueUsr); - - logger.debug("session uid: " + mcSession.getUid()); - logger.debug("mcQueUsr: " + mcQueUsr); - mcService.createMcQueUsr(mcQueUsr); - logger.debug("created mcQueUsr in the db: " + mcQueUsr); + String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + McLearningAction.logger.debug("toolSessionID: " + toolSessionID); + mcLearningForm.setToolSessionID(toolSessionID); + + McSession mcSession = mcService.retrieveMcSession(new Long(toolSessionID)); + McLearningAction.logger.debug("retrieving mcSession: " + mcSession); + + String toolContentId = mcSession.getMcContent().getMcContentId().toString(); + McLearningAction.logger.debug("toolContentId: " + toolContentId); + mcLearningForm.setToolContentID(toolContentId); + + McLearningAction.logger.debug("mcLearningForm nextQuestionSelected : " + + mcLearningForm.getNextQuestionSelected()); + + LearningUtil.saveFormRequestData(request, mcLearningForm, false); + McLearningAction.logger.debug("requested learner finished, the learner should be directed to next activity."); + + McLearningAction.logger.debug("toolSessionID: " + toolSessionID); + + String userID = ""; + HttpSession ss = SessionManager.getSession(); + McLearningAction.logger.debug("ss: " + ss); + + if (ss != null) { + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + if (user != null && user.getUserID() != null) { + userID = user.getUserID().toString(); + McLearningAction.logger.debug("retrieved userId: " + userID); } - - - - mcQueUsr.setResponseFinalised(true); - mcService.updateMcQueUsr(mcQueUsr); - logger.debug("response finalised for user:" + mcQueUsr); - - mcQueUsr.setViewSummaryRequested(true); - mcService.updateMcQueUsr(mcQueUsr); - logger.debug("view summary requested by mcQueUsr: " + mcQueUsr); - - List userAttempts=mcService.getLatestAttemptsForAUser(mcQueUsr.getUid()); - logger.debug("userAttempts:" + userAttempts); - - Iterator itAttempts=userAttempts.iterator(); - while (itAttempts.hasNext()) - { - McUsrAttempt mcUsrAttempt=(McUsrAttempt)itAttempts.next(); - mcUsrAttempt.setFinished(true); - mcService.updateMcUsrAttempt(mcUsrAttempt); - } - - logger.debug("redirecting to the nextUrl: "+ nextUrl); - response.sendRedirect(nextUrl); - - return null; - } - + } - + McLearningAction.logger.debug("attempting to leave/complete session with toolSessionId:" + toolSessionID + + " and userID:" + userID); + + McUtils.cleanUpSessionAbsolute(request); + + String nextUrl = null; + try { + nextUrl = mcService.leaveToolSession(new Long(toolSessionID), new Long(userID)); + McLearningAction.logger.debug("nextUrl: " + nextUrl); + } catch (DataMissingException e) { + McLearningAction.logger.debug("failure getting nextUrl: " + e); + return mapping.findForward(McAppConstants.LEARNING_STARTER); + } catch (ToolException e) { + McLearningAction.logger.debug("failure getting nextUrl: " + e); + return mapping.findForward(McAppConstants.LEARNING_STARTER); + } catch (Exception e) { + McLearningAction.logger.debug("unknown exception getting nextUrl: " + e); + return mapping.findForward(McAppConstants.LEARNING_STARTER); + } + + McLearningAction.logger.debug("success getting nextUrl: " + nextUrl); + + McQueUsr mcQueUsr = mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); + McLearningAction.logger.debug("mcQueUsr:" + mcQueUsr); + + /* it is possible that mcQueUsr can be null if the content is set as runoffline and reflection is on */ + if (mcQueUsr == null) { + McLearningAction.logger + .debug("attempt creating user record since it must exist for the runOffline + reflection screens"); + + UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); + McLearningAction.logger.debug("retrieving toolUser: " + toolUser); + McLearningAction.logger.debug("retrieving toolUser userId: " + toolUser.getUserID()); + McLearningAction.logger.debug("retrieving toolUser username: " + toolUser.getLogin()); + + String userName = toolUser.getLogin(); + String fullName = toolUser.getFirstName() + " " + toolUser.getLastName(); + McLearningAction.logger.debug("retrieving toolUser fullname: " + fullName); + + Long userId = new Long(toolUser.getUserID().longValue()); + McLearningAction.logger.debug("userId: " + userId); + McLearningAction.logger.debug("retrieving toolUser fullname: " + fullName); + + mcQueUsr = new McQueUsr(userId, userName, fullName, mcSession, new TreeSet()); + mcService.createMcQueUsr(mcQueUsr); + McLearningAction.logger.debug("createMcQueUsr - mcQueUsr: " + mcQueUsr); + + McLearningAction.logger.debug("session uid: " + mcSession.getUid()); + McLearningAction.logger.debug("mcQueUsr: " + mcQueUsr); + mcService.createMcQueUsr(mcQueUsr); + McLearningAction.logger.debug("created mcQueUsr in the db: " + mcQueUsr); + } + + mcQueUsr.setResponseFinalised(true); + mcService.updateMcQueUsr(mcQueUsr); + McLearningAction.logger.debug("response finalised for user:" + mcQueUsr); + + mcQueUsr.setViewSummaryRequested(true); + mcService.updateMcQueUsr(mcQueUsr); + McLearningAction.logger.debug("view summary requested by mcQueUsr: " + mcQueUsr); + + List userAttempts = mcService.getLatestAttemptsForAUser(mcQueUsr.getUid()); + McLearningAction.logger.debug("userAttempts:" + userAttempts); + + Iterator itAttempts = userAttempts.iterator(); + while (itAttempts.hasNext()) { + McUsrAttempt mcUsrAttempt = (McUsrAttempt) itAttempts.next(); + mcUsrAttempt.setFinished(true); + mcService.updateMcUsrAttempt(mcUsrAttempt); + } + + McLearningAction.logger.debug("redirecting to the nextUrl: " + nextUrl); + response.sendRedirect(nextUrl); + + return null; + } + /** * Set parseLearnerInput(List learnerInput, McContent mcContent, IMcService mcService) * @@ -477,623 +428,571 @@ * @param mcService * @return */ - protected Set parseLearnerInput(List learnerInput, McContent mcContent, IMcService mcService) - { - logger.debug("starting parseLearnerInput: " + learnerInput); - logger.debug("mcContent: " + mcContent); - logger.debug("mcContent uid: " + mcContent.getUid()); - - Set questionUids= new HashSet(); + protected Set parseLearnerInput(List learnerInput, McContent mcContent, IMcService mcService) { + McLearningAction.logger.debug("starting parseLearnerInput: " + learnerInput); + McLearningAction.logger.debug("mcContent: " + mcContent); + McLearningAction.logger.debug("mcContent uid: " + mcContent.getUid()); - Iterator listLearnerInputIterator=learnerInput.iterator(); - while (listLearnerInputIterator.hasNext()) - { - String input=(String)listLearnerInputIterator.next(); - logger.debug("input: " + input); - int pos=input.indexOf("-"); - logger.debug("pos: " + pos); - String questionUid=input.substring(0,pos); - logger.debug("questionUid: " + questionUid); - questionUids.add(questionUid); - } - logger.debug("final set questionUid: " + questionUids); - - - List questionEntriesOrdered=mcService.getAllQuestionEntries(mcContent.getUid()); - logger.debug("questionEntriesOrdered: " + questionEntriesOrdered); - - Set questionOrderedUids= new TreeSet(new McComparator()); - Iterator questionEntriesOrderedIterator=questionEntriesOrdered.iterator(); - while (questionEntriesOrderedIterator.hasNext()) - { - McQueContent mcQueContent= (McQueContent)questionEntriesOrderedIterator.next(); - logger.debug("mcQueContent: " + mcQueContent); - logger.debug("mcQueContent text: " + mcQueContent.getQuestion()); - - - Iterator questionUidsIterator=questionUids.iterator(); - while (questionUidsIterator.hasNext()) - { - String questionUid= (String)questionUidsIterator.next(); - logger.debug("questionUid: " + questionUid); - - logger.debug("questionUid versus objects uid : " + questionUid + " versus " + mcQueContent.getUid()); - if (questionUid.equals(mcQueContent.getUid().toString())) - { - questionOrderedUids.add(questionUid); - } - } - } - logger.debug("questionOrderedUids: " + questionOrderedUids); - return questionOrderedUids; + Set questionUids = new HashSet(); + + Iterator listLearnerInputIterator = learnerInput.iterator(); + while (listLearnerInputIterator.hasNext()) { + String input = (String) listLearnerInputIterator.next(); + McLearningAction.logger.debug("input: " + input); + int pos = input.indexOf("-"); + McLearningAction.logger.debug("pos: " + pos); + String questionUid = input.substring(0, pos); + McLearningAction.logger.debug("questionUid: " + questionUid); + questionUids.add(questionUid); + } + McLearningAction.logger.debug("final set questionUid: " + questionUids); + + List questionEntriesOrdered = mcService.getAllQuestionEntries(mcContent.getUid()); + McLearningAction.logger.debug("questionEntriesOrdered: " + questionEntriesOrdered); + + Set questionOrderedUids = new TreeSet(new McComparator()); + Iterator questionEntriesOrderedIterator = questionEntriesOrdered.iterator(); + while (questionEntriesOrderedIterator.hasNext()) { + McQueContent mcQueContent = (McQueContent) questionEntriesOrderedIterator.next(); + McLearningAction.logger.debug("mcQueContent: " + mcQueContent); + McLearningAction.logger.debug("mcQueContent text: " + mcQueContent.getQuestion()); + + Iterator questionUidsIterator = questionUids.iterator(); + while (questionUidsIterator.hasNext()) { + String questionUid = (String) questionUidsIterator.next(); + McLearningAction.logger.debug("questionUid: " + questionUid); + + McLearningAction.logger.debug("questionUid versus objects uid : " + questionUid + " versus " + + mcQueContent.getUid()); + if (questionUid.equals(mcQueContent.getUid().toString())) { + questionOrderedUids.add(questionUid); + } + } + } + McLearningAction.logger.debug("questionOrderedUids: " + questionOrderedUids); + return questionOrderedUids; } - /** - * List buildSelectedQuestionAndCandidateAnswersDTO(List learnerInput, McTempDataHolderDTO mcTempDataHolderDTO, - IMcService mcService, McContent mcContent) - + * List buildSelectedQuestionAndCandidateAnswersDTO(List learnerInput, McTempDataHolderDTO mcTempDataHolderDTO, + * IMcService mcService, McContent mcContent) + * * @param learnerInput * @param mcTempDataHolderDTO * @param mcService * @param mcContent * @return */ - protected List buildSelectedQuestionAndCandidateAnswersDTO(List learnerInput, McTempDataHolderDTO mcTempDataHolderDTO, - IMcService mcService, McContent mcContent) - { - if ( log.isDebugEnabled() ) { - logger.debug("starting buildSelectedQuestionAndCandidateAnswersDTO using learnerInput: " + learnerInput - +" and mcContent: " + mcContent); - } - - int learnerMarks=0; - int totalMarksPossible=0; - - Set questionUids=parseLearnerInput(learnerInput, mcContent, mcService); - if ( log.isDebugEnabled() ) - logger.debug("set questionUids: " + questionUids); - - List questionAndCandidateAnswersList= new LinkedList(); - - Iterator questionIterator = mcContent.getMcQueContents().iterator(); - while (questionIterator.hasNext()) - { - McQueContent mcQueContent = (McQueContent) questionIterator.next(); - String currentQuestionUid = mcQueContent.getUid().toString(); - int currentMark= mcQueContent.getMark().intValue(); - totalMarksPossible+=currentMark; + protected List buildSelectedQuestionAndCandidateAnswersDTO(List learnerInput, + McTempDataHolderDTO mcTempDataHolderDTO, IMcService mcService, McContent mcContent) { + if (LamsDispatchAction.log.isDebugEnabled()) { + McLearningAction.logger.debug("starting buildSelectedQuestionAndCandidateAnswersDTO using learnerInput: " + + learnerInput + " and mcContent: " + mcContent); + } - McLearnerAnswersDTO mcLearnerAnswersDTO= new McLearnerAnswersDTO(); - mcLearnerAnswersDTO.setQuestion(mcQueContent.getQuestion()); - mcLearnerAnswersDTO.setDisplayOrder(mcQueContent.getDisplayOrder().toString()); - mcLearnerAnswersDTO.setQuestionUid(mcQueContent.getUid()); - mcLearnerAnswersDTO.setFeedback(mcQueContent.getFeedback() != null ? mcQueContent.getFeedback() : ""); - - Map caMap= new TreeMap(new McStringComparator()); - Set caIds= new HashSet(); - long mapIndex=new Long(1); - - Iterator listLearnerInputIterator=learnerInput.iterator(); - while (listLearnerInputIterator.hasNext()) - { - String input=(String)listLearnerInputIterator.next(); - int pos=input.indexOf("-"); - String localQuestionUid=input.substring(0,pos); + int learnerMarks = 0; + int totalMarksPossible = 0; - if ( log.isDebugEnabled() ) { - logger.debug("input: " + input); - logger.debug("pos: " + pos); - logger.debug("localQuestionUid: " + localQuestionUid); - } - - if (currentQuestionUid.equals(localQuestionUid)) - { - String caUid=input.substring(pos+1); - McOptsContent mcOptsContent= mcQueContent.getOptionsContentByUID(new Long(caUid)); - String mapIndexAsString = new Long(mapIndex).toString(); - caMap.put(mapIndexAsString, mcOptsContent.getMcQueOptionText()); - caIds.add( caUid ); - mapIndex++; - - if ( log.isDebugEnabled() ) { - logger.debug("equal uids found : " + localQuestionUid+" caUid: " + caUid); - logger.debug("mcOptsContent: " + mcOptsContent); - logger.debug("mcOptsContent text: " + mcOptsContent.getMcQueOptionText()); - } - } - } - mcLearnerAnswersDTO.setCandidateAnswers(caMap); - - List correctOptions = (List) mcService.getPersistedSelectedOptions(mcQueContent.getUid()); - boolean compareResult = LearningUtil.isQuestionCorrect(correctOptions, caIds); - mcLearnerAnswersDTO.setAttemptCorrect(new Boolean(compareResult).toString()); - if (compareResult) - { - mcLearnerAnswersDTO.setFeedbackCorrect(mcQueContent.getFeedback()); - mcLearnerAnswersDTO.setMark(new Integer(currentMark)); - learnerMarks+=currentMark; - } - else - { - mcLearnerAnswersDTO.setFeedbackIncorrect(mcQueContent.getFeedback()); - mcLearnerAnswersDTO.setMark(new Integer(0)); - } + Set questionUids = parseLearnerInput(learnerInput, mcContent, mcService); + if (LamsDispatchAction.log.isDebugEnabled()) { + McLearningAction.logger.debug("set questionUids: " + questionUids); + } - if ( log.isDebugEnabled() ) { - logger.debug("mark:: " + learnerMarks); - logger.debug("current mcLearnerAnswersDTO: " + mcLearnerAnswersDTO); - } - - questionAndCandidateAnswersList.add(mcLearnerAnswersDTO); - - }//end question iterator - - mcTempDataHolderDTO.setLearnerMark(new Integer(learnerMarks)); - mcTempDataHolderDTO.setTotalMarksPossible(new Integer(totalMarksPossible)); - - if ( log.isDebugEnabled() ) { - logger.debug("final questionAndCandidateAnswersList: " + questionAndCandidateAnswersList); - logger.debug("final userMarks: " + learnerMarks); - logger.debug("totalMarksPossible: " + totalMarksPossible); - logger.debug("mcTempDataHolderDTO before return : " + mcTempDataHolderDTO); - } - - return questionAndCandidateAnswersList; + List questionAndCandidateAnswersList = new LinkedList(); + + Iterator questionIterator = mcContent.getMcQueContents().iterator(); + while (questionIterator.hasNext()) { + McQueContent mcQueContent = (McQueContent) questionIterator.next(); + String currentQuestionUid = mcQueContent.getUid().toString(); + int currentMark = mcQueContent.getMark().intValue(); + totalMarksPossible += currentMark; + + McLearnerAnswersDTO mcLearnerAnswersDTO = new McLearnerAnswersDTO(); + mcLearnerAnswersDTO.setQuestion(mcQueContent.getQuestion()); + mcLearnerAnswersDTO.setDisplayOrder(mcQueContent.getDisplayOrder().toString()); + mcLearnerAnswersDTO.setQuestionUid(mcQueContent.getUid()); + mcLearnerAnswersDTO.setFeedback(mcQueContent.getFeedback() != null ? mcQueContent.getFeedback() : ""); + + Map caMap = new TreeMap(new McStringComparator()); + List caIds = new LinkedList(); + long mapIndex = new Long(1); + + Iterator listLearnerInputIterator = learnerInput.iterator(); + while (listLearnerInputIterator.hasNext()) { + String input = (String) listLearnerInputIterator.next(); + int pos = input.indexOf("-"); + String localQuestionUid = input.substring(0, pos); + + if (LamsDispatchAction.log.isDebugEnabled()) { + McLearningAction.logger.debug("input: " + input); + McLearningAction.logger.debug("pos: " + pos); + McLearningAction.logger.debug("localQuestionUid: " + localQuestionUid); + } + + if (currentQuestionUid.equals(localQuestionUid)) { + String caUid = input.substring(pos + 1); + McOptsContent mcOptsContent = mcQueContent.getOptionsContentByUID(new Long(caUid)); + String mapIndexAsString = new Long(mapIndex).toString(); + caMap.put(mapIndexAsString, mcOptsContent.getMcQueOptionText()); + caIds.add(caUid); + mapIndex++; + + if (LamsDispatchAction.log.isDebugEnabled()) { + McLearningAction.logger.debug("equal uids found : " + localQuestionUid + " caUid: " + caUid); + McLearningAction.logger.debug("mcOptsContent: " + mcOptsContent); + McLearningAction.logger.debug("mcOptsContent text: " + mcOptsContent.getMcQueOptionText()); + } + } + } + mcLearnerAnswersDTO.setCandidateAnswers(caMap); + + List correctOptions = mcService.getPersistedSelectedOptions(mcQueContent.getUid()); + boolean compareResult = LearningUtil.isQuestionCorrect(correctOptions, caIds); + mcLearnerAnswersDTO.setAttemptCorrect(new Boolean(compareResult).toString()); + if (compareResult) { + mcLearnerAnswersDTO.setFeedbackCorrect(mcQueContent.getFeedback()); + mcLearnerAnswersDTO.setMark(new Integer(currentMark)); + learnerMarks += currentMark; + } else { + mcLearnerAnswersDTO.setFeedbackIncorrect(mcQueContent.getFeedback()); + mcLearnerAnswersDTO.setMark(new Integer(0)); + } + + if (LamsDispatchAction.log.isDebugEnabled()) { + McLearningAction.logger.debug("mark:: " + learnerMarks); + McLearningAction.logger.debug("current mcLearnerAnswersDTO: " + mcLearnerAnswersDTO); + } + + questionAndCandidateAnswersList.add(mcLearnerAnswersDTO); + + }// end question iterator + + mcTempDataHolderDTO.setLearnerMark(new Integer(learnerMarks)); + mcTempDataHolderDTO.setTotalMarksPossible(new Integer(totalMarksPossible)); + + if (LamsDispatchAction.log.isDebugEnabled()) { + McLearningAction.logger.debug("final questionAndCandidateAnswersList: " + questionAndCandidateAnswersList); + McLearningAction.logger.debug("final userMarks: " + learnerMarks); + McLearningAction.logger.debug("totalMarksPossible: " + totalMarksPossible); + McLearningAction.logger.debug("mcTempDataHolderDTO before return : " + mcTempDataHolderDTO); + } + + return questionAndCandidateAnswersList; } - /** - * continueOptionsCombined(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) - * + * continueOptionsCombined(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse + * response) + * * responses to learner when they answer all the questions on a single page - * + * * @param request * @param form * @param mapping * @return ActionForward */ - public ActionForward continueOptionsCombined(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - logger.debug("dispatching continueOptionsCombined..."); - McLearningForm mcLearningForm = (McLearningForm) form; - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - logger.debug("retrieving mcService: " + mcService); + public ActionForward continueOptionsCombined(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + McLearningAction.logger.debug("dispatching continueOptionsCombined..."); + McLearningForm mcLearningForm = (McLearningForm) form; + IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); + McLearningAction.logger.debug("retrieving mcService: " + mcService); - String httpSessionID=mcLearningForm.getHttpSessionID(); - logger.debug("httpSessionID: " + httpSessionID); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - logger.debug("sessionMap: " + sessionMap); + String httpSessionID = mcLearningForm.getHttpSessionID(); + McLearningAction.logger.debug("httpSessionID: " + httpSessionID); - String questionListingMode=mcLearningForm.getQuestionListingMode(); - logger.debug("questionListingMode: " + questionListingMode); - - List learnerInput= new LinkedList(); - if (questionListingMode.equals(QUESTION_LISTING_MODE_SEQUENTIAL)) - { - logger.debug("listing mode is : " + QUESTION_LISTING_MODE_SEQUENTIAL); - - List sequentialCheckedCa=(List)sessionMap.get(QUESTION_AND_CANDIDATE_ANSWERS_KEY); - logger.debug("pre sequentialCheckedCa: " + sequentialCheckedCa); - - Iterator sequentialCheckedCaIterator=sequentialCheckedCa.iterator(); - while (sequentialCheckedCaIterator.hasNext()) - { - String input=(String)sequentialCheckedCaIterator.next(); - logger.debug("input: " + input); - } - - /* checkedCa refers to candidate answers */ - String[] checkedCa=mcLearningForm.getCheckedCa(); - logger.debug("checkedCa: " + checkedCa); - - if (checkedCa != null) - { - mcLearningForm.resetCa(mapping, request); - - for (int i=0; i < checkedCa.length ; i++) - { - String currentCa=checkedCa[i]; - logger.debug("currentCa: " + currentCa); - sequentialCheckedCa.add(currentCa); - } - } - - logger.debug("post sequentialCheckedCa: " + sequentialCheckedCa); - sequentialCheckedCaIterator=sequentialCheckedCa.iterator(); - while (sequentialCheckedCaIterator.hasNext()) - { - String input=(String)sequentialCheckedCaIterator.next(); - logger.debug("input: " + input); - } + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + McLearningAction.logger.debug("sessionMap: " + sessionMap); - sessionMap.put(QUESTION_AND_CANDIDATE_ANSWERS_KEY, sequentialCheckedCa); - request.getSession().setAttribute(httpSessionID, sessionMap); + String questionListingMode = mcLearningForm.getQuestionListingMode(); + McLearningAction.logger.debug("questionListingMode: " + questionListingMode); - - learnerInput=sequentialCheckedCa; - logger.debug("end processing for mode : " + QUESTION_LISTING_MODE_SEQUENTIAL); - } - else - { - Map parameters = request.getParameterMap(); - Iterator iter = parameters.keySet().iterator(); - while ( iter.hasNext() ) { - String key = (String) iter.next(); - if ( key.startsWith("checkedCa") ) { - String currentCheckedCa = (String) request.getParameter(key); - logger.debug("Found matching checkedCa: key "+key+" value "+currentCheckedCa+"."); - if (currentCheckedCa != null ) { - learnerInput.add(currentCheckedCa); - } - } - } + List learnerInput = new LinkedList(); + if (questionListingMode.equals(McAppConstants.QUESTION_LISTING_MODE_SEQUENTIAL)) { + McLearningAction.logger.debug("listing mode is : " + McAppConstants.QUESTION_LISTING_MODE_SEQUENTIAL); - mcLearningForm.resetCa(mapping, request); + List sequentialCheckedCa = (List) sessionMap.get(McAppConstants.QUESTION_AND_CANDIDATE_ANSWERS_KEY); + McLearningAction.logger.debug("pre sequentialCheckedCa: " + sequentialCheckedCa); + + Iterator sequentialCheckedCaIterator = sequentialCheckedCa.iterator(); + + while (sequentialCheckedCaIterator.hasNext()) { + String input = (String) sequentialCheckedCaIterator.next(); + McLearningAction.logger.debug("input: " + input); } - - logger.debug("final learnerInput: " + learnerInput); - - String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - - McSession mcSession=mcService.retrieveMcSession(new Long(toolSessionID)); - logger.debug("retrieving mcSession: " + mcSession); - - String toolContentId=mcSession.getMcContent().getMcContentId().toString(); - logger.debug("toolContentId: " + toolContentId); - + /* checkedCa refers to candidate answers */ + String[] checkedCa = mcLearningForm.getCheckedCa(); + McLearningAction.logger.debug("checkedCa: " + checkedCa); - /* process the answers */ - McContent mcContent=mcService.retrieveMc(new Long(toolContentId)); - logger.debug("mcContent: " + mcContent); + if (checkedCa != null) { + mcLearningForm.resetCa(mapping, request); - McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO=LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); - logger.debug("constructed a new mcGeneralLearnerFlowDTO"); - - McTempDataHolderDTO mcTempDataHolderDTO= new McTempDataHolderDTO(); - - boolean allQuestionsChecked=allQuestionsChecked(mcService,learnerInput, mcContent, mcTempDataHolderDTO); - logger.debug("allQuestionsChecked: " + allQuestionsChecked); - logger.debug("mcTempDataHolderDTO displayOrder: " + mcTempDataHolderDTO.getDisplayOrder()); - - - if (!allQuestionsChecked) - { - logger.debug("there are no selected answers for any questions: " + learnerInput); - ActionMessages errors = new ActionMessages(); - - ActionMessage error = new ActionMessage("answers.submitted.none"); - errors.add(ActionMessages.GLOBAL_MESSAGE, error); - logger.debug("errors: " + errors); - saveErrors(request, errors); - logger.debug("errors saved: " + errors); + for (int i = 0; i < checkedCa.length; i++) { + String currentCa = checkedCa[i]; + McLearningAction.logger.debug("currentCa: " + currentCa); + sequentialCheckedCa.add(currentCa); + } + } - McLearningStarterAction mcLearningStarterAction= new McLearningStarterAction(); - mcLearningStarterAction.commonContentSetup(request, mcContent, mcService, mcLearningForm, toolSessionID); - - mcGeneralLearnerFlowDTO.setQuestionIndex(mcTempDataHolderDTO.getDisplayOrder()); + McLearningAction.logger.debug("post sequentialCheckedCa: " + sequentialCheckedCa); + sequentialCheckedCaIterator = sequentialCheckedCa.iterator(); - request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); - logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + request.getAttribute(MC_GENERAL_LEARNER_FLOW_DTO)); - - logger.debug("returning to LOAD_LEARNER: " + LOAD_LEARNER); - return (mapping.findForward(LOAD_LEARNER)); - } - - + while (sequentialCheckedCaIterator.hasNext()) { + String input = (String) sequentialCheckedCaIterator.next(); + McLearningAction.logger.debug("input: " + input); + } - List selectedQuestionAndCandidateAnswersDTO=buildSelectedQuestionAndCandidateAnswersDTO(learnerInput,mcTempDataHolderDTO, mcService, mcContent); - logger.debug("selectedQuestionAndCandidateAnswersDTO: " + selectedQuestionAndCandidateAnswersDTO); - request.setAttribute(LIST_SELECTED_QUESTION_CANDIDATEANSWERS_DTO, selectedQuestionAndCandidateAnswersDTO); - logger.debug("LIST_SELECTED_QUESTION_CANDIDATEANSWERS_DTO: " + request.getAttribute(LIST_SELECTED_QUESTION_CANDIDATEANSWERS_DTO)); - - logger.debug("mcTempDataHolderDTO becomes: " + mcTempDataHolderDTO); - - mcGeneralLearnerFlowDTO.setQuestionListingMode(QUESTION_LISTING_MODE_COMBINED); - - Integer learnerMark = mcTempDataHolderDTO.getLearnerMark(); - mcGeneralLearnerFlowDTO.setLearnerMark(learnerMark); - int totalQuestionCount=mcContent.getMcQueContents().size(); - mcGeneralLearnerFlowDTO.setTotalQuestionCount(new Integer(totalQuestionCount)); - mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcTempDataHolderDTO.getTotalMarksPossible()); - + sessionMap.put(McAppConstants.QUESTION_AND_CANDIDATE_ANSWERS_KEY, sequentialCheckedCa); request.getSession().setAttribute(httpSessionID, sessionMap); - - Long toolSessionUid=mcSession.getUid(); - logger.debug("toolSessionUid: " + toolSessionUid); - - boolean isUserDefined=false; - - String userID = ""; - HttpSession ss = SessionManager.getSession(); - logger.debug("ss: " + ss); - - if (ss != null) - { - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - if ((user != null) && (user.getUserID() != null)) - { - userID = user.getUserID().toString(); - logger.debug("retrieved userId: " + userID); + learnerInput = sequentialCheckedCa; + + McLearningAction.logger.debug("end processing for mode : " + + McAppConstants.QUESTION_LISTING_MODE_SEQUENTIAL); + } else { + Map parameters = request.getParameterMap(); + Iterator iter = parameters.keySet().iterator(); + while (iter.hasNext()) { + String key = (String) iter.next(); + if (key.startsWith("checkedCa")) { + String currentCheckedCa = request.getParameter(key); + McLearningAction.logger.debug("Found matching checkedCa: key " + key + " value " + currentCheckedCa + + "."); + if (currentCheckedCa != null) { + learnerInput.add(currentCheckedCa); } + } } - - - logger.debug("userID: " + userID); - McQueUsr existingMcQueUsr=mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); - logger.debug("existingMcQueUsr: " + existingMcQueUsr); - - if (existingMcQueUsr != null) - isUserDefined=true; - - logger.debug("isUserDefined: " + isUserDefined); - McQueUsr mcQueUsr=null; - if (isUserDefined == false) - { - mcQueUsr=LearningUtil.createUser(request, mcService, new Long(toolSessionID)); - logger.debug("created user in the db: " + mcQueUsr); - } - else - { - mcQueUsr=existingMcQueUsr; - logger.debug("assign"); - } - - logger.debug("final mcQueUsr: " + mcQueUsr); - - - Integer currentHighestAttemptOrder= mcQueUsr.getLastAttemptOrder(); - int newHighestAttempOrder = currentHighestAttemptOrder != null ? currentHighestAttemptOrder.intValue()+1 : 1; - logger.debug("newHighestAttempOrder: " + newHighestAttempOrder); + mcLearningForm.resetCa(mapping, request); + } - // Have to work out in advance if passed so that we can store it against the attempts - boolean passed = mcQueUsr.isMarkPassed(learnerMark); - mcGeneralLearnerFlowDTO.setUserOverPassMark(new Boolean(passed).toString()); - mcGeneralLearnerFlowDTO.setPassMarkApplicable(new Boolean(mcContent.getPassMark()!=null).toString()); - - LearningUtil.createLearnerAttempt(request, mcQueUsr, selectedQuestionAndCandidateAnswersDTO, passed, newHighestAttempOrder, null, mcService); - logger.debug("created user attempt in the db"); - - mcQueUsr.setLastAttemptOrder(newHighestAttempOrder); - mcQueUsr.setLastAttemptTotalMark(learnerMark); - mcService.updateMcQueUsr(mcQueUsr); + McLearningAction.logger.debug("final learnerInput: " + learnerInput); - logger.debug("displayAnswers: " + mcContent.isDisplayAnswers()); - mcGeneralLearnerFlowDTO.setDisplayAnswers(new Boolean(mcContent.isDisplayAnswers()).toString()); + String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + McLearningAction.logger.debug("toolSessionID: " + toolSessionID); - logger.debug("showMarks: " + mcContent.isShowMarks()); - mcGeneralLearnerFlowDTO.setShowMarks(new Boolean(mcContent.isShowMarks()).toString()); - if ( mcContent.isShowMarks() ) { - Integer[] markStatistics = mcService.getMarkStatistics(mcSession); - mcGeneralLearnerFlowDTO.setTopMark(markStatistics[0]); - mcGeneralLearnerFlowDTO.setLowestMark(markStatistics[1]); - mcGeneralLearnerFlowDTO.setAverageMark(markStatistics[2]); - } else { - Integer zero = new Integer(0); - mcGeneralLearnerFlowDTO.setTopMark(zero); - mcGeneralLearnerFlowDTO.setLowestMark(zero); - mcGeneralLearnerFlowDTO.setAverageMark(zero); - } - - - Map mapQuestionMarks=LearningUtil.buildMarksMap(request, mcContent.getMcContentId(), mcService); - logger.debug("mapQuestionMarks:" + mapQuestionMarks); - - logger.debug("user over passmark:" + mcGeneralLearnerFlowDTO.getUserOverPassMark()); - logger.debug("is passmark applicable:" + mcGeneralLearnerFlowDTO.getPassMarkApplicable()); - - logger.debug("is tool reflective: " + mcContent.isReflect()); - mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); - logger.debug("reflection subject: " + mcContent.getReflectionSubject()); - - String reflectionSubject=McUtils.replaceNewLines(mcContent.getReflectionSubject()); - mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + McSession mcSession = mcService.retrieveMcSession(new Long(toolSessionID)); + McLearningAction.logger.debug("retrieving mcSession: " + mcSession); - mcGeneralLearnerFlowDTO.setLatestAttemptMark(mcQueUsr.getLastAttemptTotalMark()); - - logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); - - request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); - logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + request.getAttribute(MC_GENERAL_LEARNER_FLOW_DTO)); - - return (mapping.findForward(INDIVIDUAL_REPORT)); + String toolContentId = mcSession.getMcContent().getMcContentId().toString(); + McLearningAction.logger.debug("toolContentId: " + toolContentId); + + /* process the answers */ + McContent mcContent = mcService.retrieveMc(new Long(toolContentId)); + McLearningAction.logger.debug("mcContent: " + mcContent); + + McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO = LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); + McLearningAction.logger.debug("constructed a new mcGeneralLearnerFlowDTO"); + + McTempDataHolderDTO mcTempDataHolderDTO = new McTempDataHolderDTO(); + + boolean allQuestionsChecked = allQuestionsChecked(mcService, learnerInput, mcContent, mcTempDataHolderDTO); + McLearningAction.logger.debug("allQuestionsChecked: " + allQuestionsChecked); + McLearningAction.logger.debug("mcTempDataHolderDTO displayOrder: " + mcTempDataHolderDTO.getDisplayOrder()); + + if (!allQuestionsChecked) { + McLearningAction.logger.debug("there are no selected answers for any questions: " + learnerInput); + ActionMessages errors = new ActionMessages(); + + ActionMessage error = new ActionMessage("answers.submitted.none"); + errors.add(ActionMessages.GLOBAL_MESSAGE, error); + McLearningAction.logger.debug("errors: " + errors); + saveErrors(request, errors); + McLearningAction.logger.debug("errors saved: " + errors); + + McLearningStarterAction mcLearningStarterAction = new McLearningStarterAction(); + mcLearningStarterAction.commonContentSetup(request, mcContent, mcService, mcLearningForm, toolSessionID); + + mcGeneralLearnerFlowDTO.setQuestionIndex(mcTempDataHolderDTO.getDisplayOrder()); + + request.setAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); + McLearningAction.logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + + request.getAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO)); + + McLearningAction.logger.debug("returning to LOAD_LEARNER: " + McAppConstants.LOAD_LEARNER); + return mapping.findForward(McAppConstants.LOAD_LEARNER); + } + + List selectedQuestionAndCandidateAnswersDTO = buildSelectedQuestionAndCandidateAnswersDTO(learnerInput, + mcTempDataHolderDTO, mcService, mcContent); + McLearningAction.logger.debug("selectedQuestionAndCandidateAnswersDTO: " + + selectedQuestionAndCandidateAnswersDTO); + request.setAttribute(McAppConstants.LIST_SELECTED_QUESTION_CANDIDATEANSWERS_DTO, + selectedQuestionAndCandidateAnswersDTO); + McLearningAction.logger.debug("LIST_SELECTED_QUESTION_CANDIDATEANSWERS_DTO: " + + request.getAttribute(McAppConstants.LIST_SELECTED_QUESTION_CANDIDATEANSWERS_DTO)); + + McLearningAction.logger.debug("mcTempDataHolderDTO becomes: " + mcTempDataHolderDTO); + + mcGeneralLearnerFlowDTO.setQuestionListingMode(McAppConstants.QUESTION_LISTING_MODE_COMBINED); + + Integer learnerMark = mcTempDataHolderDTO.getLearnerMark(); + mcGeneralLearnerFlowDTO.setLearnerMark(learnerMark); + int totalQuestionCount = mcContent.getMcQueContents().size(); + mcGeneralLearnerFlowDTO.setTotalQuestionCount(new Integer(totalQuestionCount)); + mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcTempDataHolderDTO.getTotalMarksPossible()); + + request.getSession().setAttribute(httpSessionID, sessionMap); + + Long toolSessionUid = mcSession.getUid(); + McLearningAction.logger.debug("toolSessionUid: " + toolSessionUid); + + boolean isUserDefined = false; + + String userID = ""; + HttpSession ss = SessionManager.getSession(); + McLearningAction.logger.debug("ss: " + ss); + + if (ss != null) { + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + if (user != null && user.getUserID() != null) { + userID = user.getUserID().toString(); + McLearningAction.logger.debug("retrieved userId: " + userID); + } + } + + McLearningAction.logger.debug("userID: " + userID); + McQueUsr existingMcQueUsr = mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); + McLearningAction.logger.debug("existingMcQueUsr: " + existingMcQueUsr); + + if (existingMcQueUsr != null) { + isUserDefined = true; + } + + McLearningAction.logger.debug("isUserDefined: " + isUserDefined); + + McQueUsr mcQueUsr = null; + if (isUserDefined == false) { + mcQueUsr = LearningUtil.createUser(request, mcService, new Long(toolSessionID)); + McLearningAction.logger.debug("created user in the db: " + mcQueUsr); + } else { + mcQueUsr = existingMcQueUsr; + McLearningAction.logger.debug("assign"); + } + + McLearningAction.logger.debug("final mcQueUsr: " + mcQueUsr); + + Integer currentHighestAttemptOrder = mcQueUsr.getLastAttemptOrder(); + int newHighestAttempOrder = currentHighestAttemptOrder != null ? currentHighestAttemptOrder.intValue() + 1 : 1; + McLearningAction.logger.debug("newHighestAttempOrder: " + newHighestAttempOrder); + + // Have to work out in advance if passed so that we can store it against the attempts + boolean passed = mcQueUsr.isMarkPassed(learnerMark); + mcGeneralLearnerFlowDTO.setUserOverPassMark(new Boolean(passed).toString()); + mcGeneralLearnerFlowDTO.setPassMarkApplicable(new Boolean(mcContent.getPassMark() != null).toString()); + + LearningUtil.createLearnerAttempt(request, mcQueUsr, selectedQuestionAndCandidateAnswersDTO, passed, + newHighestAttempOrder, null, mcService); + McLearningAction.logger.debug("created user attempt in the db"); + + mcQueUsr.setLastAttemptOrder(newHighestAttempOrder); + mcQueUsr.setLastAttemptTotalMark(learnerMark); + mcService.updateMcQueUsr(mcQueUsr); + + McLearningAction.logger.debug("displayAnswers: " + mcContent.isDisplayAnswers()); + mcGeneralLearnerFlowDTO.setDisplayAnswers(new Boolean(mcContent.isDisplayAnswers()).toString()); + + McLearningAction.logger.debug("showMarks: " + mcContent.isShowMarks()); + mcGeneralLearnerFlowDTO.setShowMarks(new Boolean(mcContent.isShowMarks()).toString()); + if (mcContent.isShowMarks()) { + Integer[] markStatistics = mcService.getMarkStatistics(mcSession); + mcGeneralLearnerFlowDTO.setTopMark(markStatistics[0]); + mcGeneralLearnerFlowDTO.setLowestMark(markStatistics[1]); + mcGeneralLearnerFlowDTO.setAverageMark(markStatistics[2]); + } else { + Integer zero = new Integer(0); + mcGeneralLearnerFlowDTO.setTopMark(zero); + mcGeneralLearnerFlowDTO.setLowestMark(zero); + mcGeneralLearnerFlowDTO.setAverageMark(zero); + } + + Map mapQuestionMarks = LearningUtil.buildMarksMap(request, mcContent.getMcContentId(), mcService); + McLearningAction.logger.debug("mapQuestionMarks:" + mapQuestionMarks); + + McLearningAction.logger.debug("user over passmark:" + mcGeneralLearnerFlowDTO.getUserOverPassMark()); + McLearningAction.logger.debug("is passmark applicable:" + mcGeneralLearnerFlowDTO.getPassMarkApplicable()); + + McLearningAction.logger.debug("is tool reflective: " + mcContent.isReflect()); + mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); + McLearningAction.logger.debug("reflection subject: " + mcContent.getReflectionSubject()); + + String reflectionSubject = McUtils.replaceNewLines(mcContent.getReflectionSubject()); + mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + + mcGeneralLearnerFlowDTO.setLatestAttemptMark(mcQueUsr.getLastAttemptTotalMark()); + + McLearningAction.logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); + + request.setAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); + McLearningAction.logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + + request.getAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO)); + + return mapping.findForward(McAppConstants.INDIVIDUAL_REPORT); } - - - + public boolean allQuestionsChecked(IMcService mcService, List learnerInput, McContent mcContent, - McTempDataHolderDTO mcTempDataHolderDTO) - { - logger.debug("starting allQuestionsChecked learnerInput: " + learnerInput); - - boolean questionSelected=false; - Iterator listIterator=mcContent.getMcQueContents().iterator(); - while (listIterator.hasNext()) - { - McQueContent mcQueContent = (McQueContent)listIterator.next(); - String uid=(String)mcQueContent.getUid().toString(); - logger.debug("using uid: " + uid); - - questionSelected=false; - Iterator learnerInputIterator=learnerInput.iterator(); - while (learnerInputIterator.hasNext() && !questionSelected) - { - String learnerInputLine=(String)learnerInputIterator.next(); - logger.debug("using learnerInputLine: " + learnerInputLine); - - int sepIndex=learnerInputLine.indexOf("-"); - logger.debug("having sepIndex: " + sepIndex); - - String selectedUid=learnerInputLine.substring(0, sepIndex); - logger.debug("selectedUid: " + selectedUid); - - if (uid.equals(selectedUid)) - { - logger.debug("equal uids found: " + selectedUid); - questionSelected=true; - } - - } - logger.debug("iterated loop questionSelected: " + questionSelected); + McTempDataHolderDTO mcTempDataHolderDTO) { + McLearningAction.logger.debug("starting allQuestionsChecked learnerInput: " + learnerInput); - if (questionSelected == false) - { - if ( log.isDebugEnabled() ) { - logger.debug("Question not selected by user mcQueContent :" + mcQueContent); - logger.debug("mcQueContent displayorder:" + mcQueContent.getDisplayOrder()); - } - mcTempDataHolderDTO.setDisplayOrder(mcQueContent.getDisplayOrder()); - return false; - } - } - - return true; + boolean questionSelected = false; + Iterator listIterator = mcContent.getMcQueContents().iterator(); + while (listIterator.hasNext()) { + McQueContent mcQueContent = (McQueContent) listIterator.next(); + String uid = mcQueContent.getUid().toString(); + McLearningAction.logger.debug("using uid: " + uid); + + questionSelected = false; + Iterator learnerInputIterator = learnerInput.iterator(); + while (learnerInputIterator.hasNext() && !questionSelected) { + String learnerInputLine = (String) learnerInputIterator.next(); + McLearningAction.logger.debug("using learnerInputLine: " + learnerInputLine); + + int sepIndex = learnerInputLine.indexOf("-"); + McLearningAction.logger.debug("having sepIndex: " + sepIndex); + + String selectedUid = learnerInputLine.substring(0, sepIndex); + McLearningAction.logger.debug("selectedUid: " + selectedUid); + + if (uid.equals(selectedUid)) { + McLearningAction.logger.debug("equal uids found: " + selectedUid); + questionSelected = true; + } + + } + McLearningAction.logger.debug("iterated loop questionSelected: " + questionSelected); + + if (questionSelected == false) { + if (LamsDispatchAction.log.isDebugEnabled()) { + McLearningAction.logger.debug("Question not selected by user mcQueContent :" + mcQueContent); + McLearningAction.logger.debug("mcQueContent displayorder:" + mcQueContent.getDisplayOrder()); + } + mcTempDataHolderDTO.setDisplayOrder(mcQueContent.getDisplayOrder()); + return false; + } + } + + return true; } /** * - * continueOptionsCombined(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) - - takes the learner to the next set of questions + * continueOptionsCombined(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse + * response) * + * takes the learner to the next set of questions + * * @param request * @param form * @param mapping * @return ActionForward */ - public ActionForward getNextOptions(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - logger.debug("dispatching getNextOptions..."); - McLearningForm mcLearningForm = (McLearningForm) form; - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - logger.debug("mcService: " + mcService); - - String questionIndex=mcLearningForm.getQuestionIndex(); - logger.debug("questionIndex: " + questionIndex); - - String httpSessionID=mcLearningForm.getHttpSessionID(); - logger.debug("httpSessionID: " + httpSessionID); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - logger.debug("sessionMap: " + sessionMap); - - List sequentialCheckedCa=(List)sessionMap.get(QUESTION_AND_CANDIDATE_ANSWERS_KEY); - - logger.debug("pre sequentialCheckedCa: " + sequentialCheckedCa); - Iterator sequentialCheckedCaIterator=sequentialCheckedCa.iterator(); - while (sequentialCheckedCaIterator.hasNext()) - { - String input=(String)sequentialCheckedCaIterator.next(); - logger.debug("input: " + input); - } + public ActionForward getNextOptions(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + McLearningAction.logger.debug("dispatching getNextOptions..."); + McLearningForm mcLearningForm = (McLearningForm) form; + IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); + McLearningAction.logger.debug("mcService: " + mcService); - - /* checkedCa refers to candidate answers */ - String[] checkedCa=mcLearningForm.getCheckedCa(); - logger.debug("checkedCa: " + checkedCa); - - if (checkedCa != null) - { - mcLearningForm.resetCa(mapping, request); - - for (int i=0; i < checkedCa.length ; i++) - { - String currentCa=checkedCa[i]; - logger.debug("currentCa: " + currentCa); - sequentialCheckedCa.add(currentCa); - } - } - - logger.debug("post sequentialCheckedCa: " + sequentialCheckedCa); - sequentialCheckedCaIterator=sequentialCheckedCa.iterator(); - while (sequentialCheckedCaIterator.hasNext()) - { - String input=(String)sequentialCheckedCaIterator.next(); - logger.debug("input: " + input); - } + String questionIndex = mcLearningForm.getQuestionIndex(); + McLearningAction.logger.debug("questionIndex: " + questionIndex); - - sessionMap.put(QUESTION_AND_CANDIDATE_ANSWERS_KEY, sequentialCheckedCa); - request.getSession().setAttribute(httpSessionID, sessionMap); - - logger.debug("updated sessionMap : " + sessionMap); - - String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - - McSession mcSession=mcService.retrieveMcSession(new Long(toolSessionID)); - logger.debug("retrieving mcSession: " + mcSession); - - String toolContentId=mcSession.getMcContent().getMcContentId().toString(); - logger.debug("toolContentId: " + toolContentId); - - McContent mcContent=mcService.retrieveMc(new Long(toolContentId)); - logger.debug("mcContent: " + mcContent); - - boolean randomize=mcContent.isRandomize(); - logger.debug("randomize: " + randomize); - - List listQuestionAndCandidateAnswersDTO=LearningUtil.buildQuestionAndCandidateAnswersDTO(request, mcContent, randomize, mcService); - logger.debug("listQuestionAndCandidateAnswersDTO: " + listQuestionAndCandidateAnswersDTO); - request.setAttribute(LIST_QUESTION_CANDIDATEANSWERS_DTO, listQuestionAndCandidateAnswersDTO); - logger.debug("LIST_QUESTION_CANDIDATEANSWERS_DTO: " + request.getAttribute(LIST_QUESTION_CANDIDATEANSWERS_DTO)); + String httpSessionID = mcLearningForm.getHttpSessionID(); + McLearningAction.logger.debug("httpSessionID: " + httpSessionID); - McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO=LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + McLearningAction.logger.debug("sessionMap: " + sessionMap); - Integer totalQuestionCount=mcGeneralLearnerFlowDTO.getTotalQuestionCount(); - Integer intQuestionIndex=new Integer(questionIndex); - logger.debug("intTotalQuestionCount versus intCurrentQuestionIndex: " + totalQuestionCount + " versus " + intQuestionIndex); - if (totalQuestionCount.equals(intQuestionIndex)) - { - logger.debug("totalQuestionCount has been reached :" + totalQuestionCount); - mcGeneralLearnerFlowDTO.setTotalCountReached(new Boolean(true).toString()); - } - - logger.debug("is tool reflective: " + mcContent.isReflect()); - mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); - logger.debug("reflection subject: " + mcContent.getReflectionSubject()); - - String reflectionSubject=McUtils.replaceNewLines(mcContent.getReflectionSubject()); - mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); - - mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); - - mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); + List sequentialCheckedCa = (List) sessionMap.get(McAppConstants.QUESTION_AND_CANDIDATE_ANSWERS_KEY); - - logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); - mcGeneralLearnerFlowDTO.setQuestionIndex(new Integer(questionIndex)); - request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); + McLearningAction.logger.debug("pre sequentialCheckedCa: " + sequentialCheckedCa); + Iterator sequentialCheckedCaIterator = sequentialCheckedCa.iterator(); + while (sequentialCheckedCaIterator.hasNext()) { + String input = (String) sequentialCheckedCaIterator.next(); + McLearningAction.logger.debug("input: " + input); + } - return (mapping.findForward(LOAD_LEARNER)); - } + /* checkedCa refers to candidate answers */ + String[] checkedCa = mcLearningForm.getCheckedCa(); + McLearningAction.logger.debug("checkedCa: " + checkedCa); + if (checkedCa != null) { + mcLearningForm.resetCa(mapping, request); + for (int i = 0; i < checkedCa.length; i++) { + String currentCa = checkedCa[i]; + McLearningAction.logger.debug("currentCa: " + currentCa); + sequentialCheckedCa.add(currentCa); + } + } + + McLearningAction.logger.debug("post sequentialCheckedCa: " + sequentialCheckedCa); + sequentialCheckedCaIterator = sequentialCheckedCa.iterator(); + while (sequentialCheckedCaIterator.hasNext()) { + String input = (String) sequentialCheckedCaIterator.next(); + McLearningAction.logger.debug("input: " + input); + } + + sessionMap.put(McAppConstants.QUESTION_AND_CANDIDATE_ANSWERS_KEY, sequentialCheckedCa); + request.getSession().setAttribute(httpSessionID, sessionMap); + + McLearningAction.logger.debug("updated sessionMap : " + sessionMap); + + String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + McLearningAction.logger.debug("toolSessionID: " + toolSessionID); + + McSession mcSession = mcService.retrieveMcSession(new Long(toolSessionID)); + McLearningAction.logger.debug("retrieving mcSession: " + mcSession); + + String toolContentId = mcSession.getMcContent().getMcContentId().toString(); + McLearningAction.logger.debug("toolContentId: " + toolContentId); + + McContent mcContent = mcService.retrieveMc(new Long(toolContentId)); + McLearningAction.logger.debug("mcContent: " + mcContent); + + boolean randomize = mcContent.isRandomize(); + McLearningAction.logger.debug("randomize: " + randomize); + + List listQuestionAndCandidateAnswersDTO = LearningUtil.buildQuestionAndCandidateAnswersDTO(request, mcContent, + randomize, mcService); + McLearningAction.logger.debug("listQuestionAndCandidateAnswersDTO: " + listQuestionAndCandidateAnswersDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_CANDIDATEANSWERS_DTO, listQuestionAndCandidateAnswersDTO); + McLearningAction.logger.debug("LIST_QUESTION_CANDIDATEANSWERS_DTO: " + + request.getAttribute(McAppConstants.LIST_QUESTION_CANDIDATEANSWERS_DTO)); + + McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO = LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); + + Integer totalQuestionCount = mcGeneralLearnerFlowDTO.getTotalQuestionCount(); + Integer intQuestionIndex = new Integer(questionIndex); + McLearningAction.logger.debug("intTotalQuestionCount versus intCurrentQuestionIndex: " + totalQuestionCount + + " versus " + intQuestionIndex); + if (totalQuestionCount.equals(intQuestionIndex)) { + McLearningAction.logger.debug("totalQuestionCount has been reached :" + totalQuestionCount); + mcGeneralLearnerFlowDTO.setTotalCountReached(new Boolean(true).toString()); + } + + McLearningAction.logger.debug("is tool reflective: " + mcContent.isReflect()); + mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); + McLearningAction.logger.debug("reflection subject: " + mcContent.getReflectionSubject()); + + String reflectionSubject = McUtils.replaceNewLines(mcContent.getReflectionSubject()); + mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + + mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); + + mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); + + McLearningAction.logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); + mcGeneralLearnerFlowDTO.setQuestionIndex(new Integer(questionIndex)); + request.setAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); + + return mapping.findForward(McAppConstants.LOAD_LEARNER); + } + /** * - * redoQuestions(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) + * redoQuestions(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) * * allows the learner to take the activity again * @@ -1102,369 +1001,337 @@ * @param mapping * @return ActionForward */ - public ActionForward redoQuestions(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - logger.debug("dispatching redoQuestions..."); - McLearningForm mcLearningForm = (McLearningForm) form; - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - - McSession mcSession=mcService.retrieveMcSession(new Long(toolSessionID)); - logger.debug("retrieving mcSession: " + mcSession); - - String toolContentId=mcSession.getMcContent().getMcContentId().toString(); - logger.debug("toolContentId: " + toolContentId); + public ActionForward redoQuestions(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + McLearningAction.logger.debug("dispatching redoQuestions..."); + McLearningForm mcLearningForm = (McLearningForm) form; + IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - McContent mcContent=mcService.retrieveMc(new Long(toolContentId)); - logger.debug("mcContent: " + mcContent); - - boolean randomize=mcContent.isRandomize(); - logger.debug("randomize: " + randomize); - - - List listQuestionAndCandidateAnswersDTO=LearningUtil.buildQuestionAndCandidateAnswersDTO(request, mcContent, randomize, mcService); - logger.debug("listQuestionAndCandidateAnswersDTO: " + listQuestionAndCandidateAnswersDTO); - request.setAttribute(LIST_QUESTION_CANDIDATEANSWERS_DTO, listQuestionAndCandidateAnswersDTO); - logger.debug("LIST_QUESTION_CANDIDATEANSWERS_DTO: " + request.getAttribute(LIST_QUESTION_CANDIDATEANSWERS_DTO)); + String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + McLearningAction.logger.debug("toolSessionID: " + toolSessionID); - McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO=LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); - mcGeneralLearnerFlowDTO.setCurrentQuestionIndex(new Integer(1)); - mcGeneralLearnerFlowDTO.setTotalCountReached(new Boolean(false).toString()); + McSession mcSession = mcService.retrieveMcSession(new Long(toolSessionID)); + McLearningAction.logger.debug("retrieving mcSession: " + mcSession); - /*use existing session to extract PASSMARK_APPLICABLE and USER_OVER_PASSMARK*/ - String httpSessionID=mcLearningForm.getHttpSessionID(); - logger.debug("httpSessionID: " + httpSessionID); - - /*create a new session*/ - SessionMap sessionMap = new SessionMap(); - List sequentialCheckedCa= new LinkedList(); - sessionMap.put(QUESTION_AND_CANDIDATE_ANSWERS_KEY, sequentialCheckedCa); - request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); - mcLearningForm.setHttpSessionID(sessionMap.getSessionID()); + String toolContentId = mcSession.getMcContent().getMcContentId().toString(); + McLearningAction.logger.debug("toolContentId: " + toolContentId); - String userID = ""; - HttpSession ss = SessionManager.getSession(); - logger.debug("ss: " + ss); - - if (ss != null) - { - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - if ((user != null) && (user.getUserID() != null)) - { - userID = user.getUserID().toString(); - logger.debug("retrieved userId: " + userID); - } + McContent mcContent = mcService.retrieveMc(new Long(toolContentId)); + McLearningAction.logger.debug("mcContent: " + mcContent); + + boolean randomize = mcContent.isRandomize(); + McLearningAction.logger.debug("randomize: " + randomize); + + List listQuestionAndCandidateAnswersDTO = LearningUtil.buildQuestionAndCandidateAnswersDTO(request, mcContent, + randomize, mcService); + McLearningAction.logger.debug("listQuestionAndCandidateAnswersDTO: " + listQuestionAndCandidateAnswersDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_CANDIDATEANSWERS_DTO, listQuestionAndCandidateAnswersDTO); + McLearningAction.logger.debug("LIST_QUESTION_CANDIDATEANSWERS_DTO: " + + request.getAttribute(McAppConstants.LIST_QUESTION_CANDIDATEANSWERS_DTO)); + + McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO = LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); + mcGeneralLearnerFlowDTO.setCurrentQuestionIndex(new Integer(1)); + mcGeneralLearnerFlowDTO.setTotalCountReached(new Boolean(false).toString()); + + /* use existing session to extract PASSMARK_APPLICABLE and USER_OVER_PASSMARK */ + String httpSessionID = mcLearningForm.getHttpSessionID(); + McLearningAction.logger.debug("httpSessionID: " + httpSessionID); + + /* create a new session */ + SessionMap sessionMap = new SessionMap(); + List sequentialCheckedCa = new LinkedList(); + sessionMap.put(McAppConstants.QUESTION_AND_CANDIDATE_ANSWERS_KEY, sequentialCheckedCa); + request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); + mcLearningForm.setHttpSessionID(sessionMap.getSessionID()); + + String userID = ""; + HttpSession ss = SessionManager.getSession(); + McLearningAction.logger.debug("ss: " + ss); + + if (ss != null) { + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + if (user != null && user.getUserID() != null) { + userID = user.getUserID().toString(); + McLearningAction.logger.debug("retrieved userId: " + userID); } - - - McQueUsr mcQueUsr=mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); - logger.debug("mcQueUsr: " + mcQueUsr); - - mcGeneralLearnerFlowDTO.setLatestAttemptMark(mcQueUsr.getLastAttemptTotalMark()); + } - String passMarkApplicable=new Boolean(mcContent.isPassMarkApplicable()).toString(); - mcGeneralLearnerFlowDTO.setPassMarkApplicable(passMarkApplicable); - mcLearningForm.setPassMarkApplicable(passMarkApplicable); - - String userOverPassMark=new Boolean(mcQueUsr.isLastAttemptMarkPassed()).toString(); - mcGeneralLearnerFlowDTO.setUserOverPassMark (userOverPassMark); - mcLearningForm.setUserOverPassMark (userOverPassMark); - - mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); - - String reflectionSubject=McUtils.replaceNewLines(mcContent.getReflectionSubject()); - mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); - - mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); - - mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); - - request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); + McQueUsr mcQueUsr = mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); + McLearningAction.logger.debug("mcQueUsr: " + mcQueUsr); - if ( logger.isDebugEnabled() ) - logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); - - return (mapping.findForward(REDO_QUESTIONS)); + mcGeneralLearnerFlowDTO.setLatestAttemptMark(mcQueUsr.getLastAttemptTotalMark()); + + String passMarkApplicable = new Boolean(mcContent.isPassMarkApplicable()).toString(); + mcGeneralLearnerFlowDTO.setPassMarkApplicable(passMarkApplicable); + mcLearningForm.setPassMarkApplicable(passMarkApplicable); + + String userOverPassMark = new Boolean(mcQueUsr.isLastAttemptMarkPassed()).toString(); + mcGeneralLearnerFlowDTO.setUserOverPassMark(userOverPassMark); + mcLearningForm.setUserOverPassMark(userOverPassMark); + + mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); + + String reflectionSubject = McUtils.replaceNewLines(mcContent.getReflectionSubject()); + mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + + mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); + + mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); + + request.setAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); + + if (McLearningAction.logger.isDebugEnabled()) { + McLearningAction.logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); + } + + return mapping.findForward(McAppConstants.REDO_QUESTIONS); } - /** - * void prepareViewAnswersData(ActionMapping mapping, - McLearningForm mcLearningForm, - HttpServletRequest request, - HttpServletResponse response) - + * void prepareViewAnswersData(ActionMapping mapping, McLearningForm mcLearningForm, HttpServletRequest request, + * HttpServletResponse response) + * * @param mapping * @param mcLearningForm * @param request * @param response */ - public void prepareViewAnswersData(ActionMapping mapping, - McLearningForm mcLearningForm, - HttpServletRequest request, - HttpServletResponse response) - { - logger.debug("running prepareViewAnswersData..." + mcLearningForm); - - // may have to get service from the form - if class has been created by starter action, rather than by struts - IMcService mcService=null; - if (getServlet() != null) - mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - else - mcService=mcLearningForm.getMcService(); - - String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - McSession mcSession=mcService.retrieveMcSession(new Long(toolSessionID)); - - String toolContentId=mcSession.getMcContent().getMcContentId().toString(); - McContent mcContent=mcService.retrieveMc(new Long(toolContentId)); + public void prepareViewAnswersData(ActionMapping mapping, McLearningForm mcLearningForm, + HttpServletRequest request, HttpServletResponse response) { + McLearningAction.logger.debug("running prepareViewAnswersData..." + mcLearningForm); - if ( logger.isDebugEnabled() ) { - logger.debug("retrieving mcSession: " + mcSession); - logger.debug("mcContent: " + mcContent); - } - - McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO=LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); - - Map mapQuestionsUidContent=AuthoringUtil.rebuildQuestionUidMapfromDB(request, new Long(toolContentId), mcService); - - Map mapStartupGeneralOptionsContent=AuthoringUtil.rebuildStartupGeneralOptionsContentMapfromDB(request, mapQuestionsUidContent, mcService); - mcGeneralLearnerFlowDTO.setMapGeneralOptionsContent(mapStartupGeneralOptionsContent); + // may have to get service from the form - if class has been created by starter action, rather than by struts + IMcService mcService = null; + if (getServlet() != null) { + mcService = McServiceProxy.getMcService(getServlet().getServletContext()); + } else { + mcService = mcLearningForm.getMcService(); + } - Map mapQuestionsContent=AuthoringUtil.rebuildQuestionMapfromDB(request, new Long(toolContentId), mcService); - mcGeneralLearnerFlowDTO.setMapQuestionsContent(mapQuestionsContent); - - Map mapFeedbackContent=AuthoringUtil.rebuildFeedbackMapfromDB(request, new Long(toolContentId), mcService); - mcGeneralLearnerFlowDTO.setMapFeedbackContent(mapFeedbackContent); + String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + McSession mcSession = mcService.retrieveMcSession(new Long(toolSessionID)); - // Set up the user details. If this is the learner progress screen then we that id, - // otherwise we use the user from the session. + String toolContentId = mcSession.getMcContent().getMcContentId().toString(); + McContent mcContent = mcService.retrieveMc(new Long(toolContentId)); - String learnerProgress=mcLearningForm.getLearnerProgress(); - String learnerProgressUserId=mcLearningForm.getLearnerProgressUserId(); - mcGeneralLearnerFlowDTO.setLearnerProgressUserId(learnerProgressUserId); - mcGeneralLearnerFlowDTO.setLearnerProgress(learnerProgress); - - Boolean learnerProgressOn=Boolean.parseBoolean(learnerProgress); - logger.debug("learnerProgressOn:" + learnerProgressOn); + if (McLearningAction.logger.isDebugEnabled()) { + McLearningAction.logger.debug("retrieving mcSession: " + mcSession); + McLearningAction.logger.debug("mcContent: " + mcContent); + } - McQueUsr mcQueUsr=null; - if (learnerProgressOn.equals(Boolean.FALSE)) { - logger.debug("learnerProgress off, using user from session"); - mcQueUsr=LearningUtil.getUser(request, mcService, toolSessionID); - } - else { - logger.debug("using learnerProgressUserId: " + learnerProgressUserId); - mcQueUsr=mcService.getMcUserBySession(new Long(learnerProgressUserId), mcSession.getUid()); - } - - if ( logger.isDebugEnabled() ) { - logger.debug("final mcQueUsr: " + mcQueUsr); - } - - Long toolContentUID=mcContent.getUid(); - - Map[] attemptMaps = LearningUtil.getAttemptMapsForUser( mcContent.getMcQueContents().size(), toolContentUID, mcContent.isRetries(), mcService, mcQueUsr); - mcGeneralLearnerFlowDTO.setMapFinalAnswersIsContent(attemptMaps[0]); - mcGeneralLearnerFlowDTO.setMapFinalAnswersContent(attemptMaps[1]); - mcGeneralLearnerFlowDTO.setMapQueAttempts(attemptMaps[2]); - mcGeneralLearnerFlowDTO.setMapQueCorrectAttempts(attemptMaps[3]); - mcGeneralLearnerFlowDTO.setMapQueIncorrectAttempts(attemptMaps[4]); - - mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); - String reflectionSubject=McUtils.replaceNewLines(mcContent.getReflectionSubject()); - mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO = LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); - NotebookEntry notebookEntry = mcService.getEntry(new Long(toolSessionID), - CoreNotebookConstants.NOTEBOOK_TOOL, - MY_SIGNATURE, new Integer(mcQueUsr.getQueUsrId().intValue())); - if (notebookEntry != null) { - String notebookEntryPresentable = notebookEntry.getEntry(); - notebookEntryPresentable=McUtils.replaceNewLines(notebookEntryPresentable); - mcGeneralLearnerFlowDTO.setNotebookEntry(notebookEntryPresentable); - } - - mcGeneralLearnerFlowDTO.setReportViewOnly(mcLearningForm.getReportViewOnly()); - mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); - mcGeneralLearnerFlowDTO.setPassMarkApplicable(new Boolean(mcContent.isPassMarkApplicable()).toString()); - mcGeneralLearnerFlowDTO.setUserOverPassMark (new Boolean(mcQueUsr.isLastAttemptMarkPassed()).toString()); - mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); - mcGeneralLearnerFlowDTO.setShowMarks(new Boolean(mcContent.isShowMarks()).toString()); - mcGeneralLearnerFlowDTO.setDisplayAnswers(new Boolean(mcContent.isDisplayAnswers()).toString()); - if ( mcContent.isShowMarks() ) { - Integer[] markStatistics = mcService.getMarkStatistics(mcSession); - mcGeneralLearnerFlowDTO.setTopMark(markStatistics[0]); - mcGeneralLearnerFlowDTO.setLowestMark(markStatistics[1]); - mcGeneralLearnerFlowDTO.setAverageMark(markStatistics[2]); - } else { - Integer zero = new Integer(0); - mcGeneralLearnerFlowDTO.setTopMark(zero); - mcGeneralLearnerFlowDTO.setLowestMark(zero); - mcGeneralLearnerFlowDTO.setAverageMark(zero); - } + Map mapQuestionsUidContent = AuthoringUtil.rebuildQuestionUidMapfromDB(request, new Long(toolContentId), + mcService); - - logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); - - request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); - logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + request.getAttribute(MC_GENERAL_LEARNER_FLOW_DTO)); - logger.debug("end of prepareViewAnswersData."); + Map mapStartupGeneralOptionsContent = AuthoringUtil.rebuildStartupGeneralOptionsContentMapfromDB(request, + mapQuestionsUidContent, mcService); + mcGeneralLearnerFlowDTO.setMapGeneralOptionsContent(mapStartupGeneralOptionsContent); + + Map mapQuestionsContent = AuthoringUtil.rebuildQuestionMapfromDB(request, new Long(toolContentId), mcService); + mcGeneralLearnerFlowDTO.setMapQuestionsContent(mapQuestionsContent); + + Map mapFeedbackContent = AuthoringUtil.rebuildFeedbackMapfromDB(request, new Long(toolContentId), mcService); + mcGeneralLearnerFlowDTO.setMapFeedbackContent(mapFeedbackContent); + + // Set up the user details. If this is the learner progress screen then we that id, + // otherwise we use the user from the session. + + String learnerProgress = mcLearningForm.getLearnerProgress(); + String learnerProgressUserId = mcLearningForm.getLearnerProgressUserId(); + mcGeneralLearnerFlowDTO.setLearnerProgressUserId(learnerProgressUserId); + mcGeneralLearnerFlowDTO.setLearnerProgress(learnerProgress); + + Boolean learnerProgressOn = Boolean.parseBoolean(learnerProgress); + McLearningAction.logger.debug("learnerProgressOn:" + learnerProgressOn); + + McQueUsr mcQueUsr = null; + if (learnerProgressOn.equals(Boolean.FALSE)) { + McLearningAction.logger.debug("learnerProgress off, using user from session"); + mcQueUsr = LearningUtil.getUser(request, mcService, toolSessionID); + } else { + McLearningAction.logger.debug("using learnerProgressUserId: " + learnerProgressUserId); + mcQueUsr = mcService.getMcUserBySession(new Long(learnerProgressUserId), mcSession.getUid()); + } + + if (McLearningAction.logger.isDebugEnabled()) { + McLearningAction.logger.debug("final mcQueUsr: " + mcQueUsr); + } + + Long toolContentUID = mcContent.getUid(); + + Map[] attemptMaps = LearningUtil.getAttemptMapsForUser(mcContent.getMcQueContents().size(), toolContentUID, + mcContent.isRetries(), mcService, mcQueUsr); + mcGeneralLearnerFlowDTO.setMapFinalAnswersIsContent(attemptMaps[0]); + mcGeneralLearnerFlowDTO.setMapFinalAnswersContent(attemptMaps[1]); + mcGeneralLearnerFlowDTO.setMapQueAttempts(attemptMaps[2]); + mcGeneralLearnerFlowDTO.setMapQueCorrectAttempts(attemptMaps[3]); + mcGeneralLearnerFlowDTO.setMapQueIncorrectAttempts(attemptMaps[4]); + + mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); + String reflectionSubject = McUtils.replaceNewLines(mcContent.getReflectionSubject()); + mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + + NotebookEntry notebookEntry = mcService.getEntry(new Long(toolSessionID), CoreNotebookConstants.NOTEBOOK_TOOL, + McAppConstants.MY_SIGNATURE, new Integer(mcQueUsr.getQueUsrId().intValue())); + if (notebookEntry != null) { + String notebookEntryPresentable = notebookEntry.getEntry(); + notebookEntryPresentable = McUtils.replaceNewLines(notebookEntryPresentable); + mcGeneralLearnerFlowDTO.setNotebookEntry(notebookEntryPresentable); + } + + mcGeneralLearnerFlowDTO.setReportViewOnly(mcLearningForm.getReportViewOnly()); + mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); + mcGeneralLearnerFlowDTO.setPassMarkApplicable(new Boolean(mcContent.isPassMarkApplicable()).toString()); + mcGeneralLearnerFlowDTO.setUserOverPassMark(new Boolean(mcQueUsr.isLastAttemptMarkPassed()).toString()); + mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); + mcGeneralLearnerFlowDTO.setShowMarks(new Boolean(mcContent.isShowMarks()).toString()); + mcGeneralLearnerFlowDTO.setDisplayAnswers(new Boolean(mcContent.isDisplayAnswers()).toString()); + if (mcContent.isShowMarks()) { + Integer[] markStatistics = mcService.getMarkStatistics(mcSession); + mcGeneralLearnerFlowDTO.setTopMark(markStatistics[0]); + mcGeneralLearnerFlowDTO.setLowestMark(markStatistics[1]); + mcGeneralLearnerFlowDTO.setAverageMark(markStatistics[2]); + } else { + Integer zero = new Integer(0); + mcGeneralLearnerFlowDTO.setTopMark(zero); + mcGeneralLearnerFlowDTO.setLowestMark(zero); + mcGeneralLearnerFlowDTO.setAverageMark(zero); + } + + McLearningAction.logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); + + request.setAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); + McLearningAction.logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + + request.getAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO)); + McLearningAction.logger.debug("end of prepareViewAnswersData."); } - /** * - * viewAnswers(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) - - allows the learner to view their answer history + * viewAnswers(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) * + * allows the learner to view their answer history + * * @param request * @param form * @param mapping * @return ActionForward */ - public ActionForward viewAnswers(ActionMapping mapping, - McLearningForm mcLearningForm, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - logger.debug("dispatching viewLearnerProgress..." + mcLearningForm); - logger.debug("mcLearningForm :" + mcLearningForm); - - prepareViewAnswersData(mapping, mcLearningForm, request, response); - logger.debug("post prepareViewAnswersData"); - return (mapping.findForward(VIEW_ANSWERS)); - } + public ActionForward viewAnswers(ActionMapping mapping, McLearningForm mcLearningForm, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + McLearningAction.logger.debug("dispatching viewLearnerProgress..." + mcLearningForm); + McLearningAction.logger.debug("mcLearningForm :" + mcLearningForm); + prepareViewAnswersData(mapping, mcLearningForm, request, response); + McLearningAction.logger.debug("post prepareViewAnswersData"); + return mapping.findForward(McAppConstants.VIEW_ANSWERS); + } /** - * - * viewSummary(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) * + * viewSummary(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + * * allows the learner to view all the other learners' activity summary * * @param request * @param form * @param mapping * @return ActionForward */ - public ActionForward viewSummary(ActionMapping mapping, - ActionForm form, - HttpServletRequest request, - HttpServletResponse response) throws IOException, - ServletException - { - logger.debug("dispatching viewSummary..."); - McLearningForm mcLearningForm = (McLearningForm) form; - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - logger.debug("mcService: " + mcService); - - String userID=request.getParameter(AttributeNames.PARAM_USER_ID); - logger.debug("userID: " + userID); - - String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - - McSession mcSession=mcService.retrieveMcSession(new Long(toolSessionID)); - logger.debug("retrieving mcSession: " + mcSession); - - McQueUsr mcQueUsr=mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); - logger.debug("mcQueUsr: " + mcQueUsr); - - mcQueUsr.setViewSummaryRequested(true); - mcService.updateMcQueUsr(mcQueUsr); - logger.debug("view summary requested by mcQueUsr: " + mcQueUsr); - - - String toolContentId=mcSession.getMcContent().getMcContentId().toString(); - logger.debug("toolContentId: " + toolContentId); - - McContent mcContent=mcService.retrieveMc(new Long(toolContentId)); - logger.debug("mcContent: " + mcContent); + public ActionForward viewSummary(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + McLearningAction.logger.debug("dispatching viewSummary..."); + McLearningForm mcLearningForm = (McLearningForm) form; + IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); + McLearningAction.logger.debug("mcService: " + mcService); - McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO=LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); - - mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); - mcGeneralLearnerFlowDTO.setNotebookEntriesVisible(new Boolean(false).toString()); + String userID = request.getParameter(AttributeNames.PARAM_USER_ID); + McLearningAction.logger.debug("userID: " + userID); - - int countSessionComplete=0; - Iterator sessionsIterator=mcContent.getMcSessions().iterator(); - while (sessionsIterator.hasNext()) - { - McSession mcSessionLocal= (McSession)sessionsIterator.next(); - if (mcSession != null) - { - logger.debug("mcSessionLocal: " + mcSessionLocal); - if (mcSessionLocal.getSessionStatus().equals(COMPLETED)) - { - logger.debug("COMPLETED session found: " + mcSessionLocal); - ++countSessionComplete; - } - } - } - logger.debug("countSessionComplete: " + countSessionComplete); - - Integer[] markStatistics = mcService.getMarkStatistics(mcSession); - - logger.debug("countSessionComplete: " + countSessionComplete); - logger.debug("topMark: " + markStatistics[0]); - logger.debug("lowestMark: " + markStatistics[1]); - logger.debug("averageMark: " + markStatistics[2]); - - mcGeneralLearnerFlowDTO.setCountSessionComplete(new Integer(countSessionComplete).toString()); - mcGeneralLearnerFlowDTO.setTopMark(markStatistics[0]); - mcGeneralLearnerFlowDTO.setLowestMark(markStatistics[1]); - mcGeneralLearnerFlowDTO.setAverageMark(markStatistics[2]); + String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + McLearningAction.logger.debug("toolSessionID: " + toolSessionID); - logger.debug("is tool reflective: " + mcContent.isReflect()); - mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); - logger.debug("reflection subject: " + mcContent.getReflectionSubject()); - - String reflectionSubject=McUtils.replaceNewLines(mcContent.getReflectionSubject()); - mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); - - logger.debug("mcContent.isRetries(): " + mcContent.isRetries()); - mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); - - String passMarkApplicable=new Boolean(mcContent.isPassMarkApplicable()).toString(); - mcGeneralLearnerFlowDTO.setPassMarkApplicable(passMarkApplicable); - mcLearningForm.setPassMarkApplicable(passMarkApplicable); - - String userOverPassMark=new Boolean(mcQueUsr.isLastAttemptMarkPassed()).toString(); - mcGeneralLearnerFlowDTO.setUserOverPassMark (userOverPassMark); - mcLearningForm.setUserOverPassMark (userOverPassMark); - - String httpSessionID=mcLearningForm.getHttpSessionID(); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - request.getSession().setAttribute(httpSessionID, sessionMap); + McSession mcSession = mcService.retrieveMcSession(new Long(toolSessionID)); + McLearningAction.logger.debug("retrieving mcSession: " + mcSession); - mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); + McQueUsr mcQueUsr = mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); + McLearningAction.logger.debug("mcQueUsr: " + mcQueUsr); - logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); + mcQueUsr.setViewSummaryRequested(true); + mcService.updateMcQueUsr(mcQueUsr); + McLearningAction.logger.debug("view summary requested by mcQueUsr: " + mcQueUsr); - request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); - logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + request.getAttribute(MC_GENERAL_LEARNER_FLOW_DTO)); - - return (mapping.findForward(RESULTS_SUMMARY)); - } - + String toolContentId = mcSession.getMcContent().getMcContentId().toString(); + McLearningAction.logger.debug("toolContentId: " + toolContentId); - + McContent mcContent = mcService.retrieveMc(new Long(toolContentId)); + McLearningAction.logger.debug("mcContent: " + mcContent); + McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO = LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); + + mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); + mcGeneralLearnerFlowDTO.setNotebookEntriesVisible(new Boolean(false).toString()); + + int countSessionComplete = 0; + Iterator sessionsIterator = mcContent.getMcSessions().iterator(); + while (sessionsIterator.hasNext()) { + McSession mcSessionLocal = (McSession) sessionsIterator.next(); + if (mcSession != null) { + McLearningAction.logger.debug("mcSessionLocal: " + mcSessionLocal); + if (mcSessionLocal.getSessionStatus().equals(McAppConstants.COMPLETED)) { + McLearningAction.logger.debug("COMPLETED session found: " + mcSessionLocal); + ++countSessionComplete; + } + } + } + McLearningAction.logger.debug("countSessionComplete: " + countSessionComplete); + + Integer[] markStatistics = mcService.getMarkStatistics(mcSession); + + McLearningAction.logger.debug("countSessionComplete: " + countSessionComplete); + McLearningAction.logger.debug("topMark: " + markStatistics[0]); + McLearningAction.logger.debug("lowestMark: " + markStatistics[1]); + McLearningAction.logger.debug("averageMark: " + markStatistics[2]); + + mcGeneralLearnerFlowDTO.setCountSessionComplete(new Integer(countSessionComplete).toString()); + mcGeneralLearnerFlowDTO.setTopMark(markStatistics[0]); + mcGeneralLearnerFlowDTO.setLowestMark(markStatistics[1]); + mcGeneralLearnerFlowDTO.setAverageMark(markStatistics[2]); + + McLearningAction.logger.debug("is tool reflective: " + mcContent.isReflect()); + mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); + McLearningAction.logger.debug("reflection subject: " + mcContent.getReflectionSubject()); + + String reflectionSubject = McUtils.replaceNewLines(mcContent.getReflectionSubject()); + mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + + McLearningAction.logger.debug("mcContent.isRetries(): " + mcContent.isRetries()); + mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); + + String passMarkApplicable = new Boolean(mcContent.isPassMarkApplicable()).toString(); + mcGeneralLearnerFlowDTO.setPassMarkApplicable(passMarkApplicable); + mcLearningForm.setPassMarkApplicable(passMarkApplicable); + + String userOverPassMark = new Boolean(mcQueUsr.isLastAttemptMarkPassed()).toString(); + mcGeneralLearnerFlowDTO.setUserOverPassMark(userOverPassMark); + mcLearningForm.setUserOverPassMark(userOverPassMark); + + String httpSessionID = mcLearningForm.getHttpSessionID(); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); + request.getSession().setAttribute(httpSessionID, sessionMap); + + mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); + + McLearningAction.logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); + + request.setAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); + McLearningAction.logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + + request.getAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO)); + + return mapping.findForward(McAppConstants.RESULTS_SUMMARY); + } + /** * setContentInUse(HttpServletRequest request, String toolContentId, IMcService mcService) * @@ -1474,19 +1341,17 @@ * @param toolContentId * @param mcService */ - protected void setContentInUse(HttpServletRequest request, String toolContentId, IMcService mcService) - { - logger.debug("starting setContentInUse"); - logger.debug("toolContentId:" + toolContentId); - - McContent mcContent=mcService.retrieveMc(new Long(toolContentId)); - logger.debug("mcContent:" + mcContent); - mcContent.setContentInUse(true); - logger.debug("content has been set to inuse"); - mcService.saveMcContent(mcContent); + protected void setContentInUse(HttpServletRequest request, String toolContentId, IMcService mcService) { + McLearningAction.logger.debug("starting setContentInUse"); + McLearningAction.logger.debug("toolContentId:" + toolContentId); + + McContent mcContent = mcService.retrieveMc(new Long(toolContentId)); + McLearningAction.logger.debug("mcContent:" + mcContent); + mcContent.setContentInUse(true); + McLearningAction.logger.debug("content has been set to inuse"); + mcService.saveMcContent(mcContent); } - - + /** * redoQuestions(HttpServletRequest request, McLearningForm mcLearningForm, ActionMapping mapping) * @@ -1495,87 +1360,88 @@ * @param mapping * @return */ - public ActionForward redoQuestions(HttpServletRequest request, McLearningForm mcLearningForm, ActionMapping mapping) - { - logger.debug("requested redoQuestions..."); - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - - /* reset the checked options MAP */ - Map mapGeneralCheckedOptionsContent= new TreeMap(new McComparator()); + public ActionForward redoQuestions(HttpServletRequest request, McLearningForm mcLearningForm, ActionMapping mapping) { + McLearningAction.logger.debug("requested redoQuestions..."); + IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - - McSession mcSession=mcService.retrieveMcSession(new Long(toolSessionID)); - logger.debug("retrieving mcSession: " + mcSession); - - String toolContentId=mcSession.getMcContent().getMcContentId().toString(); - logger.debug("toolContentId: " + toolContentId); - - McContent mcContent=mcService.retrieveMc(new Long(toolContentId)); - logger.debug("mcContent: " + mcContent); - - boolean randomize=mcContent.isRandomize(); - logger.debug("randomize: " + randomize); - - - List listQuestionAndCandidateAnswersDTO=LearningUtil.buildQuestionAndCandidateAnswersDTO(request, mcContent, randomize,mcService); - logger.debug("listQuestionAndCandidateAnswersDTO: " + listQuestionAndCandidateAnswersDTO); - request.setAttribute(LIST_QUESTION_CANDIDATEANSWERS_DTO, listQuestionAndCandidateAnswersDTO); - logger.debug("LIST_QUESTION_CANDIDATEANSWERS_DTO: " + request.getAttribute(LIST_QUESTION_CANDIDATEANSWERS_DTO)); - - McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO=LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); - mcGeneralLearnerFlowDTO.setQuestionIndex(new Integer(1)); - - logger.debug("is tool reflective: " + mcContent.isReflect()); - mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); - logger.debug("reflection subject: " + mcContent.getReflectionSubject()); - - String reflectionSubject=McUtils.replaceNewLines(mcContent.getReflectionSubject()); - mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); - - logger.debug("mcContent.isRetries(): " + mcContent.isRetries()); - mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); - - String passMarkApplicable=new Boolean(mcContent.isPassMarkApplicable()).toString(); - mcGeneralLearnerFlowDTO.setPassMarkApplicable(passMarkApplicable); - mcLearningForm.setPassMarkApplicable(passMarkApplicable); - - String userOverPassMark=Boolean.FALSE.toString(); - mcGeneralLearnerFlowDTO.setUserOverPassMark (userOverPassMark); - mcLearningForm.setUserOverPassMark (userOverPassMark); + /* reset the checked options MAP */ + Map mapGeneralCheckedOptionsContent = new TreeMap(new McComparator()); - mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); - - // should we show the marks for each question - we show the marks if any of the questions - // have a mark > 1. - Boolean showMarks = LearningUtil.isShowMarksOnQuestion(listQuestionAndCandidateAnswersDTO); - mcGeneralLearnerFlowDTO.setShowMarks(showMarks.toString()); - - logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); - request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); - logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + request.getAttribute(MC_GENERAL_LEARNER_FLOW_DTO)); + String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + McLearningAction.logger.debug("toolSessionID: " + toolSessionID); - logger.debug("fwding to LOAD_LEARNER: " + LOAD_LEARNER); - return (mapping.findForward(LOAD_LEARNER)); + McSession mcSession = mcService.retrieveMcSession(new Long(toolSessionID)); + McLearningAction.logger.debug("retrieving mcSession: " + mcSession); + + String toolContentId = mcSession.getMcContent().getMcContentId().toString(); + McLearningAction.logger.debug("toolContentId: " + toolContentId); + + McContent mcContent = mcService.retrieveMc(new Long(toolContentId)); + McLearningAction.logger.debug("mcContent: " + mcContent); + + boolean randomize = mcContent.isRandomize(); + McLearningAction.logger.debug("randomize: " + randomize); + + List listQuestionAndCandidateAnswersDTO = LearningUtil + .buildQuestionAndCandidateAnswersDTO(request, mcContent, randomize, mcService); + McLearningAction.logger.debug("listQuestionAndCandidateAnswersDTO: " + listQuestionAndCandidateAnswersDTO); + request.setAttribute(McAppConstants.LIST_QUESTION_CANDIDATEANSWERS_DTO, listQuestionAndCandidateAnswersDTO); + McLearningAction.logger.debug("LIST_QUESTION_CANDIDATEANSWERS_DTO: " + + request.getAttribute(McAppConstants.LIST_QUESTION_CANDIDATEANSWERS_DTO)); + + McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO = LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); + mcGeneralLearnerFlowDTO.setQuestionIndex(new Integer(1)); + + McLearningAction.logger.debug("is tool reflective: " + mcContent.isReflect()); + mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); + McLearningAction.logger.debug("reflection subject: " + mcContent.getReflectionSubject()); + + String reflectionSubject = McUtils.replaceNewLines(mcContent.getReflectionSubject()); + mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + + McLearningAction.logger.debug("mcContent.isRetries(): " + mcContent.isRetries()); + mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); + + String passMarkApplicable = new Boolean(mcContent.isPassMarkApplicable()).toString(); + mcGeneralLearnerFlowDTO.setPassMarkApplicable(passMarkApplicable); + mcLearningForm.setPassMarkApplicable(passMarkApplicable); + + String userOverPassMark = Boolean.FALSE.toString(); + mcGeneralLearnerFlowDTO.setUserOverPassMark(userOverPassMark); + mcLearningForm.setUserOverPassMark(userOverPassMark); + + mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); + + // should we show the marks for each question - we show the marks if any of the questions + // have a mark > 1. + Boolean showMarks = LearningUtil.isShowMarksOnQuestion(listQuestionAndCandidateAnswersDTO); + mcGeneralLearnerFlowDTO.setShowMarks(showMarks.toString()); + + McLearningAction.logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); + request.setAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); + McLearningAction.logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + + request.getAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO)); + + McLearningAction.logger.debug("fwding to LOAD_LEARNER: " + McAppConstants.LOAD_LEARNER); + return mapping.findForward(McAppConstants.LOAD_LEARNER); } /** * persists error messages to request scope + * * @param request * @param message */ - public void persistError(HttpServletRequest request, String message) - { - ActionMessages errors= new ActionMessages(); - errors.add(Globals.ERROR_KEY, new ActionMessage(message)); - logger.debug("add " + message +" to ActionMessages:"); - saveErrors(request,errors); - } + public void persistError(HttpServletRequest request, String message) { + ActionMessages errors = new ActionMessages(); + errors.add(Globals.ERROR_KEY, new ActionMessage(message)); + McLearningAction.logger.debug("add " + message + " to ActionMessages:"); + saveErrors(request, errors); + } - /** - * submitReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + * submitReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse + * response) * * @param mapping * @param form @@ -1586,93 +1452,87 @@ * @throws ServletException * @throws ToolException */ - public ActionForward submitReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException, ToolException - { - logger.debug("dispatching submitReflection..."); - McLearningForm mcLearningForm = (McLearningForm) form; - - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - logger.debug("mcService: " + mcService); + public ActionForward submitReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException, ToolException { + McLearningAction.logger.debug("dispatching submitReflection..."); + McLearningForm mcLearningForm = (McLearningForm) form; - String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - mcLearningForm.setToolSessionID(toolSessionID); + IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); + McLearningAction.logger.debug("mcService: " + mcService); - String userID=request.getParameter("userID"); - logger.debug("userID: " + userID); - mcLearningForm.setUserID(userID); - - String reflectionEntry=request.getParameter(ENTRY_TEXT); - logger.debug("reflectionEntry: " + reflectionEntry); + String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + McLearningAction.logger.debug("toolSessionID: " + toolSessionID); + mcLearningForm.setToolSessionID(toolSessionID); - McSession mcSession=mcService.retrieveMcSession(new Long(toolSessionID)); - logger.debug("retrieving mcSession: " + mcSession); - - McQueUsr mcQueUsr=mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); - logger.debug("McQueUsr:" + mcQueUsr); - - /* it is possible that mcQueUsr can be null if the content is set as runoffline and reflection is on*/ - if (mcQueUsr == null) - { - logger.debug("attempt creating user record since it must exist for the runOffline + reflection screens"); - HttpSession ss = SessionManager.getSession(); + String userID = request.getParameter("userID"); + McLearningAction.logger.debug("userID: " + userID); + mcLearningForm.setUserID(userID); - UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); - logger.debug("retrieving toolUser: " + toolUser); - logger.debug("retrieving toolUser userId: " + toolUser.getUserID()); - logger.debug("retrieving toolUser username: " + toolUser.getLogin()); + String reflectionEntry = request.getParameter(McAppConstants.ENTRY_TEXT); + McLearningAction.logger.debug("reflectionEntry: " + reflectionEntry); - String userName=toolUser.getLogin(); - String fullName= toolUser.getFirstName() + " " + toolUser.getLastName(); - logger.debug("retrieving toolUser fullname: " + fullName); - - Long userId=new Long(toolUser.getUserID().longValue()); - logger.debug("userId: " + userId); - logger.debug("retrieving toolUser fullname: " + fullName); - - mcQueUsr= new McQueUsr(userId, - userName, - fullName, - mcSession, - new TreeSet()); - mcService.createMcQueUsr(mcQueUsr); - logger.debug("createMcQueUsr - mcQueUsr: " + mcQueUsr); - - logger.debug("session uid: " + mcSession.getUid()); - logger.debug("mcQueUsr: " + mcQueUsr); - mcService.createMcQueUsr(mcQueUsr); - logger.debug("created mcQueUsr in the db: " + mcQueUsr); - } - - logger.debug("McQueUsr:" + mcQueUsr); - logger.debug("toolSessionID:" + toolSessionID); - logger.debug("CoreNotebookConstants.NOTEBOOK_TOOL:" + CoreNotebookConstants.NOTEBOOK_TOOL); - logger.debug("MY_SIGNATURE:" + MY_SIGNATURE); - logger.debug("userID:" + userID); - logger.debug("reflectionEntry:" + reflectionEntry); - - logger.debug("attempt getting notebookEntry: "); - NotebookEntry notebookEntry = mcService.getEntry(new Long(toolSessionID), - CoreNotebookConstants.NOTEBOOK_TOOL, - MY_SIGNATURE, new Integer(userID)); - - logger.debug("notebookEntry: " + notebookEntry); - - if (notebookEntry != null) { - notebookEntry.setEntry(reflectionEntry); - mcService.updateEntry(notebookEntry); - } else { - mcService.createNotebookEntry(new Long(toolSessionID), CoreNotebookConstants.NOTEBOOK_TOOL, - MY_SIGNATURE, new Integer(userID), reflectionEntry); - } - - return endLearning(mapping, form, request, response); + McSession mcSession = mcService.retrieveMcSession(new Long(toolSessionID)); + McLearningAction.logger.debug("retrieving mcSession: " + mcSession); + + McQueUsr mcQueUsr = mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); + McLearningAction.logger.debug("McQueUsr:" + mcQueUsr); + + /* it is possible that mcQueUsr can be null if the content is set as runoffline and reflection is on */ + if (mcQueUsr == null) { + McLearningAction.logger + .debug("attempt creating user record since it must exist for the runOffline + reflection screens"); + HttpSession ss = SessionManager.getSession(); + + UserDTO toolUser = (UserDTO) ss.getAttribute(AttributeNames.USER); + McLearningAction.logger.debug("retrieving toolUser: " + toolUser); + McLearningAction.logger.debug("retrieving toolUser userId: " + toolUser.getUserID()); + McLearningAction.logger.debug("retrieving toolUser username: " + toolUser.getLogin()); + + String userName = toolUser.getLogin(); + String fullName = toolUser.getFirstName() + " " + toolUser.getLastName(); + McLearningAction.logger.debug("retrieving toolUser fullname: " + fullName); + + Long userId = new Long(toolUser.getUserID().longValue()); + McLearningAction.logger.debug("userId: " + userId); + McLearningAction.logger.debug("retrieving toolUser fullname: " + fullName); + + mcQueUsr = new McQueUsr(userId, userName, fullName, mcSession, new TreeSet()); + mcService.createMcQueUsr(mcQueUsr); + McLearningAction.logger.debug("createMcQueUsr - mcQueUsr: " + mcQueUsr); + + McLearningAction.logger.debug("session uid: " + mcSession.getUid()); + McLearningAction.logger.debug("mcQueUsr: " + mcQueUsr); + mcService.createMcQueUsr(mcQueUsr); + McLearningAction.logger.debug("created mcQueUsr in the db: " + mcQueUsr); } - + McLearningAction.logger.debug("McQueUsr:" + mcQueUsr); + McLearningAction.logger.debug("toolSessionID:" + toolSessionID); + McLearningAction.logger.debug("CoreNotebookConstants.NOTEBOOK_TOOL:" + CoreNotebookConstants.NOTEBOOK_TOOL); + McLearningAction.logger.debug("MY_SIGNATURE:" + McAppConstants.MY_SIGNATURE); + McLearningAction.logger.debug("userID:" + userID); + McLearningAction.logger.debug("reflectionEntry:" + reflectionEntry); + + McLearningAction.logger.debug("attempt getting notebookEntry: "); + NotebookEntry notebookEntry = mcService.getEntry(new Long(toolSessionID), CoreNotebookConstants.NOTEBOOK_TOOL, + McAppConstants.MY_SIGNATURE, new Integer(userID)); + + McLearningAction.logger.debug("notebookEntry: " + notebookEntry); + + if (notebookEntry != null) { + notebookEntry.setEntry(reflectionEntry); + mcService.updateEntry(notebookEntry); + } else { + mcService.createNotebookEntry(new Long(toolSessionID), CoreNotebookConstants.NOTEBOOK_TOOL, + McAppConstants.MY_SIGNATURE, new Integer(userID), reflectionEntry); + } + + return endLearning(mapping, form, request, response); + } + /** - * forwardtoReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + * forwardtoReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse + * response) * * @param mapping * @param form @@ -1683,65 +1543,58 @@ * @throws ServletException * @throws ToolException */ - public ActionForward forwardtoReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException, ToolException - { - logger.debug("dispatching forwardtoReflection..."); - McLearningForm mcLearningForm = (McLearningForm) form; - IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); - logger.debug("mcService: " + mcService); - - String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); + public ActionForward forwardtoReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException, ToolException { + McLearningAction.logger.debug("dispatching forwardtoReflection..."); + McLearningForm mcLearningForm = (McLearningForm) form; + IMcService mcService = McServiceProxy.getMcService(getServlet().getServletContext()); + McLearningAction.logger.debug("mcService: " + mcService); - McSession mcSession=mcService.retrieveMcSession(new Long(toolSessionID)); - logger.debug("retrieving mcSession: " + mcSession); - - McContent mcContent=mcSession.getMcContent(); - logger.debug("using mcContent: " + mcContent); - - McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO= new McGeneralLearnerFlowDTO(); - mcGeneralLearnerFlowDTO.setActivityTitle(mcContent.getTitle()); - String reflectionSubject=mcContent.getReflectionSubject(); - - reflectionSubject=McUtils.replaceNewLines(reflectionSubject); - mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); - - String userID = ""; - HttpSession ss = SessionManager.getSession(); - logger.debug("ss: " + ss); - - if (ss != null) - { - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - if ((user != null) && (user.getUserID() != null)) - { - userID = user.getUserID().toString(); - logger.debug("retrieved userId: " + userID); - } + String toolSessionID = request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + McLearningAction.logger.debug("toolSessionID: " + toolSessionID); + + McSession mcSession = mcService.retrieveMcSession(new Long(toolSessionID)); + McLearningAction.logger.debug("retrieving mcSession: " + mcSession); + + McContent mcContent = mcSession.getMcContent(); + McLearningAction.logger.debug("using mcContent: " + mcContent); + + McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO = new McGeneralLearnerFlowDTO(); + mcGeneralLearnerFlowDTO.setActivityTitle(mcContent.getTitle()); + String reflectionSubject = mcContent.getReflectionSubject(); + + reflectionSubject = McUtils.replaceNewLines(reflectionSubject); + mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + + String userID = ""; + HttpSession ss = SessionManager.getSession(); + McLearningAction.logger.debug("ss: " + ss); + + if (ss != null) { + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + if (user != null && user.getUserID() != null) { + userID = user.getUserID().toString(); + McLearningAction.logger.debug("retrieved userId: " + userID); } - - logger.debug("attempt getting notebookEntry: "); - NotebookEntry notebookEntry = mcService.getEntry(new Long(toolSessionID), - CoreNotebookConstants.NOTEBOOK_TOOL, - MY_SIGNATURE, new Integer(userID)); - - logger.debug("notebookEntry: " + notebookEntry); - - if (notebookEntry != null) { - String notebookEntryPresentable= notebookEntry.getEntry(); - mcLearningForm.setEntryText(notebookEntryPresentable); - - } + } - request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); - logger.debug("final mcGeneralLearnerFlowDTO: " + mcGeneralLearnerFlowDTO); - - - logger.debug("fwd'ing to: " + NOTEBOOK); - return (mapping.findForward(NOTEBOOK)); + McLearningAction.logger.debug("attempt getting notebookEntry: "); + NotebookEntry notebookEntry = mcService.getEntry(new Long(toolSessionID), CoreNotebookConstants.NOTEBOOK_TOOL, + McAppConstants.MY_SIGNATURE, new Integer(userID)); + + McLearningAction.logger.debug("notebookEntry: " + notebookEntry); + + if (notebookEntry != null) { + String notebookEntryPresentable = notebookEntry.getEntry(); + mcLearningForm.setEntryText(notebookEntryPresentable); + } - - + + request.setAttribute(McAppConstants.MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); + McLearningAction.logger.debug("final mcGeneralLearnerFlowDTO: " + mcGeneralLearnerFlowDTO); + + McLearningAction.logger.debug("fwd'ing to: " + McAppConstants.NOTEBOOK); + return mapping.findForward(McAppConstants.NOTEBOOK); + } + } - \ No newline at end of file