Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java =================================================================== diff -u -re4ab7517268533520c11b8cb076abd74d7721d89 -ra34930f8fa7bcceb2f7849fb2f0f38966a674ec0 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision e4ab7517268533520c11b8cb076abd74d7721d89) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision a34930f8fa7bcceb2f7849fb2f0f38966a674ec0) @@ -25,7 +25,6 @@ import java.io.IOException; import java.util.Collection; -import java.util.LinkedHashMap; import java.util.List; import java.util.Set; @@ -45,7 +44,6 @@ import org.lamsfoundation.lams.tool.scratchie.model.ScratchieSession; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieUser; import org.lamsfoundation.lams.tool.service.ICommonToolService; -import org.lamsfoundation.lams.util.excel.ExcelCell; import org.lamsfoundation.lams.util.excel.ExcelSheet; import org.quartz.SchedulerException; @@ -74,7 +72,7 @@ */ void populateItemsWithConfidenceLevels(Long userId, Long toolSessionId, Integer confidenceLevelsActivityUiid, Collection items); - + // /** // * Populate scratchie items with the VSA answers from the Assessment activity specified in author // * @@ -94,7 +92,7 @@ * @return */ Set getActivitiesProvidingConfidenceLevels(Long toolContentId); - + /** * Returns all activities that precede specified activity and produce VSA answers (only Assessments at the moment). * @@ -103,7 +101,7 @@ * @return */ Set getActivitiesProvidingVsaAnswers(Long toolContentId); - + /** * Set specified user as a leader. Also the previous leader (if any) is marked as non-leader. * @@ -167,6 +165,8 @@ */ ScratchieUser getUserByIDAndSession(Long userId, Long sessionId); + ScratchieUser getUserByLoginAndSessionId(String login, long toolSessionId); + /** * Get users by given toolSessionId. * @@ -224,10 +224,10 @@ * @return */ int countSessionsByContentId(Long toolContentId); - + /** * Return all sessions. - * + * * @param toolContentId * @return */ @@ -256,7 +256,7 @@ * @param scratchieItemList */ Collection getItemsWithIndicatedScratches(Long toolSessionId); - + /** * Return log for VSA type item. */ @@ -267,7 +267,7 @@ * update all the marks. */ void recordItemScratched(Long toolSessionId, Long itemUid, Long scratchieItemUid); - + /** * Leader has left this answer. We will store this answer for all users in his group. It will also * update all the marks. @@ -336,7 +336,7 @@ * @return */ List exportExcel(Long contentId); - + /** * Used by TblMonitoringController.tra() to get numberOfFirstChoiceEvents. */ Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java =================================================================== diff -u -re4ab7517268533520c11b8cb076abd74d7721d89 -ra34930f8fa7bcceb2f7849fb2f0f38966a674ec0 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision e4ab7517268533520c11b8cb076abd74d7721d89) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision a34930f8fa7bcceb2f7849fb2f0f38966a674ec0) @@ -203,7 +203,15 @@ return scratchieUserDao.getUserByUserIDAndSessionID(userId, sessionId); } + @SuppressWarnings("unchecked") @Override + public ScratchieUser getUserByLoginAndSessionId(String login, long toolSessionId) { + List user = scratchieUserDao.findByProperty(User.class, "login", login); + return user.isEmpty() ? null + : scratchieUserDao.getUserByUserIDAndSessionID(user.get(0).getUserId().longValue(), toolSessionId); + } + + @Override public int countUsersByContentId(Long contentId) { return scratchieUserDao.countUsersByContentId(contentId); } @@ -419,7 +427,7 @@ public int countSessionsByContentId(Long toolContentId) { return scratchieSessionDao.getByContentId(toolContentId).size(); } - + @Override public List getSessionsByContentId(Long toolContentId) { return scratchieSessionDao.getByContentId(toolContentId); @@ -854,7 +862,7 @@ optionDto.setCorrect(assessmentAnswer.isCorrect()); optionDto.setUserId(assessmentAnswer.getUserId()); optionDto.setQbQuestionUid(assessmentAnswer.getQbQuestionUid()); -optionDto.setDisplayOrder(-100); + optionDto.setDisplayOrder(-100); if (!scratchie.isConfidenceLevelsEnabled()) { //don't show confidence levels for (ConfidenceLevelDTO confidenceLevel : assessmentAnswer.getConfidenceLevels()) { @@ -963,8 +971,7 @@ public static boolean isItemUnraveledByAnswers(ScratchieItem item, List userAnswers) { QbQuestion qbQuestion = item.getQbQuestion(); - QbOption correctAnswersGroup = qbQuestion.getQbOptions().get(0).isCorrect() - ? qbQuestion.getQbOptions().get(0) + QbOption correctAnswersGroup = qbQuestion.getQbOptions().get(0).isCorrect() ? qbQuestion.getQbOptions().get(0) : qbQuestion.getQbOptions().get(1); String[] correctAnswers = correctAnswersGroup.getName().strip().split("\\r\\n"); for (String correctAnswer : correctAnswers) { @@ -1060,7 +1067,8 @@ GroupSummary groupSummary = new GroupSummary(session); List sessionAttempts = scratchieAnswerVisitDao.getLogsBySessionAndItem(sessionId, itemUid); - int numberColumns = options.size() > sessionAttempts.size() || isMcqItem ? options.size() : sessionAttempts.size(); + int numberColumns = options.size() > sessionAttempts.size() || isMcqItem ? options.size() + : sessionAttempts.size(); groupSummary.setNumberColumns(numberColumns); Map optionMap = new HashMap<>(); @@ -1082,14 +1090,15 @@ Long optionUid; if (isMcqItem) { optionUid = attempt.getQbOption().getUid(); - + } else { String answer = attempt.getAnswer(); boolean isCorrect = ScratchieServiceImpl.isItemUnraveledByAnswers(item, List.of(answer)); boolean isFirstAnswersGroupCorrect = options.get(0).isCorrect(); - optionUid = isCorrect && isFirstAnswersGroupCorrect - || !isCorrect && !isFirstAnswersGroupCorrect ? options.get(0).getUid() : options.get(1).getUid(); + optionUid = isCorrect && isFirstAnswersGroupCorrect || !isCorrect && !isFirstAnswersGroupCorrect + ? options.get(0).getUid() + : options.get(1).getUid(); } OptionDTO optionDto = optionMap.get(optionUid); int[] attempts = optionDto.getAttempts(); @@ -1279,7 +1288,7 @@ public ScratchieUser getUser(Long uid) { return (ScratchieUser) scratchieUserDao.getObject(ScratchieUser.class, uid); } - + /** * Return list of correct AnswerLetters, one per each item */ @@ -1299,7 +1308,7 @@ } answerCount++; } - + } else { List options = item.getQbQuestion().getQbOptions(); if (!options.isEmpty()) { @@ -1308,7 +1317,7 @@ } correctAnswerLetters.add(correctAnswerLetter); } - + return correctAnswerLetters; } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/controller/LearningWebsocketServer.java =================================================================== diff -u -rf27fea8eb6533208beffced8d55e3544857577e8 -ra34930f8fa7bcceb2f7849fb2f0f38966a674ec0 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/controller/LearningWebsocketServer.java (.../LearningWebsocketServer.java) (revision f27fea8eb6533208beffced8d55e3544857577e8) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/controller/LearningWebsocketServer.java (.../LearningWebsocketServer.java) (revision a34930f8fa7bcceb2f7849fb2f0f38966a674ec0) @@ -25,6 +25,7 @@ import org.lamsfoundation.lams.tool.scratchie.dto.OptionDTO; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieItem; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieSession; +import org.lamsfoundation.lams.tool.scratchie.model.ScratchieUser; import org.lamsfoundation.lams.tool.scratchie.service.IScratchieService; import org.lamsfoundation.lams.util.hibernate.HibernateSessionManager; import org.lamsfoundation.lams.web.session.SessionManager; @@ -229,6 +230,14 @@ public void registerUser(Session websocket) throws IOException { Long toolSessionId = Long .valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0)); + String login = websocket.getUserPrincipal().getName(); + ScratchieUser user = LearningWebsocketServer.getScratchieService().getUserByLoginAndSessionId(login, + toolSessionId); + if (user == null) { + throw new SecurityException("User \"" + login + + "\" is not a participant in Scratchie activity with tool session ID " + toolSessionId); + } + Set sessionWebsockets = LearningWebsocketServer.websockets.get(toolSessionId); if (sessionWebsockets == null) { sessionWebsockets = ConcurrentHashMap.newKeySet(); @@ -240,8 +249,7 @@ sessionWebsockets.add(websocket); if (log.isDebugEnabled()) { - log.debug("User " + websocket.getUserPrincipal().getName() + " entered Scratchie with toolSessionId: " - + toolSessionId); + log.debug("User " + login + " entered Scratchie with toolSessionId: " + toolSessionId); } }