Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/GroupingController.java =================================================================== diff -u -r20aa6cbca9fc96d341080e6ad39f82593443f792 -r20b0f9dcce5dda74c6adcf70239de3b75a7e775d --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/GroupingController.java (.../GroupingController.java) (revision 20aa6cbca9fc96d341080e6ad39f82593443f792) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/GroupingController.java (.../GroupingController.java) (revision 20b0f9dcce5dda74c6adcf70239de3b75a7e775d) @@ -85,7 +85,6 @@ // --------------------------------------------------------------------- public static final String GROUPS = "groups"; public static final String FINISHED_BUTTON = "finishedButton"; - public static final String LOCAL_FILES = "localFiles"; public static final String TITLE = "title"; public static final String MAX_LEARNERS_PER_GROUP = "maxLearnersPerGroup"; public static final String VIEW_STUDENTS_BEFORE_SELECTION = "viewStudentsBeforeSelection"; @@ -118,34 +117,11 @@ groupingForm.setActivityID(activity.getActivityId()); request.setAttribute(AttributeNames.PARAM_LESSON_ID, lessonId); - SortedSet groups = new TreeSet<>(GroupDTO.GROUP_NAME_COMPARATOR); - Grouping grouping = ((GroupingActivity) activity).getCreateGrouping(); - if (grouping != null) { - for (Group group : grouping.getGroups()) { - GroupDTO groupDTO = new GroupDTO(group, true); - groupDTO.getUserList().sort(UserBasicDTO.USER_BASIC_DTO_COMPARATOR); - - //set isUserBelongsToGroup - for (UserBasicDTO userDto : groupDTO.getUserList()) { - if (userDto.getUserID().equals(currentUserId)) { - groupDTO.setUserBelongsToGroup(true); - break; - } - } - - groups.add(groupDTO); - } - } - request.setAttribute(GroupingController.GROUPS, groups); - request.setAttribute(GroupingController.TITLE, activity.getTitle()); - request.setAttribute(AttributeNames.PARAM_ACTIVITY_ID, activity.getActivityId()); - request.setAttribute(ConfigurationKeys.RESTRICTED_DISPLAYING_OF_USER_NAMES_IN_GROUPS, - Configuration.getAsBoolean(ConfigurationKeys.RESTRICTED_DISPLAYING_OF_USER_NAMES_IN_GROUPS)); + prepareDataForShowPage(currentUserId, request); //Load up the grouping information and forward to the jsp page to display all the groups and members. if (groupingDone) { request.setAttribute(GroupingController.FINISHED_BUTTON, Boolean.TRUE); - request.setAttribute(GroupingController.LOCAL_FILES, Boolean.FALSE); ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, AttributeNames.PARAM_MODE, true); request.setAttribute(GroupingController.FINISHED_BUTTON, new Boolean((mode == null) || !mode.isTeacher())); @@ -167,7 +143,6 @@ LearnerChoiceGrouping groupingDb = (LearnerChoiceGrouping) learnerService.getGrouping(groupingId); request.setAttribute(GroupingController.MAX_LEARNERS_PER_GROUP, maxNumberOfLeaernersPerGroup); - request.setAttribute(GroupingController.LOCAL_FILES, Boolean.FALSE); request.setAttribute(GroupingController.VIEW_STUDENTS_BEFORE_SELECTION, groupingDb.getViewStudentsBeforeSelection()); return "grouping/choose"; @@ -176,7 +151,50 @@ return "grouping/wait"; } } + + /** + * Load up the grouping information and forward to the jsp page to display all the groups and members. This method is used only to show show.jsp page to the teacher. + */ + @RequestMapping("/viewGrouping") + public String viewGrouping(HttpServletRequest request) throws IOException, ServletException { + int userId = WebUtil.readIntParam(request, AttributeNames.PARAM_USER_ID); + prepareDataForShowPage(userId, request); + + request.setAttribute(GroupingController.FINISHED_BUTTON, false); + return "grouping/show"; + } + + /** + * Common method for performGrouping(GroupingForm, HttpServletRequest) and viewGrouping(HttpServletRequest) + */ + private void prepareDataForShowPage(Integer userId, HttpServletRequest request) { + Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); + SortedSet groups = new TreeSet<>(GroupDTO.GROUP_NAME_COMPARATOR); + Grouping grouping = ((GroupingActivity) activity).getCreateGrouping(); + if (grouping != null) { + for (Group group : grouping.getGroups()) { + GroupDTO groupDTO = new GroupDTO(group, true); + groupDTO.getUserList().sort(UserBasicDTO.USER_BASIC_DTO_COMPARATOR); + + //set isUserBelongsToGroup + for (UserBasicDTO userDto : groupDTO.getUserList()) { + if (userDto.getUserID().equals(userId)) { + groupDTO.setUserBelongsToGroup(true); + break; + } + } + + groups.add(groupDTO); + } + } + request.setAttribute(GroupingController.GROUPS, groups); + request.setAttribute(GroupingController.TITLE, activity.getTitle()); + request.setAttribute(AttributeNames.PARAM_ACTIVITY_ID, activity.getActivityId()); + request.setAttribute(ConfigurationKeys.RESTRICTED_DISPLAYING_OF_USER_NAMES_IN_GROUPS, + Configuration.getAsBoolean(ConfigurationKeys.RESTRICTED_DISPLAYING_OF_USER_NAMES_IN_GROUPS)); + } + /** * Complete the current tool activity and forward to the url of next activity in the learning design. */ Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java =================================================================== diff -u -rca315d61493129fe9d83112e81844633d83aeda9 -r20b0f9dcce5dda74c6adcf70239de3b75a7e775d --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision ca315d61493129fe9d83112e81844633d83aeda9) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision 20b0f9dcce5dda74c6adcf70239de3b75a7e775d) @@ -32,7 +32,6 @@ import java.util.Date; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; @@ -99,7 +98,6 @@ import org.lamsfoundation.lams.util.JsonUtil; import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.NumberUtil; -import org.lamsfoundation.lams.util.excel.ExcelCell; import org.lamsfoundation.lams.util.excel.ExcelRow; import org.lamsfoundation.lams.util.excel.ExcelSheet; @@ -303,7 +301,15 @@ public Set getPrecedingConfidenceLevelsActivities(Long toolContentId) { return toolService.getPrecedingConfidenceLevelsActivities(toolContentId); } + + @Override + public boolean isUserGroupLeader(Long userId, Long toolSessionId) { + ScratchieSession session = getScratchieSessionBySessionId(toolSessionId); + ScratchieUser groupLeader = session.getGroupLeader(); + return (groupLeader != null) && userId.equals(groupLeader.getUserId()); + } + @Override public ScratchieUser checkLeaderSelectToolForSessionLeader(ScratchieUser user, Long toolSessionId) { if ((user == null) || (toolSessionId == null)) { @@ -382,7 +388,7 @@ List users = this.getUsersBySession(sessionId); for (ScratchieUser user : users) { - toolService.updateActivityMark(new Double(newMark), null, user.getUserId().intValue(), + toolService.updateActivityMark(newMark.doubleValue(), null, user.getUserId().intValue(), user.getSession().getSessionId(), false); // record mark change with audit service @@ -469,7 +475,7 @@ if (isPropagateToGradebook) { List users = this.getUsersBySession(sessionId); for (ScratchieUser user : users) { - toolService.updateActivityMark(new Double(mark), null, user.getUserId().intValue(), + toolService.updateActivityMark(Double.valueOf(mark), null, user.getUserId().intValue(), user.getSession().getSessionId(), false); } } @@ -605,7 +611,20 @@ ScratchieUser user = scratchieUserDao.getUserByUserIDAndSessionID(userId, toolSessionId); user.setSessionFinished(true); scratchieUserDao.saveObject(user); + + //if this is a leader finishes, complete all non-leaders as well + boolean isUserGroupLeader = user.getSession().isUserGroupLeader(user.getUid()); + if (isUserGroupLeader) { + getUsersBySession(toolSessionId).forEach(sessionUser -> { + //finish non-leader + sessionUser.setSessionFinished(true); + scratchieUserDao.saveObject(user); + // as long as there is no individual results in Scratchie tool (but rather one for entire group) there is no + // need to copyAnswersFromLeader() + }); + } + nextUrl = this.leaveToolSession(toolSessionId, userId); } catch (DataMissingException e) { throw new ScratchieApplicationException(e); @@ -877,7 +896,7 @@ // show total groupSummary if there is more than 1 group available if (sessionList.size() > 1) { GroupSummary groupSummaryTotal = new GroupSummary(); - groupSummaryTotal.setSessionId(new Long(0)); + groupSummaryTotal.setSessionId(0l); groupSummaryTotal.setSessionName("Summary"); groupSummaryTotal.setMark(0); @@ -1112,7 +1131,7 @@ } row.addCell(isFirstChoice, color); } - row.addCell(new Integer(numberOfFirstChoiceEvents)); + row.addCell(Integer.valueOf(numberOfFirstChoiceEvents)); double percentage = (numberOfItems == 0) ? 0 : (double) numberOfFirstChoiceEvents / numberOfItems; row.addPercentageCell(percentage); } @@ -1175,7 +1194,7 @@ } row.addCell(itemDto.getAnswersSequence(), color); } - row.addCell(new Integer(numberOfFirstChoiceEvents)); + row.addCell(Integer.valueOf(numberOfFirstChoiceEvents)); double percentage = (numberOfItems == 0) ? 0 : (double) numberOfFirstChoiceEvents / numberOfItems; row.addPercentageCell(percentage); @@ -1267,8 +1286,8 @@ color = IndexedColors.RED; } row.addCell(isFirstChoice, color); - row.addCell(new Long(attempts), color); - Long mark = (itemDto.getUserMark() == -1) ? null : new Long(itemDto.getUserMark()); + row.addCell(Integer.valueOf(attempts), color); + Long mark = (itemDto.getUserMark() == -1) ? null : Long.valueOf(itemDto.getUserMark()); row.addCell(mark); } } @@ -1292,8 +1311,8 @@ for (ScratchieUser user : summary.getUsers()) { row = researchAndAnalysisSheet.initRow(); row.addCell(user.getFirstName() + " " + user.getLastName()); - row.addCell(new Long(summary.getTotalAttempts())); - Long mark = (summary.getTotalAttempts() == 0) ? null : new Long(summary.getMark()); + row.addCell(Long.valueOf(summary.getTotalAttempts())); + Long mark = (summary.getTotalAttempts() == 0) ? null : Long.valueOf(summary.getMark()); row.addCell(mark); row.addCell(summary.getSessionName()); } @@ -1344,7 +1363,7 @@ row.addCell(answerTitle, color); for (int numberAttempts : answer.getAttempts()) { - row.addCell(new Long(numberAttempts)); + row.addCell(Integer.valueOf(numberAttempts)); } } researchAndAnalysisSheet.addEmptyRow(); @@ -1367,7 +1386,7 @@ row = researchAndAnalysisSheet.initRow(); row.addEmptyCell(); for (int i = 0; i < answers.size(); i++) { - row.addCell(new Long(i + 1)); + row.addCell(Integer.valueOf(i + 1)); } for (ScratchieAnswer answer : answers) { @@ -1379,7 +1398,7 @@ row.addCell(answerTitle); for (int numberAttempts : answer.getAttempts()) { - row.addCell(new Long(numberAttempts)); + row.addCell(Integer.valueOf(numberAttempts)); } } @@ -1408,7 +1427,7 @@ Long attempts = (long) scratchieAnswerVisitDao.getLogCountTotal(sessionId); row.addCell(attempts); row.addCell(getMessage("label.mark") + ":"); - row.addCell(new Long(session.getMark())); + row.addCell(Long.valueOf(session.getMark())); row = researchAndAnalysisSheet.initRow(); row.addCell(getMessage("label.team.leader") + session.getSessionName()); @@ -1423,7 +1442,7 @@ item.getUid()); for (ScratchieAnswerVisitLog log : logs) { row = researchAndAnalysisSheet.initRow(); - row.addCell(new Long(i++)); + row.addCell(Integer.valueOf(i++)); String answerDescr = removeHtmlMarkup(log.getScratchieAnswer().getDescription()); row.addCell(answerDescr); row.addCell(fullDateFormat.format(log.getAccessDate())); @@ -1484,7 +1503,7 @@ // group name row.addCell(summary.getSessionName()); // question number - row.addCell(new Long(questionCount++)); + row.addCell(Integer.valueOf(questionCount++)); // question title row.addCell(itemDto.getTitle()); @@ -1510,9 +1529,9 @@ } row.addCell(isFirstChoice); // attempts - row.addCell(new Long(attempts)); + row.addCell(Integer.valueOf(attempts)); // mark - Object mark = (itemDto.getUserMark() == -1) ? "" : new Long(itemDto.getUserMark()); + Object mark = (itemDto.getUserMark() == -1) ? "" : Long.valueOf(itemDto.getUserMark()); row.addCell(mark); // Answers selected @@ -2086,17 +2105,31 @@ return; } - // as long as leader aware feature is always ON - copy answers from leader to non-leader user - ScratchieUser scratchieUser = scratchieUserDao.getUserByUserIDAndSessionID(userId, toolSessionId); // create user if he hasn't accessed this activity yet if (scratchieUser == null) { scratchieUser = new ScratchieUser(user.getUserDTO(), session); createUser(scratchieUser); } + + checkLeaderSelectToolForSessionLeader(scratchieUser, toolSessionId); + //if this is a leader finishes, complete all non-leaders as well + boolean isUserGroupLeader = session.isUserGroupLeader(scratchieUser.getUid()); + if (isUserGroupLeader) { + getUsersBySession(toolSessionId).forEach(sessionUser -> { + //finish users + sessionUser.setSessionFinished(true); + scratchieUserDao.saveObject(user); - // as long as there is no individual results in Scratchie tool (but rather one for entire group) there is no - // need to copyAnswersFromLeader() + // as long as there is no individual results in Scratchie tool (but rather one for entire group) there is no + // need to copyAnswersFromLeader() + }); + + } else { + //finish user + scratchieUser.setSessionFinished(true); + scratchieUserDao.saveObject(scratchieUser); + } } /* =================================================================================== */ @@ -2182,7 +2215,6 @@ * "questionText", "displayOrder" (Integer) and a ArrayNode "answers". The answers entry should be ArrayNode * containing JSON objects, which in turn must contain "answerText", "displayOrder" (Integer), "correct" (Boolean). */ - @SuppressWarnings("unchecked") @Override public void createRestToolContent(Integer userID, Long toolContentID, ObjectNode toolContentJSON) {