Index: lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java =================================================================== diff -u -r8eefd9a2f57ce5b05eb75908e36bb042c5fe7fce -rf777da65e4da8c529923ed6eb3a50d6a8cf98f96 --- lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java (.../AssessmentServiceImpl.java) (revision 8eefd9a2f57ce5b05eb75908e36bb042c5fe7fce) +++ lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java (.../AssessmentServiceImpl.java) (revision f777da65e4da8c529923ed6eb3a50d6a8cf98f96) @@ -62,6 +62,7 @@ import org.lamsfoundation.lams.qb.model.QbOption; import org.lamsfoundation.lams.qb.model.QbQuestion; import org.lamsfoundation.lams.qb.model.QbQuestionUnit; +import org.lamsfoundation.lams.qb.model.QbToolQuestion; import org.lamsfoundation.lams.qb.service.IQbService; import org.lamsfoundation.lams.rest.RestTags; import org.lamsfoundation.lams.rest.ToolRestManager; @@ -2164,12 +2165,13 @@ for (AssessmentQuestion oldQuestion : oldQuestions) { if (QbQuestion.TYPE_ESSAY == oldQuestion.getType() - || QbQuestion.TYPE_MATCHING_PAIRS == oldQuestion.getType()) { + || QbQuestion.TYPE_MATCHING_PAIRS == oldQuestion.getType() + || QbQuestion.TYPE_ORDERING == oldQuestion.getType()) { continue; } for (AssessmentQuestion newQuestion : newQuestions) { - if (oldQuestion.getUid().equals(newQuestion.getUid())) { + if (oldQuestion.getDisplayOrder() == newQuestion.getDisplayOrder()) { boolean isQuestionModified = false; @@ -2186,14 +2188,11 @@ List newOptions = newQuestion.getQbQuestion().getQbOptions(); for (QbOption oldOption : oldOptions) { for (QbOption newOption : newOptions) { - if (oldOption.getUid().equals(newOption.getUid())) { + if (oldOption.getDisplayOrder() == newOption.getDisplayOrder()) { - //ordering - if (((oldQuestion.getType() == QbQuestion.TYPE_ORDERING) - && (oldOption.getDisplayOrder() != newOption.getDisplayOrder())) - //short answer - || ((oldQuestion.getType() == QbQuestion.TYPE_SHORT_ANSWER) - && !StringUtils.equals(oldOption.getName(), newOption.getName())) + //short answer + if (((oldQuestion.getType() == QbQuestion.TYPE_SHORT_ANSWER) + && !StringUtils.equals(oldOption.getName(), newOption.getName())) //numbering || (oldOption.getNumericalOption() != newOption.getNumericalOption()) || (oldOption.getAcceptedError() != newOption.getAcceptedError()) @@ -2256,17 +2255,49 @@ // [+] if the question is modified for (AssessmentQuestionResult questionResult : questionResults) { - QuestionDTO questionDto = new QuestionDTO(questionResult.getQbToolQuestion()); + QbToolQuestion oldQuestion = questionResult.getQbToolQuestion(); + Float oldQuestionAnswerMark = questionResult.getMark(); + int oldResultMaxMark = questionResult.getMaxMark() == null ? 0 + : questionResult.getMaxMark().intValue(); //check whether according question was modified for (AssessmentQuestion modifiedQuestion : modifiedQuestions) { - if (questionDto.getUid().equals(modifiedQuestion.getUid())) { - Float oldQuestionAnswerMark = questionResult.getMark(); - + if (oldQuestion.getDisplayOrder() == modifiedQuestion.getDisplayOrder()) { + + //update questionResult's qbQuestion with the new one + questionResult.setQbToolQuestion(modifiedQuestion); + //update questionResult's qbOption +// for (QbOption newOption : modifiedQuestion.getQbQuestion().getQbOptions()) { +// if (questionResult.getQbOption().getDisplayOrder() == newOption.getDisplayOrder()) { +// questionResult.setQbOption(newOption); +// break; +// } +// } + //update questionResult's optionAnswers + for (AssessmentOptionAnswer oldOptionAnswer : questionResult.getOptionAnswers()) { + + //find according old qbOption + QbOption oldOption = null; + for (QbOption oldOptionIter: oldQuestion.getQbQuestion().getQbOptions()) { + if (oldOptionIter.getUid().equals(oldOptionAnswer.getOptionUid())) { + oldOption = oldOptionIter; + } + } + + //update + for (QbOption newOption : modifiedQuestion.getQbQuestion().getQbOptions()) { + if (oldOption.getDisplayOrder() == newOption.getDisplayOrder()) { + oldOptionAnswer.setOptionUid(newOption.getUid()); + break; + } + } + } + //actually recalculate marks - questionDto.setMaxMark(questionResult.getMaxMark().intValue()); - loadupQuestionResultIntoQuestionDto(questionDto, questionResult); - calculateAnswerMark(assessmentUid, user.getUserId(), questionResult, questionDto); + QuestionDTO modifiedQuestionDto = new QuestionDTO(modifiedQuestion); + modifiedQuestionDto.setMaxMark(oldResultMaxMark); + loadupQuestionResultIntoQuestionDto(modifiedQuestionDto, questionResult); + calculateAnswerMark(assessmentUid, user.getUserId(), questionResult, modifiedQuestionDto); assessmentQuestionResultDao.saveObject(questionResult); float newQuestionAnswerMark = questionResult.getMark(); @@ -2324,7 +2355,8 @@ int newReferenceMaxMark = modifiedReference.getMaxMark(); int oldReferenceMaxMark = modifiedReferences.get(modifiedReference); - if (randomQuestionResult.getMaxMark().intValue() == oldReferenceMaxMark) { + if (randomQuestionResult.getMaxMark() != null + && randomQuestionResult.getMaxMark().intValue() == oldReferenceMaxMark) { // update question answer's mark Float oldQuestionResultMark = randomQuestionResult.getMark(); @@ -3187,11 +3219,6 @@ "Assessment Tool does not support REST Authoring for anything but Essay Type and Multiple Choice. Found type " + type); } - // public static final short QUESTION_TYPE_MATCHING_PAIRS = 2; - // public static final short QUESTION_TYPE_SHORT_ANSWER = 3; - // public static final short QUESTION_TYPE_NUMERICAL = 4; - // public static final short QUESTION_TYPE_TRUE_FALSE = 5; - // public static final short QUESTION_TYPE_ORDERING = 7; } @Override Index: lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/web/controller/AuthoringController.java =================================================================== diff -u -r0ebe2a9625e896e58700f9e6aaacab2190e6e348 -rf777da65e4da8c529923ed6eb3a50d6a8cf98f96 --- lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/web/controller/AuthoringController.java (.../AuthoringController.java) (revision 0ebe2a9625e896e58700f9e6aaacab2190e6e348) +++ lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/web/controller/AuthoringController.java (.../AuthoringController.java) (revision f777da65e4da8c529923ed6eb3a50d6a8cf98f96) @@ -230,7 +230,6 @@ Assessment assessment = assessmentForm.getAssessment(); Assessment assessmentPO = service.getAssessmentByContentId(assessmentForm.getAssessment().getContentId()); - //TODO **part of markrecalculation** Set oldQuestions = (assessmentPO == null) ? new HashSet<>() : assessmentPO.getQuestions(); Set oldReferences = (assessmentPO == null) ? new HashSet<>() : assessmentPO.getQuestionReferences(); @@ -243,20 +242,17 @@ assessmentPO.setCreated(new Timestamp(new Date().getTime())); } else { - //TODO **part of markrecalculation** // copyProperties() below sets assessmentPO items to empty collection // but the items still exist in Hibernate cache, so we need to evict them now for (AssessmentQuestion question : oldQuestions) { service.releaseFromCache(question); -// service.releaseFromCache(question.getQbQuestion()); } for (QuestionReference reference : oldReferences) { service.releaseFromCache(reference); if (reference.getQuestion() != null) { service.releaseFromCache(reference.getQuestion()); } } - assessmentPO.getQuestions().clear(); Long uid = assessmentPO.getUid(); assessmentUser = assessmentPO.getCreatedBy(); @@ -300,9 +296,7 @@ if (!reference.isRandomQuestion()) { AssessmentQuestion question = reference.getQuestion(); newQuestions.add(question); - } - //TODO check -// removeNewLineCharacters(question); + } } for (AssessmentQuestion question : newQuestions) { @@ -311,13 +305,12 @@ assessmentPO.setQuestions(newQuestions); - //TODO **part of markrecalculation** // // recalculate results in case content is edited from monitoring and it's been already attempted by a student -// boolean isAuthoringRestricted = (boolean) sessionMap.get(AssessmentConstants.ATTR_IS_AUTHORING_RESTRICTED); -// if (isAuthoringRestricted) { -// service.recalculateUserAnswers(assessmentPO.getUid(), assessmentPO.getContentId(), oldQuestions, -// newQuestions, oldReferences, newReferences); -// } + boolean isAuthoringRestricted = (boolean) sessionMap.get(AssessmentConstants.ATTR_IS_AUTHORING_RESTRICTED); + if (isAuthoringRestricted) { + service.recalculateUserAnswers(assessmentPO.getUid(), assessmentPO.getContentId(), oldQuestions, + newQuestions, oldReferences, newReferences); + } // Handle question references assessmentPO.setQuestionReferences(newReferences); @@ -507,7 +500,6 @@ && oldQbQuestionUid.equals(reference.getQuestion().getQbQuestion().getUid())) { AssessmentQuestion assessmentQuestion = reference.getQuestion(); assessmentQuestion.setQbQuestion(qbQuestion); - assessmentQuestion.setDisplayOrder(getNextDisplayOrder(sessionMap)); break; } } @@ -608,9 +600,7 @@ @SuppressWarnings("unchecked") @RequestMapping(value = "/importQbQuestion", method = RequestMethod.POST) private String importQbQuestion(HttpServletRequest request, @RequestParam String sessionMapID, - @RequestParam Long qbQuestionUid) { - //TODO perform updateQuestionReferencesMaxMarks prior to runnning this method - + @RequestParam Long qbQuestionUid) { SessionMap sessionMap = (SessionMap) request.getSession() .getAttribute(sessionMapID); QbQuestion qbQuestion = qbService.getQuestionByUid(qbQuestionUid); Index: lams_tool_assessment/web/pages/authoring/parts/questionlistRestricted.jsp =================================================================== diff -u -r475b1970be027a5c59a08d33ad1aa1f6b2443402 -rf777da65e4da8c529923ed6eb3a50d6a8cf98f96 --- lams_tool_assessment/web/pages/authoring/parts/questionlistRestricted.jsp (.../questionlistRestricted.jsp) (revision 475b1970be027a5c59a08d33ad1aa1f6b2443402) +++ lams_tool_assessment/web/pages/authoring/parts/questionlistRestricted.jsp (.../questionlistRestricted.jsp) (revision f777da65e4da8c529923ed6eb3a50d6a8cf98f96) @@ -64,23 +64,12 @@ - + - - - - - - - - - - - - + ?sessionMapID=${sessionMapID}&questionReferenceIndex=${status.index}&KeepThis=true&TB_iframe=true&modal=true