Index: lams_tool_leader/build.xml =================================================================== diff -u -rac8b64b03ce6d8c718e55823f23fd995159b7ca0 -ra5ee55c529ff5dbfb9e102604f7f253c141861ba --- lams_tool_leader/build.xml (.../build.xml) (revision ac8b64b03ce6d8c718e55823f23fd995159b7ca0) +++ lams_tool_leader/build.xml (.../build.xml) (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -18,7 +18,7 @@ ${ant.project.name}: Copying additional Java classes to WAR Fisheye: Tag a5ee55c529ff5dbfb9e102604f7f253c141861ba refers to a dead (removed) revision in file `lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/actions/AuthoringAction.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag a5ee55c529ff5dbfb9e102604f7f253c141861ba refers to a dead (removed) revision in file `lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/actions/ClearSessionAction.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag a5ee55c529ff5dbfb9e102604f7f253c141861ba refers to a dead (removed) revision in file `lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/actions/LearningAction.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag a5ee55c529ff5dbfb9e102604f7f253c141861ba refers to a dead (removed) revision in file `lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/actions/LearningWebsocketServer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag a5ee55c529ff5dbfb9e102604f7f253c141861ba refers to a dead (removed) revision in file `lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/actions/MonitoringAction.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag a5ee55c529ff5dbfb9e102604f7f253c141861ba refers to a dead (removed) revision in file `lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/actions/TblMonitoringAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/AuthoringController.java =================================================================== diff -u --- lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/AuthoringController.java (revision 0) +++ lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/AuthoringController.java (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -0,0 +1,156 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.tool.leaderselection.web.controller; + +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.authoring.web.AuthoringConstants; +import org.lamsfoundation.lams.tool.ToolAccessMode; +import org.lamsfoundation.lams.tool.leaderselection.model.Leaderselection; +import org.lamsfoundation.lams.tool.leaderselection.service.ILeaderselectionService; +import org.lamsfoundation.lams.tool.leaderselection.util.LeaderselectionConstants; +import org.lamsfoundation.lams.tool.leaderselection.web.forms.AuthoringForm; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.lamsfoundation.lams.web.util.SessionMap; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * + * + * + */ +@Controller +@RequestMapping("/authoring") +public class AuthoringController { + + private static Logger logger = Logger.getLogger(AuthoringController.class); + + @Autowired + @Qualifier("leaderselectionService") + private ILeaderselectionService leaderselectionService; + + // Authoring SessionMap key names + private static final String KEY_TOOL_CONTENT_ID = "toolContentID"; + private static final String KEY_CONTENT_FOLDER_ID = "contentFolderID"; + private static final String KEY_MODE = "mode"; + + /** + * Default method when no dispatch parameter is specified. It is expected that the parameter + * toolContentID will be passed in. This will be used to retrieve content for this tool. + * + */ + @RequestMapping("") + protected String unspecified(AuthoringForm authoringForm, HttpServletRequest request) { + + // Extract toolContentID from parameters. + Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); + + String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); + + ToolAccessMode mode = WebUtil.readToolAccessModeAuthorDefaulted(request); + + // retrieving Leaderselection with given toolContentID + Leaderselection leaderselection = leaderselectionService.getContentByContentId(toolContentID); + if (leaderselection == null) { + leaderselection = leaderselectionService.copyDefaultContent(toolContentID); + leaderselection.setCreateDate(new Date()); + leaderselectionService.saveOrUpdateLeaderselection(leaderselection); + // TODO NOTE: this causes DB orphans when LD not saved. + } + + if (mode.isTeacher()) { + // Set the defineLater flag so that learners cannot use content + // while we + // are editing. This flag is released when updateContent is called. + leaderselection.setDefineLater(true); + leaderselectionService.saveOrUpdateLeaderselection(leaderselection); + + //audit log the teacher has started editing activity in monitor + leaderselectionService.auditLogStartEditingActivityInMonitor(toolContentID); + } + + // Set up the authForm. + authoringForm.setTitle(leaderselection.getTitle()); + authoringForm.setInstructions(leaderselection.getInstructions()); + + // Set up sessionMap + SessionMap map = new SessionMap<>(); + map.put(AuthoringController.KEY_MODE, mode); + map.put(AuthoringController.KEY_CONTENT_FOLDER_ID, contentFolderID); + map.put(AuthoringController.KEY_TOOL_CONTENT_ID, toolContentID); + authoringForm.setSessionMapID(map.getSessionID()); + + // add the sessionMap to HTTPSession. + request.getSession().setAttribute(map.getSessionID(), map); + request.setAttribute(LeaderselectionConstants.ATTR_SESSION_MAP, map); + + return "pages/authoring"; + } + + @RequestMapping("/updateContent") + public String updateContent(@ModelAttribute("authoringForm") AuthoringForm authoringForm, + HttpServletRequest request, HttpServletResponse response) { + // TODO need error checking. + + // get authForm and session map. + SessionMap map = (SessionMap) request.getSession() + .getAttribute(authoringForm.getSessionMapID()); + + // get leaderselection content. + Leaderselection leaderselection = leaderselectionService + .getContentByContentId((Long) map.get(AuthoringController.KEY_TOOL_CONTENT_ID)); + + // update leaderselection content using form inputs. + ToolAccessMode mode = (ToolAccessMode) map.get(AuthoringController.KEY_MODE); + leaderselection.setTitle(authoringForm.getTitle()); + leaderselection.setInstructions(authoringForm.getInstructions()); + + // set the update date + leaderselection.setUpdateDate(new Date()); + + // releasing defineLater flag so that learner can start using the tool. + leaderselection.setDefineLater(false); + + leaderselectionService.saveOrUpdateLeaderselection(leaderselection); + + request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); + + // add the sessionMapID to form + authoringForm.setSessionMapID(map.getSessionID()); + + request.setAttribute(LeaderselectionConstants.ATTR_SESSION_MAP, map); + request.setAttribute("authoringForm", authoringForm); + + return "pages/authoring"; + } +} Index: lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/ClearSessionController.java =================================================================== diff -u --- lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/ClearSessionController.java (revision 0) +++ lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/ClearSessionController.java (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -0,0 +1,65 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + + +package org.lamsfoundation.lams.tool.leaderselection.web.controller; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.lamsfoundation.lams.authoring.web.LamsAuthoringFinishAction; +import org.lamsfoundation.lams.authoring.web.LamsAuthoringFinishController; +import org.lamsfoundation.lams.tool.ToolAccessMode; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +/** + * This class give a chance to clear HttpSession when user save/close authoring page. + * + * + * + */ +@Controller +public class ClearSessionController extends LamsAuthoringFinishController{ + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/clearsession") + public void execute(HttpServletRequest request, HttpServletResponse response) throws IOException { + super.execute(request, response, applicationContext); + } + + @Override + public void clearSession(String customiseSessionID, HttpSession session, ToolAccessMode mode) { + if (mode.isAuthor()) { + session.removeAttribute(customiseSessionID); + } + } + +} Index: lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/LearningController.java =================================================================== diff -u --- lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/LearningController.java (revision 0) +++ lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/LearningController.java (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -0,0 +1,206 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.tool.leaderselection.web.controller; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForward; +import org.lamsfoundation.lams.learning.web.util.LearningWebUtil; +import org.lamsfoundation.lams.tool.ToolAccessMode; +import org.lamsfoundation.lams.tool.ToolSessionManager; +import org.lamsfoundation.lams.tool.exception.DataMissingException; +import org.lamsfoundation.lams.tool.exception.ToolException; +import org.lamsfoundation.lams.tool.leaderselection.model.Leaderselection; +import org.lamsfoundation.lams.tool.leaderselection.model.LeaderselectionSession; +import org.lamsfoundation.lams.tool.leaderselection.model.LeaderselectionUser; +import org.lamsfoundation.lams.tool.leaderselection.service.ILeaderselectionService; +import org.lamsfoundation.lams.tool.leaderselection.service.LeaderselectionServiceProxy; +import org.lamsfoundation.lams.tool.leaderselection.util.LeaderselectionConstants; +import org.lamsfoundation.lams.tool.leaderselection.util.LeaderselectionException; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +/** + * + * + * + */ +@Controller +@RequestMapping("/learning") +public class LearningController { + + private static Logger log = Logger.getLogger(LearningController.class); + + @Autowired + @Qualifier("leaderselectionService") + private ILeaderselectionService leaderselectionService; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("") + public String unspecified(HttpServletRequest request) throws Exception { + + // 'toolSessionID' and 'mode' paramters are expected to be present. + ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, AttributeNames.PARAM_MODE, false); + // set up service + initService(); + + // Retrieve the session and content. + Long toolSessionId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID); + LeaderselectionSession session = leaderselectionService.getSessionBySessionId(toolSessionId); + if (session == null) { + throw new LeaderselectionException("Cannot retrieve session with toolSessionID" + toolSessionId); + } + + Leaderselection content = session.getLeaderselection(); + request.setAttribute(LeaderselectionConstants.ATTR_CONTENT, content); + + // check defineLater + if (content.isDefineLater()) { + return "pages/learning/defineLater"; + } + + // set mode, toolSessionID and LeaderselectionDTO + request.setAttribute("mode", mode.toString()); + request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, toolSessionId); + + // Set the content in use flag. + if (!content.isContentInUse()) { + content.setContentInUse(new Boolean(true)); + leaderselectionService.saveOrUpdateLeaderselection(content); + } + + LearningWebUtil.putActivityPositionInRequestByToolSessionId(toolSessionId, request, + applicationContext.getServletContext()); + + LeaderselectionUser user; + if (mode.equals(ToolAccessMode.TEACHER)) { + Long userID = WebUtil.readLongParam(request, AttributeNames.PARAM_USER_ID, false); + user = leaderselectionService.getUserByUserIdAndSessionId(userID, toolSessionId); + } else { + user = getCurrentUser(toolSessionId); + } + + LeaderselectionUser groupLeader = session.getGroupLeader(); + request.setAttribute(LeaderselectionConstants.ATTR_GROUP_LEADER, groupLeader); + List groupUsers = leaderselectionService.getUsersBySession(toolSessionId); + request.setAttribute(LeaderselectionConstants.ATTR_GROUP_USERS, groupUsers); + request.setAttribute(LeaderselectionConstants.ATTR_TOOL_SESSION_ID, toolSessionId); + + // checks whether to display dialog prompting to become a leader + boolean isSelectLeaderActive = (groupLeader == null) && !user.isFinishedActivity() && !mode.isTeacher(); + request.setAttribute("isSelectLeaderActive", isSelectLeaderActive); + + return "pages/learning/leaderselection"; + } + + /** + * Sets current user as a leader of a group. + * + * @throws JSONException + */ + @RequestMapping("/becomeLeader") + public String becomeLeader(HttpServletRequest request) throws IOException { + initService(); + Long toolSessionId = new Long(request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID)); + LeaderselectionSession session = leaderselectionService.getSessionBySessionId(toolSessionId); + + LeaderselectionUser groupLeader = session.getGroupLeader(); + // check there is no leader yet. Just in case somebody has pressed "Yes" button faster + if (groupLeader == null) { + LeaderselectionUser user = getCurrentUser(toolSessionId); + leaderselectionService.setGroupLeader(user.getUid(), toolSessionId); + } + + return null; + } + + @RequestMapping("/finishActivity") + public ActionForward finishActivity(HttpServletRequest request, HttpServletResponse response) { + + Long toolSessionID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID); + + LeaderselectionUser user = getCurrentUser(toolSessionID); + + if (user != null) { + user.setFinishedActivity(true); + leaderselectionService.saveOrUpdateUser(user); + } else { + log.error("finishActivity(): couldn't find LeaderselectionUser with id: " + user.getUserId() + + "and toolSessionID: " + toolSessionID); + } + + ToolSessionManager sessionMgrService = LeaderselectionServiceProxy + .getLeaderselectionSessionManager(applicationContext.getServletContext()); + + String nextActivityUrl; + try { + nextActivityUrl = sessionMgrService.leaveToolSession(toolSessionID, user.getUserId()); + response.sendRedirect(nextActivityUrl); + } catch (DataMissingException e) { + throw new LeaderselectionException(e); + } catch (ToolException e) { + throw new LeaderselectionException(e); + } catch (IOException e) { + throw new LeaderselectionException(e); + } + + return null; + } + + private void initService() { + if (leaderselectionService == null) { + leaderselectionService = LeaderselectionServiceProxy + .getLeaderselectionService(this.applicationContext.getServletContext()); + } + } + + private LeaderselectionUser getCurrentUser(Long toolSessionId) { + UserDTO user = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + + // attempt to retrieve user using userId and toolSessionId + LeaderselectionUser leaderselectionUser = leaderselectionService + .getUserByUserIdAndSessionId(new Long(user.getUserID().intValue()), toolSessionId); + + if (leaderselectionUser == null) { + LeaderselectionSession leaderselectionSession = leaderselectionService.getSessionBySessionId(toolSessionId); + leaderselectionUser = leaderselectionService.createLeaderselectionUser(user, leaderselectionSession); + } + + return leaderselectionUser; + } +} Index: lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/LearningWebsocketServer.java =================================================================== diff -u --- lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/LearningWebsocketServer.java (revision 0) +++ lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/LearningWebsocketServer.java (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -0,0 +1,166 @@ +package org.lamsfoundation.lams.tool.leaderselection.web.controller; + +import java.io.IOException; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import javax.websocket.CloseReason; +import javax.websocket.CloseReason.CloseCodes; +import javax.websocket.OnClose; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +import org.apache.log4j.Logger; + + +import org.lamsfoundation.lams.tool.leaderselection.service.ILeaderselectionService; +import org.lamsfoundation.lams.tool.leaderselection.service.LeaderselectionServiceProxy; +import org.lamsfoundation.lams.util.hibernate.HibernateSessionManager; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; + +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Sends leader has been selected event to the learners. + * + * @author Marcin Cieslak + * @author Andrey Balan + */ +@ServerEndpoint("/learningWebsocket") +public class LearningWebsocketServer { + /** + * A singleton which updates Learners with Leader selection. + */ + private static class SendWorker extends Thread { + private boolean stopFlag = false; + // how ofter the thread runs + private static final long CHECK_INTERVAL = 3000; + + @Override + public void run() { + while (!stopFlag) { + try { + // websocket communication bypasses standard HTTP filters, so Hibernate session needs to be initialised manually + HibernateSessionManager.openSession(); + Iterator>> entryIterator = LearningWebsocketServer.websockets.entrySet() + .iterator(); + // go through activities and update registered learners with reports and vote count + while (entryIterator.hasNext()) { + Entry> entry = entryIterator.next(); + Long toolSessionId = entry.getKey(); + // if all learners left the activity, remove the obsolete mapping + Set sessionWebsockets = entry.getValue(); + if (sessionWebsockets.isEmpty()) { + entryIterator.remove(); + continue; + } + + boolean finished = LearningWebsocketServer.getLeaderService() + .getSessionBySessionId(toolSessionId).getGroupLeader() != null; + if (finished) { + LearningWebsocketServer.sendPageRefreshRequest(toolSessionId); + } + } + } catch (Exception e) { + // error caught, but carry on + LearningWebsocketServer.log.error("Error in Leader worker thread", e); + } finally { + HibernateSessionManager.closeSession(); + try { + Thread.sleep(SendWorker.CHECK_INTERVAL); + } catch (InterruptedException e) { + LearningWebsocketServer.log.warn("Stopping Leader worker thread"); + stopFlag = true; + } + } + } + } + }; + + private static final Logger log = Logger.getLogger(LearningWebsocketServer.class); + + private static final SendWorker sendWorker = new SendWorker(); + private static final Map> websockets = new ConcurrentHashMap<>(); + private static ILeaderselectionService leaderService; + + static { + // run the singleton thread + LearningWebsocketServer.sendWorker.start(); + } + + /** + * Registeres the Learner for processing. + */ + @OnOpen + public void registerUser(Session websocket) throws IOException { + Long toolSessionId = Long + .valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0)); + Set sessionWebsockets = websockets.get(toolSessionId); + if (sessionWebsockets == null) { + sessionWebsockets = ConcurrentHashMap.newKeySet(); + websockets.put(toolSessionId, sessionWebsockets); + } + sessionWebsockets.add(websocket); + + if (log.isDebugEnabled()) { + log.debug("User " + websocket.getUserPrincipal().getName() + + " entered Leader Selection with toolSessionId: " + toolSessionId); + } + } + + /** + * When user leaves the activity. + */ + @OnClose + public void unregisterUser(Session websocket, CloseReason reason) { + Long toolSessionId = Long + .valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0)); + websockets.get(toolSessionId).remove(websocket); + + if (log.isDebugEnabled()) { + // If there was something wrong with the connection, put it into logs. + log.debug("User " + websocket.getUserPrincipal().getName() + " left Leader Selection with Tool Session ID: " + + toolSessionId + + (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY) + || reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE)) + ? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: " + + reason.getReasonPhrase() + : "")); + } + } + + /** + * This method is called when leader has been selected and all non-leaders should refresh their pages in order + * to see new leader name and a Finish button. + */ + public static void sendPageRefreshRequest(Long toolSessionId) throws IOException { + Set sessionWebsockets = websockets.get(toolSessionId); + if (sessionWebsockets == null) { + return; + } + + ObjectNode responseJSON = JsonNodeFactory.instance.objectNode(); + responseJSON.put("pageRefresh", true); + String response = responseJSON.toString(); + + for (Session websocket : sessionWebsockets) { + if (websocket.isOpen()) { + websocket.getBasicRemote().sendText(response); + } + } + } + + private static ILeaderselectionService getLeaderService() { + if (LearningWebsocketServer.leaderService == null) { + LearningWebsocketServer.leaderService = LeaderselectionServiceProxy + .getLeaderselectionService(SessionManager.getServletContext()); + } + return LearningWebsocketServer.leaderService; + } +} \ No newline at end of file Index: lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/MonitoringController.java =================================================================== diff -u --- lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/MonitoringController.java (revision 0) +++ lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/MonitoringController.java (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -0,0 +1,137 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.tool.leaderselection.web.controller; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.tool.leaderselection.dto.LeaderselectionDTO; +import org.lamsfoundation.lams.tool.leaderselection.dto.LeaderselectionSessionDTO; +import org.lamsfoundation.lams.tool.leaderselection.model.Leaderselection; +import org.lamsfoundation.lams.tool.leaderselection.service.ILeaderselectionService; +import org.lamsfoundation.lams.tool.leaderselection.util.LeaderselectionConstants; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.lamsfoundation.lams.web.util.SessionMap; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * + * + * + * + */ +@Controller +@RequestMapping("/monitoring") +public class MonitoringController { + + private static Logger log = Logger.getLogger(MonitoringController.class); + + @Autowired + @Qualifier("leaderselectionService") + private ILeaderselectionService leaderselectionService; + + @RequestMapping("") + public String unspecified(HttpServletRequest request) { + + // initialize Session Map + SessionMap sessionMap = new SessionMap<>(); + request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); + request.setAttribute(LeaderselectionConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); + + Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); + String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); + Leaderselection content = leaderselectionService.getContentByContentId(toolContentID); + if (content == null) { + // TODO error page. + } + + // // cache into sessionMap + boolean isGroupedActivity = leaderselectionService.isGroupedActivity(toolContentID); + sessionMap.put(LeaderselectionConstants.ATTR_IS_GROUPED_ACTIVITY, isGroupedActivity); + // sessionMap.put(ScratchieConstants.PAGE_EDITABLE, scratchie.isContentInUse()); + // sessionMap.put(ScratchieConstants.ATTR_SCRATCHIE, scratchie); + // sessionMap.put(ScratchieConstants.ATTR_TOOL_CONTENT_ID, toolContentID); + // sessionMap.put(AttributeNames.PARAM_CONTENT_FOLDER_ID, + // WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID)); + // sessionMap.put(ScratchieConstants.ATTR_REFLECTION_ON, scratchie.isReflectOnActivity()); + + LeaderselectionDTO leaderselectionDT0 = new LeaderselectionDTO(content); + sessionMap.put("leaderselectionDT0", leaderselectionDT0); + + Long currentTab = WebUtil.readLongParam(request, AttributeNames.PARAM_CURRENT_TAB, true); + leaderselectionDT0.setCurrentTab(currentTab); + + request.setAttribute("leaderselectionDTO", leaderselectionDT0); + request.setAttribute("contentFolderID", contentFolderID); + request.setAttribute("isGroupedActivity", isGroupedActivity); + + return "pages/monitoring/monitoring"; + } + + /** + * Show leaders manage page + */ + @RequestMapping("/manageLeaders") + public String manageLeaders(HttpServletRequest request) { + String sessionMapID = request.getParameter(LeaderselectionConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); + request.setAttribute(LeaderselectionConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); + return "/pages/monitoring/manageLeaders"; + } + + /** + * Save selected users as a leaders + * + * @throws IOException + * @throws JSONException + */ + @RequestMapping("/saveLeaders") + public String saveLeaders(HttpServletRequest request) throws IOException { + String sessionMapID = request.getParameter(LeaderselectionConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); + request.setAttribute(LeaderselectionConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); + + LeaderselectionDTO leaderselectionDT0 = (LeaderselectionDTO) sessionMap.get("leaderselectionDT0"); + for (LeaderselectionSessionDTO sessionDto : leaderselectionDT0.getSessionDTOs()) { + Long toolSessionId = sessionDto.getSessionID(); + Long leaderUserUid = WebUtil.readLongParam(request, "sessionId" + toolSessionId, true); + + // save selected users as a leaders + if (leaderUserUid != null) { + leaderselectionService.setGroupLeader(leaderUserUid, toolSessionId); + } + } + + return null; + } + +} Index: lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/TblMonitoringController.java =================================================================== diff -u --- lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/TblMonitoringController.java (revision 0) +++ lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/controller/TblMonitoringController.java (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -0,0 +1,63 @@ +package org.lamsfoundation.lams.tool.leaderselection.web.controller; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.tool.leaderselection.model.LeaderselectionUser; +import org.lamsfoundation.lams.tool.leaderselection.service.ILeaderselectionService; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.action.LamsDispatchAction; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +@Controller +@RequestMapping("/TblMonitoring") +public class TblMonitoringController { + + private static Logger log = Logger.getLogger(TblMonitoringController.class); + + @Autowired + @Qualifier("leaderselectionService") + private ILeaderselectionService leaderselectionService; + + /** + * Save selected user as a leader + * + * @throws IOException + * @throws JSONException + */ + @RequestMapping(path="/changeLeader", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + @ResponseBody + public String changeLeader(HttpServletRequest request) throws IOException { + + Long leaderUserId = WebUtil.readLongParam(request, AttributeNames.PARAM_USER_ID); + Long toolContentId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID); + LeaderselectionUser user = leaderselectionService.getUserByUserIdAndContentId(leaderUserId, toolContentId); + + // save selected user as a leader + boolean isSuccessful = false; + if (user != null) { + Long toolSessionId = user.getLeaderselectionSession().getSessionId(); + log.info("Changing group leader for toolSessionId=" + toolSessionId + ". New leader's userUid=" + + leaderUserId); + isSuccessful = leaderselectionService.setGroupLeader(user.getUid(), toolSessionId); + } + + // build JSON + ObjectNode responseJSON = JsonNodeFactory.instance.objectNode(); + responseJSON.put("isSuccessful", isSuccessful); + return responseJSON.toString(); + } + +} \ No newline at end of file Index: lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/forms/AuthoringForm.java =================================================================== diff -u -r2f725f8ef2aa09a2663b2335bf67213074426d11 -ra5ee55c529ff5dbfb9e102604f7f253c141861ba --- lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/forms/AuthoringForm.java (.../AuthoringForm.java) (revision 2f725f8ef2aa09a2663b2335bf67213074426d11) +++ lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/forms/AuthoringForm.java (.../AuthoringForm.java) (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -37,7 +37,7 @@ /** * */ -public class AuthoringForm extends ActionForm { +public class AuthoringForm { private static final long serialVersionUID = 3950453134542135495L; @@ -61,13 +61,7 @@ private SessionMap sessionMap; - @Override - public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) { - ActionErrors ac = new ActionErrors(); - ac.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("this is an error")); - return ac; - } public String getSessionMapID() { return sessionMapID; Index: lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/forms/MonitoringForm.java =================================================================== diff -u -r2f725f8ef2aa09a2663b2335bf67213074426d11 -ra5ee55c529ff5dbfb9e102604f7f253c141861ba --- lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/forms/MonitoringForm.java (.../MonitoringForm.java) (revision 2f725f8ef2aa09a2663b2335bf67213074426d11) +++ lams_tool_leader/src/java/org/lamsfoundation/lams/tool/leaderselection/web/forms/MonitoringForm.java (.../MonitoringForm.java) (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -21,16 +21,12 @@ * **************************************************************** */ - - package org.lamsfoundation.lams.tool.leaderselection.web.forms; -import org.apache.struts.action.ActionForm; - /** * */ -public class MonitoringForm extends ActionForm { +public class MonitoringForm { private static final long serialVersionUID = 9096908688391850595L; Index: lams_tool_leader/web/WEB-INF/spring-servlet.xml =================================================================== diff -u -rc05d26819a155980f333e1a4aea16afe974119e3 -ra5ee55c529ff5dbfb9e102604f7f253c141861ba --- lams_tool_leader/web/WEB-INF/spring-servlet.xml (.../spring-servlet.xml) (revision c05d26819a155980f333e1a4aea16afe974119e3) +++ lams_tool_leader/web/WEB-INF/spring-servlet.xml (.../spring-servlet.xml) (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -8,7 +8,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> - + Index: lams_tool_leader/web/pages/authoring/authoring.jsp =================================================================== diff -u -rc05d26819a155980f333e1a4aea16afe974119e3 -ra5ee55c529ff5dbfb9e102604f7f253c141861ba --- lams_tool_leader/web/pages/authoring/authoring.jsp (.../authoring.jsp) (revision c05d26819a155980f333e1a4aea16afe974119e3) +++ lams_tool_leader/web/pages/authoring/authoring.jsp (.../authoring.jsp) (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -25,7 +25,7 @@ - + Index: lams_tool_leader/web/pages/learning/defineLater.jsp =================================================================== diff -u -rc05d26819a155980f333e1a4aea16afe974119e3 -ra5ee55c529ff5dbfb9e102604f7f253c141861ba --- lams_tool_leader/web/pages/learning/defineLater.jsp (.../defineLater.jsp) (revision c05d26819a155980f333e1a4aea16afe974119e3) +++ lams_tool_leader/web/pages/learning/defineLater.jsp (.../defineLater.jsp) (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -3,21 +3,43 @@ <%@ include file="/common/taglibs.jsp"%> - + + + + + + + + + + <fmt:message key="activity.title" /> + + + + + + + + + - + + + + + + + + - - - - - - - Index: lams_tool_leader/web/pages/monitoring/monitoring.jsp =================================================================== diff -u -ra6f139bf7f2aeceb96792867e30e3de3959bd1f0 -ra5ee55c529ff5dbfb9e102604f7f253c141861ba --- lams_tool_leader/web/pages/monitoring/monitoring.jsp (.../monitoring.jsp) (revision a6f139bf7f2aeceb96792867e30e3de3959bd1f0) +++ lams_tool_leader/web/pages/monitoring/monitoring.jsp (.../monitoring.jsp) (revision a5ee55c529ff5dbfb9e102604f7f253c141861ba) @@ -1,27 +1,65 @@ + + <%@ include file="/common/taglibs.jsp"%> <%@ page import="org.lamsfoundation.lams.tool.leaderselection.util.LeaderselectionConstants"%> + + + + + + + - - + + + <fmt:message key="activity.title" /> + + + + + + + + + + + + + + + - - - - - + - + + + - - - - - - - + + + + + + + -