Index: lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java =================================================================== diff -u -rb26f90eccf164c7058201360d2ca771adcfb597a -rd39b9df30d44b56c287b8a1d4409407e60692dc4 --- lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java (.../AssessmentServiceImpl.java) (revision b26f90eccf164c7058201360d2ca771adcfb597a) +++ lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java (.../AssessmentServiceImpl.java) (revision d39b9df30d44b56c287b8a1d4409407e60692dc4) @@ -335,15 +335,15 @@ @Override public List getPagedUsersBySession(Long sessionId, int page, int size, String sortBy, String sortOrder, String searchString) { - return assessmentUserDao.getPagedUsersBySession(sessionId, page, size, sortBy, sortOrder, - searchString, userManagementService); + return assessmentUserDao.getPagedUsersBySession(sessionId, page, size, sortBy, sortOrder, searchString, + userManagementService); } @Override public int getCountUsersBySession(Long sessionId, String searchString) { return assessmentUserDao.getCountUsersBySession(sessionId, searchString); } - + @Override public int getCountUsersByContentId(Long contentId) { return assessmentUserDao.getCountUsersByContentId(contentId); @@ -358,13 +358,13 @@ @Override public Long getPortraitId(Long userId) { - if ( userId != null ) { + if (userId != null) { User user = (User) userManagementService.findById(User.class, userId.intValue()); return user != null ? user.getPortraitUuid() : null; } return null; } - + @Override public Assessment getAssessmentByContentId(Long contentId) { Assessment rs = assessmentDao.getByContentId(contentId); @@ -404,7 +404,7 @@ public AssessmentUser getUserCreatedAssessment(Long userId, Long contentId) { return assessmentUserDao.getUserCreatedAssessment(userId, contentId); } - + @Override public AssessmentUser getUserByIdAndContent(Long userId, Long contentId) { return assessmentUserDao.getUserByIdAndContent(userId, contentId); @@ -422,7 +422,7 @@ String newHash = question.getQuestion() == null ? null : HashUtil.sha1(question.getQuestion()); question.setQuestionHash(newHash); } - + //store object in DB assessmentDao.saveObject(assessment); } @@ -455,7 +455,7 @@ public AssessmentSession getSessionBySessionId(Long sessionId) { return assessmentSessionDao.getSessionBySessionId(sessionId); } - + @Override public List getSessionsByContentId(Long toolContentId) { return assessmentSessionDao.getByContentId(toolContentId); @@ -464,7 +464,7 @@ @Override public void setAttemptStarted(Assessment assessment, AssessmentUser assessmentUser, Long toolSessionId) { Set questions = assessment.getQuestions(); - + AssessmentResult lastResult = getLastAssessmentResult(assessment.getUid(), assessmentUser.getUserId()); if (lastResult != null) { @@ -493,7 +493,7 @@ assessmentResultDao.saveObject(lastResult); return; - // mark previous attempt as being not the latest any longer + // mark previous attempt as being not the latest any longer } else { lastResult.setLatest(null); assessmentResultDao.saveObject(lastResult); @@ -565,7 +565,8 @@ for (QuestionDTO questionDto : questionsForOnePage) { // in case single MarkHedging question needs to be stored -- search for that question - if ((singleMarkHedgingQuestionUid != null) && !questionDto.getUid().equals(singleMarkHedgingQuestionUid)) { + if ((singleMarkHedgingQuestionUid != null) + && !questionDto.getUid().equals(singleMarkHedgingQuestionUid)) { continue; } @@ -622,24 +623,24 @@ * @param isAutosave * in case of autosave there is no need to calculate marks * @return grade that user scored by answering that question - * @throws NoSuchMethodException - * @throws InvocationTargetException - * @throws IllegalAccessException + * @throws NoSuchMethodException + * @throws InvocationTargetException + * @throws IllegalAccessException */ - private float storeUserAnswer(AssessmentResult assessmentResult, QuestionDTO questionDto, boolean isAutosave) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { + private float storeUserAnswer(AssessmentResult assessmentResult, QuestionDTO questionDto, boolean isAutosave) + throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Assessment assessment = assessmentResult.getAssessment(); - + AssessmentQuestionResult questionResult = null; // get questionResult from DB instance of AssessmentResult for (AssessmentQuestionResult questionResultIter : assessmentResult.getQuestionResults()) { if (questionDto.getUid().equals(questionResultIter.getAssessmentQuestion().getUid())) { questionResult = questionResultIter; } } - + //if teacher edited content in monitor (modified question) it led to removal if autosaved questionResult - if (assessment.isContentModifiedInMonitor(assessmentResult.getStartDate()) - && questionResult == null) { + if (assessment.isContentModifiedInMonitor(assessmentResult.getStartDate()) && questionResult == null) { //update questionDto AssessmentQuestion modifiedQuestion = assessmentQuestionDao.getByUid(questionDto.getUid()); QuestionDTO updatedQuestionDto = modifiedQuestion.getQuestionDTO(); @@ -670,7 +671,7 @@ optionAnswer.setAnswerInt(j++); } } - + // store confidence levels entered by the learner if (assessment.isEnableConfidenceLevels()) { questionResult.setConfidenceLevel(questionDto.getConfidenceLevel()); @@ -712,7 +713,7 @@ } else if (questionDto.getType() == AssessmentConstants.QUESTION_TYPE_SHORT_ANSWER) { //clear previous answer questionResult.setSubmittedOptionUid(null); - + for (OptionDTO optionDto : questionDto.getOptionDtos()) { //prepare regex which takes into account only * special character @@ -737,7 +738,8 @@ java.util.regex.Pattern.CASE_INSENSITIVE | java.util.regex.Pattern.UNICODE_CASE); } boolean isAnswerMatchedCurrentOption = (questionDto.getAnswerString() != null) - ? pattern.matcher(questionDto.getAnswerString().trim()).matches() : false; + ? pattern.matcher(questionDto.getAnswerString().trim()).matches() + : false; if (isAnswerMatchedCurrentOption) { mark = optionDto.getGrade() * maxMark; @@ -753,7 +755,8 @@ boolean isAnswerMatchedCurrentOption = false; try { float answerFloat = Float.valueOf(questionDto.getAnswerString()); - isAnswerMatchedCurrentOption = ((answerFloat >= (optionDto.getOptionFloat() - optionDto.getAcceptedError())) + isAnswerMatchedCurrentOption = ((answerFloat >= (optionDto.getOptionFloat() + - optionDto.getAcceptedError())) && (answerFloat <= (optionDto.getOptionFloat() + optionDto.getAcceptedError()))); } catch (Exception e) { } @@ -771,7 +774,8 @@ answerFloat = answerFloat / unit.getMultiplier(); isAnswerMatchedCurrentOption = ((answerFloat >= (optionDto.getOptionFloat() - optionDto.getAcceptedError())) - && (answerFloat <= (optionDto.getOptionFloat() + optionDto.getAcceptedError()))); + && (answerFloat <= (optionDto.getOptionFloat() + + optionDto.getAcceptedError()))); if (isAnswerMatchedCurrentOption) { break; } @@ -789,7 +793,8 @@ } } else if (questionDto.getType() == AssessmentConstants.QUESTION_TYPE_TRUE_FALSE) { - if ((questionDto.getAnswerBoolean() == questionDto.getCorrectAnswer()) && (questionDto.getAnswerString() != null)) { + if ((questionDto.getAnswerBoolean() == questionDto.getCorrectAnswer()) + && (questionDto.getAnswerString() != null)) { mark = maxMark; } @@ -914,7 +919,7 @@ public Integer getLastFinishedAssessmentResultTimeTaken(Long assessmentUid, Long userId) { return assessmentResultDao.getLastFinishedAssessmentResultTimeTaken(assessmentUid, userId); } - + @Override public int countAttemptsPerOption(Long optionUid) { return assessmentResultDao.countAttemptsPerOption(optionUid); @@ -923,13 +928,13 @@ @Override public AssessmentResult getLastFinishedAssessmentResultNotFromChache(Long assessmentUid, Long userId) { AssessmentResult finishedResult = getLastFinishedAssessmentResult(assessmentUid, userId); - + //in case user played tricks with accessing Assessment using two tabs, finishedResult can be null and thus we need to request the last *not finished* result if (finishedResult == null) { AssessmentResult notFinishedResult = getLastAssessmentResult(assessmentUid, userId); assessmentQuestionDao.evict(notFinishedResult); return getLastAssessmentResult(assessmentUid, userId); - + } else { assessmentQuestionDao.evict(finishedResult); return getLastFinishedAssessmentResult(assessmentUid, userId); @@ -1039,14 +1044,20 @@ SessionDTO sessionDto = new SessionDTO(sessionId, session.getSessionName()); //for statistics tab - if ( includeStatistics ) { + if (includeStatistics) { int countUsers = assessmentUserDao.getCountUsersBySession(sessionId, ""); sessionDto.setNumberLearners(countUsers); Object[] markStats = assessmentUserDao.getStatsMarksBySession(sessionId); - if ( markStats != null ) { - sessionDto.setMinMark(markStats[0] != null ? NumberUtil.formatLocalisedNumber((Float)markStats[0], (Locale)null, 2) : "0.00"); - sessionDto.setAvgMark(markStats[1] != null ? NumberUtil.formatLocalisedNumber((Float)markStats[1], (Locale)null, 2) : "0.00"); - sessionDto.setMaxMark(markStats[2] != null ? NumberUtil.formatLocalisedNumber((Float)markStats[2], (Locale)null, 2) : "0.00"); + if (markStats != null) { + sessionDto.setMinMark(markStats[0] != null + ? NumberUtil.formatLocalisedNumber((Float) markStats[0], (Locale) null, 2) + : "0.00"); + sessionDto.setAvgMark(markStats[1] != null + ? NumberUtil.formatLocalisedNumber((Float) markStats[1], (Locale) null, 2) + : "0.00"); + sessionDto.setMaxMark(markStats[2] != null + ? NumberUtil.formatLocalisedNumber((Float) markStats[2], (Locale) null, 2) + : "0.00"); } } @@ -1060,20 +1071,26 @@ public LeaderResultsDTO getLeaderResultsDTOForLeaders(Long contentId) { LeaderResultsDTO newDto = new LeaderResultsDTO(contentId); Object[] markStats = assessmentUserDao.getStatsMarksForLeaders(contentId); - if ( markStats != null ) { - newDto.setMinMark(markStats[0] != null ? NumberUtil.formatLocalisedNumber((Float)markStats[0], (Locale)null, 2) : "0.00"); - newDto.setAvgMark(markStats[1] != null ? NumberUtil.formatLocalisedNumber((Float)markStats[1], (Locale)null, 2) : "0.00"); - newDto.setMaxMark(markStats[2] != null ? NumberUtil.formatLocalisedNumber((Float)markStats[2], (Locale)null, 2) : "0.00"); - newDto.setNumberGroupsLeaderFinished((Integer)markStats[3]); + if (markStats != null) { + newDto.setMinMark( + markStats[0] != null ? NumberUtil.formatLocalisedNumber((Float) markStats[0], (Locale) null, 2) + : "0.00"); + newDto.setAvgMark( + markStats[1] != null ? NumberUtil.formatLocalisedNumber((Float) markStats[1], (Locale) null, 2) + : "0.00"); + newDto.setMaxMark( + markStats[2] != null ? NumberUtil.formatLocalisedNumber((Float) markStats[2], (Locale) null, 2) + : "0.00"); + newDto.setNumberGroupsLeaderFinished((Integer) markStats[3]); } return newDto; } - + @Override public AssessmentResultDTO getUserMasterDetail(Long sessionId, Long userId) { AssessmentResultDTO resultDto = new AssessmentResultDTO(); resultDto.setSessionId(sessionId); - + AssessmentResult lastFinishedResult = assessmentResultDao.getLastFinishedAssessmentResultByUser(sessionId, userId); if (lastFinishedResult != null) { @@ -1088,7 +1105,7 @@ if (assessment.hasRandomQuestion()) { questionResultsToDisplay.addAll(questionResults); - //otherwise show only questions from the question list + //otherwise show only questions from the question list } else { for (QuestionReference reference : questionReferences) { for (AssessmentQuestionResult questionResult : questionResults) { @@ -1098,7 +1115,7 @@ } } } - + resultDto.setQuestionResults(questionResultsToDisplay); //escaping @@ -1111,7 +1128,7 @@ @Override public UserSummary getUserSummary(Long contentId, Long userId, Long sessionId) { Assessment assessment = assessmentDao.getByContentId(contentId); - + UserSummary userSummary = new UserSummary(); AssessmentUser user = assessmentUserDao.getUserByUserIDAndSessionID(userId, sessionId); userSummary.setUser(user); @@ -1126,7 +1143,7 @@ if (lastFinishedResult != null) { userSummary.setLastAttemptGrade(lastFinishedResult.getGrade()); } - + if (!results.isEmpty()) { //prepare list of the questions to display, filtering out questions that aren't supposed to be answered @@ -1295,7 +1312,7 @@ ExcelCell[] sessionTitle = new ExcelCell[1]; sessionTitle[0] = new ExcelCell(sessionDTO.getSessionName(), true); summaryTab.add(sessionTitle); - + List userDtos = new ArrayList(); // in case of UseSelectLeaderToolOuput - display only one user if (assessment.isUseSelectLeaderToolOuput()) { @@ -1323,11 +1340,14 @@ } ArrayList summaryTabLearnerList = new ArrayList(); - + ExcelCell[] summaryRowTitle = new ExcelCell[3]; - summaryRowTitle[0] = new ExcelCell(getMessage("label.export.user.id"), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); - summaryRowTitle[1] = new ExcelCell(getMessage("label.monitoring.summary.user.name"), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); - summaryRowTitle[2] = new ExcelCell(getMessage("label.monitoring.summary.total"), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); + summaryRowTitle[0] = new ExcelCell(getMessage("label.export.user.id"), true, + ExcelCell.BORDER_STYLE_BOTTOM_THIN); + summaryRowTitle[1] = new ExcelCell(getMessage("label.monitoring.summary.user.name"), true, + ExcelCell.BORDER_STYLE_BOTTOM_THIN); + summaryRowTitle[2] = new ExcelCell(getMessage("label.monitoring.summary.total"), true, + ExcelCell.BORDER_STYLE_BOTTOM_THIN); summaryTabLearnerList.add(summaryRowTitle); float minGrade = -9999999; @@ -1342,18 +1362,19 @@ userResultRow[2] = new ExcelCell(grade, false); summaryTabLearnerList.add(userResultRow); - if ( grade < minGrade || minGrade == -9999999 ) + if (grade < minGrade || minGrade == -9999999) minGrade = grade; - if ( grade > maxGrade ) + if (grade > maxGrade) maxGrade = grade; } - if ( minGrade == -9999999) + if (minGrade == -9999999) minGrade = 0; - LinkedHashMap markSummary = getMarksSummaryForSession(userDtos, minGrade, maxGrade, 10); + LinkedHashMap markSummary = getMarksSummaryForSession(userDtos, minGrade, maxGrade, + 10); // work out total marks so we can do percentages. need as float for the correct divisions int totalNumEntries = 0; - for ( Map.Entry entry : markSummary.entrySet() ) { + for (Map.Entry entry : markSummary.entrySet()) { totalNumEntries += entry.getValue(); } @@ -1365,25 +1386,29 @@ summaryTab.add(minMaxRow); minMaxRow = new ExcelCell[2]; minMaxRow[0] = new ExcelCell(getMessage("label.lowest.mark"), true); - minMaxRow[1] = new ExcelCell((double)minGrade, false); + minMaxRow[1] = new ExcelCell((double) minGrade, false); summaryTab.add(minMaxRow); minMaxRow = new ExcelCell[2]; minMaxRow[0] = new ExcelCell(getMessage("label.highest.mark"), true); - minMaxRow[1] = new ExcelCell((double)maxGrade, false); + minMaxRow[1] = new ExcelCell((double) maxGrade, false); summaryTab.add(minMaxRow); - + summaryTab.add(EMPTY_ROW); ExcelCell[] binSummaryRow = new ExcelCell[3]; - binSummaryRow[0] = new ExcelCell(getMessage("label.authoring.basic.list.header.mark"), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); - binSummaryRow[1] = new ExcelCell(getMessage("label.number.learners"), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); - binSummaryRow[2] = new ExcelCell(getMessage("label.percentage"), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); + binSummaryRow[0] = new ExcelCell(getMessage("label.authoring.basic.list.header.mark"), true, + ExcelCell.BORDER_STYLE_BOTTOM_THIN); + binSummaryRow[1] = new ExcelCell(getMessage("label.number.learners"), true, + ExcelCell.BORDER_STYLE_BOTTOM_THIN); + binSummaryRow[2] = new ExcelCell(getMessage("label.percentage"), true, + ExcelCell.BORDER_STYLE_BOTTOM_THIN); summaryTab.add(binSummaryRow); - float totalNumEntriesAsFloat = (float) totalNumEntries; - for ( Map.Entry entry : markSummary.entrySet() ) { + float totalNumEntriesAsFloat = (float) totalNumEntries; + for (Map.Entry entry : markSummary.entrySet()) { binSummaryRow = new ExcelCell[3]; - binSummaryRow[0] = new ExcelCell(entry.getKey(),false); - binSummaryRow[1] = new ExcelCell(entry.getValue(),false); - binSummaryRow[2] = new ExcelCell(Math.round(entry.getValue() / totalNumEntriesAsFloat * 100),false); + binSummaryRow[0] = new ExcelCell(entry.getKey(), false); + binSummaryRow[1] = new ExcelCell(entry.getValue(), false); + binSummaryRow[2] = new ExcelCell(Math.round(entry.getValue() / totalNumEntriesAsFloat * 100), + false); summaryTab.add(binSummaryRow); } summaryTab.add(EMPTY_ROW); @@ -1440,13 +1465,13 @@ ExcelCell.BORDER_STYLE_BOTTOM_THIN); int questionNumber = 1; - + for (AssessmentQuestion question : questions) { int colsNum = showUserNames ? 10 : 9; ExcelCell[] questionTitle = new ExcelCell[1]; - questionTitle[0] = new ExcelCell(getMessage("label.monitoring.question.summary.question") + " " - + questionNumber++, true); + questionTitle[0] = new ExcelCell( + getMessage("label.monitoring.question.summary.question") + " " + questionNumber++, true); questionSummaryTab.add(questionTitle); // set up the summary table data for the top of the question area. @@ -1463,7 +1488,7 @@ if (doSummaryTable) { questionSummaryTab.add(startSummaryTable(question, summaryOfAnswers, trueKey, falseKey)); } - + ArrayList questionSummaryTabTemp = new ArrayList(); //add question title row @@ -1546,9 +1571,10 @@ } else { userResultRow[count++] = new ExcelCell( AssessmentEscapeUtils.printResponsesForExcelExport(questionResult), false); - - if ( doSummaryTable ) { - summaryNACount = updateSummaryCounts(question, questionResult, summaryOfAnswers, summaryNACount); + + if (doSummaryTable) { + summaryNACount = updateSummaryCounts(question, questionResult, summaryOfAnswers, + summaryNACount); } } @@ -1576,10 +1602,11 @@ } if (doSummaryTable) { - questionSummaryTab.add(outputSummaryTable(question, summaryOfAnswers, summaryNACount, trueKey, falseKey)); + questionSummaryTab + .add(outputSummaryTable(question, summaryOfAnswers, summaryNACount, trueKey, falseKey)); questionSummaryTab.add(EMPTY_ROW); } - + // Calculating the averages ExcelCell[] averageRow; @@ -1615,7 +1642,7 @@ questionSummaryTab.addAll(questionSummaryTabTemp); questionSummaryTab.add(averageRow); questionSummaryTab.add(EMPTY_ROW); - + } } @@ -1633,11 +1660,16 @@ userSummaryTab.add(userSummaryTitle); ExcelCell[] summaryRowTitle = new ExcelCell[5]; - summaryRowTitle[0] = new ExcelCell(getMessage("label.monitoring.question.summary.question"), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); - summaryRowTitle[1] = new ExcelCell(getMessage("label.authoring.basic.list.header.type"), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); - summaryRowTitle[2] = new ExcelCell(getMessage("label.authoring.basic.penalty.factor"), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); - summaryRowTitle[3] = new ExcelCell(getMessage("label.monitoring.question.summary.default.mark"), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); - summaryRowTitle[4] = new ExcelCell(getMessage("label.monitoring.question.summary.average.mark"), true, ExcelCell.BORDER_STYLE_BOTTOM_THIN); + summaryRowTitle[0] = new ExcelCell(getMessage("label.monitoring.question.summary.question"), true, + ExcelCell.BORDER_STYLE_BOTTOM_THIN); + summaryRowTitle[1] = new ExcelCell(getMessage("label.authoring.basic.list.header.type"), true, + ExcelCell.BORDER_STYLE_BOTTOM_THIN); + summaryRowTitle[2] = new ExcelCell(getMessage("label.authoring.basic.penalty.factor"), true, + ExcelCell.BORDER_STYLE_BOTTOM_THIN); + summaryRowTitle[3] = new ExcelCell(getMessage("label.monitoring.question.summary.default.mark"), true, + ExcelCell.BORDER_STYLE_BOTTOM_THIN); + summaryRowTitle[4] = new ExcelCell(getMessage("label.monitoring.question.summary.average.mark"), true, + ExcelCell.BORDER_STYLE_BOTTOM_THIN); userSummaryTab.add(summaryRowTitle); Float totalGradesPossible = new Float(0); Float totalAverage = new Float(0); @@ -1810,30 +1842,26 @@ summaryTable = new ExcelCell[question.getOptions().size() + 1]; for (AssessmentQuestionOption option : question.getOptions()) { summaryOfAnswers.put(option.getUid(), 0); - StringBuilder bldr = new StringBuilder(getMessage("label.authoring.basic.option.answer")) - .append(" ") - .append(i + 1) - .append(" - "); - if ( question.getType() == AssessmentConstants.QUESTION_TYPE_NUMERICAL ) { - bldr.append(option.getOptionFloat()) - .append(" +- ") - .append(option.getAcceptedError()); + StringBuilder bldr = new StringBuilder(getMessage("label.authoring.basic.option.answer")).append(" ") + .append(i + 1).append(" - "); + if (question.getType() == AssessmentConstants.QUESTION_TYPE_NUMERICAL) { + bldr.append(option.getOptionFloat()).append(" +- ").append(option.getAcceptedError()); } else { bldr.append(option.getOptionString().replaceAll("\\<.*?\\>", "")); } summaryTable[i] = new ExcelCell(bldr.toString(), false); i++; } - if ( question.getType() == AssessmentConstants.QUESTION_TYPE_MULTIPLE_CHOICE ) { - summaryTable[i++] = new ExcelCell(getMessage("label.not.answered"), false); + if (question.getType() == AssessmentConstants.QUESTION_TYPE_MULTIPLE_CHOICE) { + summaryTable[i++] = new ExcelCell(getMessage("label.not.answered"), false); } else { - summaryTable[i++] = new ExcelCell(getMessage("label.other"), false); + summaryTable[i++] = new ExcelCell(getMessage("label.other"), false); } } else { summaryTable = new ExcelCell[3]; summaryTable[0] = new ExcelCell(getMessage("label.authoring.true.false.true"), false); summaryTable[1] = new ExcelCell(getMessage("label.authoring.true.false.false"), false); - summaryTable[2] = new ExcelCell(getMessage("label.not.answered"), false); + summaryTable[2] = new ExcelCell(getMessage("label.not.answered"), false); summaryOfAnswers.put(trueKey, 0); summaryOfAnswers.put(falseKey, 0); } @@ -1850,11 +1878,10 @@ if (optionAnswer.getAnswerBoolean()) { Integer currentCount = summaryOfAnswers.get(optionAnswer.getOptionUid()); if (currentCount == null) { - log.error("Assessment Export: Unable to count answer in summary, refers to an unexpected option. QuestionResult " - + questionResult.getUid() - + " OptionUid " - + optionAnswer.getOptionUid() - + " question " + question.getUid()); + log.error( + "Assessment Export: Unable to count answer in summary, refers to an unexpected option. QuestionResult " + + questionResult.getUid() + " OptionUid " + optionAnswer.getOptionUid() + + " question " + question.getUid()); } else { summaryOfAnswers.put(optionAnswer.getOptionUid(), currentCount + 1); foundOption = true; @@ -1871,12 +1898,10 @@ if (submittedUid != null) { Integer currentCount = summaryOfAnswers.get(submittedUid); if (currentCount == null) { - log.error("Assessment Export: Unable to count answer in summary, refers to an unexpected option. QuestionResult " - + questionResult.getUid() - + " submittedOptionUid " - + submittedUid - + " question " - + question.getUid()); + log.error( + "Assessment Export: Unable to count answer in summary, refers to an unexpected option. QuestionResult " + + questionResult.getUid() + " submittedOptionUid " + submittedUid + " question " + + question.getUid()); } else { summaryOfAnswers.put(submittedUid, currentCount + 1); } @@ -1897,39 +1922,38 @@ private String valueAsPercentage(Integer value, int total) { Double percentage = (double) value / total * 100; - return NumberUtil.formatLocalisedNumber(percentage, (Locale)null, 2) + "%"; - } - + return NumberUtil.formatLocalisedNumber(percentage, (Locale) null, 2) + "%"; + } + private ExcelCell[] outputSummaryTable(AssessmentQuestion question, Map summaryOfAnswers, Integer summaryNACount, Long trueKey, Long falseKey) { - ExcelCell[] summaryTable = new ExcelCell[summaryOfAnswers.size()+1]; + ExcelCell[] summaryTable = new ExcelCell[summaryOfAnswers.size() + 1]; int total = summaryNACount; - for ( int value : summaryOfAnswers.values() ) { - total += value; + for (int value : summaryOfAnswers.values()) { + total += value; } int i = 0; if (question.getType() == AssessmentConstants.QUESTION_TYPE_MULTIPLE_CHOICE || question.getType() == AssessmentConstants.QUESTION_TYPE_SHORT_ANSWER - || question.getType() == AssessmentConstants.QUESTION_TYPE_NUMERICAL ) { - for (AssessmentQuestionOption option : question.getOptions()) { - summaryTable[i] = new ExcelCell(valueAsPercentage(summaryOfAnswers.get(option.getUid()), total), false); - if ( option.getGrade() > 0 ) { - summaryTable[i].setColor(IndexedColors.GREEN); + || question.getType() == AssessmentConstants.QUESTION_TYPE_NUMERICAL) { + for (AssessmentQuestionOption option : question.getOptions()) { + summaryTable[i] = new ExcelCell(valueAsPercentage(summaryOfAnswers.get(option.getUid()), total), false); + if (option.getGrade() > 0) { + summaryTable[i].setColor(IndexedColors.GREEN); + } + i++; } - i++; - } - summaryTable[i++] = new ExcelCell(valueAsPercentage(summaryNACount, total), false); + summaryTable[i++] = new ExcelCell(valueAsPercentage(summaryNACount, total), false); } else { - summaryTable = new ExcelCell[3]; - summaryTable[0] = new ExcelCell(valueAsPercentage(summaryOfAnswers.get(trueKey), total), false); - summaryTable[1] = new ExcelCell(valueAsPercentage(summaryOfAnswers.get(falseKey), total), false); - summaryTable[2] = new ExcelCell(valueAsPercentage(summaryNACount,total), false); - summaryTable[question.getCorrectAnswer() ? 0 : 1].setColor(IndexedColors.GREEN); + summaryTable = new ExcelCell[3]; + summaryTable[0] = new ExcelCell(valueAsPercentage(summaryOfAnswers.get(trueKey), total), false); + summaryTable[1] = new ExcelCell(valueAsPercentage(summaryOfAnswers.get(falseKey), total), false); + summaryTable[2] = new ExcelCell(valueAsPercentage(summaryNACount, total), false); + summaryTable[question.getCorrectAnswer() ? 0 : 1].setColor(IndexedColors.GREEN); } return summaryTable; } - /** * Used only for excell export (for getUserSummaryData() method). */ @@ -2103,7 +2127,7 @@ user.getUserId()); AssessmentResult lastFinishedAssessmentResult = (assessmentResults.isEmpty()) ? null : assessmentResults.get(assessmentResults.size() - 1); - + //add autosave assessmentResult as well AssessmentResult lastAssessmentResult = getLastAssessmentResult(assessment.getUid(), user.getUserId()); if (lastAssessmentResult != null && lastAssessmentResult.getFinishDate() == null) { @@ -2292,7 +2316,7 @@ public boolean isGroupedActivity(long toolContentID) { return toolService.isGroupedActivity(toolContentID); } - + @Override public void auditLogStartEditingActivityInMonitor(long toolContentID) { toolService.auditLogStartEditingActivityInMonitor(toolContentID); @@ -2318,7 +2342,7 @@ String message = messageService.getMessage("event.learner.completes.attempt.body", new Object[] { userName }); eventNotificationService.notifyLessonMonitors(sessionId, message, false); } - + @Override public List getMarksArray(Long sessionId) { return assessmentUserDao.getRawUserMarksBySession(sessionId); @@ -2329,66 +2353,68 @@ return assessmentUserDao.getRawLeaderMarksByToolContentId(toolContentId); } - private LinkedHashMap getMarksSummaryForSession(List userDtos, float minGrade, float maxGrade, Integer numBuckets) { + private LinkedHashMap getMarksSummaryForSession(List userDtos, float minGrade, + float maxGrade, Integer numBuckets) { LinkedHashMap summary = new LinkedHashMap(); TreeMap inProgress = new TreeMap(); - - if ( numBuckets == null ) + + if (numBuckets == null) numBuckets = 10; - + int bucketSize = 1; - int intMinGrade = (int)Math.floor(minGrade); + int intMinGrade = (int) Math.floor(minGrade); float gradeDifference = maxGrade - minGrade; - if ( gradeDifference <= 10 ) { - for ( int i= intMinGrade; i <= (int)Math.ceil(maxGrade); i++ ) { + if (gradeDifference <= 10) { + for (int i = intMinGrade; i <= (int) Math.ceil(maxGrade); i++) { inProgress.put(i, 0); } } else { int intGradeDifference = (int) Math.ceil(gradeDifference); - bucketSize = (int) Math.ceil(intGradeDifference / numBuckets); - for ( int i=intMinGrade; i <= maxGrade; i = i+bucketSize ) { + bucketSize = (int) Math.ceil(intGradeDifference / numBuckets); + for (int i = intMinGrade; i <= maxGrade; i = i + bucketSize) { inProgress.put(i, 0); } } - + for (AssessmentUserDTO userDto : userDtos) { float grade = userDto.getGrade(); int bucketStart = intMinGrade; - int bucketStop = bucketStart+bucketSize; + int bucketStop = bucketStart + bucketSize; boolean looking = true; - while ( bucketStart <= maxGrade && looking ) { - if ( grade >= bucketStart && grade < bucketStop ) { + while (bucketStart <= maxGrade && looking) { + if (grade >= bucketStart && grade < bucketStop) { inProgress.put(bucketStart, inProgress.get(bucketStart) + 1); looking = false; } else { bucketStart = bucketStop; - bucketStop = bucketStart+bucketSize; + bucketStop = bucketStart + bucketSize; } } } - - for ( Map.Entry entry : inProgress.entrySet() ) { + + for (Map.Entry entry : inProgress.entrySet()) { String key; - if ( bucketSize == 1 ) + if (bucketSize == 1) key = entry.getKey().toString(); else { - if ( maxGrade >= entry.getKey() && maxGrade <= entry.getKey()+bucketSize-1) { - if ( (int)maxGrade == entry.getKey() ) - key = NumberUtil.formatLocalisedNumber(maxGrade, (Locale)null, 2); - else + if (maxGrade >= entry.getKey() && maxGrade <= entry.getKey() + bucketSize - 1) { + if ((int) maxGrade == entry.getKey()) + key = NumberUtil.formatLocalisedNumber(maxGrade, (Locale) null, 2); + else key = new StringBuilder().append(entry.getKey()).append(" - ") - .append(NumberUtil.formatLocalisedNumber(maxGrade, (Locale)null, 2)).toString(); + .append(NumberUtil.formatLocalisedNumber(maxGrade, (Locale) null, 2)).toString(); } else { - key = new StringBuilder().append(entry.getKey()).append(" - ").append(entry.getKey()+bucketSize-.01).toString(); + key = new StringBuilder().append(entry.getKey()).append(" - ") + .append(entry.getKey() + bucketSize - .01).toString(); } } summary.put(key, entry.getValue()); } - + return summary; } - + // ***************************************************************************** // private methods // ***************************************************************************** @@ -2620,7 +2646,7 @@ } // propagade changes to Gradebook - gradebookService.updateActivityMark(null, null, userId, session.getSessionId(), false); + gradebookService.removeActivityMark(userId, session.getSessionId()); assessmentUserDao.removeObject(AssessmentUser.class, user.getUid()); } @@ -2692,14 +2718,14 @@ public List getToolOutputs(String name, Long toolContentId) { return assessmentOutputFactory.getToolOutputs(name, this, toolContentId); } - + @Override public List getConfidenceLevels(Long toolSessionId) { List confidenceLevelDtos = new ArrayList(); if (toolSessionId == null) { return confidenceLevelDtos; } - + Assessment assessment = getAssessmentBySessionId(toolSessionId); //in case Assessment is leader aware return all leaders confidences, otherwise - confidences from the users from the same group as requestor List assessmentResultsAndPortraits = assessment.isUseSelectLeaderToolOuput() @@ -2711,18 +2737,19 @@ Long portraitUuid = assessmentResultsAndPortraitIter[1] == null ? null : ((Number) assessmentResultsAndPortraitIter[1]).longValue(); Long userId = assessmentResult.getUser().getUserId(); - + //fill in question's and user answer's hashes for (AssessmentQuestionResult questionResult : assessmentResult.getQuestionResults()) { AssessmentQuestion question = questionResult.getAssessmentQuestion(); - + List answers = new LinkedList(); - + if (question.getType() == AssessmentConstants.QUESTION_TYPE_MULTIPLE_CHOICE) { - + for (AssessmentQuestionOption option : question.getOptions()) { for (AssessmentOptionAnswer optionAnswer : questionResult.getOptionAnswers()) { - if (optionAnswer.getAnswerBoolean() && (optionAnswer.getOptionUid().equals(option.getUid()))) { + if (optionAnswer.getAnswerBoolean() + && (optionAnswer.getOptionUid().equals(option.getUid()))) { answers.add(option.getOptionString()); } } @@ -2740,28 +2767,28 @@ if (questionResult.getAnswerString() != null) { answers.add("" + questionResult.getAnswerBoolean()); } - + } else if (question.getType() == AssessmentConstants.QUESTION_TYPE_ESSAY) { answers.add(questionResult.getAnswerString()); } else if (question.getType() == AssessmentConstants.QUESTION_TYPE_ORDERING) { } else if (question.getType() == AssessmentConstants.QUESTION_TYPE_MARK_HEDGING) { - + } - + for (String answer : answers) { ConfidenceLevelDTO confidenceLevelDto = new ConfidenceLevelDTO(); confidenceLevelDto.setUserId(userId.intValue()); confidenceLevelDto.setPortraitUuid(portraitUuid); confidenceLevelDto.setLevel(questionResult.getConfidenceLevel()); confidenceLevelDto.setQuestion(question.getQuestion()); confidenceLevelDto.setAnswer(answer); - + confidenceLevelDtos.add(confidenceLevelDto); } } - + } return confidenceLevelDtos; Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java =================================================================== diff -u -r045ebfd1d11d9ed0a1f81a00abb1a2ea373e8d93 -rd39b9df30d44b56c287b8a1d4409407e60692dc4 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision 045ebfd1d11d9ed0a1f81a00abb1a2ea373e8d93) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision d39b9df30d44b56c287b8a1d4409407e60692dc4) @@ -305,7 +305,7 @@ userId = message.getCreatedBy().getUserId(); loginName = message.getCreatedBy().getLoginName(); } - if ( message.getToolSession() != null && message.getToolSession().getForum() != null ) { + if (message.getToolSession() != null && message.getToolSession().getForum() != null) { toolContentId = message.getToolSession().getForum().getContentId(); } if (hideFlag) { @@ -965,7 +965,7 @@ user.setSessionFinished(false); forumUserDao.save(user); - gradebookService.updateActivityMark(null, null, userId, session.getSessionId(), false); + gradebookService.removeActivityMark(userId, session.getSessionId()); } } } @@ -1198,7 +1198,7 @@ public List getToolOutputs(String name, Long toolContentId) { return new ArrayList<>(); } - + @Override public List getConfidenceLevels(Long toolSessionId) { return null; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McService.java =================================================================== diff -u -rb26f90eccf164c7058201360d2ca771adcfb597a -rd39b9df30d44b56c287b8a1d4409407e60692dc4 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McService.java (.../McService.java) (revision b26f90eccf164c7058201360d2ca771adcfb597a) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McService.java (.../McService.java) (revision d39b9df30d44b56c287b8a1d4409407e60692dc4) @@ -202,7 +202,7 @@ leaderAttempt.isAttemptCorrect(), leaderAttempt.getConfidenceLevel()); mcUsrAttemptDAO.saveMcUsrAttempt(userAttempt); - // if it's been changed by the leader + // if it's been changed by the leader } else if (leaderAttempt.getAttemptTime().compareTo(userAttempt.getAttemptTime()) != 0) { userAttempt.setMcOptionsContent(leaderAttempt.getMcOptionsContent()); userAttempt.setConfidenceLevel(leaderAttempt.getConfidenceLevel()); @@ -251,7 +251,7 @@ //update questions' hash String newHash = mcQueContent.getQuestion() == null ? null : HashUtil.sha1(mcQueContent.getQuestion()); mcQueContent.setQuestionHash(newHash); - + mcQueContentDAO.saveOrUpdateMcQueContent(mcQueContent); } @@ -380,20 +380,21 @@ public McQueUsr getMcUserByUID(Long uid) { return mcUserDAO.getMcUserByUID(uid); } - + @Override public McQueUsr getMcUserByContentId(Long userId, Long contentId) { return mcUserDAO.getMcUserByContentId(userId, contentId); } @Override public Long getPortraitId(Long userId) { - if ( userId != null ) { + if (userId != null) { User user = (User) userManagementService.findById(User.class, userId.intValue()); return user != null ? user.getPortraitUuid() : null; } return null; } + @Override public List getPagedUsersBySession(Long sessionId, int page, int size, String sortBy, String sortOrder, String searchString) { @@ -473,7 +474,7 @@ e); } } - + @Override public int getAttemptsCountPerOption(Long optionUid) { return mcUsrAttemptDAO.getAttemptsCountPerOption(optionUid); @@ -581,7 +582,8 @@ for (McUsrAttempt attempt : finalizedUserAttempts) { Integer displayOrder = attempt.getMcQueContent().getDisplayOrder(); int arrayIndex = (displayOrder != null) && (displayOrder.intValue() > 0) - ? displayOrder.intValue() - 1 : 1; + ? displayOrder.intValue() - 1 + : 1; if (userMarks[arrayIndex] == null) { // We get the mark for the attempt if the answer is correct and we don't allow @@ -640,7 +642,7 @@ public McUsrAttempt getUserAttemptByQuestion(Long queUsrUid, Long mcQueContentId) throws McApplicationException { return mcUsrAttemptDAO.getUserAttemptByQuestion(queUsrUid, mcQueContentId); } - + @Override public List getLearnerMarksByContentId(Long toolContentId) { return mcUsrAttemptDAO.getLearnerMarksByContentId(toolContentId); @@ -761,9 +763,9 @@ } else { String error = new StringBuilder( "Attempting to update the mark for a non-leader. Cannot update. Session ") - .append(mcSession.getSession_name()).append(":").append(mcSession.getMcSessionId()) - .append(" user ").append(selectedUser.getUsername()).append(":") - .append(selectedUser.getQueUsrId()).toString(); + .append(mcSession.getSession_name()).append(":").append(mcSession.getMcSessionId()) + .append(" user ").append(selectedUser.getUsername()).append(":") + .append(selectedUser.getQueUsrId()).toString(); logger.warn(error); } } else { @@ -772,7 +774,7 @@ } for (McUsrAttempt attempt : userAttempts) { - + attempt.setMark(newMark); mcUsrAttemptDAO.saveMcUsrAttempt(attempt); @@ -782,7 +784,7 @@ updateMcQueUsr(user); // propagate changes to Gradebook - gradebookService.updateActivityMark(new Double(totalMark), null, user.getQueUsrId().intValue(), + gradebookService.updateActivityMark(new Double(totalMark), null, user.getQueUsrId().intValue(), mcSession.getMcSessionId(), false); // record mark change with audit service @@ -919,7 +921,7 @@ if (newTotalMark != oldTotalMark) { user.setLastAttemptTotalMark(newTotalMark); updateMcQueUsr(user); - + gradebookService.updateActivityMark(new Double(newTotalMark), null, user.getQueUsrId().intValue(), toolSessionId, false); } @@ -1318,7 +1320,7 @@ mcUserDAO.removeMcUser(user); - gradebookService.updateActivityMark(null, null, userId, session.getMcSessionId(), false); + gradebookService.removeActivityMark(userId, session.getMcSessionId()); } } } @@ -1527,7 +1529,7 @@ public ToolOutput getToolOutput(String name, Long toolSessionId, Long learnerId) { return mcOutputFactory.getToolOutput(name, this, toolSessionId, learnerId); } - + @Override public List getToolOutputs(String name, Long toolContentId) { return mcOutputFactory.getToolOutputs(name, this, toolContentId); @@ -1539,9 +1541,9 @@ if (toolSessionId == null) { return confidenceLevelDtos; } - + McContent content = getMcSessionById(toolSessionId).getMcContent(); - + //in case McContent is leader aware return all leaders confidences, otherwise - confidences from the users from the same group as requestor List userAttemptsAndPortraits = content.isUseSelectLeaderToolOuput() ? mcUsrAttemptDAO.getLeadersFinalizedAttemptsByContentId(content.getMcContentId()) @@ -1623,10 +1625,10 @@ public boolean isGroupedActivity(long toolContentID) { return toolService.isGroupedActivity(toolContentID); } - + @Override public void auditLogStartEditingActivityInMonitor(long toolContentID) { - toolService.auditLogStartEditingActivityInMonitor(toolContentID); + toolService.auditLogStartEditingActivityInMonitor(toolContentID); } @Override @@ -1735,8 +1737,8 @@ new Integer(user.getQueUsrId().toString())); if (notebookEntry != null) { - ReflectionDTO reflectionDTO = new ReflectionDTO(user, - mcSession.getMcSessionId().toString(), notebookEntry); + ReflectionDTO reflectionDTO = new ReflectionDTO(user, mcSession.getMcSessionId().toString(), + notebookEntry); reflectionsContainerDTO.add(reflectionDTO); } } @@ -1847,15 +1849,21 @@ public LeaderResultsDTO getLeaderResultsDTOForLeaders(Long contentId) { LeaderResultsDTO newDto = new LeaderResultsDTO(contentId); Object[] markStats = mcUserDAO.getStatsMarksForLeaders(contentId); - if ( markStats != null ) { - newDto.setMinMark(markStats[0] != null ? NumberUtil.formatLocalisedNumber((Float)markStats[0], (Locale)null, 2) : "0.00"); - newDto.setAvgMark(markStats[1] != null ? NumberUtil.formatLocalisedNumber((Float)markStats[1], (Locale)null, 2) : "0.00"); - newDto.setMaxMark(markStats[2] != null ? NumberUtil.formatLocalisedNumber((Float)markStats[2], (Locale)null, 2) : "0.00"); - newDto.setNumberGroupsLeaderFinished((Integer)markStats[3]); + if (markStats != null) { + newDto.setMinMark( + markStats[0] != null ? NumberUtil.formatLocalisedNumber((Float) markStats[0], (Locale) null, 2) + : "0.00"); + newDto.setAvgMark( + markStats[1] != null ? NumberUtil.formatLocalisedNumber((Float) markStats[1], (Locale) null, 2) + : "0.00"); + newDto.setMaxMark( + markStats[2] != null ? NumberUtil.formatLocalisedNumber((Float) markStats[2], (Locale) null, 2) + : "0.00"); + newDto.setNumberGroupsLeaderFinished((Integer) markStats[3]); } return newDto; } - + @SuppressWarnings("unchecked") @Override public List getSessionDtos(Long contentId, boolean includeStatistics) { @@ -1876,11 +1884,14 @@ Object[] markStats = mcUserDAO.getStatsMarksBySession(session.getMcSessionId()); if (markStats != null) { sessionDto.setMinMark(markStats[0] != null - ? NumberUtil.formatLocalisedNumber((Float) markStats[0], (Locale) null, 2) : "0.00"); + ? NumberUtil.formatLocalisedNumber((Float) markStats[0], (Locale) null, 2) + : "0.00"); sessionDto.setAvgMark(markStats[1] != null - ? NumberUtil.formatLocalisedNumber((Float) markStats[1], (Locale) null, 2) : "0.00"); + ? NumberUtil.formatLocalisedNumber((Float) markStats[1], (Locale) null, 2) + : "0.00"); sessionDto.setMaxMark(markStats[2] != null - ? NumberUtil.formatLocalisedNumber((Float) markStats[2], (Locale) null, 2) : "0.00"); + ? NumberUtil.formatLocalisedNumber((Float) markStats[2], (Locale) null, 2) + : "0.00"); } } @@ -1889,7 +1900,7 @@ } return sessionDtos; } - + @Override public List getMarksArray(Long sessionId) { return mcUserDAO.getRawUserMarksBySession(sessionId); Index: lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/SubmitFilesService.java =================================================================== diff -u -r045ebfd1d11d9ed0a1f81a00abb1a2ea373e8d93 -rd39b9df30d44b56c287b8a1d4409407e60692dc4 --- lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/SubmitFilesService.java (.../SubmitFilesService.java) (revision 045ebfd1d11d9ed0a1f81a00abb1a2ea373e8d93) +++ lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/SubmitFilesService.java (.../SubmitFilesService.java) (revision d39b9df30d44b56c287b8a1d4409407e60692dc4) @@ -21,8 +21,6 @@ * **************************************************************** */ - - package org.lamsfoundation.lams.tool.sbmt.service; import java.io.FileNotFoundException; @@ -254,38 +252,36 @@ if (entry != null) { submitFilesContentDAO.delete(entry); } - gradebookService.updateActivityMark(null, null, user.getUserID(), session.getSessionID(), false); + gradebookService.removeActivityMark(user.getUserID(), session.getSessionID()); submitUserDAO.delete(user); } } } - - - + @Override public void copyLearnerContent(SubmitUser fromUser, SubmitUser toUser) throws ToolException { - List leadersubmissions = submissionDetailsDAO.getBySessionAndLearner(fromUser.getSessionID(),fromUser.getUserID()); + List leadersubmissions = submissionDetailsDAO.getBySessionAndLearner(fromUser.getSessionID(), + fromUser.getUserID()); for (SubmissionDetails leadersubmission : leadersubmissions) { - if(leadersubmission.getSubmitFileSession().getSessionID().equals(toUser.getSessionID())){ + if (leadersubmission.getSubmitFileSession().getSessionID().equals(toUser.getSessionID())) { SubmissionDetails usersubmission = new SubmissionDetails(); - usersubmission.setLearner(toUser); - usersubmission.setDateOfSubmission(new Date()); - usersubmission.setFileDescription(leadersubmission.getFileDescription()); - usersubmission.setFilePath(leadersubmission.getFilePath()); - usersubmission.setSubmitFileSession(leadersubmission.getSubmitFileSession()); - usersubmission.setVersionID(leadersubmission.getVersionID()); - SubmitFilesReport report1 = new SubmitFilesReport(); - usersubmission.setReport(report1); - usersubmission.setRemoved(leadersubmission.isRemoved()); - usersubmission.setUuid(leadersubmission.getUuid()); - submissionDetailsDAO.save(usersubmission); + usersubmission.setLearner(toUser); + usersubmission.setDateOfSubmission(new Date()); + usersubmission.setFileDescription(leadersubmission.getFileDescription()); + usersubmission.setFilePath(leadersubmission.getFilePath()); + usersubmission.setSubmitFileSession(leadersubmission.getSubmitFileSession()); + usersubmission.setVersionID(leadersubmission.getVersionID()); + SubmitFilesReport report1 = new SubmitFilesReport(); + usersubmission.setReport(report1); + usersubmission.setRemoved(leadersubmission.isRemoved()); + usersubmission.setUuid(leadersubmission.getUuid()); + submissionDetailsDAO.save(usersubmission); } } } - @Override public List getSessionsByContentID(Long toolContentID) { return submitFilesSessionDAO.getSubmitFilesSessionByContentID(toolContentID); @@ -558,12 +554,12 @@ public ToolOutput getToolOutput(String name, Long toolSessionId, Long learnerId) { return getSubmitFilesOutputFactory().getToolOutput(name, this, toolSessionId, learnerId); } - + @Override public List getToolOutputs(String name, Long toolContentId) { return new ArrayList(); } - + @Override public List getConfidenceLevels(Long toolSessionId) { return null; @@ -649,7 +645,8 @@ * java.lang.Long) */ @Override - public List getFilesUploadedByUser(Integer userID, Long sessionID, Locale currentLocale, boolean includeRemovedFiles) { + public List getFilesUploadedByUser(Integer userID, Long sessionID, Locale currentLocale, + boolean includeRemovedFiles) { List list = submissionDetailsDAO.getBySessionAndLearner(sessionID, userID); SortedSet details = new TreeSet(this.new FileDtoComparator()); if (list == null) { @@ -658,7 +655,7 @@ NumberFormat numberFormat = currentLocale != null ? NumberFormat.getInstance(currentLocale) : null; for (SubmissionDetails submissionDetails : list) { - if ( includeRemovedFiles || ! submissionDetails.isRemoved() ) { + if (includeRemovedFiles || !submissionDetails.isRemoved()) { FileDetailsDTO detailDto = new FileDetailsDTO(submissionDetails, numberFormat); details.add(detailDto); } @@ -727,8 +724,7 @@ @Override public void updateMarks(Long reportID, Float marks, String comments, FormFile markFile, Long sessionID) throws InvalidParameterException, RepositoryCheckedException { - - + SubmitFilesSession session = getSessionById(sessionID); SubmitFilesContent content = session.getContent(); if (content.isUseSelectLeaderToolOuput()) { @@ -764,41 +760,40 @@ submitFilesReportDAO.update(report); } - + } + } else { + IToolContentHandler toolContentHandler = getSbmtToolContentHandler(); + SubmitFilesReport report = submitFilesReportDAO.getReportByID(reportID); + if (report != null) { + report.setComments(comments); + report.setMarks(marks); + + // If there is a new file, delete the existing and add the mark file + if ((markFile != null) && !StringUtils.isEmpty(markFile.getFileName())) { + + // Delete the existing + if (report.getMarkFileUUID() != null) { + toolContentHandler.deleteFile(report.getMarkFileUUID()); + report.setMarkFileName(null); + report.setMarkFileUUID(null); + report.setMarkFileVersionID(null); + } + + // Add the new file + NodeKey nodeKey = this.processFile(markFile); + // NodeKey nodeKey = toolContentHandler.uploadFile(marksFileInputStream, marksFileName, null, + // IToolContentHandler.TYPE_ONLINE); + + report.setMarkFileName(markFile.getFileName()); + report.setMarkFileUUID(nodeKey.getUuid()); + report.setMarkFileVersionID(nodeKey.getVersion()); + } + + submitFilesReportDAO.update(report); + } } - else{ - IToolContentHandler toolContentHandler = getSbmtToolContentHandler(); - SubmitFilesReport report = submitFilesReportDAO.getReportByID(reportID); - if (report != null) { - report.setComments(comments); - report.setMarks(marks); - - // If there is a new file, delete the existing and add the mark file - if ((markFile != null) && !StringUtils.isEmpty(markFile.getFileName())) { - - // Delete the existing - if (report.getMarkFileUUID() != null) { - toolContentHandler.deleteFile(report.getMarkFileUUID()); - report.setMarkFileName(null); - report.setMarkFileUUID(null); - report.setMarkFileVersionID(null); - } - - // Add the new file - NodeKey nodeKey = this.processFile(markFile); - // NodeKey nodeKey = toolContentHandler.uploadFile(marksFileInputStream, marksFileName, null, - // IToolContentHandler.TYPE_ONLINE); - - report.setMarkFileName(markFile.getFileName()); - report.setMarkFileUUID(nodeKey.getUuid()); - report.setMarkFileVersionID(nodeKey.getVersion()); - } - - submitFilesReportDAO.update(report); - } - } } @@ -814,16 +809,15 @@ } } - @Override public void removeLearnerFile(Long detailID, UserDTO monitor) { SubmissionDetails detail = submissionDetailsDAO.getSubmissionDetailsByID(detailID); if (detail != null) { - if(monitor != null){ + if (monitor != null) { - auditRemoveRestore(monitor, detail, "audit.file.delete"); + auditRemoveRestore(monitor, detail, "audit.file.delete"); } detail.setRemoved(true); @@ -833,13 +827,13 @@ @Override public void restoreLearnerFile(Long detailID, UserDTO monitor) { - + SubmissionDetails detail = submissionDetailsDAO.getSubmissionDetailsByID(detailID); if (detail != null) { - - auditRemoveRestore(monitor, detail,"audit.file.restore"); - + + auditRemoveRestore(monitor, detail, "audit.file.restore"); + detail.setRemoved(false); submissionDetailsDAO.update(detail); } @@ -906,7 +900,7 @@ details = (SubmissionDetails) iter.next(); report = details.getReport(); report.setDateMarksReleased(new Date()); - if (notifyLearnersOnMarkRelease && ! details.isRemoved()) { + if (notifyLearnersOnMarkRelease && !details.isRemoved()) { SubmitUser user = details.getLearner(); StringBuilder notificationMessage = notificationMessages.get(user.getUserID()); if (notificationMessage == null) { @@ -950,15 +944,15 @@ SubmitUser learner = submitUserDAO.getLearner(sessionID, userID); learner.setFinished(true); submitUserDAO.saveOrUpdateUser(learner); - + SubmitFilesContent content = getSessionById(sessionID).getContent(); - if(content.isUseSelectLeaderToolOuput()){ - SubmitFilesSession sbmtFilesSession = submitFilesSessionDAO.getSessionByID(sessionID); - if(sbmtFilesSession.getGroupLeader().getUserID().equals(learner.getUserID())){ - sbmtFilesSession.setGroupLeader(learner); - submitFilesSessionDAO.insertOrUpdate(sbmtFilesSession); - } + if (content.isUseSelectLeaderToolOuput()) { + SubmitFilesSession sbmtFilesSession = submitFilesSessionDAO.getSessionByID(sessionID); + if (sbmtFilesSession.getGroupLeader().getUserID().equals(learner.getUserID())) { + sbmtFilesSession.setGroupLeader(learner); + submitFilesSessionDAO.insertOrUpdate(sbmtFilesSession); + } } } @@ -976,7 +970,7 @@ if (detailsList != null) { Float totalMark = null; for (SubmissionDetails details : detailsList) { - if ( ! details.isRemoved() ) { + if (!details.isRemoved()) { SubmitFilesReport report = details.getReport(); if (report != null) { if (totalMark == null) { @@ -1058,10 +1052,10 @@ public boolean isGroupedActivity(long toolContentID) { return toolService.isGroupedActivity(toolContentID); } - + @Override public void auditLogStartEditingActivityInMonitor(long toolContentID) { - toolService.auditLogStartEditingActivityInMonitor(toolContentID); + toolService.auditLogStartEditingActivityInMonitor(toolContentID); } @Override @@ -1110,8 +1104,7 @@ public List getStatisticsBySession(final Long contentId) { return submitUserDAO.getStatisticsBySession(contentId); } - - + @Override public List getLeaderStatisticsBySession(final Long contentId) { return submitUserDAO.getLeaderStatisticsBySession(contentId); @@ -1265,10 +1258,9 @@ public void setCoreNotebookService(ICoreNotebookService coreNotebookService) { this.coreNotebookService = coreNotebookService; } - - + public IUserManagementService getUserManagementService() { - return userManagementService; + return userManagementService; } public void setUserManagementService(IUserManagementService userManagementService) { @@ -1294,11 +1286,11 @@ } public ILogEventService getLogEventService() { - return logEventService; + return logEventService; } public void setLogEventService(ILogEventService logEventService) { - this.logEventService = logEventService; + this.logEventService = logEventService; } public void setGradebookService(IGradebookService gradebookService) { @@ -1318,7 +1310,7 @@ public void setSubmitFilesOutputFactory(SubmitFilesOutputFactory submitFilesOutputFactory) { this.submitFilesOutputFactory = submitFilesOutputFactory; } - + @Override public ToolCompletionStatus getCompletionStatus(Long learnerId, Long toolSessionId) { SubmitUser learner = getSessionUser(toolSessionId, learnerId.intValue()); @@ -1329,16 +1321,16 @@ Date startDate = null; Date endDate = null; List list = submissionDetailsDAO.getBySessionAndLearner(toolSessionId, learnerId.intValue()); - for ( SubmissionDetails detail : list ) { + for (SubmissionDetails detail : list) { Date newDate = detail.getDateOfSubmission(); - if ( newDate != null ) { - if ( startDate == null || newDate.before(startDate) ) + if (newDate != null) { + if (startDate == null || newDate.before(startDate)) startDate = newDate; - if ( endDate == null || newDate.after(endDate) ) + if (endDate == null || newDate.after(endDate)) endDate = newDate; } } - + if (learner.isFinished()) return new ToolCompletionStatus(ToolCompletionStatus.ACTIVITY_COMPLETED, startDate, endDate); else @@ -1386,8 +1378,7 @@ saveOrUpdateContent(content); } - - + @Override public SubmitUser checkLeaderSelectToolForSessionLeader(SubmitUser user, Long toolSessionId) { if ((user == null) || (toolSessionId == null)) { @@ -1402,15 +1393,15 @@ if (leader == null) { Long leaderUserId = toolService.getLeaderUserId(toolSessionId, user.getUserID().intValue()); if (leaderUserId != null) { - leader = submitUserDAO.getLearner(toolSessionId, (Integer)leaderUserId.intValue()); + leader = submitUserDAO.getLearner(toolSessionId, (Integer) leaderUserId.intValue()); // create new user in a DB if (leader == null) { SubmitFilesService.log.debug("creating new user with userId: " + leaderUserId); User leaderDto = (User) getUserManagementService().findById(User.class, leaderUserId.intValue()); String userName = leaderDto.getLogin(); String fullName = leaderDto.getFirstName() + " " + leaderDto.getLastName(); - // leader = new SubmitUser(leaderDto.getUserDTO(), submitFileSession); - leader = new SubmitUser(); + // leader = new SubmitUser(leaderDto.getUserDTO(), submitFileSession); + leader = new SubmitUser(); leader.setLogin(leaderDto.getLogin()); leader.setFirstName(leaderDto.getFirstName()); leader.setLastName(leaderDto.getLastName()); @@ -1427,7 +1418,7 @@ return leader; } - + @Override public void createUser(SubmitUser submitUser) { // make sure the user was not created in the meantime @@ -1440,8 +1431,7 @@ // Sometimes session save is earlier that user save in another thread, leading to an exception. submitUserDAO.insertOrUpdate(user); } - - + @Override public boolean isUserGroupLeader(SubmitUser user, Long toolSessionId) { @@ -1450,9 +1440,5 @@ return (groupLeader != null) && user.getUserID().equals(groupLeader.getUserID()); } - - - - } \ No newline at end of file Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java =================================================================== diff -u -rb26f90eccf164c7058201360d2ca771adcfb597a -rd39b9df30d44b56c287b8a1d4409407e60692dc4 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision b26f90eccf164c7058201360d2ca771adcfb597a) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision d39b9df30d44b56c287b8a1d4409407e60692dc4) @@ -203,7 +203,7 @@ public ScratchieUser getUserByIDAndSession(Long userId, Long sessionId) { return scratchieUserDao.getUserByUserIDAndSessionID(userId, sessionId); } - + @Override public int countUsersByContentId(Long contentId) { return scratchieUserDao.countUsersByContentId(contentId); @@ -230,7 +230,7 @@ public void saveOrUpdateScratchieConfigItem(ScratchieConfigItem item) { scratchieConfigItemDao.saveOrUpdate(item); } - + @Override public String[] getPresetMarks(Scratchie scratchie) { String presetMarks = ""; @@ -242,10 +242,10 @@ presetMarks = defaultPresetMarks.getConfigValue(); } } - + return presetMarks.split(","); } - + @Override public int getMaxPossibleScore(Scratchie scratchie) { int itemsNumber = scratchie.getScratchieItems().size(); @@ -260,22 +260,22 @@ } return maxPossibleScore; - } + } @Override public void deleteScratchieItem(Long uid) { scratchieItemDao.removeObject(ScratchieItem.class, uid); } - + @Override public void populateItemsWithConfidenceLevels(Long userId, Long toolSessionId, Integer confidenceLevelsActivityUiid, Collection items) { List confidenceLevelDtos = toolService .getConfidenceLevelsByActivity(confidenceLevelsActivityUiid, userId.intValue(), toolSessionId); - + //populate Scratchie items with confidence levels for (ScratchieItem item : items) { - + //init answers' confidenceLevelDtos list for (ScratchieAnswer answer : (Set) item.getAnswers()) { LinkedList confidenceLevelDtosTemp = new LinkedList(); @@ -284,7 +284,7 @@ //Assessment (similar with Scratchie) adds '\n' at the end of question, MCQ - '\r\n' String question = item.getDescription() == null ? "" : item.getDescription().replaceAll("(\\r|\\n)", ""); - + //find according confidenceLevelDto for (ConfidenceLevelDTO confidenceLevelDto : confidenceLevelDtos) { if (question.equals(confidenceLevelDto.getQuestion().replaceAll("(\\r|\\n)", ""))) { @@ -296,13 +296,13 @@ answer.getConfidenceLevelDtos().add(confidenceLevelDto); } } - + } } - + } } - + @Override public Set getPrecedingConfidenceLevelsActivities(Long toolContentId) { return toolService.getPrecedingConfidenceLevelsActivities(toolContentId); @@ -365,7 +365,7 @@ notebookEntry = getEntry(toolSessionId, CoreNotebookConstants.NOTEBOOK_TOOL, ScratchieConstants.TOOL_SIGNATURE, groupLeader.getUserId().intValue()); } - + // return whether it's waiting for the leader to submit notebook return isReflectOnActivity && (notebookEntry == null); } @@ -392,10 +392,11 @@ // record mark change with audit service Long toolContentId = null; if (session.getScratchie() != null) { - toolContentId = session.getScratchie().getContentId(); - } + toolContentId = session.getScratchie().getContentId(); + } - logEventService.logMarkChange(user.getUserId(), user.getLoginName(), toolContentId, "" + oldMark, "" + newMark); + logEventService.logMarkChange(user.getUserId(), user.getLoginName(), toolContentId, "" + oldMark, + "" + newMark); } } @@ -412,7 +413,7 @@ public ScratchieSession getScratchieSessionBySessionId(Long sessionId) { return scratchieSessionDao.getSessionBySessionId(sessionId); } - + @Override public int countSessionsByContentId(Long toolContentId) { return scratchieSessionDao.getByContentId(toolContentId).size(); @@ -640,7 +641,7 @@ public List getUsersBySession(Long toolSessionId) { return scratchieUserDao.getBySessionID(toolSessionId); } - + @Override public ScratchieUser getUserByUserIDAndContentID(Long userId, Long contentId) { return scratchieUserDao.getUserByUserIDAndContentID(userId, contentId); @@ -652,7 +653,8 @@ } @Override - /* If isIncludeOnlyLeaders then include the portrait ids needed for monitoring. If false then it + /* + * If isIncludeOnlyLeaders then include the portrait ids needed for monitoring. If false then it * is probably the export and that doesn't need portraits. */ public List getMonitoringSummary(Long contentId, boolean isIncludeOnlyLeaders) { @@ -912,7 +914,8 @@ } @Override - public List getBurningQuestionDtos(Scratchie scratchie, Long sessionId, boolean includeEmptyItems) { + public List getBurningQuestionDtos(Scratchie scratchie, Long sessionId, + boolean includeEmptyItems) { Set items = new TreeSet<>(new ScratchieItemComparator()); items.addAll(scratchie.getScratchieItems()); @@ -935,7 +938,7 @@ burningQuestionDtosOfSpecifiedItem.add(burningQuestionDto); } } - + //skip empty items if required if (!burningQuestionDtosOfSpecifiedItem.isEmpty() || includeEmptyItems) { BurningQuestionItemDTO burningQuestionItemDto = new BurningQuestionItemDTO(); @@ -972,8 +975,8 @@ String escapedSessionName = StringEscapeUtils.escapeJavaScript(burningQuestionDto.getSessionName()); burningQuestionDto.setSessionName(escapedSessionName); - String escapedBurningQuestion = StringEscapeUtils.escapeJavaScript( - burningQuestionDto.getBurningQuestion().getQuestion()); + String escapedBurningQuestion = StringEscapeUtils + .escapeJavaScript(burningQuestionDto.getBurningQuestion().getQuestion()); burningQuestionDto.setEscapedBurningQuestion(escapedBurningQuestion); } } @@ -2048,7 +2051,7 @@ scratchieUserDao.removeObject(ScratchieUser.class, user.getUid()); - gradebookService.updateActivityMark(null, null, userId, session.getSessionId(), false); + gradebookService.removeActivityMark(userId, session.getSessionId()); } } } @@ -2117,7 +2120,7 @@ public List getToolOutputs(String name, Long toolContentId) { return new ArrayList<>(); } - + @Override public List getConfidenceLevels(Long toolSessionId) { return null;