Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/model/McSession.java =================================================================== diff -u -r1ee503e3d0e0228ea8a45025fddf15d9623c0377 -rb0523a63bf120c687d9b50748f4221f8d54aefea --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/model/McSession.java (.../McSession.java) (revision 1ee503e3d0e0228ea8a45025fddf15d9623c0377) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/model/McSession.java (.../McSession.java) (revision b0523a63bf120c687d9b50748f4221f8d54aefea) @@ -23,9 +23,9 @@ package org.lamsfoundation.lams.tool.mc.model; import java.io.Serializable; +import java.util.ArrayList; import java.util.Date; -import java.util.HashSet; -import java.util.Set; +import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -83,51 +83,51 @@ private org.lamsfoundation.lams.tool.mc.model.McContent mcContent; @OneToMany(mappedBy = "mcSession", cascade = CascadeType.ALL, orphanRemoval = true) - private Set mcQueUsers; + private List mcQueUsers; @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn(name = "mc_group_leader_uid") private McQueUsr groupLeader; /** full constructor */ public McSession(Long mcSessionId, Date sessionStartDate, Date sessionEndDate, String sessionStatus, - org.lamsfoundation.lams.tool.mc.model.McContent mcContent, Set mcQueUsers) { + org.lamsfoundation.lams.tool.mc.model.McContent mcContent, List mcQueUsers) { this.mcSessionId = mcSessionId; this.sessionStartDate = sessionStartDate; this.sessionEndDate = sessionEndDate; this.sessionStatus = sessionStatus; this.mcContent = mcContent; - this.mcQueUsers = mcQueUsers != null ? mcQueUsers : new HashSet(); + this.mcQueUsers = mcQueUsers != null ? mcQueUsers : new ArrayList<>(); } public McSession(Long mcSessionId, Date sessionStartDate, String sessionStatus, String session_name, - org.lamsfoundation.lams.tool.mc.model.McContent mcContent, Set mcQueUsers) { + org.lamsfoundation.lams.tool.mc.model.McContent mcContent, List mcQueUsers) { this.mcSessionId = mcSessionId; this.sessionStartDate = sessionStartDate; this.sessionStatus = sessionStatus; this.session_name = session_name; this.mcContent = mcContent; - this.mcQueUsers = mcQueUsers != null ? mcQueUsers : new HashSet(); + this.mcQueUsers = mcQueUsers != null ? mcQueUsers : new ArrayList<>(); } public McSession(Long mcSessionId, Date sessionStartDate, String sessionStatus, - org.lamsfoundation.lams.tool.mc.model.McContent mcContent, Set mcQueUsers) { + org.lamsfoundation.lams.tool.mc.model.McContent mcContent, List mcQueUsers) { this.mcSessionId = mcSessionId; this.sessionStartDate = sessionStartDate; this.sessionStatus = sessionStatus; this.mcContent = mcContent; - this.mcQueUsers = mcQueUsers != null ? mcQueUsers : new HashSet(); + this.mcQueUsers = mcQueUsers != null ? mcQueUsers : new ArrayList<>(); } /** default constructor */ public McSession() { - this.mcQueUsers = new HashSet(); + this.mcQueUsers = new ArrayList<>(); } /** minimal constructor */ - public McSession(Long mcSessionId, Set mcQueUsers) { + public McSession(Long mcSessionId, List mcQueUsers) { this.mcSessionId = mcSessionId; - this.mcQueUsers = mcQueUsers != null ? mcQueUsers : new HashSet(); + this.mcQueUsers = mcQueUsers != null ? mcQueUsers : new ArrayList<>(); } public Long getUid() { @@ -208,15 +208,15 @@ * @return Returns the mcQueUsers. */ - public Set getMcQueUsers() { + public List getMcQueUsers() { return this.mcQueUsers; } /** * @param mcQueUsers * The mcQueUsers to set. */ - public void setMcQueUsers(Set mcQueUsers) { + public void setMcQueUsers(List mcQueUsers) { this.mcQueUsers = mcQueUsers; } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McService.java =================================================================== diff -u -r18ffef3eac77674c112b895ca5bb1963a399c340 -rb0523a63bf120c687d9b50748f4221f8d54aefea --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McService.java (.../McService.java) (revision 18ffef3eac77674c112b895ca5bb1963a399c340) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McService.java (.../McService.java) (revision b0523a63bf120c687d9b50748f4221f8d54aefea) @@ -294,8 +294,8 @@ // persist candidate answers List optionDTOs = questionDTO.getOptionDtos(); Set oldOptions = question.getMcOptionsContents(); - Set newOptions = new HashSet(); - Set wantedUids = new HashSet(); + Set newOptions = new HashSet<>(); + Set wantedUids = new HashSet<>(); int displayOrderOption = 1; for (McOptionDTO optionDTO : optionDTOs) { @@ -315,12 +315,12 @@ option.setCorrectOption(isCorrectOption); option.setMcQueOptionText(optionText); option.setMcQueContent(question); - + newOptions.add(option); displayOrderOption++; } question.setMcOptionsContents(newOptions); - + // updating the existing question content saveOrUpdateMcQueContent(question); @@ -330,7 +330,7 @@ @Override public void releaseQuestionsFromCache(McContent content) { - for (McQueContent question : (Set) content.getMcQueContents()) { + for (McQueContent question : content.getMcQueContents()) { mcQueContentDAO.releaseQuestionFromCache(question); } } @@ -465,27 +465,27 @@ public int getAttemptsCountPerOption(Long optionUid) { return mcUsrAttemptDAO.getAttemptsCountPerOption(optionUid); } - + @Override public boolean isMcContentAttempted(Long mcContentUid) { return mcUsrAttemptDAO.isMcContentAttempted(mcContentUid); } @Override public List getAnswersFromDatabase(McContent mcContent, McQueUsr user) { - List answerDtos = new LinkedList(); + List answerDtos = new LinkedList<>(); List questions = this.getQuestionsByContentUid(mcContent.getUid()); for (McQueContent question : questions) { AnswerDTO answerDto = new AnswerDTO(); Set optionSet = question.getMcOptionsContents(); - List optionList = new LinkedList(optionSet); + List optionList = new LinkedList<>(optionSet); boolean randomize = mcContent.isRandomize(); if (randomize) { - ArrayList shuffledList = new ArrayList(optionList); + ArrayList shuffledList = new ArrayList<>(optionList); Collections.shuffle(shuffledList); - optionList = new LinkedList(shuffledList); + optionList = new LinkedList<>(shuffledList); } answerDto.setQuestion(question.getQuestion()); @@ -524,8 +524,8 @@ @Override public List buildGroupsMarkData(McContent mcContent, boolean isFullAttemptDetailsRequired) { - List listMonitoredMarksContainerDTO = new LinkedList(); - Set sessions = new TreeSet(new McSessionComparator()); + List listMonitoredMarksContainerDTO = new LinkedList<>(); + Set sessions = new TreeSet<>(new McSessionComparator()); sessions.addAll(mcContent.getMcSessions()); int numQuestions = mcContent.getMcQueContents().size(); @@ -535,7 +535,7 @@ mcSessionMarkDTO.setSessionId(session.getMcSessionId().toString()); mcSessionMarkDTO.setSessionName(session.getSession_name().toString()); - Set sessionUsers = session.getMcQueUsers(); + List sessionUsers = session.getMcQueUsers(); Iterator usersIterator = sessionUsers.iterator(); Map mapSessionUsersData = new TreeMap( @@ -588,8 +588,7 @@ // find out the answered option's sequential letter - A,B,C... String answeredOptionLetter = ""; int optionCount = 1; - for (McOptsContent option : (Set) attempt.getMcQueContent() - .getMcOptionsContents()) { + for (McOptsContent option : attempt.getMcQueContent().getMcOptionsContents()) { if (attempt.getMcOptionsContent().getUid().equals(option.getUid())) { answeredOptionLetter = String.valueOf((char) ((optionCount + 'A') - 1)); break; @@ -744,7 +743,7 @@ int oldTotalMark = mcUsrAttemptDAO.getUserTotalMark(userUid); int totalMark = (oldMark == null) ? oldTotalMark + newMark : (oldTotalMark - oldMark) + newMark; - List userAttempts = new ArrayList(); + List userAttempts = new ArrayList<>(); McQueUsr groupLeader = mcSession.getGroupLeader(); if (groupLeader != null) { if (groupLeader.equals(selectedUser)) { @@ -760,7 +759,7 @@ logger.warn(error); } } else { - userAttempts = new ArrayList(); + userAttempts = new ArrayList<>(); userAttempts.add(userAttemptToUpdate); } @@ -792,10 +791,10 @@ public void recalculateUserAnswers(McContent content, Set oldQuestions, List questionDTOs) { // create list of modified questions - List modifiedQuestions = new ArrayList(); + List modifiedQuestions = new ArrayList<>(); // create list of questions where only mark was modified - List modifiedQuestionsMarksOnly = new ArrayList(); - + List modifiedQuestionsMarksOnly = new ArrayList<>(); + for (McQueContent oldQuestion : oldQuestions) { for (McQuestionDTO questionDTO : questionDTOs) { if (oldQuestion.getUid().equals(questionDTO.getUid())) { @@ -824,7 +823,7 @@ } } } - + // a new option is added if (oldOptions.size() != optionDTOs.size()) { isQuestionModified = true; @@ -843,7 +842,7 @@ Set sessionList = content.getMcSessions(); for (McSession session : sessionList) { Long toolSessionId = session.getMcSessionId(); - Set sessionUsers = session.getMcQueUsers(); + List sessionUsers = session.getMcQueUsers(); for (McQueUsr user : sessionUsers) { @@ -878,7 +877,7 @@ // [+] if the question is modified for (McQuestionDTO modifiedQuestion : modifiedQuestions) { if (question.getUid().equals(modifiedQuestion.getUid())) { - + //check whether user has selected correct answer, taking into account changes done to modifiedQuestion boolean isAnswerCorrect = false; McOptsContent selectedOption = userAttempt.getMcOptionsContent(); @@ -887,15 +886,15 @@ isAnswerCorrect = "Correct".equals(modifiedOption.getCorrect()); } } - + //recalculate mark Integer newActualMark = isAnswerCorrect ? Integer.valueOf(modifiedQuestion.getMark()) : 0; boolean passed = user.isMarkPassed(newActualMark); userAttempt.setMark(newActualMark); userAttempt.setPassed(passed); userAttempt.setAttemptCorrect(isAnswerCorrect); mcUsrAttemptDAO.saveMcUsrAttempt(userAttempt); - + newTotalMark += newActualMark - oldUserMark; break; @@ -928,7 +927,7 @@ } int totalNumberOfUsers = 0; - for (McSession session : (Set) mcContent.getMcSessions()) { + for (McSession session : mcContent.getMcSessions()) { totalNumberOfUsers += session.getMcQueUsers().size(); } @@ -974,7 +973,7 @@ rowCount++; int totalPercentage = 0; - for (McOptsContent option : (Set) question.getMcOptionsContents()) { + for (McOptsContent option : question.getMcOptionsContents()) { int optionAttemptCount = mcUsrAttemptDAO.getAttemptsCountPerOption(option.getUid()); cell = row.createCell(count++); int percentage = (optionAttemptCount * 100) / totalNumberOfUsers; @@ -1020,15 +1019,15 @@ row = sheet.createRow(rowCount++); count = 1; - ArrayList correctAnswers = new ArrayList(); + ArrayList correctAnswers = new ArrayList<>(); cell = row.createCell(count++); cell.setCellValue(messageService.getMessage("label.correct.answer")); for (McQueContent question : questions) { // find out the correct answer's sequential letter - A,B,C... String correctAnswerLetter = ""; int answerCount = 1; - for (McOptsContent option : (Set) question.getMcOptionsContents()) { + for (McOptsContent option : question.getMcOptionsContents()) { if (option.isCorrectOption()) { correctAnswerLetter = String.valueOf((char) ((answerCount + 'A') - 1)); break; @@ -1047,7 +1046,7 @@ cell = row.createCell(count++); cell.setCellValue(messageService.getMessage("label.learner")); - ArrayList totalPercentList = new ArrayList(); + ArrayList totalPercentList = new ArrayList<>(); int[] numberOfCorrectAnswersPerQuestion = new int[questions.size()]; for (McSessionMarkDTO sessionMarkDTO : sessionMarkDTOs) { Map usersMarksMap = sessionMarkDTO.getUserMarks(); @@ -1257,7 +1256,7 @@ return; } - for (McSession session : (Set) mcContent.getMcSessions()) { + for (McSession session : mcContent.getMcSessions()) { List entries = coreNotebookService.getEntry(session.getMcSessionId(), CoreNotebookConstants.NOTEBOOK_TOOL, McAppConstants.TOOL_SIGNATURE); for (NotebookEntry entry : entries) { @@ -1288,7 +1287,7 @@ McContent content = mcContentDAO.findMcContentById(toolContentId); if (content != null) { - for (McSession session : (Set) content.getMcSessions()) { + for (McSession session : content.getMcSessions()) { McQueUsr user = mcUserDAO.getMcUserBySession(userId.longValue(), session.getUid()); if (user != null) { mcUsrAttemptDAO.removeAllUserAttempts(user.getUid()); @@ -1379,7 +1378,7 @@ @Override public boolean isReadOnly(Long toolContentId) { McContent content = mcContentDAO.findMcContentById(toolContentId); - for (McSession session : (Set) content.getMcSessions()) { + for (McSession session : content.getMcSessions()) { if (!session.getMcQueUsers().isEmpty()) { return true; } @@ -1415,7 +1414,7 @@ if (!existsSession(toolSessionId)) { try { McSession mcSession = new McSession(toolSessionId, new Date(System.currentTimeMillis()), - McSession.INCOMPLETE, toolSessionName, mcContent, new TreeSet()); + McSession.INCOMPLETE, toolSessionName, mcContent, new ArrayList()); mcSessionDAO.saveMcSession(mcSession); @@ -1521,7 +1520,7 @@ @Override public List getConfidenceLevels(Long toolSessionId) { - List confidenceLevelDtos = new ArrayList(); + List confidenceLevelDtos = new ArrayList<>(); if (toolSessionId == null) { return confidenceLevelDtos; } @@ -1616,7 +1615,7 @@ public void auditLogStartEditingActivityInMonitor(long toolContentID) { toolService.auditLogStartEditingActivityInMonitor(toolContentID); } - + @Override public boolean isLastActivity(Long toolSessionId) { return toolService.isLastActivity(toolSessionId); @@ -1706,8 +1705,8 @@ @Override public List getReflectionList(McContent mcContent, Long userID) { - List reflectionsContainerDTO = new LinkedList(); - for (McSession mcSession : (Set) mcContent.getMcSessions()) { + List reflectionsContainerDTO = new LinkedList<>(); + for (McSession mcSession : mcContent.getMcSessions()) { for (McQueUsr user : (Set) mcSession.getMcQueUsers()) { // if all users mode or single user mode and found right user if (userID == null || user.getQueUsrId().equals(userID)) { @@ -1849,11 +1848,11 @@ @SuppressWarnings("unchecked") @Override public List getSessionDtos(Long contentId, boolean includeStatistics) { - List sessionDtos = new ArrayList(); + List sessionDtos = new ArrayList<>(); McContent mcContent = getMcContent(contentId); if (mcContent != null) { - Set sessions = new TreeSet(new McSessionComparator()); + Set sessions = new TreeSet<>(new McSessionComparator()); sessions.addAll(mcContent.getMcSessions()); for (McSession session : sessions) { SessionDTO sessionDto = new SessionDTO(); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/controller/McLearningController.java =================================================================== diff -u -r6ec43132d9df310eebff50fac6fca9f095757bd7 -rb0523a63bf120c687d9b50748f4221f8d54aefea --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/controller/McLearningController.java (.../McLearningController.java) (revision 6ec43132d9df310eebff50fac6fca9f095757bd7) +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/controller/McLearningController.java (.../McLearningController.java) (revision b0523a63bf120c687d9b50748f4221f8d54aefea) @@ -29,7 +29,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.TimeZone; import java.util.TreeMap; @@ -242,8 +241,8 @@ // forwards to the leaderSelection page if (groupLeader == null && !mode.equals(ToolAccessMode.TEACHER.toString())) { - Set groupUsers = mcSession.getMcQueUsers();// mcService.getUsersBySession(new - // Long(toolSessionID).longValue()); + List groupUsers = mcSession.getMcQueUsers();// mcService.getUsersBySession(new + // Long(toolSessionID).longValue()); request.setAttribute(McAppConstants.ATTR_GROUP_USERS, groupUsers); request.setAttribute(McAppConstants.TOOL_SESSION_ID, toolSessionID); request.setAttribute(McAppConstants.ATTR_CONTENT, mcContent); @@ -325,11 +324,12 @@ return null; } - protected List buildAnswerDtos(List answers, Map confidenceLevels, McContent content, HttpServletRequest request) { + protected List buildAnswerDtos(List answers, Map confidenceLevels, + McContent content, HttpServletRequest request) { List answerDtos = new LinkedList<>(); - for (McQueContent question : (Set) content.getMcQueContents()) { + for (McQueContent question : content.getMcQueContents()) { String questionUid = question.getUid().toString(); int questionMark = question.getMark().intValue(); @@ -363,12 +363,13 @@ answerDto.setMark(0); } - // handle confidence levels + // handle confidence levels if (content.isEnableConfidenceLevels()) { String wantedKey = "confidenceLevel" + question.getUid(); Integer confidenceLevel = confidenceLevels.get(wantedKey); - if ( confidenceLevel != null ) + if (confidenceLevel != null) { answerDto.setConfidenceLevel(confidenceLevel); + } } answerDtos.add(answerDto); @@ -397,14 +398,16 @@ mcContent.isQuestionsSequenced()); Map learnerConfidenceLevels = null; - if (mcContent.isEnableConfidenceLevels()) + if (mcContent.isEnableConfidenceLevels()) { learnerConfidenceLevels = parseLearnerConfidenceLevels(mcLearningForm, request, mcContent.isQuestionsSequenced()); + } if (mcContent.isQuestionsSequenced()) { sessionMap.put(McAppConstants.QUESTION_AND_CANDIDATE_ANSWERS_KEY, answers); - if ( mcContent.isEnableConfidenceLevels() ) + if (mcContent.isEnableConfidenceLevels()) { sessionMap.put(McAppConstants.CONFIDENCE_LEVELS_KEY, learnerConfidenceLevels); + } } mcLearningForm.resetCa(request); @@ -469,7 +472,7 @@ mcContent.isQuestionsSequenced()); sessionMap.put(McAppConstants.CONFIDENCE_LEVELS_KEY, learnerConfidenceLevels); } - + //save user attempt List answerDtos = buildAnswerDtos(answers, learnerConfidenceLevels, mcContent, request); mcService.saveUserAttempt(user, answerDtos); @@ -784,9 +787,10 @@ List answers = McLearningController.parseLearnerAnswers(mcLearningForm, request, mcContent.isQuestionsSequenced()); Map learnerConfidenceLevels = null; - if (mcContent.isEnableConfidenceLevels()) + if (mcContent.isEnableConfidenceLevels()) { learnerConfidenceLevels = parseLearnerConfidenceLevels(mcLearningForm, request, mcContent.isQuestionsSequenced()); + } List answerDtos = buildAnswerDtos(answers, learnerConfidenceLevels, mcContent, request); mcService.saveUserAttempt(user, answerDtos); @@ -838,12 +842,13 @@ String httpSessionID = mcLearningForm.getHttpSessionID(); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - Map confidenceLevels = new HashMap(); + Map confidenceLevels = new HashMap<>(); if (isQuestionsSequenced) { Map previousConfidenceLevels = (Map) sessionMap .get(McAppConstants.CONFIDENCE_LEVELS_KEY); - if ( previousConfidenceLevels != null ) + if (previousConfidenceLevels != null) { confidenceLevels.putAll(previousConfidenceLevels); + } } Map parameters = request.getParameterMap(); @@ -856,7 +861,7 @@ } return confidenceLevels; } - + private McQueUsr getCurrentUser(String toolSessionId) { // get back login user DTO