Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java =================================================================== diff -u -re4c72d9ff29d298b32927e0e1c0970b653acb86e -rf6866695fd368dd029f7045601b43e15f884b54c --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision e4c72d9ff29d298b32927e0e1c0970b653acb86e) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision f6866695fd368dd029f7045601b43e15f884b54c) @@ -74,34 +74,6 @@ } /** - * verifies that there are no duplicate questions - */ - public static boolean checkDuplicateQuestions(List questionDTOs, String newQuestion) { - - Map mapQuestionContent = new TreeMap(new McComparator()); - Iterator iter = questionDTOs.iterator(); - int queIndex = 0; - while (iter.hasNext()) { - McQuestionDTO questionDto = iter.next(); - - queIndex++; - mapQuestionContent.put(new Integer(queIndex).toString(), questionDto.getQuestion()); - } - - Iterator> itMap = mapQuestionContent.entrySet().iterator(); - while (itMap.hasNext()) { - Entry pairs = itMap.next(); - if ((pairs.getValue() != null) && (!pairs.getValue().equals(""))) { - - if (pairs.getValue().equals(newQuestion)) { - return true; - } - } - } - return false; - } - - /** * persisting content */ public static McContent saveOrUpdateMcContent(IMcService mcService, HttpServletRequest request, McContent mcContent, Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java =================================================================== diff -u -r3785bef410416b5fb3e651c18631fd38ed83d2b8 -rf6866695fd368dd029f7045601b43e15f884b54c --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java (.../McAction.java) (revision 3785bef410416b5fb3e651c18631fd38ed83d2b8) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java (.../McAction.java) (revision f6866695fd368dd029f7045601b43e15f884b54c) @@ -87,7 +87,7 @@ ToolAccessMode mode = (ToolAccessMode) sessionMap.get(AttributeNames.ATTR_MODE); List deletedQuestionDTOs = (List) sessionMap .get(McAppConstants.LIST_DELETED_QUESTION_DTOS); - + if (questionDTOs.isEmpty()) { ActionMessages errors = new ActionMessages(); ActionMessage error = new ActionMessage("questions.none.submitted"); @@ -147,7 +147,7 @@ request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); return mapping.findForward(McAppConstants.LOAD_AUTHORING); } - + /** * opens up an new screen within the current page for editing a question */ @@ -161,12 +161,12 @@ List questionDtos = (List) sessionMap.get(McAppConstants.QUESTION_DTOS); Integer questionIndex = WebUtil.readIntParam(request, "questionIndex", true); - + McQuestionDTO questionDto = null; //editing existing question if (questionIndex != null) { mcAuthoringForm.setQuestionIndex(questionIndex); - + //find according questionDto for (McQuestionDTO questionDtoIter : questionDtos) { Integer displayOrder = questionDtoIter.getDisplayOrder(); @@ -176,12 +176,12 @@ break; } } - - //adding new question + + //adding new question } else { // prepare question for adding new question page questionDto = new McQuestionDTO(); - List newOptions = new ArrayList(); + List newOptions = new ArrayList<>(); McOptionDTO newOption1 = new McOptionDTO(); newOption1.setCorrect("Correct"); McOptionDTO newOption2 = new McOptionDTO(); @@ -205,14 +205,14 @@ SessionMap sessionMap = (SessionMap) request.getSession() .getAttribute(sessionMapId); request.setAttribute(McAppConstants.ATTR_SESSION_MAP_ID, sessionMapId); - + Integer questionIndexToDelete = WebUtil.readIntParam(request, "questionIndex"); mcAuthoringForm.setQuestionIndex(questionIndexToDelete); List questionDTOs = (List) sessionMap.get(McAppConstants.QUESTION_DTOS); //exclude Question with questionIndex From List - List tempQuestionDtos = new LinkedList(); + List tempQuestionDtos = new LinkedList<>(); int queIndex = 0; for (McQuestionDTO questionDTO : questionDTOs) { @@ -224,7 +224,7 @@ ++queIndex; questionDTO.setDisplayOrder(queIndex); tempQuestionDtos.add(questionDTO); - + } else { List deletedQuestionDTOs = (List) sessionMap .get(McAppConstants.LIST_DELETED_QUESTION_DTOS); @@ -303,7 +303,7 @@ return questionDTOs; } - List questionDtos = new LinkedList(); + List questionDtos = new LinkedList<>(); Iterator iter = questionDTOs.iterator(); while (iter.hasNext()) { @@ -331,10 +331,10 @@ } /* - *Auxiliary method for moveQuestionDown() and moveQuestionUp() + * Auxiliary method for moveQuestionDown() and moveQuestionUp() */ private static List reorderQuestionDtos(List questionDTOs) { - List tempQuestionDtos = new LinkedList(); + List tempQuestionDtos = new LinkedList<>(); int queIndex = 0; Iterator iter = questionDTOs.iterator(); @@ -374,9 +374,9 @@ String mark = request.getParameter("mark"); List options = McAction.repopulateOptionDTOs(request, false); - + //remove blank options - List optionsWithoutEmptyOnes = new LinkedList(); + List optionsWithoutEmptyOnes = new LinkedList<>(); for (McOptionDTO optionDTO : options) { String optionText = optionDTO.getCandidateAnswer(); if ((optionText != null) && (optionText.length() > 0)) { @@ -396,31 +396,25 @@ // adding new question if (questionIndex == null) { - boolean duplicates = AuthoringUtil.checkDuplicateQuestions(questionDTOs, newQuestion); - if (!duplicates) { - - //finding max displayOrder - int maxDisplayOrder = 0; - for (McQuestionDTO questionDTO : questionDTOs) { - int displayOrder = new Integer(questionDTO.getDisplayOrder()); - if (displayOrder > maxDisplayOrder) { - maxDisplayOrder = displayOrder; - } + //finding max displayOrder + int maxDisplayOrder = 0; + for (McQuestionDTO questionDTO : questionDTOs) { + int displayOrder = new Integer(questionDTO.getDisplayOrder()); + if (displayOrder > maxDisplayOrder) { + maxDisplayOrder = displayOrder; } + } - McQuestionDTO questionDTO = new McQuestionDTO(); - questionDTO.setQuestion(newQuestion); - questionDTO.setFeedback(feedback); - questionDTO.setDisplayOrder(maxDisplayOrder + 1); - questionDTO.setOptionDtos(options); - questionDTO.setMark(mark); + McQuestionDTO questionDTO = new McQuestionDTO(); + questionDTO.setQuestion(newQuestion); + questionDTO.setFeedback(feedback); + questionDTO.setDisplayOrder(maxDisplayOrder + 1); + questionDTO.setOptionDtos(options); + questionDTO.setMark(mark); - questionDTOs.add(questionDTO); - } else { - // duplicate question entry, not adding - } + questionDTOs.add(questionDTO); - // updating existing question + // updating existing question } else { McQuestionDTO questionDto = null; for (McQuestionDTO questionDtoIter : questionDTOs) { @@ -476,12 +470,7 @@ questionText = QuestionParser.processHTMLField(questionText, false, contentFolderID, question.getResourcesFolderPath()); - if (AuthoringUtil.checkDuplicateQuestions(questionDtos, questionText)) { - logger.warn("Skipping duplicate question: " + questionText); - continue; - } - - List optionDtos = new ArrayList(); + List optionDtos = new ArrayList<>(); String correctAnswer = null; Integer correctAnswerScore = 1; @@ -495,8 +484,7 @@ continue; } if ((correctAnswer != null) && correctAnswer.equals(answerText)) { - logger - .warn("Skipping an answer with same text as the correct answer: " + answerText); + logger.warn("Skipping an answer with same text as the correct answer: " + answerText); continue; } @@ -559,7 +547,7 @@ request.setAttribute(McAppConstants.ATTR_SESSION_MAP_ID, sessionMapId); List questionDtos = (List) sessionMap.get(McAppConstants.QUESTION_DTOS); - List questions = new LinkedList(); + List questions = new LinkedList<>(); for (McQuestionDTO mcQuestion : questionDtos) { Question question = new Question(); @@ -568,7 +556,7 @@ question.setTitle("Question " + mcQuestion.getDisplayOrder()); question.setText(mcQuestion.getQuestion()); question.setFeedback(mcQuestion.getFeedback()); - List answers = new ArrayList(); + List answers = new ArrayList<>(); for (McOptionDTO mcAnswer : mcQuestion.getOptionDtos()) { Answer answer = new Answer(); @@ -605,7 +593,7 @@ //moveAddedCandidateUp McQuestionDTO questionDto = (McQuestionDTO) sessionMap.get(McAppConstants.QUESTION_DTO); - List listCandidates = new LinkedList(); + List listCandidates = new LinkedList<>(); listCandidates = McAction.swapOptions(optionDtos, candidateIndex, "up"); questionDto.setOptionDtos(listCandidates); sessionMap.put(McAppConstants.QUESTION_DTO, questionDto); @@ -627,14 +615,14 @@ //moveAddedCandidateDown McQuestionDTO questionDto = (McQuestionDTO) sessionMap.get(McAppConstants.QUESTION_DTO); - List swapedOptions = new LinkedList(); + List swapedOptions = new LinkedList<>(); swapedOptions = McAction.swapOptions(optionDtos, candidateIndex, "down"); questionDto.setOptionDtos(swapedOptions); sessionMap.put(McAppConstants.QUESTION_DTO, questionDto); return (mapping.findForward("candidateAnswersList")); } - + /* * swaps options in the list */ @@ -656,7 +644,7 @@ return optionDtos; } - List newOptionDtos = new LinkedList(); + List newOptionDtos = new LinkedList<>(); int queIndex = 1; for (McOptionDTO option : optionDtos) { @@ -695,7 +683,7 @@ McQuestionDTO questionDto = (McQuestionDTO) sessionMap.get(McAppConstants.QUESTION_DTO); List optionDtos = McAction.repopulateOptionDTOs(request, false); - List listFinalCandidatesDTO = new LinkedList(); + List listFinalCandidatesDTO = new LinkedList<>(); int caIndex = 0; for (McOptionDTO mcOptionDTO : optionDtos) { caIndex++; @@ -744,7 +732,7 @@ intCorrect = new Integer(correct).intValue(); } - List optionDtos = new LinkedList(); + List optionDtos = new LinkedList<>(); for (int i = 0; i < McAppConstants.MAX_OPTION_COUNT; i++) { String optionText = request.getParameter("ca" + i); Long optionUid = WebUtil.readLongParam(request, "caUid" + i, true);