Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java =================================================================== diff -u -r2f725f8ef2aa09a2663b2335bf67213074426d11 -rae63df3e06f618712e1eab064a05015eb45c2f17 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision 2f725f8ef2aa09a2663b2335bf67213074426d11) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision ae63df3e06f618712e1eab064a05015eb45c2f17) @@ -23,11 +23,13 @@ package org.lamsfoundation.lams.tool.scratchie.service; +import java.io.IOException; import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Set; +import org.apache.tomcat.util.json.JSONException; import org.lamsfoundation.lams.events.IEventNotificationService; import org.lamsfoundation.lams.notebook.model.NotebookEntry; import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionItemDTO; @@ -206,8 +208,10 @@ * Mark all users in agroup as ScratchingFinished so that users can't continue scratching after this. * * @param toolSessionId + * @throws IOException + * @throws JSONException */ - void setScratchingFinished(Long toolSessionId); + void setScratchingFinished(Long toolSessionId) throws JSONException, IOException; /** * If success return next activity's url, otherwise return null. Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java =================================================================== diff -u -rdc660d5e57f3257022e196805ba472fd8a42996a -rae63df3e06f618712e1eab064a05015eb45c2f17 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision dc660d5e57f3257022e196805ba472fd8a42996a) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision ae63df3e06f618712e1eab064a05015eb45c2f17) @@ -23,6 +23,7 @@ package org.lamsfoundation.lams.tool.scratchie.service; +import java.io.IOException; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -89,6 +90,7 @@ import org.lamsfoundation.lams.tool.scratchie.util.ScratchieAnswerComparator; import org.lamsfoundation.lams.tool.scratchie.util.ScratchieItemComparator; import org.lamsfoundation.lams.tool.scratchie.util.ScratchieToolContentHandler; +import org.lamsfoundation.lams.tool.scratchie.web.action.LearningWebsocketServer; import org.lamsfoundation.lams.tool.service.ILamsToolService; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -471,11 +473,12 @@ } @Override - public void setScratchingFinished(Long toolSessionId) { + public void setScratchingFinished(Long toolSessionId) throws JSONException, IOException { ScratchieSession session = this.getScratchieSessionBySessionId(toolSessionId); session.setScratchingFinished(true); - scratchieSessionDao.saveObject(session); + + LearningWebsocketServer.sendCloseRequest(toolSessionId); } @Override Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java =================================================================== diff -u -r654c98e30631f9b0cb5bd4ebab7d82b2cfb8e384 -rae63df3e06f618712e1eab064a05015eb45c2f17 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java (.../LearningAction.java) (revision 654c98e30631f9b0cb5bd4ebab7d82b2cfb8e384) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java (.../LearningAction.java) (revision ae63df3e06f618712e1eab064a05015eb45c2f17) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.tool.scratchie.web.action; import java.io.IOException; @@ -143,9 +142,9 @@ ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, AttributeNames.PARAM_MODE, true); final Long toolSessionId = new Long(request.getParameter(ScratchieConstants.PARAM_TOOL_SESSION_ID)); - ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(toolSessionId); + ScratchieSession toolSession = service.getScratchieSessionBySessionId(toolSessionId); // get back the scratchie and item list and display them on page - final Scratchie scratchie = LearningAction.service.getScratchieBySessionId(toolSessionId); + final Scratchie scratchie = service.getScratchieBySessionId(toolSessionId); boolean isReflectOnActivity = scratchie.isReflectOnActivity(); final ScratchieUser user; @@ -157,13 +156,13 @@ user = getCurrentUser(toolSessionId); } - ScratchieUser groupLeader = LearningAction.service.checkLeaderSelectToolForSessionLeader(user, toolSessionId); + ScratchieUser groupLeader = service.checkLeaderSelectToolForSessionLeader(user, toolSessionId); // forwards to the leaderSelection page if ((groupLeader == null) && !mode.isTeacher()) { // get group users and store it to request as DTO objects - List groupUsers = LearningAction.service.getUsersBySession(toolSessionId); + List groupUsers = service.getUsersBySession(toolSessionId); List groupUserDtos = new ArrayList(); for (ScratchieUser groupUser : groupUsers) { User groupUserDto = new User(); @@ -185,7 +184,7 @@ // get notebook entry NotebookEntry notebookEntry = null; if (isReflectOnActivity && (groupLeader != null)) { - notebookEntry = LearningAction.service.getEntry(toolSessionId, CoreNotebookConstants.NOTEBOOK_TOOL, + notebookEntry = service.getEntry(toolSessionId, CoreNotebookConstants.NOTEBOOK_TOOL, ScratchieConstants.TOOL_SIGNATURE, groupLeader.getUserId().intValue()); } String entryText = (notebookEntry == null) ? null : notebookEntry.getEntry(); @@ -247,18 +246,18 @@ } // set scratched flag for display purpose - Collection items = LearningAction.service.getItemsWithIndicatedScratches(toolSessionId); + Collection items = service.getItemsWithIndicatedScratches(toolSessionId); // for teacher in monitoring display the number of attempt. if (mode.isTeacher()) { - LearningAction.service.getScratchesOrder(items, toolSessionId); + service.getScratchesOrder(items, toolSessionId); } // populate items with the existing burning questions for displaying purposes List burningQuestions = null; if (scratchie.isBurningQuestionsEnabled()) { - burningQuestions = LearningAction.service.getBurningQuestionsBySession(toolSessionId); + burningQuestions = service.getBurningQuestionsBySession(toolSessionId); for (ScratchieItem item : items) { // find corresponding burningQuestion @@ -350,7 +349,7 @@ final Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); final Long answerUid = NumberUtils.createLong(request.getParameter(ScratchieConstants.PARAM_ANSWER_UID)); - ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(toolSessionId); + ScratchieSession toolSession = service.getScratchieSessionBySessionId(toolSessionId); ScratchieUser leader = this.getCurrentUser(toolSessionId); // only leader is allowed to scratch answers @@ -365,7 +364,7 @@ } // Return whether scratchie answer is correct or not - ScratchieAnswer answer = LearningAction.service.getScratchieAnswerByUid(answerUid); + ScratchieAnswer answer = service.getScratchieAnswerByUid(answerUid); if (answer == null) { return null; } @@ -380,7 +379,7 @@ Thread recordItemScratchedThread = new Thread(new Runnable() { @Override public void run() { - LearningAction.service.recordItemScratched(toolSessionId, answerUid); + service.recordItemScratched(toolSessionId, answerUid); } }, "LAMS_recordItemScratched_thread"); recordItemScratchedThread.start(); @@ -413,15 +412,13 @@ .get(ScratchieConstants.ATTR_IS_BURNING_QUESTIONS_ENABLED); final Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); - ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(toolSessionId); + ScratchieSession toolSession = service.getScratchieSessionBySessionId(toolSessionId); Long userUid = (Long) sessionMap.get(ScratchieConstants.ATTR_USER_UID); // in case of the leader (and if he hasn't done this when accessing notebook) we should let all other learners // see Next Activity button if (toolSession.isUserGroupLeader(userUid) && !toolSession.isScratchingFinished()) { - LearningAction.service.setScratchingFinished(toolSessionId); - - LearningWebsocketServer.sendCloseRequest(toolSessionId); + service.setScratchingFinished(toolSessionId); } // get updated score from ScratchieSession @@ -433,15 +430,14 @@ // display other groups' BurningQuestions if (isBurningQuestionsEnabled) { Scratchie scratchie = toolSession.getScratchie(); - List burningQuestionItemDtos = LearningAction.service - .getBurningQuestionDtos(scratchie, toolSessionId); + List burningQuestionItemDtos = service.getBurningQuestionDtos(scratchie, + toolSessionId); request.setAttribute(ScratchieConstants.ATTR_BURNING_QUESTION_ITEM_DTOS, burningQuestionItemDtos); } // display other groups' notebooks if (isReflectOnActivity) { - List reflections = LearningAction.service - .getReflectionList(toolSession.getScratchie().getContentId()); + List reflections = service.getReflectionList(toolSession.getScratchie().getContentId()); // remove current session leader reflection Iterator refIterator = reflections.iterator(); @@ -474,7 +470,7 @@ SessionMap sessionMap = (SessionMap) request.getSession() .getAttribute(sessionMapID); final Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); - ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(sessionId); + ScratchieSession toolSession = service.getScratchieSessionBySessionId(sessionId); Long burningQuestionUid = WebUtil.readLongParam(request, ScratchieConstants.PARAM_BURNING_QUESTION_UID); @@ -502,7 +498,7 @@ SessionMap sessionMap = (SessionMap) request.getSession() .getAttribute(sessionMapID); final Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); - ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(sessionId); + ScratchieSession toolSession = service.getScratchieSessionBySessionId(sessionId); Long burningQuestionUid = WebUtil.readLongParam(request, ScratchieConstants.PARAM_BURNING_QUESTION_UID); @@ -541,11 +537,11 @@ String nextActivityUrl = null; try { - nextActivityUrl = LearningAction.service.finishToolSession(toolSessionId, userId); + nextActivityUrl = service.finishToolSession(toolSessionId, userId); request.setAttribute(ScratchieConstants.ATTR_NEXT_ACTIVITY_URL, nextActivityUrl); } catch (ScratchieApplicationException e) { - LearningAction.log.error("Failed get next activity url:" + e.getMessage()); + log.error("Failed get next activity url:" + e.getMessage()); } return mapping.findForward(ScratchieConstants.SUCCESS); } @@ -559,9 +555,11 @@ * @param response * @return * @throws ScratchieApplicationException + * @throws IOException + * @throws JSONException */ private ActionForward showBurningQuestions(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws ScratchieApplicationException { + HttpServletResponse response) throws ScratchieApplicationException, JSONException, IOException { initializeScratchieService(); String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); SessionMap sessionMap = (SessionMap) request.getSession() @@ -572,12 +570,12 @@ // set scratched flag for display purpose Collection items = (Collection) sessionMap.get(ScratchieConstants.ATTR_ITEM_LIST); - LearningAction.service.getItemsWithIndicatedScratches(toolSessionId, items); + service.getItemsWithIndicatedScratches(toolSessionId, items); // in case of the leader we should let all other learners see Next Activity button - ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(toolSessionId); + ScratchieSession toolSession = service.getScratchieSessionBySessionId(toolSessionId); if (toolSession.isUserGroupLeader(userUid) && !toolSession.isScratchingFinished()) { - LearningAction.service.setScratchingFinished(toolSessionId); + service.setScratchingFinished(toolSessionId); } return mapping.findForward(ScratchieConstants.SUCCESS); @@ -619,12 +617,12 @@ item.setBurningQuestion(question); // update new entry - LearningAction.service.saveBurningQuestion(sessionId, itemUid, question); + service.saveBurningQuestion(sessionId, itemUid, question); } // handle general burning question final String generalQuestion = request.getParameter(ScratchieConstants.ATTR_GENERAL_BURNING_QUESTION); - LearningAction.service.saveBurningQuestion(sessionId, null, generalQuestion); + service.saveBurningQuestion(sessionId, null, generalQuestion); // update general question in sessionMap sessionMap.put(ScratchieConstants.ATTR_GENERAL_BURNING_QUESTION, generalQuestion); @@ -650,9 +648,11 @@ * @param response * @return * @throws ScratchieApplicationException + * @throws IOException + * @throws JSONException */ private ActionForward newReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws ScratchieApplicationException { + HttpServletResponse response) throws ScratchieApplicationException, JSONException, IOException { initializeScratchieService(); String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); @@ -669,18 +669,18 @@ refForm.setSessionMapID(sessionMapID); // get the existing reflection entry - NotebookEntry entry = LearningAction.service.getEntry(toolSessionId, CoreNotebookConstants.NOTEBOOK_TOOL, + NotebookEntry entry = service.getEntry(toolSessionId, CoreNotebookConstants.NOTEBOOK_TOOL, ScratchieConstants.TOOL_SIGNATURE, user.getUserID()); if (entry != null) { refForm.setEntryText(entry.getEntry()); } - ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(toolSessionId); + ScratchieSession toolSession = service.getScratchieSessionBySessionId(toolSessionId); // in case of the leader we should let all other learners see Next Activity button if (toolSession.isUserGroupLeader(userUid) && !toolSession.isScratchingFinished()) { - LearningAction.service.setScratchingFinished(toolSessionId); + service.setScratchingFinished(toolSessionId); } return mapping.findForward(ScratchieConstants.NOTEBOOK); @@ -709,18 +709,18 @@ final Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); // check for existing notebook entry - final NotebookEntry entry = LearningAction.service.getEntry(sessionId, CoreNotebookConstants.NOTEBOOK_TOOL, + final NotebookEntry entry = service.getEntry(sessionId, CoreNotebookConstants.NOTEBOOK_TOOL, ScratchieConstants.TOOL_SIGNATURE, userId); if (entry == null) { // create new entry - LearningAction.service.createNotebookEntry(sessionId, CoreNotebookConstants.NOTEBOOK_TOOL, + service.createNotebookEntry(sessionId, CoreNotebookConstants.NOTEBOOK_TOOL, ScratchieConstants.TOOL_SIGNATURE, userId, entryText); } else { // update existing entry entry.setEntry(entryText); entry.setLastModified(new Date()); - LearningAction.service.updateEntry(entry); + service.updateEntry(entry); } sessionMap.put(ScratchieConstants.ATTR_REFLECTION_ENTRY, entryText); @@ -734,10 +734,10 @@ // ************************************************************************************* private void initializeScratchieService() { - if (LearningAction.service == null) { + if (service == null) { WebApplicationContext wac = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); - LearningAction.service = (IScratchieService) wac.getBean(ScratchieConstants.SCRATCHIE_SERVICE); + service = (IScratchieService) wac.getBean(ScratchieConstants.SCRATCHIE_SERVICE); } } @@ -746,25 +746,23 @@ HttpSession ss = SessionManager.getSession(); // get back login user DTO UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - ScratchieUser scratchieUser = LearningAction.service.getUserByIDAndSession(user.getUserID().longValue(), - sessionId); + ScratchieUser scratchieUser = service.getUserByIDAndSession(user.getUserID().longValue(), sessionId); if (scratchieUser == null) { - ScratchieSession session = LearningAction.service.getScratchieSessionBySessionId(sessionId); + ScratchieSession session = service.getScratchieSessionBySessionId(sessionId); final ScratchieUser newScratchieUser = new ScratchieUser(user, session); - LearningAction.service.createUser(newScratchieUser); + service.createUser(newScratchieUser); scratchieUser = newScratchieUser; } return scratchieUser; } private ScratchieUser getSpecifiedUser(Long sessionId, Integer userId) { - ScratchieUser scratchieUser = LearningAction.service.getUserByIDAndSession(userId.longValue(), sessionId); + ScratchieUser scratchieUser = service.getUserByIDAndSession(userId.longValue(), sessionId); if (scratchieUser == null) { - LearningAction.log - .error("Unable to find specified user for scratchie activity. Screens are likely to fail. SessionId=" - + sessionId + " UserId=" + userId); + log.error("Unable to find specified user for scratchie activity. Screens are likely to fail. SessionId=" + + sessionId + " UserId=" + userId); } return scratchieUser; } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningWebsocketServer.java =================================================================== diff -u -rd99ea45728271c1c5125fe468d61c99fa7d5f8a8 -rae63df3e06f618712e1eab064a05015eb45c2f17 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningWebsocketServer.java (.../LearningWebsocketServer.java) (revision d99ea45728271c1c5125fe468d61c99fa7d5f8a8) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningWebsocketServer.java (.../LearningWebsocketServer.java) (revision ae63df3e06f618712e1eab064a05015eb45c2f17) @@ -212,7 +212,7 @@ /** * The leader finished the activity. Non-leaders will have Finish button displayed. */ - static void sendCloseRequest(Long toolSessionId) throws JSONException, IOException { + public static void sendCloseRequest(Long toolSessionId) throws JSONException, IOException { Set sessionWebsockets = LearningWebsocketServer.websockets.get(toolSessionId); if (sessionWebsockets == null) { return;