Index: lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressEngine.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressEngine.java,v diff -u -r1.21.4.4 -r1.21.4.5 --- lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressEngine.java 10 Apr 2007 05:03:22 -0000 1.21.4.4 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressEngine.java 11 Apr 2007 07:05:04 -0000 1.21.4.5 @@ -37,6 +37,7 @@ import org.lamsfoundation.lams.learningdesign.Transition; import org.lamsfoundation.lams.learningdesign.dao.IActivityDAO; import org.lamsfoundation.lams.lesson.LearnerProgress; +import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.lesson.ParallelWaitActivity; import org.lamsfoundation.lams.usermanagement.User; @@ -119,7 +120,7 @@ } else if ( progress.getCompletedActivities().contains(ld.getFirstActivity()) ) { // special case - recalculating the appropriate current activity. return calculateProgress(progress.getUser(), ld.getFirstActivity(), progress); - } else if ( canDoActivity(ld, ld.getFirstActivity()) ) { + } else if ( canDoActivity(progress.getLesson(), ld.getFirstActivity()) ) { // normal case progress.setCurrentActivity(ld.getFirstActivity()); progress.setNextActivity(ld.getFirstActivity()); @@ -144,8 +145,9 @@ * @param activity * @return */ - private boolean canDoActivity(LearningDesign design, Activity activity) { - return ! design.getEditOverrideLock() || activity.isActivityReadOnly() ; + private boolean canDoActivity(Lesson lesson, Activity activity) { + LearningDesign design = lesson.getLearningDesign(); + return ! lesson.getLockedForEdit() && ( ! design.getEditOverrideLock() || activity.isActivityReadOnly() ) ; } /** @@ -220,7 +222,7 @@ populateCurrentCompletedActivityList(learnerProgress); - if ( canDoActivity(learnerProgress.getLesson().getLearningDesign(), nextActivity) ) { + if ( canDoActivity(learnerProgress.getLesson(), nextActivity) ) { learnerProgress.setCurrentActivity(nextActivity); @@ -305,7 +307,7 @@ // learnerProgress.setNextActivity(null); populateCurrentCompletedActivityList(learnerProgress); } - else if ( canDoActivity(learnerProgress.getLesson().getLearningDesign(), nextActivity) ) + else if ( canDoActivity(learnerProgress.getLesson(), nextActivity) ) { learnerProgress.setParallelWaiting(false); learnerProgress.setNextActivity(nextActivity); Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/CompleteActivityAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/CompleteActivityAction.java,v diff -u -r1.14.4.3 -r1.14.4.4 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/CompleteActivityAction.java 10 Apr 2007 23:32:52 -0000 1.14.4.3 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/CompleteActivityAction.java 11 Apr 2007 07:05:04 -0000 1.14.4.4 @@ -80,22 +80,24 @@ Integer learnerId = LearningWebUtil.getUserId(); Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); - LearnerProgress progress = LearningWebUtil.getLearnerProgress(request, learnerService); + // This must get the learner progress from the progress id, not cached from the request, + // otherwise we may be using an old version of a lesson while a teacher is starting a + // live edit, and then the lock flag can't be checked correctly. + LearnerProgress progress = learnerService.getProgressById(WebUtil.readLongParam(request,LearningWebUtil.PARAM_PROGRESS_ID, true)); - String progressURL = null; + ActionForward forward = null; // Set activity as complete try { - progressURL = LearningWebUtil.completeActivity(request, response, + forward = LearningWebUtil.completeActivity(request, response, actionMappings, progress, activity, - learnerId, learnerService); + learnerId, learnerService, false); } catch (LearnerServiceException e) { return mapping.findForward("error"); } setupProgressString(actionForm, request); - response.sendRedirect(progressURL); - return null; + return forward; } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayActivityAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayActivityAction.java,v diff -u -r1.17 -r1.17.4.1 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayActivityAction.java 3 Nov 2006 07:13:13 -0000 1.17 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayActivityAction.java 11 Apr 2007 07:05:04 -0000 1.17.4.1 @@ -24,6 +24,8 @@ /* $$Id$$ */ package org.lamsfoundation.lams.learning.web.action; +import java.io.UnsupportedEncodingException; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -72,11 +74,12 @@ * Gets an activity from the request (attribute) and forwards onto a * display action using the ActionMappings class. If no activity is * in request then use the current activity in learnerProgress. + * @throws UnsupportedEncodingException */ public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, - HttpServletResponse response) + HttpServletResponse response) throws UnsupportedEncodingException { ICoreLearnerService learnerService = getLearnerService(); @@ -92,7 +95,7 @@ LearningWebUtil.putLearnerProgressInRequest(request, learnerProgress); ActivityMapping actionMappings = LearnerServiceProxy.getActivityMapping(getServlet().getServletContext()); - ActionForward forward =actionMappings.getProgressForward(learnerProgress,false,request,learnerService); + ActionForward forward =actionMappings.getProgressForward(learnerProgress,false,true,request,learnerService); setupProgressString(actionForm, request); if(log.isDebugEnabled()) 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.14.4.4 -r1.14.4.5 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GateAction.java 10 Apr 2007 23:32:52 -0000 1.14.4.4 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GateAction.java 11 Apr 2007 07:05:04 -0000 1.14.4.5 @@ -160,11 +160,9 @@ if ( learnerProgress == null ) { learnerProgress = learnerService.getProgress(learner.getUserId(), lessonId); } - String progressURL = LearningWebUtil.completeActivity(request, response, + return LearningWebUtil.completeActivity(request, response, actionMappings, learnerProgress, activity, - learner.getUserId(), learnerService); - response.sendRedirect(progressURL); - return null; + learner.getUserId(), learnerService, true); } //--------------------------------------------------------------------- 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.24.4.3 -r1.24.4.4 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GroupingAction.java 10 Apr 2007 23:32:52 -0000 1.24.4.3 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GroupingAction.java 11 Apr 2007 07:05:04 -0000 1.24.4.4 @@ -271,11 +271,9 @@ Integer learnerId = LearningWebUtil.getUserId(); // so manually resume the progress. The completeActivity code can cope with a missing activity. - String progressURL = LearningWebUtil.completeActivity(request, response, + return LearningWebUtil.completeActivity(request, response, getActivityMapping(), progress, groupingActivity, - learnerId, learnerService); - response.sendRedirect(progressURL); - return null; + learnerId, learnerService, true); } } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMapping.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMapping.java,v diff -u -r1.31.2.3 -r1.31.2.4 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMapping.java 10 Apr 2007 05:03:22 -0000 1.31.2.3 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMapping.java 11 Apr 2007 07:05:03 -0000 1.31.2.4 @@ -87,6 +87,10 @@ //String strutsAction = getActivityAction(activity, progress); String strutsAction = this.activityMappingStrategy.getActivityAction(activity); + strutsAction = WebUtil.appendParameterToURL(strutsAction, + LearningWebUtil.PARAM_PROGRESS_ID, + progress.getLearnerProgressId().toString()); + if (activity != null && activity.isToolActivity()) { // always use redirect false for a ToolActivity as ToolDisplayActivity @@ -109,12 +113,17 @@ * cleared. * @param progress, the LearnerProgress associated with the Activity and learner * @param redirect, If true a RedirectActionForward is used + * @param displayParallelFrames, if true then try to display the parallel activity frames rather than the + * internal tool screen. This is only set to true for DisplayActivityAction, which + * is called when the user joins/resumes the lesson. * @return + * @throws UnsupportedEncodingException */ public ActionForward getProgressForward(LearnerProgress progress, boolean redirect, + boolean displayParallelFrames, HttpServletRequest request, - ICoreLearnerService learnerService) + ICoreLearnerService learnerService) throws UnsupportedEncodingException { ActionForward actionForward = null; @@ -135,8 +144,9 @@ else { - if (progress.getCurrentActivity()!=null && ! progress.getCurrentActivity().isParallelActivity() && progress.isParallelWaiting()) + if (! displayParallelFrames && progress.isParallelWaiting()) { + // processing the screen WITHIN parallel activity frames. // progress is waiting, goto waiting page String strutsAction = this.getActivityMappingStrategy() .getWaitingAction(); @@ -173,13 +183,17 @@ return actionForward; } - public ActionForward getRedirectForward(LearnerProgress progress, boolean redirect) { + public ActionForward getRedirectForward(LearnerProgress progress, boolean redirect) throws UnsupportedEncodingException { ActionForward actionForward = null; - String strutsAction = "/requestDisplay.do"; String activityURL = this.getActivityURL(progress.getNextActivity()); - strutsAction += "?url=" + activityURL; + activityURL = URLEncoder.encode(activityURL, "UTF-8"); + String strutsAction = "/requestDisplay.do?url=" + activityURL; + strutsAction = WebUtil.appendParameterToURL(strutsAction, + LearningWebUtil.PARAM_PROGRESS_ID, + progress.getLearnerProgressId().toString()); + actionForward = strutsActionToForward(strutsAction, null, redirect); @@ -201,64 +215,6 @@ } /** - * Generates an ActivityURL for the next Activity using it's progress. The URL - * is for the client and so includes hostname etc. - * Note that this method always returns a LAMS URLs, if a ToolActivity is next - * the URL will be the action for displaying the tool. - * Note that the URL could also be a wait message or a jsp to clear the frames. - * @param progress, the current LearnerProgress. - * @throws UnsupportedEncodingException - */ - public String getProgressURL(LearnerProgress progress) throws UnsupportedEncodingException - { - String activityURL = null; - - if (progress.isLessonComplete()) - { - // If lesson complete forward to lesson complete action. This action will - // cause a client request to clear ALL frames. Need to append the progress - // id as getting to the end from an activity can't have the progress in the request - // and there isn't an activity from which we can determine the lesson and hence - // the progress. - String strutsAction = this.getActivityMappingStrategy() - .getLessonCompleteAction(); - strutsAction = WebUtil.appendParameterToURL(strutsAction, LearningWebUtil.PARAM_PROGRESS_ID, progress.getLearnerProgressId().toString()); - return activityURL = strutsActionToURL(strutsAction, null, true); - } - else - { - if (progress.isParallelWaiting()) - { - // progress is waiting, goto waiting page - String strutsAction = this.getActivityMappingStrategy() - .getWaitingAction(); - activityURL = strutsActionToURL(strutsAction, null, true); - } - else - { - // display next activity - activityURL = this.getActivityURL(progress.getNextActivity()); - if (progress.getPreviousActivity() != null && progress.getPreviousActivity().isParallelActivity()) - { - // if previous activity was a parallel activity then we need to - // clear frames. - String strutsAction = "/requestDisplay.do"; - String redirectURL = strutsActionToURL(strutsAction, - null, - true); - activityURL = URLEncoder.encode(activityURL, "UTF-8"); - activityURL = redirectURL + "?url=" + activityURL; - } - } - } - - return WebUtil.appendParameterToURL(activityURL, - LearningWebUtil.PARAM_PROGRESS_ID, - progress.getLearnerProgressId().toString()); - - } - - /** * Generates an ActivityURL for a Tool Activity or SystemToolActivity. * The URL is for the tool and not for the tool loading page. The URL also * includes toolSessionId or toolContentId and all other required data. @@ -371,8 +327,8 @@ this.activityMappingStrategy = activityMappingStrategy; } - public String getCloseURL() { - return strutsActionToURL(this.activityMappingStrategy.getCloseWindowAction(), null, true); + public ActionForward getCloseForward() { + return strutsActionToForward(this.activityMappingStrategy.getCloseWindowAction(), null, false); } public String getProgressBrokenURL() { Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java,v diff -u -r1.16.4.1 -r1.16.4.2 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java 10 Apr 2007 23:33:02 -0000 1.16.4.1 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java 11 Apr 2007 07:05:03 -0000 1.16.4.2 @@ -31,6 +31,7 @@ import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForward; import org.lamsfoundation.lams.learning.service.ICoreLearnerService; import org.lamsfoundation.lams.learning.service.LearnerServiceException; import org.lamsfoundation.lams.learning.web.action.ActivityAction; @@ -186,27 +187,28 @@ /** "Complete" an activity from the web layer's perspective. Used for CompleteActivityAction and the Gate and Grouping actions. * Calls the learningService to actually complete the activity and progress. + * @param redirect Should this call redirect to the next screen (true) or use a forward (false) * @throws UnsupportedEncodingException * */ - public static String completeActivity(HttpServletRequest request, HttpServletResponse response, + public static ActionForward completeActivity(HttpServletRequest request, HttpServletResponse response, ActivityMapping actionMappings, LearnerProgress currentProgress, Activity currentActivity, - Integer learnerId, ICoreLearnerService learnerService) throws LearnerServiceException, UnsupportedEncodingException { + Integer learnerId, ICoreLearnerService learnerService, boolean redirect) throws LearnerServiceException, UnsupportedEncodingException { LearnerProgress newProgress=null; Lesson lesson = currentProgress.getLesson(); - if ( lesson.getLockedForEdit() || currentActivity == null ) { + if ( currentActivity == null ) { newProgress = learnerService.joinLesson(learnerId, lesson.getLessonId()); } else if ( currentProgress.getCompletedActivities().contains(currentActivity) ){ - return actionMappings.getCloseURL(); + return actionMappings.getCloseForward(); } else { // Set activity as complete newProgress = learnerService.completeActivity(learnerId, currentActivity,currentProgress); } LearningWebUtil.putActivityInRequest(request, newProgress.getNextActivity(), learnerService); LearningWebUtil.putLearnerProgressInRequest(request,newProgress); - return actionMappings.getProgressURL(newProgress); + return actionMappings.getProgressForward(newProgress, redirect, false, request, learnerService); } }