Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/ICoreLearnerService.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/service/ICoreLearnerService.java,v diff -u -r1.4 -r1.5 --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/ICoreLearnerService.java 17 Sep 2006 06:17:58 -0000 1.4 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/ICoreLearnerService.java 8 Nov 2006 06:39:58 -0000 1.5 @@ -135,9 +135,10 @@ * * @param learnerId the learner who are running this activity in the design. * @param activity the activity is being run. + * @param lessonId lesson id * @return the url for next activity. */ - public String completeActivity(Integer learnerId,Long activityId); + public String completeActivity(Integer learnerId,Long activityId,Long lessonId); /** * Complete the activity in the progress engine and delegate to the progress @@ -147,9 +148,10 @@ * * @param learnerId the learner who are running this activity in the design. * @param activity the activity is being run. + * @param lessonId lesson id * @return the url for next activity. */ - public String completeActivity(Integer learnerId,Activity activity); + public String completeActivity(Integer learnerId,Activity activity,Long lessonId); /** * Retrieve all lessons that has been started, suspended or finished. All Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java,v diff -u -r1.60 -r1.61 --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java 19 Oct 2006 01:26:26 -0000 1.60 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java 8 Nov 2006 06:39:58 -0000 1.61 @@ -400,25 +400,8 @@ ToolSession toolSession = lamsCoreToolService.getToolSessionById(toolSessionId); // in the future, we might want to see if the entire tool session is completed at this point. - LearnerProgress currentProgress = getProgress(new Integer(learnerId.intValue()), toolSession.getLesson().getLessonId()); - - // Need to synchronise the next bit of code so that if the tool calls - // this twice in quick succession, with the same parameters, it won't update - // the database twice! This may happen if a tool has a double submission problem. - // I don't want to synchronise on (this), as this could cause too much of a bottleneck, - // but if its not synchronised, we get db errors if the same tool session is completed twice - // (invalid index). I can'tfind another object on which to synchronise - Hibernate does not give me the - // same object for tool session or current progress and user is cached via login, not userid. - String returnURL = null; - // bottleneck synchronized (this) { - if (currentProgress.getCompletedActivities().contains(toolSession.getToolActivity())) { - // return close window url - returnURL = ActivityMapping.getCloseURL(); - } else { - returnURL = completeActivity(new Integer(learnerId.intValue()), toolSession.getToolActivity()); - } - //} - + String returnURL = completeActivity(new Integer(learnerId.intValue()), toolSession.getToolActivity(), toolSession.getLesson().getLessonId()); + if ( log.isDebugEnabled() ) { log.debug("Moving onto next activity after tool session id "+toolSessionId+" learnerId "+learnerId+" url is "+returnURL); } @@ -428,28 +411,48 @@ } /** - * @see org.lamsfoundation.lams.learning.service.ICoreLearnerService#completeActivity(java.lang.Integer, java.lang.Long) + * @see org.lamsfoundation.lams.learning.service.ICoreLearnerService#completeActivity(java.lang.Integer, java.lang.Long, java.lang.Long) */ - public String completeActivity(Integer learnerId,Long activityId) { + public String completeActivity(Integer learnerId,Long activityId,Long lessonId) { Activity activity = getActivity(activityId); - return completeActivity(learnerId, activity); + return completeActivity(learnerId, activity,lessonId); } /** * @see org.lamsfoundation.lams.learning.service.ICoreLearnerService#completeActivity(java.lang.Integer, org.lamsfoundation.lams.learningdesign.Activity, java.lang.Long ) */ - public String completeActivity(Integer learnerId,Activity activity) + public String completeActivity(Integer learnerId,Activity activity,Long lessonId) { - try - { - LearnerProgress nextLearnerProgress = calculateProgress(activity, learnerId); - return activityMapping.getProgressURL(nextLearnerProgress); - } - catch (UnsupportedEncodingException e) - { - log.error("error occurred in 'getProgressURL':"+e.getMessage()); - throw new LearnerServiceException(e.getMessage()); - } + LearnerProgress currentProgress = getProgress(new Integer(learnerId.intValue()), lessonId); + + // Need to synchronise the next bit of code so that if the tool calls + // this twice in quick succession, with the same parameters, it won't update + // the database twice! This may happen if a tool has a double submission problem. + // I don't want to synchronise on (this), as this could cause too much of a bottleneck, + // but if its not synchronised, we get db errors if the same tool session is completed twice + // (invalid index). I can'tfind another object on which to synchronise - Hibernate does not give me the + // same object for tool session or current progress and user is cached via login, not userid. + String returnURL = null; + // bottleneck synchronized (this) { + if (currentProgress.getCompletedActivities().contains(activity)) { + // return close window url + returnURL = ActivityMapping.getCloseURL(); + + } else { + + try + { + LearnerProgress nextLearnerProgress = calculateProgress(activity, learnerId); + returnURL = activityMapping.getProgressURL(nextLearnerProgress); + } + catch (UnsupportedEncodingException e) + { + log.error("error occurred in 'getProgressURL':"+e.getMessage()); + throw new LearnerServiceException(e.getMessage()); + } + } + //} + return returnURL; } /** @@ -495,26 +498,26 @@ if ( groupingActivity != null && groupingActivity.getCreateGrouping()!=null && learner != null ) { Grouping grouping = groupingActivity.getCreateGrouping(); - if ( grouping.isRandomGrouping() ) { - // normal and preview cases for random grouping - lessonService.performGrouping(lessonId, groupingActivity, learner); - groupingDone = true; - - } else if ( forceGrouping ) { - // preview case for chosen grouping - Lesson lesson = getLesson(lessonId); - if ( lesson.isPreviewLesson() ) { - ArrayList learnerList = new ArrayList(); - learnerList.add(learner); - lessonService.performGrouping(groupingActivity, (String)null, learnerList); - groupingDone = true; - } - } + // first check if the grouping already done for the user. If done, then skip the processing. + groupingDone = grouping.doesLearnerExist(learner); - if ( ! groupingDone ) { - // normal case for chosen grouping - groupingDone = grouping.doesLearnerExist(learner); - } + if ( ! groupingDone ) { + if ( grouping.isRandomGrouping() ) { + // normal and preview cases for random grouping + lessonService.performGrouping(lessonId, groupingActivity, learner); + groupingDone = true; + + } else if ( forceGrouping ) { + // preview case for chosen grouping + Lesson lesson = getLesson(lessonId); + if ( lesson.isPreviewLesson() ) { + ArrayList learnerList = new ArrayList(); + learnerList.add(learner); + lessonService.performGrouping(groupingActivity, (String)null, learnerList); + groupingDone = true; + } + } + } } else { String error = "Grouping activity "+groupingActivity.getActivityId()+" learner "+learnerId+" does not exist. Cannot perform grouping."; Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GateAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GateAction.java,v diff -u -r1.13 -r1.14 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GateAction.java 17 Sep 2006 06:17:57 -0000 1.13 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GateAction.java 8 Nov 2006 06:39:58 -0000 1.14 @@ -135,7 +135,7 @@ // if we reuse our cached entries, hibernate may throw session errors (if the objects are CGLIB entities). if(gateOpen) { - String nextActivityUrl = learnerService.completeActivity(learner.getUserId(),activityId); + String nextActivityUrl = learnerService.completeActivity(learner.getUserId(),activityId,lesson.getLessonId()); response.sendRedirect(nextActivityUrl); return null; } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GroupingAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GroupingAction.java,v diff -u -r1.23 -r1.24 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GroupingAction.java 17 Sep 2006 06:17:57 -0000 1.23 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GroupingAction.java 8 Nov 2006 06:39:58 -0000 1.24 @@ -38,14 +38,16 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; import org.lamsfoundation.lams.learning.service.ICoreLearnerService; -import org.lamsfoundation.lams.learning.service.LearnerServiceException; import org.lamsfoundation.lams.learning.service.LearnerServiceProxy; +import org.lamsfoundation.lams.learning.web.util.ActivityMapping; import org.lamsfoundation.lams.learning.web.util.LearningWebUtil; import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.Group; import org.lamsfoundation.lams.learningdesign.GroupComparator; import org.lamsfoundation.lams.learningdesign.Grouping; import org.lamsfoundation.lams.learningdesign.GroupingActivity; import org.lamsfoundation.lams.lesson.LearnerProgress; +import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.action.LamsDispatchAction; import org.lamsfoundation.lams.web.util.AttributeNames; @@ -130,17 +132,22 @@ //initialize service object ICoreLearnerService learnerService = LearnerServiceProxy.getLearnerService(getServlet().getServletContext()); LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgress(request, learnerService); - validateLearnerProgress(learnerProgress); - + Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); + if (!(activity instanceof GroupingActivity)) + { + log.error(className+": activity not GroupingActivity"); + return mapping.findForward(ActivityMapping.ERROR); + } + boolean groupingDone = learnerService.performGrouping(learnerProgress.getLesson().getLessonId(), - learnerProgress.getNextActivity().getActivityId(), + activity.getActivityId(), LearningWebUtil.getUserId(),forceGroup); - LearningWebUtil.putActivityInRequest(request, learnerProgress.getNextActivity(), learnerService); + LearningWebUtil.putActivityInRequest(request, activity, learnerService); DynaActionForm groupForm = (DynaActionForm)form; groupForm.set("previewLesson",learnerProgress.getLesson().isPreviewLesson()); - groupForm.set("title", learnerProgress.getNextActivity().getTitle()); + groupForm.set("title", activity.getTitle()); if ( groupingDone ) { request.setAttribute(FINISHED_BUTTON, Boolean.TRUE); @@ -169,7 +176,7 @@ //initialize service object ICoreLearnerService learnerService = LearnerServiceProxy.getLearnerService(getServlet().getServletContext()); - SortedSet groups = new TreeSet(new GroupComparator()); + SortedSet groups = new TreeSet(new GroupComparator()); Activity activity = LearningWebUtil.getActivityFromRequest(request,learnerService); @@ -247,40 +254,12 @@ ICoreLearnerService learnerService = LearnerServiceProxy.getLearnerService(getServlet().getServletContext()); LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgress(request,learnerService); Activity groupingActivity = LearningWebUtil.getActivityFromRequest(request,learnerService); - + Lesson lesson = learnerService.getLessonByActivity(groupingActivity); + String nextActivityUrl = learnerService.completeActivity(learnerProgress.getUser().getUserId(), - groupingActivity); + groupingActivity, lesson.getLessonId()); response.sendRedirect(nextActivityUrl); return null; } - //--------------------------------------------------------------------- - // 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().isGroupingActivity()); - } - + }