Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java =================================================================== diff -u -r7213f7efef305780b43d6d8f8c3f0616237ba8ec -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java (.../ILearnerService.java) (revision 7213f7efef305780b43d6d8f8c3f0616237ba8ec) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java (.../ILearnerService.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -21,7 +21,10 @@ package org.lamsfoundation.lams.learning.service; +import java.util.List; + import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.GroupingActivity; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.lesson.dto.LessonDTO; @@ -115,7 +118,32 @@ */ public void exitLesson(LearnerProgress progress); - + /** + * Returns an activity according to the activity id. + * @param activityId the activity id. + * @return the activity requested. + */ public Activity getActivity(Long activityId); + /** + * Returns all the active learners by the lesson id. + * @param lessonId the requested lesson id. + * @return the list of learners. + */ + public List getActiveLearnersByLesson(long lessonId); + + /** + * Perform random grouping for a list of learners based on the grouping + * activity. + * @param groupingActivity the activity that has create grouping. + * @param learners the list of learners need to be grouped. + */ + public void performGrouping(GroupingActivity groupingActivity, List learners); + + /** + * Perform random grouping a single learner based on the grouping activity. + * @param groupingActivity the activity that has create grouping. + * @param learner the learner needs to be grouped + */ + public void performGrouping(GroupingActivity groupingActivity, User learner); } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java =================================================================== diff -u -r7213f7efef305780b43d6d8f8c3f0616237ba8ec -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 7213f7efef305780b43d6d8f8c3f0616237ba8ec) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -1,25 +1,26 @@ -/* -Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) +/*************************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * ***********************************************************************/ -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; either version 2 of the License, or -(at your option) any later version. -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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -USA - -http://www.gnu.org/licenses/gpl.txt -*/ - - package org.lamsfoundation.lams.learning.service; import java.io.UnsupportedEncodingException; @@ -33,8 +34,11 @@ import org.lamsfoundation.lams.learning.web.util.ActivityMapping; import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.Grouping; +import org.lamsfoundation.lams.learningdesign.GroupingActivity; import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.learningdesign.dao.IActivityDAO; +import org.lamsfoundation.lams.learningdesign.dao.IGroupingDAO; import org.lamsfoundation.lams.lesson.Lesson; @@ -63,6 +67,7 @@ private ILearnerProgressDAO learnerProgressDAO; private ILessonDAO lessonDAO; private IActivityDAO activityDAO; + private IGroupingDAO groupingDAO; private ProgressEngine progressEngine; private IToolSessionDAO toolSessionDAO; private ILamsCoreToolService lamsCoreToolService; @@ -122,6 +127,14 @@ { this.activityDAO = activityDAO; } + + /** + * @param groupingDAO The groupingDAO to set. + */ + public void setGroupingDAO(IGroupingDAO groupingDAO) + { + this.groupingDAO = groupingDAO; + } //--------------------------------------------------------------------- // Service Methods //--------------------------------------------------------------------- @@ -154,6 +167,7 @@ * we assume tool session will always initialize before it becomes a * current activity.

The action servlet that triggers the system driven grouping + * (random grouping) and allows the learner to view the result of the grouping. + *

+ * + * @author Jacky Fang + * @since 2005-3-29 + * @version 1.1 + * + * ----------------XDoclet Tags-------------------- + * + * @struts:action path="/grouping" + * parameter="method" + * validate="false" + * @struts.action-exception key="error.system.learner" scope="request" + * type="org.lamsfoundation.lams.learning.service.LearnerServiceException" + * path=".systemError" + * handler="org.lamsfoundation.lams.util.CustomStrutsExceptionHandler" + * @struts:action-forward name="viewGrouping" path="/grouping.do?method=viewGrouping" + * @struts:action-forward name="showGroup" path=".grouping" + * ----------------XDoclet Tags-------------------- + * + */ +public class GroupingAction extends LamsDispatchAction +{ + + //--------------------------------------------------------------------- + // Instance variables + //--------------------------------------------------------------------- + private static Logger log = Logger.getLogger(GroupingAction.class); + //--------------------------------------------------------------------- + // Class level constants - Session Attributes + //--------------------------------------------------------------------- + private static final String GROUPS = "groups"; + + //--------------------------------------------------------------------- + // Class level constants - Struts forward + //--------------------------------------------------------------------- + private static final String VIEW_GROUPING = "viewGrouping"; + private static final String SHOW_GROUP = "showGroup"; + + //--------------------------------------------------------------------- + // Struts Dispatch Method + //--------------------------------------------------------------------- + /** + * Perform the grouping for the users who are currently running the lesson. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws IOException + * @throws ServletException + */ + public ActionForward performGrouping(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) throws IOException, + ServletException + { + LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgressByID(request, + getServlet().getServletContext()); + validateLearnerProgress(learnerProgress); + + //initialize service object + ILearnerService learnerService = LearnerServiceProxy.getLearnerService(getServlet().getServletContext()); + + + List currentLearners = LessonLearnerDataManager.getAllLessonLearners(getServlet().getServletContext(), + learnerProgress.getLesson().getLessonId().longValue(), + learnerService); + learnerService.performGrouping((GroupingActivity)learnerProgress.getNextActivity(), + currentLearners); + + request.setAttribute(ActivityAction.ACTIVITY_REQUEST_ATTRIBUTE,learnerProgress.getNextActivity()); + + return mapping.findForward(VIEW_GROUPING); + } + + /** + * Load up the grouping information and forward to the jsp page to display + * all the groups and members. + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws IOException + * @throws ServletException + */ + public ActionForward viewGrouping(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) throws IOException, + ServletException + { + //initialize service object + ILearnerService learnerService = LearnerServiceProxy.getLearnerService(getServlet().getServletContext()); + + Activity groupingActivity = LearningWebUtil.getActivityFromRequest(request,learnerService); + + List groups = new ArrayList(((GroupingActivity)groupingActivity).getCreateGrouping() + .getGroups()); + request.getSession().setAttribute(GROUPS,groups); + + return mapping.findForward(SHOW_GROUP); + } + + //--------------------------------------------------------------------- + // Helper method + //--------------------------------------------------------------------- + /** + * @param learnerProgress + */ + private void validateLearnerProgress(LearnerProgress learnerProgress) + { + if(learnerProgress ==null) + throw new LearnerServiceException("Can't perform grouping without knowing" + + " the learner progress."); + + if(!isNextActivityValid(learnerProgress)) + throw new LearnerServiceException("Error in progress engine. Getting " + +learnerProgress.getNextActivity().toString() + +" where it should be grouping activity"); + } + + + /** + * Validate the next activity within the learner progress. It should not + * be null and it should be the grouping activity. + * @param learnerProgress the learner progress for current learner. + * @return whether the next activity is valid. + */ + private boolean isNextActivityValid(LearnerProgress learnerProgress) + { + return learnerProgress.getNextActivity()!=null&&(learnerProgress.getNextActivity() instanceof GroupingActivity); + } + +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/LearnerAction.java =================================================================== diff -u -r7213f7efef305780b43d6d8f8c3f0616237ba8ec -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/LearnerAction.java (.../LearnerAction.java) (revision 7213f7efef305780b43d6d8f8c3f0616237ba8ec) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/LearnerAction.java (.../LearnerAction.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -33,9 +33,9 @@ import org.apache.struts.action.ActionMapping; import org.lamsfoundation.lams.learning.service.ILearnerService; import org.lamsfoundation.lams.learning.service.LearnerServiceProxy; -import org.lamsfoundation.lams.learning.web.bean.SessionBean; import org.lamsfoundation.lams.learning.web.util.ActivityMapping; import org.lamsfoundation.lams.learning.web.util.LearningWebUtil; +import org.lamsfoundation.lams.learning.web.util.LessonLearnerDataManager; import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.learningdesign.dto.ProgressActivityDTO; @@ -183,10 +183,14 @@ if(log.isDebugEnabled()) log.debug("The learner ["+learner.getUserId()+"] joined lesson. The" +"porgress data is:"+learnerProgress.toString()); + + + LessonLearnerDataManager.cacheLessonUser(getServlet().getServletContext(), + lesson,learner); //setup session attributes - request.getSession().setAttribute(SessionBean.NAME,new SessionBean(learner, - lesson, - learnerProgress)); + //request.getSession().setAttribute(SessionBean.NAME,new SessionBean(learner, + // lesson, + // learnerProgress)); request.getSession().setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,learnerProgress); //serialize a acknowledgement flash message with the path of display next @@ -236,13 +240,17 @@ //initialize service object ILearnerService learnerService = LearnerServiceProxy.getLearnerService(getServlet().getServletContext()); - SessionBean sessionBean = LearningWebUtil.getSessionBean(request,getServlet().getServletContext()); + //SessionBean sessionBean = LearningWebUtil.getSessionBean(request,getServlet().getServletContext()); + LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgressByUser(request,getServlet().getServletContext()); if(log.isDebugEnabled()) - log.debug("Lesson id is: "+sessionBean.getLesson().getLessonId()); + log.debug("Lesson id is: "+learnerProgress.getLesson().getLessonId()); - learnerService.exitLesson(sessionBean.getLearnerProgress()); + learnerService.exitLesson(learnerProgress); + LessonLearnerDataManager.removeLessonUserFromCache(getServlet().getServletContext(), + learnerProgress.getLesson(), + learnerProgress.getUser()); //send acknowledgment to flash as it is triggerred by flash String lessonExitted = WDDXProcessor.serialize(new FlashMessage("exitLesson",null)); if(log.isDebugEnabled()) @@ -286,10 +294,11 @@ if(log.isDebugEnabled()) log.debug("Getting Flash progress data..."); - SessionBean sessionBean = LearningWebUtil.getSessionBean(request,getServlet().getServletContext()); + //SessionBean sessionBean = LearningWebUtil.getSessionBean(request,getServlet().getServletContext()); + LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgressByID(request,getServlet().getServletContext()); String progressData = WDDXProcessor.serialize(new FlashMessage("getFlashProgressData", - sessionBean.getLearnerProgress().getLearnerProgressData())); + learnerProgress.getLearnerProgressData())); if(log.isDebugEnabled()) log.debug("Sending learner progress data to flash:"+progressData); Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMapping.java =================================================================== diff -u -r7213f7efef305780b43d6d8f8c3f0616237ba8ec -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMapping.java (.../ActivityMapping.java) (revision 7213f7efef305780b43d6d8f8c3f0616237ba8ec) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMapping.java (.../ActivityMapping.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -38,7 +38,6 @@ import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.tool.ToolAccessMode; -import org.lamsfoundation.lams.tool.ToolSession; import org.lamsfoundation.lams.tool.service.ILamsCoreToolService; import org.lamsfoundation.lams.tool.service.LamsToolServiceException; import org.lamsfoundation.lams.usermanagement.User; @@ -231,8 +230,10 @@ } } - return activityURL+"&"+LearningWebUtil.PARAM_PROGRESS_ID+"=" - +progress.getLearnerProgressId(); + return WebUtil.appendParameterToURL(activityURL, + LearningWebUtil.PARAM_PROGRESS_ID, + progress.getLearnerProgressId().toString()); + } /** @@ -244,23 +245,15 @@ */ public String getLearnerToolURL(ToolActivity activity, User learner) { - - ToolSession toolSession; try { - // Get tool session using learner and activity - toolSession = toolService.getToolSessionByLearner(learner, activity); + return toolService.getLearnerToolURLByMode(activity,learner,ToolAccessMode.LEARNER); } catch (LamsToolServiceException e) { //TODO define an exception at web layer throw new LearnerServiceException(e.getMessage()); } - // Append toolSessionId to tool URL - return activity.getTool().getLearnerUrl() + "&" - + WebUtil.PARAM_TOOL_SESSION_ID + "=" - + toolSession.getToolSessionId().toString() + "&" - + WebUtil.PARAM_MODE + "=" + ToolAccessMode.LEARNER; } /** @@ -340,7 +333,7 @@ } else if (activity instanceof GroupingActivity) //TODO need to be changed when group action servlet is done - return "/viewGrouping.do?"; + return getActivityURL(activity, null); throw new LearnerServiceException("Fails to get the progress url view" + " for activity[" + activity.getActivityId().longValue() + "]"); Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMappingStrategy.java =================================================================== diff -u -r4e049aced5079eff1ff599aa4572624cc0314e59 -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMappingStrategy.java (.../ActivityMappingStrategy.java) (revision 4e049aced5079eff1ff599aa4572624cc0314e59) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMappingStrategy.java (.../ActivityMappingStrategy.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -48,26 +48,23 @@ protected String getActivityAction(Activity activity, LearnerProgress progress) { String strutsAction = null; - if (activity instanceof ComplexActivity) { - if (activity instanceof ParallelActivity) { + if (activity instanceof ComplexActivity) + { + if (activity instanceof ParallelActivity) strutsAction = "/DisplayParallelActivity.do"; - } - else if (activity instanceof OptionsActivity) { + else if (activity instanceof OptionsActivity) strutsAction = "/DisplayOptionsActivity.do"; - } } - else if (activity instanceof SimpleActivity) { - if (activity instanceof GroupingActivity) { - // this probably means a wait URL - } + else if (activity instanceof SimpleActivity) + { + if (activity instanceof GroupingActivity) + strutsAction = "/grouping.do?"; if (activity instanceof GateActivity) { // not completed so return wait URL } - if (activity instanceof ToolActivity) { - // get tool URL + if (activity instanceof ToolActivity) strutsAction = "/LoadToolActivity.do"; //strutsAction = "/DisplayToolActivity.do"; - } } return strutsAction; } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java =================================================================== diff -u -r7213f7efef305780b43d6d8f8c3f0616237ba8ec -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java (.../LearningWebUtil.java) (revision 7213f7efef305780b43d6d8f8c3f0616237ba8ec) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java (.../LearningWebUtil.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -30,6 +30,7 @@ import org.lamsfoundation.lams.learning.service.LearnerServiceProxy; import org.lamsfoundation.lams.learning.web.action.ActivityAction; import org.lamsfoundation.lams.learning.web.bean.SessionBean; +import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.usermanagement.User; @@ -140,4 +141,73 @@ return bean; } + /** + * Get the current learner progress. The http session attributes are checked + * first, if not in request then a new LearnerProgress is loaded by id using + * the LearnerService. The LearnerProgress is also stored in the + * session so that the Flash requests don't have to reload it. + */ + public static LearnerProgress getLearnerProgressByID(HttpServletRequest request,ServletContext servletContext) { + //TODO need to be retrieved from proper cache when caching done properly. + LearnerProgress learnerProgress = (LearnerProgress)request.getSession().getAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE); + + if (learnerProgress == null) + { + //initialize service object + ILearnerService learnerService = LearnerServiceProxy.getLearnerService(servletContext); + + long learnerProgressId = WebUtil.readLongParam(request,LearningWebUtil.PARAM_PROGRESS_ID); + + learnerProgress = learnerService.getProgressById(new Long(learnerProgressId)); + + request.getSession().setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,learnerProgress); + } + return learnerProgress; + } + /** + * Get the current learner progress. The http session attributes are checked + * first, if not in request then a new LearnerProgress is loaded by user + * and lesson using the LearnerService. The LearnerProgress is also stored + * in the session so that the Flash requests don't have to reload it. + */ + public static LearnerProgress getLearnerProgressByUser(HttpServletRequest request,ServletContext servletContext) { + + LearnerProgress learnerProgress = (LearnerProgress)request.getSession().getAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE); + + if (learnerProgress == null) + { + //initialize service object + ILearnerService learnerService = LearnerServiceProxy.getLearnerService(servletContext); + + User currentLearner = getUserData(request, servletContext); + Lesson lesson = getLessonData(request,servletContext); + + learnerProgress = learnerService.getProgress(currentLearner,lesson); + + request.getSession().setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,learnerProgress); + } + return learnerProgress; + } + + /** + * Get the activity from request. We assume there is a parameter coming in + * if there is no activity can be found in the http request. Then the + * activity id parameter is used to retrieve from database. + * @param request + * @return + */ + public static Activity getActivityFromRequest(HttpServletRequest request, + ILearnerService learnerService) + { + Activity activity = (Activity)request.getAttribute(ActivityAction.ACTIVITY_REQUEST_ATTRIBUTE); + + if(activity == null) + { + long activityId = WebUtil.readLongParam(request,PARAM_ACTIVITY_ID); + + activity = learnerService.getActivity(new Long(activityId)); + + } + return activity; + } } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LessonLearnerDataManager.java =================================================================== diff -u --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LessonLearnerDataManager.java (revision 0) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LessonLearnerDataManager.java (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -0,0 +1,166 @@ +/*************************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * ***********************************************************************/ + +package org.lamsfoundation.lams.learning.web.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Iterator; +import java.util.List; + +import javax.servlet.ServletContext; + +import org.lamsfoundation.lams.learning.service.ILearnerService; +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.usermanagement.User; + + +/** + * The utility class to managed learner cache who has joined the lesson. This + * is to avoid unecessary database call for getting learners who are doing + * the currently running lesson. + * + * The current implementation is a simple solution that is using servlet context + * as the caching container. TODO This meant to be replaced by other cache + * solution such as JBoss transactional cache. + * + * @author Jacky Fang + * @since 2005-3-30 + * @version 1.1 + * + */ +public class LessonLearnerDataManager +{ + public static final String ATTR_LESSON_USER_CACHE = "lesson-"; + + + /** + * + * @param context + * @param lesson + * @param learner + */ + public static void cacheLessonUser(ServletContext context, + Lesson lesson, + User learner) + { + synchronized (context) + { + //retrieve the map from context + HashMap lessonUsersMap = + (HashMap) context.getAttribute(ATTR_LESSON_USER_CACHE+lesson.getLessonId().toString()); + //create new if never created before + if (lessonUsersMap == null) + lessonUsersMap = new HashMap(); + //set into cache if never cached before + if (!lessonUsersMap.containsKey(learner.getUserId())) + { + lessonUsersMap.put(learner.getUserId(), learner); + context.setAttribute(ATTR_LESSON_USER_CACHE+lesson.getLessonId().toString(), lessonUsersMap); + } + } + } + + /** + * + * @param context + * @param lesson + * @param learner + */ + public static void removeLessonUserFromCache(ServletContext context, + Lesson lesson, + User learner) + { + synchronized (context) + { + //retrieve the map from context + HashMap lessonUsersMap = + (HashMap) context.getAttribute(ATTR_LESSON_USER_CACHE+lesson.getLessonId().toString()); + //don't do anything if the cache is not there. + if (lessonUsersMap == null) + return; + //remove it if it is there. + if (lessonUsersMap.containsKey(learner.getUserId())) + { + lessonUsersMap.remove(learner.getUserId()); + context.setAttribute(ATTR_LESSON_USER_CACHE+lesson.getLessonId().toString(), lessonUsersMap); + } + } + } + + /** + * + * @param context + * @param lessonId + */ + public static List getAllLessonLearners(ServletContext context, + long lessonId, + ILearnerService learnerService) + { + //retrieve the map from context + HashMap lessonUsersMap = + (HashMap) context.getAttribute(ATTR_LESSON_USER_CACHE+lessonId); + + if(lessonUsersMap==null) + lessonUsersMap = restoreMapFromDatabase(learnerService,lessonId, + context); + + ArrayList lessonUsers = new ArrayList(); + + for(Iterator i = lessonUsersMap.entrySet().iterator();i.hasNext();) + { + Map.Entry entry = (Map.Entry)i.next(); + lessonUsers.add(entry.getValue()); + } + + return lessonUsers; + } + + + /** + * + * @param learnerService + * @param lessonId + * @param context + * @return + */ + private static HashMap restoreMapFromDatabase(ILearnerService learnerService, + long lessonId, + ServletContext context) + { + HashMap learnersMap = new HashMap(); + List learners = learnerService.getActiveLearnersByLesson(lessonId); + + for(Iterator i = learners.iterator();i.hasNext();) + { + User learner = (User)i.next(); + learnersMap.put(learner.getUserId(), learner); + } + + context.setAttribute(ATTR_LESSON_USER_CACHE+lessonId, learnersMap); + + return learnersMap; + } + + +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ParallelActivityMappingStrategy.java =================================================================== diff -u -rec41df86451fb6307b8f9600958646ab4f4774bd -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ParallelActivityMappingStrategy.java (.../ParallelActivityMappingStrategy.java) (revision ec41df86451fb6307b8f9600958646ab4f4774bd) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ParallelActivityMappingStrategy.java (.../ParallelActivityMappingStrategy.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -22,18 +22,9 @@ package org.lamsfoundation.lams.learning.web.util; import org.lamsfoundation.lams.learningdesign.Activity; -import org.lamsfoundation.lams.learningdesign.ComplexActivity; -import org.lamsfoundation.lams.learningdesign.GateActivity; -import org.lamsfoundation.lams.learningdesign.GroupingActivity; -import org.lamsfoundation.lams.learningdesign.NullActivity; -import org.lamsfoundation.lams.learningdesign.OptionsActivity; -import org.lamsfoundation.lams.learningdesign.ParallelActivity; -import org.lamsfoundation.lams.learningdesign.SimpleActivity; -import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.lesson.LearnerProgress; -import org.lamsfoundation.lams.lesson.LessonCompleteActivity; -import org.lamsfoundation.lams.lesson.ParallelWaitActivity; + /** * @author daveg * @@ -46,14 +37,13 @@ * @param progress, LearnerProgress for the activity, used to check activity status * @return String representing a struts action */ - protected String getActivityAction(Activity activity, LearnerProgress progress) { + protected String getActivityAction(Activity activity, LearnerProgress progress) + { String strutsAction = null; - if (progress.getProgressState(activity) == LearnerProgress.ACTIVITY_COMPLETED) { + if (progress.getProgressState(activity) == LearnerProgress.ACTIVITY_COMPLETED) strutsAction = "/parallelWait.do"; - } - else { + else strutsAction = super.getActivityAction(activity, progress); - } return strutsAction; } Index: lams_learning/test/java/org/lamsfoundation/lams/learning/service/TestLearnerService.java =================================================================== diff -u -r7213f7efef305780b43d6d8f8c3f0616237ba8ec -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/test/java/org/lamsfoundation/lams/learning/service/TestLearnerService.java (.../TestLearnerService.java) (revision 7213f7efef305780b43d6d8f8c3f0616237ba8ec) +++ lams_learning/test/java/org/lamsfoundation/lams/learning/service/TestLearnerService.java (.../TestLearnerService.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -24,6 +24,8 @@ import org.lamsfoundation.lams.learning.progress.ProgressException; import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.Grouping; +import org.lamsfoundation.lams.learningdesign.GroupingActivity; import org.lamsfoundation.lams.learningdesign.OptionsActivity; import org.lamsfoundation.lams.learningdesign.ParallelActivity; import org.lamsfoundation.lams.learningdesign.ToolActivity; @@ -78,7 +80,7 @@ private static final long TEST_SEQUENCE_ACTIVITY_ID = 36; private static final long TEST_SR_ACTIVITY_ID = 37; private static final long TEST_SQNA_ACTIVITY_ID = 38; - private static final String HOST="http://localhost:8080/lams_learning/"; + private static final String HOST="http://localhost:8080/lams_learning"; private static final String LOAD_TOOL_URL="/LoadToolActivity.do"; private static final String PARAM_ACTIVITY_ID="?activityId="; /* @@ -153,7 +155,7 @@ assertNotNull("verify the existance of tool session",toolSession); assertEquals("verify tool session state",ToolSession.ENDED_STATE,toolSession.getToolSessionStateId()); - assertEquals("verify the returned url",HOST+LOAD_TOOL_URL+PARAM_ACTIVITY_ID+TEST_NB_ACTIVITY_ID+"progressId=1",urlForNextActivity); + assertEquals("verify the returned url",HOST+LOAD_TOOL_URL+PARAM_ACTIVITY_ID+TEST_NB_ACTIVITY_ID+"&progressId=1",urlForNextActivity); } @@ -263,6 +265,19 @@ assertTrue("verify it should be restarting",progress.isRestarting()); } + + public void testPerformGrouping() + { + Activity randomGroupingActivity = learnerService.getActivity(new Long(TEST_RGRP_ACTIVITY_ID)); + + Grouping randomGrouping = ((GroupingActivity)randomGroupingActivity).getCreateGrouping(); + + assertTrue("verify the existance of test user",!randomGrouping.doesLearnerExist(testUser)); + + learnerService.performGrouping((GroupingActivity)randomGroupingActivity,testUser); + + assertTrue("verify the existance of test user",randomGrouping.doesLearnerExist(testUser)); + } /** * @param numberOfAttemptedAct * @param testCompletedActivity Index: lams_learning/test/java/org/lamsfoundation/lams/learning/web/action/TestDisplayActivityAction.java =================================================================== diff -u -red8afe78a454a4b3b9d2ae039ac12d7ad9dc809a -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/test/java/org/lamsfoundation/lams/learning/web/action/TestDisplayActivityAction.java (.../TestDisplayActivityAction.java) (revision ed8afe78a454a4b3b9d2ae039ac12d7ad9dc809a) +++ lams_learning/test/java/org/lamsfoundation/lams/learning/web/action/TestDisplayActivityAction.java (.../TestDisplayActivityAction.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -22,8 +22,8 @@ package org.lamsfoundation.lams.learning.web.action; +import org.apache.log4j.Logger; import org.lamsfoundation.lams.AbstractLamsStrutsTestCase; -import org.lamsfoundation.lams.learning.web.bean.SessionBean; import org.lamsfoundation.lams.learningdesign.OptionsActivity; import org.lamsfoundation.lams.learningdesign.ParallelActivity; import org.lamsfoundation.lams.lesson.LearnerProgress; @@ -38,9 +38,16 @@ */ public class TestDisplayActivityAction extends AbstractLamsStrutsTestCase { + //--------------------------------------------------------------------- + // Instance variables + //--------------------------------------------------------------------- + private static Logger log = Logger.getLogger(TestDisplayActivityAction.class); + + private static final String TEST_USER_ID = "2"; private static final String TEST_LESSON_ID = "2"; - private static SessionBean testBean = null; + //private static SessionBean testBean = null; + private static LearnerProgress learnerProgress = null; /** * Constructor for TestDisplayActivityAction. * @param arg0 @@ -56,9 +63,10 @@ private static String getContextConfigLocation() { return "/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml " - +"/org/lamsfoundation/lams/tool/toolApplicationContext.xml " - +"applicationContext.xml " - +"/WEB-INF/spring/learningApplicationContext.xml"; + +"/org/lamsfoundation/lams/tool/toolApplicationContext.xml " + +"/org/lamsfoundation/lams/learningdesign/learningDesignApplicationContext.xml " + +"applicationContext.xml " + +"/WEB-INF/spring/learningApplicationContext.xml"; } /* @@ -91,8 +99,8 @@ addRequestParameter("lessonId", TEST_LESSON_ID); actionPerform(); - testBean = (SessionBean)httpSession.getAttribute(SessionBean.NAME); - + //testBean = (SessionBean)httpSession.getAttribute(SessionBean.NAME); + learnerProgress = (LearnerProgress)httpSession.getAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE); //test page loading. setRequestPathInfo("/DisplayActivity.do"); actionPerform(); @@ -102,30 +110,31 @@ public void testDisplayToolActivityFollowingParallelActivity() { //setup the session bean to display option page. - LearnerProgress progress = testBean.getLearnerProgress(); + //LearnerProgress progress = testBean.getLearnerProgress(); ParallelActivity parallelActivity= new ParallelActivity(); - progress.setPreviousActivity(parallelActivity); - testBean.setLearnerProgress(progress); - httpSession.setAttribute(SessionBean.NAME,testBean); + learnerProgress.setPreviousActivity(parallelActivity); + //testBean.setLearnerProgress(progress); + httpSession.setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,learnerProgress); setRequestPathInfo("/DisplayActivity.do"); actionPerform(); - verifyForwardPath("/requestDisplay.do?url=http://localhost:8080/lams_learning//LoadToolActivity.do?activityId=26"); + verifyForwardPath("/requestDisplay.do?url=http://localhost:8080/lams_learning/LoadToolActivity.do?activityId=26"); //restore the progress - progress = testBean.getLearnerProgress(); - progress.setPreviousActivity(null); - testBean.setLearnerProgress(progress); + //progress = testBean.getLearnerProgress(); + learnerProgress.setPreviousActivity(null); + //testBean.setLearnerProgress(progress); } public void testDisplayOptionsActivity() { //setup the session bean to display option page. - LearnerProgress progress = testBean.getLearnerProgress(); + //LearnerProgress progress = testBean.getLearnerProgress(); OptionsActivity optionActivity= new OptionsActivity(); - progress.setNextActivity(optionActivity); - testBean.setLearnerProgress(progress); - httpSession.setAttribute(SessionBean.NAME,testBean); + learnerProgress.setNextActivity(optionActivity); + //testBean.setLearnerProgress(progress); + //httpSession.setAttribute(SessionBean.NAME,testBean); + httpSession.setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,learnerProgress); setRequestPathInfo("/DisplayActivity.do"); actionPerform(); @@ -135,11 +144,12 @@ public void testDisplayParallelActivity() { //setup the session bean to display option page. - LearnerProgress progress = testBean.getLearnerProgress(); + //LearnerProgress progress = testBean.getLearnerProgress(); ParallelActivity parallelActivity= new ParallelActivity(); - progress.setNextActivity(parallelActivity); - testBean.setLearnerProgress(progress); - httpSession.setAttribute(SessionBean.NAME,testBean); + learnerProgress.setNextActivity(parallelActivity); + //testBean.setLearnerProgress(progress); + //httpSession.setAttribute(SessionBean.NAME,testBean); + httpSession.setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,learnerProgress); setRequestPathInfo("/DisplayActivity.do"); actionPerform(); @@ -151,10 +161,11 @@ public void testDisplayWaitingParallelActivity() { //setup the session bean to display parallel waiting. - LearnerProgress progress = testBean.getLearnerProgress(); - progress.setParallelWaiting(true); - testBean.setLearnerProgress(progress); - httpSession.setAttribute(SessionBean.NAME,testBean); + //LearnerProgress progress = testBean.getLearnerProgress(); + learnerProgress.setParallelWaiting(true); + //testBean.setLearnerProgress(progress); + //httpSession.setAttribute(SessionBean.NAME,testBean); + httpSession.setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,learnerProgress); setRequestPathInfo("/DisplayActivity.do"); actionPerform(); @@ -164,10 +175,11 @@ public void testDisplayCompletionPage() { //setup the session bean to display completion page. - LearnerProgress progress = testBean.getLearnerProgress(); - progress.setLessonComplete(true); - testBean.setLearnerProgress(progress); - httpSession.setAttribute(SessionBean.NAME,testBean); + //LearnerProgress progress = testBean.getLearnerProgress(); + learnerProgress.setLessonComplete(true); + //testBean.setLearnerProgress(progress); + //httpSession.setAttribute(SessionBean.NAME,testBean); + httpSession.setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,learnerProgress); setRequestPathInfo("/DisplayActivity.do"); actionPerform(); Index: lams_learning/test/java/org/lamsfoundation/lams/learning/web/action/TestLearnerAction.java =================================================================== diff -u -r3b567a2a4db4064f9c2aec96ffd5789ff7634788 -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/test/java/org/lamsfoundation/lams/learning/web/action/TestLearnerAction.java (.../TestLearnerAction.java) (revision 3b567a2a4db4064f9c2aec96ffd5789ff7634788) +++ lams_learning/test/java/org/lamsfoundation/lams/learning/web/action/TestLearnerAction.java (.../TestLearnerAction.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -22,9 +22,10 @@ package org.lamsfoundation.lams.learning.web.action; +import org.apache.log4j.Logger; import org.lamsfoundation.lams.AbstractLamsStrutsTestCase; -import org.lamsfoundation.lams.learning.web.bean.SessionBean; import org.lamsfoundation.lams.learning.web.util.LearningWebUtil; +import org.lamsfoundation.lams.lesson.LearnerProgress; /** @@ -36,12 +37,17 @@ */ public class TestLearnerAction extends AbstractLamsStrutsTestCase { - + //--------------------------------------------------------------------- + // Instance variables + //--------------------------------------------------------------------- + private static Logger log = Logger.getLogger(TestLearnerAction.class); + private static final String TEST_USER_ID = "2"; private static final String TEST_LESSON_ID = "2"; private static final String TEST_ACTIVITY_ID = "26"; - private static SessionBean joinedLessonBean = null; + //private static SessionBean joinedLessonBean = null; + private static LearnerProgress testLearnerProgress = null; /* * @see TestCase#setUp() @@ -102,16 +108,19 @@ verifyNoActionErrors(); - joinedLessonBean = (SessionBean)httpSession.getAttribute(SessionBean.NAME); - assertNotNull("verify the session bean",joinedLessonBean); - assertEquals("verify the learner in the session bean",TEST_USER_ID,joinedLessonBean.getLearner().getUserId().toString()); - assertEquals("verify the lesson in the session bean",TEST_LESSON_ID,joinedLessonBean.getLesson().getLessonId().toString()); - assertNotNull("verify the learner progress",joinedLessonBean.getLearnerProgress()); + //joinedLessonBean = (SessionBean)httpSession.getAttribute(SessionBean.NAME); + testLearnerProgress = (LearnerProgress)httpSession.getAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE); + + //assertNotNull("verify the session bean",testLearnerProgress); + assertNotNull("verify the learner progress",testLearnerProgress); + assertEquals("verify the learner in the session bean",TEST_USER_ID,testLearnerProgress.getUser().getUserId().toString()); + assertEquals("verify the lesson in the session bean",TEST_LESSON_ID,testLearnerProgress.getLesson().getLessonId().toString()); + } public void testGetFlashProgressData() { - httpSession.setAttribute(SessionBean.NAME,joinedLessonBean); + httpSession.setAttribute(ActivityAction.LEARNER_PROGRESS_REQUEST_ATTRIBUTE,testLearnerProgress); addRequestParameter("method", "getFlashProgressData"); addRequestParameter(LearningWebUtil.PARAM_USER_ID, TEST_USER_ID); addRequestParameter(LearningWebUtil.PARAM_LESSON_ID, TEST_LESSON_ID); Index: lams_learning/test/web/WEB-INF/spring/learningApplicationContext.xml =================================================================== diff -u -r7213f7efef305780b43d6d8f8c3f0616237ba8ec -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/test/web/WEB-INF/spring/learningApplicationContext.xml (.../learningApplicationContext.xml) (revision 7213f7efef305780b43d6d8f8c3f0616237ba8ec) +++ lams_learning/test/web/WEB-INF/spring/learningApplicationContext.xml (.../learningApplicationContext.xml) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -20,6 +20,7 @@ + Index: lams_learning/web/WEB-INF/spring/learningApplicationContext.xml =================================================================== diff -u -r7213f7efef305780b43d6d8f8c3f0616237ba8ec -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/web/WEB-INF/spring/learningApplicationContext.xml (.../learningApplicationContext.xml) (revision 7213f7efef305780b43d6d8f8c3f0616237ba8ec) +++ lams_learning/web/WEB-INF/spring/learningApplicationContext.xml (.../learningApplicationContext.xml) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -20,6 +20,7 @@ + Index: lams_learning/web/WEB-INF/struts/struts-config.xml =================================================================== diff -u -r7213f7efef305780b43d6d8f8c3f0616237ba8ec -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb --- lams_learning/web/WEB-INF/struts/struts-config.xml (.../struts-config.xml) (revision 7213f7efef305780b43d6d8f8c3f0616237ba8ec) +++ lams_learning/web/WEB-INF/struts/struts-config.xml (.../struts-config.xml) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb) @@ -104,38 +104,43 @@ /> + + - + + + +