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.34 -r1.34.2.1
--- lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressEngine.java 1 Apr 2009 23:49:04 -0000 1.34
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressEngine.java 22 Apr 2009 04:20:36 -0000 1.34.2.1
@@ -21,7 +21,7 @@
* ****************************************************************
*/
-/* $$Id$$ */
+/* $$Id$$ */
package org.lamsfoundation.lams.learning.progress;
import java.util.Date;
@@ -42,234 +42,243 @@
import org.lamsfoundation.lams.usermanagement.User;
/**
- * The Progress Engine controls how a learner progresses
- * through a sequence.
- *
- * Code must be re-entrant, as there is one progress engine object called by a singleton LearnerService.
+ * The Progress Engine controls how a learner progresses through a sequence.
*
- * @author chris, Jacky
+ * Code must be re-entrant, as there is one progress engine object called by a
+ * singleton LearnerService.
+ *
+ * @author chris, Jacky
*/
-public class ProgressEngine
-{
- protected Logger log = Logger.getLogger(ProgressEngine.class);
+public class ProgressEngine {
+ protected Logger log = Logger.getLogger(ProgressEngine.class);
private IActivityDAO activityDAO;
/**
- * Method determines next step for a learner based on the activity
- * they have just completed. Will clear the Parallel Waiting Complete value if it is currently set.
- * @param learner The User
who is progressing through the Lesson
.
- * @param completedActivity The Activity
the learner has just completed.
- * @param lesson The Lesson
the learner needs progress for.
+ * Method determines next step for a learner based on the activity they have
+ * just completed. Will clear the Parallel Waiting Complete value if it is
+ * currently set.
+ *
+ * @param learner
+ * The User
who is progressing through the
+ * Lesson
.
+ * @param completedActivity
+ * The Activity
the learner has just
+ * completed.
+ * @param lesson
+ * The Lesson
the learner needs progress for.
* @param learnerProgress
- * @return Progress The VO that contains the data needed to send
- * the learner to the next step.
- * @throws ProgressException if progress cannot be calculated successfully.
+ * @return Progress The VO that contains the data needed to send the learner
+ * to the next step.
+ * @throws ProgressException
+ * if progress cannot be calculated successfully.
*/
- public LearnerProgress calculateProgress(User learner,
- Activity completedActivity,
- LearnerProgress learnerProgress) throws ProgressException
- {
- if ( learnerProgress.getParallelWaiting() == LearnerProgress.PARALLEL_WAITING_COMPLETE ) {
- learnerProgress.setParallelWaiting(LearnerProgress.PARALLEL_NO_WAIT);
- }
- return doCalculateProgress(learner, completedActivity, learnerProgress, new LinkedList());
+ public LearnerProgress calculateProgress(User learner, Activity completedActivity, LearnerProgress learnerProgress)
+ throws ProgressException {
+ if (learnerProgress.getParallelWaiting() == LearnerProgress.PARALLEL_WAITING_COMPLETE) {
+ learnerProgress.setParallelWaiting(LearnerProgress.PARALLEL_NO_WAIT);
+ }
+ return doCalculateProgress(learner, completedActivity, learnerProgress, new LinkedList());
}
-
- /** Internal method used for recursion. Does the actual "work" of calculateProgress. */
- private LearnerProgress doCalculateProgress(User learner,
- Activity completedActivity,
- LearnerProgress learnerProgress,
- List completedActivityList) throws ProgressException
- {
- learnerProgress.setProgressState(completedActivity,
- LearnerProgress.ACTIVITY_COMPLETED,
- activityDAO);
- completedActivityList.add(completedActivity.getActivityId());
- if ( completedActivity.isStopAfterActivity() ) {
- // special case - terminate the lesson here.
- learnerProgress.setProgressState(completedActivity, LearnerProgress.ACTIVITY_COMPLETED,activityDAO);
- for ( Activity parentActivity = completedActivity.getParentActivity() ; parentActivity != null; parentActivity = parentActivity.getParentActivity() ) {
- learnerProgress.setProgressState(parentActivity, LearnerProgress.ACTIVITY_COMPLETED,activityDAO);
- completedActivityList.add(parentActivity.getActivityId());
- }
- populateCurrentCompletedActivityList(learnerProgress, completedActivityList);
- learnerProgress.setFinishDate(new Date());
- return setLessonComplete(learnerProgress, LearnerProgress.LESSON_IN_DESIGN_COMPLETE);
- } else if ( completedActivity.isFloating() && !completedActivity.getParentActivity().isParallelActivity()) {
- // special case - floating activity and not parallel activity (floating) child.
- return learnerProgress;
- } else {
- Transition transition = completedActivity.getTransitionFrom();
- if (transition != null)
- return progressCompletedActivity(learner,
- completedActivity,
- learnerProgress,
- transition,
- completedActivityList);
- else
- return progressParentActivity(learner,
- completedActivity,
- learnerProgress,
- completedActivityList);
- }
+ /**
+ * Internal method used for recursion. Does the actual "work" of
+ * calculateProgress.
+ */
+ private LearnerProgress doCalculateProgress(User learner, Activity completedActivity,
+ LearnerProgress learnerProgress, List completedActivityList) throws ProgressException {
+ learnerProgress.setProgressState(completedActivity, LearnerProgress.ACTIVITY_COMPLETED, activityDAO);
+ completedActivityList.add(completedActivity.getActivityId());
+
+ if (completedActivity.isStopAfterActivity()) {
+ // special case - terminate the lesson here.
+ learnerProgress.setProgressState(completedActivity, LearnerProgress.ACTIVITY_COMPLETED, activityDAO);
+ for (Activity parentActivity = completedActivity.getParentActivity(); parentActivity != null; parentActivity = parentActivity
+ .getParentActivity()) {
+ learnerProgress.setProgressState(parentActivity, LearnerProgress.ACTIVITY_COMPLETED, activityDAO);
+ completedActivityList.add(parentActivity.getActivityId());
+ }
+ populateCurrentCompletedActivityList(learnerProgress, completedActivityList);
+ learnerProgress.setFinishDate(new Date());
+ return setLessonComplete(learnerProgress, LearnerProgress.LESSON_IN_DESIGN_COMPLETE);
+ } else if (completedActivity.isFloating() && !completedActivity.getParentActivity().isParallelActivity()) {
+ // special case - floating activity and not parallel activity (floating) child.
+ return learnerProgress;
+ } else {
+ Transition transition = completedActivity.getTransitionFrom();
+ if (transition != null)
+ return progressCompletedActivity(learner, completedActivity, learnerProgress, transition,
+ completedActivityList);
+ else
+ return progressParentActivity(learner, completedActivity, learnerProgress, completedActivityList);
+ }
}
/**
* Method determines the start point for a learner when they begin a Lesson.
*
- * It is also reused to calculate where the learner should be should the progress
- * "go wrong". For example, the teacher does live edit and the learner moves to
- * the stop gate created for the live edit. When the edit is completed, the stop
- * gate is removed. But now there is no current activity for the learner.
+ * It is also reused to calculate where the learner should be should the
+ * progress "go wrong". For example, the teacher does live edit and the
+ * learner moves to the stop gate created for the live edit. When the edit
+ * is completed, the stop gate is removed. But now there is no current
+ * activity for the learner.
*
- * @param LearnerProgress The user's progress details for the User
who is starting the Lesson
.
+ * @param LearnerProgress
+ * The user's progress details for the User
+ * who is starting the Lesson
.
* @return LearnerProgress The updated user's progress details.
- * @throws ProgressException if the start point cannot be calculated successfully.
+ * @throws ProgressException
+ * if the start point cannot be calculated successfully.
*/
- public LearnerProgress setUpStartPoint(LearnerProgress progress) throws ProgressException
- {
-
- LearningDesign ld = progress.getLesson().getLearningDesign();
-
- if (progress.getLesson().getLockedForEdit()) {
- // special case - currently setting up the stop gates for live edit.
- return clearProgressNowhereToGoNotCompleted(progress,"setUpStartPoint");
- } else if (progress.isComplete() ) {
- return progress;
- } else if(ld.getFirstActivity()==null) {
- throw new ProgressException("Could not find first activity for "
- +"learning design ["+ld.getTitle()+"], id["
- +ld.getLearningDesignId().longValue()
- +"]");
- } else if ( progress.getCompletedActivities().containsKey(ld.getFirstActivity()) ) {
- // special case - recalculating the appropriate current activity.
- return doCalculateProgress(progress.getUser(), ld.getFirstActivity(), progress, new LinkedList());
- } else if ( canDoActivity(progress.getLesson(), ld.getFirstActivity()) ) {
- // normal case
- progress.setCurrentActivity(ld.getFirstActivity());
- progress.setNextActivity(ld.getFirstActivity());
- setActivityAttempted(progress, ld.getFirstActivity());
- return progress;
- } else {
- // special case - trying to get to a whole new activity (past the stop gate)
- // during a live edit
- return clearProgressNowhereToGoNotCompleted(progress,"setUpStartPoint");
- }
+ public LearnerProgress setUpStartPoint(LearnerProgress progress) throws ProgressException {
+
+ LearningDesign ld = progress.getLesson().getLearningDesign();
+
+ if (progress.getLesson().getLockedForEdit()) {
+ // special case - currently setting up the stop gates for live edit.
+ return clearProgressNowhereToGoNotCompleted(progress, "setUpStartPoint");
+ } else if (progress.isComplete()) {
+ return progress;
+ } else if (ld.getFirstActivity() == null) {
+ throw new ProgressException("Could not find first activity for " + "learning design [" + ld.getTitle()
+ + "], id[" + ld.getLearningDesignId().longValue() + "]");
+ } else if (progress.getCompletedActivities().containsKey(ld.getFirstActivity())) {
+ // special case - recalculating the appropriate current activity.
+ return doCalculateProgress(progress.getUser(), ld.getFirstActivity(), progress, new LinkedList());
+ } else if (canDoActivity(progress.getLesson(), ld.getFirstActivity())) {
+ // normal case
+ progress.setCurrentActivity(ld.getFirstActivity());
+ progress.setNextActivity(ld.getFirstActivity());
+ setActivityAttempted(progress, ld.getFirstActivity());
+ return progress;
+ } else {
+ // special case - trying to get to a whole new activity (past the stop gate)
+ // during a live edit
+ return clearProgressNowhereToGoNotCompleted(progress, "setUpStartPoint");
+ }
}
-
- /** Is it okay for me to do this activity? Most of the time yes - but you can do it
- * if the learning design is marked for edit (due to live edit) and the activity isn't read
- * only. This case should only occur if you have snuck past the stop gates while live edit
- * was being set up. Hopefully never!
+
+ /**
+ * Is it okay for me to do this activity? Most of the time yes - but you can
+ * do it if the learning design is marked for edit (due to live edit) and
+ * the activity isn't read only. This case should only occur if you have
+ * snuck past the stop gates while live edit was being set up. Hopefully
+ * never!
*
- * See the live edit documentation on the wiki for more details on the Lesson.lockedForEdit
- * and LearningDesign.activityReadOnly flags. These are set up in AuthoringService.setupEditOnFlyLock()
+ * See the live edit documentation on the wiki for more details on the
+ * Lesson.lockedForEdit and LearningDesign.activityReadOnly flags. These are
+ * set up in AuthoringService.setupEditOnFlyLock()
*
* @param design
* @param activity
* @return
*/
private boolean canDoActivity(Lesson lesson, Activity activity) {
- LearningDesign design = lesson.getLearningDesign();
- return ! lesson.getLockedForEdit() && ( ! design.getEditOverrideLock() || activity.isActivityReadOnly() ) ;
+ LearningDesign design = lesson.getLearningDesign();
+ return !lesson.getLockedForEdit() && (!design.getEditOverrideLock() || activity.isActivityReadOnly());
}
- /**
- * Oh, dear - nowhere to go. Probably because the sequence is being edited
- * while I'm trying to move to an untouched activity, or it is in the process
- * of setting up the stop gates for live edit.
+ /**
+ * Oh, dear - nowhere to go. Probably because the sequence is being edited
+ * while I'm trying to move to an untouched activity, or it is in the
+ * process of setting up the stop gates for live edit.
*
* Set the current activity and next activity to null, and the progress
- * engine should then show the "Sequence Broken" screen.
+ * engine should then show the "Sequence Broken" screen.
*
- * Writes a warning to the log if callingMethod is not null. If it is null, we assume
- * the calling code has written out a warning/error already.
+ * Writes a warning to the log if callingMethod is not null. If it is null,
+ * we assume the calling code has written out a warning/error already.
*/
private LearnerProgress clearProgressNowhereToGoNotCompleted(LearnerProgress progress, String callingMethod) {
- if ( callingMethod != null ) {
- log.warn("Learner "+progress.getUser().getFullName()+"("+progress.getUser().getUserId()
- +") has a problem with the progress for lesson "
- +progress.getLesson().getLessonName()+"("+progress.getLesson().getLessonId()
- +"). Completed activities so far was "+progress.getCurrentCompletedActivitiesList()
- +". Setting current and next activity to null. Problem detected in method "+callingMethod+".");
- }
-
- progress.setCurrentActivity(null);
- progress.setNextActivity(null);
- progress.setLessonComplete(LearnerProgress.LESSON_NOT_COMPLETE);
- return progress;
+ if (callingMethod != null) {
+ log.warn("Learner " + progress.getUser().getFullName() + "(" + progress.getUser().getUserId()
+ + ") has a problem with the progress for lesson " + progress.getLesson().getLessonName() + "("
+ + progress.getLesson().getLessonId() + "). Completed activities so far was "
+ + progress.getCurrentCompletedActivitiesList()
+ + ". Setting current and next activity to null. Problem detected in method " + callingMethod + ".");
+ }
+
+ progress.setCurrentActivity(null);
+ progress.setNextActivity(null);
+ progress.setLessonComplete(LearnerProgress.LESSON_NOT_COMPLETE);
+ return progress;
}
-
- /** Set the current activity as attempted. If it is a parallel activity, mark its children as attempted too. */
+
+ /**
+ * Set the current activity as attempted. If it is a parallel activity, mark
+ * its children as attempted too.
+ */
public void setActivityAttempted(LearnerProgress progress, Activity activity) {
- progress.setProgressState(activity,LearnerProgress.ACTIVITY_ATTEMPTED, activityDAO);
- activity.setReadOnly(true);
-
- if ( activity.isParallelActivity() ) {
- ParallelActivity parallel = (ParallelActivity) activityDAO.getActivityByActivityId(activity.getActivityId(), ParallelActivity.class);
- Iterator iter = parallel.getActivities().iterator();
- while (iter.hasNext()) {
- Activity element = (Activity) iter.next();
- setActivityAttempted(progress,element);
- }
- }
-
- // update activity
- activityDAO.insertOrUpdate(activity);
+ progress.setProgressState(activity, LearnerProgress.ACTIVITY_ATTEMPTED, activityDAO);
+ activity.setReadOnly(true);
+
+ if (activity.isParallelActivity()) {
+ ParallelActivity parallel = (ParallelActivity) activityDAO.getActivityByActivityId(
+ activity.getActivityId(), ParallelActivity.class);
+ Iterator iter = parallel.getActivities().iterator();
+ while (iter.hasNext()) {
+ Activity element = (Activity) iter.next();
+ setActivityAttempted(progress, element);
+ }
+ }
+
+ // update activity
+ activityDAO.insertOrUpdate(activity);
}
+
/**
- * We setup the progress data for a completed activity. This happens when
- * we find a transition to progress to. It should setup all activity states
+ * We setup the progress data for a completed activity. This happens when we
+ * find a transition to progress to. It should setup all activity states
* that allow web layer to calculate the url to move one to.
*
- * @param completedActivity the activity finished either by user or the
- * lams. In terms of lams completed activity, it would be
- * ParallelActivity
, SequenceActivity
,
- * OptionsActivity
and other system driven activities.
- * Whereas user activity will be mostly tool activities.
- * @param learnerProgress the progress we based on.
- * @param transition the transition we progress to.
+ * @param completedActivity
+ * the activity finished either by user or the lams. In terms
+ * of lams completed activity, it would be
+ * ParallelActivity
,
+ * SequenceActivity
,
+ * OptionsActivity
and other system driven
+ * activities. Whereas user activity will be mostly tool
+ * activities.
+ * @param learnerProgress
+ * the progress we based on.
+ * @param transition
+ * the transition we progress to.
* @return the learner progress data we calculated.
- * @throws ProgressException
+ * @throws ProgressException
*/
- private LearnerProgress progressCompletedActivity(User learner,
- Activity completedActivity,
- LearnerProgress learnerProgress,
- Transition transition,
- List completedActivityList) throws ProgressException
- {
- Activity nextActivity = transition.getToActivity();
-
- if ( ! learnerProgress.getCompletedActivities().containsKey(nextActivity) ) {
- // normal case - the next activity is still yet to be done
-
- learnerProgress.setPreviousActivity(completedActivity);
-
- populateCurrentCompletedActivityList(learnerProgress, completedActivityList);
-
- if ( canDoActivity(learnerProgress.getLesson(), nextActivity) ) {
-
- learnerProgress.setCurrentActivity(nextActivity);
- learnerProgress.setNextActivity(nextActivity);
- setActivityAttempted(learnerProgress, nextActivity);
- if ( learnerProgress.getParallelWaiting() == LearnerProgress.PARALLEL_WAITING )
- learnerProgress.setParallelWaiting(LearnerProgress.PARALLEL_WAITING_COMPLETE );
-
- } else {
- return clearProgressNowhereToGoNotCompleted(learnerProgress,"progressCompletedActivity");
- }
-
- return learnerProgress;
-
- } else {
- // abnormal case: next activity already done. Must have jumped back to an earlier
- // optional activity, done another activity and then kept going
-
- return doCalculateProgress(learner,nextActivity,learnerProgress, completedActivityList);
- }
-
+ private LearnerProgress progressCompletedActivity(User learner, Activity completedActivity,
+ LearnerProgress learnerProgress, Transition transition, List completedActivityList)
+ throws ProgressException {
+ Activity nextActivity = transition.getToActivity();
+
+ if (!learnerProgress.getCompletedActivities().containsKey(nextActivity)) {
+ // normal case - the next activity is still yet to be done
+
+ learnerProgress.setPreviousActivity(completedActivity);
+
+ populateCurrentCompletedActivityList(learnerProgress, completedActivityList);
+
+ if (canDoActivity(learnerProgress.getLesson(), nextActivity)) {
+
+ learnerProgress.setCurrentActivity(nextActivity);
+ learnerProgress.setNextActivity(nextActivity);
+ setActivityAttempted(learnerProgress, nextActivity);
+ if (learnerProgress.getParallelWaiting() == LearnerProgress.PARALLEL_WAITING)
+ learnerProgress.setParallelWaiting(LearnerProgress.PARALLEL_WAITING_COMPLETE);
+
+ } else {
+ return clearProgressNowhereToGoNotCompleted(learnerProgress, "progressCompletedActivity");
+ }
+
+ return learnerProgress;
+
+ } else {
+ // abnormal case: next activity already done. Must have jumped back to an earlier
+ // optional activity, done another activity and then kept going
+
+ return doCalculateProgress(learner, nextActivity, learnerProgress, completedActivityList);
+ }
+
}
/**
@@ -278,133 +287,127 @@
* is in the leaf node of an activity hierarchy. And we need to travesal the
* activity hierarchy upwards to find the progress information.
*
- * @param learner the current learner.
- * @param lesson the lesson that current learner progress belongs to.
- * @param completedActivity the activity finished either by user or the
- * lams. In terms of lams completed activity, it would be
- * ParallelActivity
, SequenceActivity
,
- * OptionsActivity
and other system driven activities.
- * Whereas user activity will be mostly tool activities.
- * @param learnerProgress the progress we based on.
+ * @param learner
+ * the current learner.
+ * @param lesson
+ * the lesson that current learner progress belongs to.
+ * @param completedActivity
+ * the activity finished either by user or the lams. In terms
+ * of lams completed activity, it would be
+ * ParallelActivity
,
+ * SequenceActivity
,
+ * OptionsActivity
and other system driven
+ * activities. Whereas user activity will be mostly tool
+ * activities.
+ * @param learnerProgress
+ * the progress we based on.
* @return the learner progress data we calculated.
* @throws ProgressException
*/
- private LearnerProgress progressParentActivity(User learner,
- Activity completedActivity,
- LearnerProgress learnerProgress,
- List completedActivityList) throws ProgressException
- {
- Activity parent = completedActivity.getParentActivity();
-
- if (parent != null)
- {
- if(!(parent.isComplexActivity()))
- throw new ProgressException("Parent activity is always expected" +
- " to the complex activity. But activity type"+
- parent.getActivityTypeId()+" has been found");
- //move to next activity within parent if not all children are completed.
-
-
- ComplexActivity complexParent = (ComplexActivity) activityDAO.getActivityByActivityId(parent.getActivityId(),ComplexActivity.class);
- if (! learnerProgress.getCompletedActivities().containsKey(complexParent) && !complexParent.areChildrenCompleted(learnerProgress))
- {
- Activity nextActivity = complexParent.getNextActivityByParent(completedActivity);
-
-
- if (!isNextActivityValid(nextActivity)) {
- log.error("Error occurred in progress engine."
- + " Unexpected Null activity received when progressing"
- + " to the next activity within a incomplete parent activity:"
- + " Parent activity id ["
- + parent.getActivityId()
- + "]");
- learnerProgress = clearProgressNowhereToGoNotCompleted(learnerProgress,null);
- }
- else if(isParallelWaitActivity(nextActivity))
- {
- learnerProgress.setParallelWaiting(LearnerProgress.PARALLEL_WAITING);
- // learnerProgress.setNextActivity(null);
- populateCurrentCompletedActivityList(learnerProgress, completedActivityList);
- }
- else if ( canDoActivity(learnerProgress.getLesson(), nextActivity) )
- {
- learnerProgress.setNextActivity(nextActivity);
- setActivityAttempted(learnerProgress, nextActivity);
- populateCurrentCompletedActivityList(learnerProgress, completedActivityList);
- }
- else {
- learnerProgress = clearProgressNowhereToGoNotCompleted(learnerProgress, "progressParentActivity");
- }
- }
- //recurvisely call back to calculateProgress to calculate completed
- //parent activity.
- else {
- learnerProgress.setPreviousActivity(complexParent);
- doCalculateProgress(learner, parent, learnerProgress, completedActivityList);
- if ( learnerProgress.getParallelWaiting() == LearnerProgress.PARALLEL_WAITING )
- learnerProgress.setParallelWaiting(LearnerProgress.PARALLEL_WAITING_COMPLETE );
- }
- }
- //lesson is meant to be completed if there is no transition and no parent.
- else {
- learnerProgress.setFinishDate(new Date());
- learnerProgress = setLessonComplete(learnerProgress, LearnerProgress.LESSON_END_OF_DESIGN_COMPLETE);
- }
+ private LearnerProgress progressParentActivity(User learner, Activity completedActivity,
+ LearnerProgress learnerProgress, List completedActivityList) throws ProgressException {
+ Activity parent = completedActivity.getParentActivity();
- return learnerProgress;
- }
+ if (parent != null) {
+ if (!(parent.isComplexActivity()))
+ throw new ProgressException("Parent activity is always expected"
+ + " to the complex activity. But activity type" + parent.getActivityTypeId()
+ + " has been found");
+ //move to next activity within parent if not all children are completed.
- /**
- * Set the lesson to complete for this learner.
- *
- * @param learnerProgress
- * @return updated learnerProgress
- */
- private LearnerProgress setLessonComplete(LearnerProgress learnerProgress, byte completionStatus) {
- learnerProgress.setCurrentActivity(null);
- learnerProgress.setNextActivity(null);
- learnerProgress.setLessonComplete(completionStatus);
- return learnerProgress;
+ ComplexActivity complexParent = (ComplexActivity) activityDAO.getActivityByActivityId(parent
+ .getActivityId(), ComplexActivity.class);
+ if (!learnerProgress.getCompletedActivities().containsKey(complexParent)
+ && !complexParent.areChildrenCompleted(learnerProgress)) {
+ Activity nextActivity = complexParent.getNextActivityByParent(completedActivity);
+
+ if (!isNextActivityValid(nextActivity)) {
+ log.error("Error occurred in progress engine."
+ + " Unexpected Null activity received when progressing"
+ + " to the next activity within a incomplete parent activity:" + " Parent activity id ["
+ + parent.getActivityId() + "]");
+ learnerProgress = clearProgressNowhereToGoNotCompleted(learnerProgress, null);
+ } else if (isParallelWaitActivity(nextActivity)) {
+ learnerProgress.setParallelWaiting(LearnerProgress.PARALLEL_WAITING);
+ // learnerProgress.setNextActivity(null);
+ populateCurrentCompletedActivityList(learnerProgress, completedActivityList);
+ } else if (canDoActivity(learnerProgress.getLesson(), nextActivity)) {
+ learnerProgress.setNextActivity(nextActivity);
+ setActivityAttempted(learnerProgress, nextActivity);
+ populateCurrentCompletedActivityList(learnerProgress, completedActivityList);
+ } else {
+ learnerProgress = clearProgressNowhereToGoNotCompleted(learnerProgress, "progressParentActivity");
+ }
+ }
+ //recurvisely call back to calculateProgress to calculate completed
+ //parent activity.
+ else {
+ learnerProgress.setPreviousActivity(complexParent);
+ doCalculateProgress(learner, parent, learnerProgress, completedActivityList);
+ if (learnerProgress.getParallelWaiting() == LearnerProgress.PARALLEL_WAITING)
+ learnerProgress.setParallelWaiting(LearnerProgress.PARALLEL_WAITING_COMPLETE);
+ }
}
+ //lesson is meant to be completed if there is no transition and no parent.
+ else {
+ learnerProgress.setFinishDate(new Date());
+ learnerProgress = setLessonComplete(learnerProgress, LearnerProgress.LESSON_END_OF_DESIGN_COMPLETE);
+ }
+ return learnerProgress;
+ }
+
/**
+ * Set the lesson to complete for this learner.
+ *
+ * @param learnerProgress
+ * @return updated learnerProgress
+ */
+ private LearnerProgress setLessonComplete(LearnerProgress learnerProgress, byte completionStatus) {
+ learnerProgress.setCurrentActivity(null);
+ learnerProgress.setNextActivity(null);
+ learnerProgress.setLessonComplete(completionStatus);
+ return learnerProgress;
+ }
+
+ /**
* The helper method to setup the completed activity list since the last
- * transition.
+ * transition.
+ *
* @param learnerProgress
*/
- private void populateCurrentCompletedActivityList(LearnerProgress learnerProgress, List completedActivityList)
- {
- learnerProgress.setCurrentCompletedActivitiesList(completedActivityList);
- completedActivityList.clear();
+ private void populateCurrentCompletedActivityList(LearnerProgress learnerProgress, List completedActivityList) {
+ learnerProgress.setCurrentCompletedActivitiesList(completedActivityList);
+ completedActivityList.clear();
}
-
+
/**
* The next valid is valid if it is not null activity or if it is a parallel
* waiting activity.
- * @param nextActivity the next activity we progress to.
+ *
+ * @param nextActivity
+ * the next activity we progress to.
* @return is the next activity valid.
*/
- private boolean isNextActivityValid(Activity nextActivity)
- {
- return !nextActivity.isNull()||isParallelWaitActivity(nextActivity);
+ private boolean isNextActivityValid(Activity nextActivity) {
+ return !nextActivity.isNull() || isParallelWaitActivity(nextActivity);
}
/**
- * Check up the object type to see whether it is a parallel waiting
+ * Check up the object type to see whether it is a parallel waiting
* activity.
- * @param nextActivity the next activity we progress to.
+ *
+ * @param nextActivity
+ * the next activity we progress to.
* @return is the next activity the type of parallel activity.
*/
- private boolean isParallelWaitActivity(Activity nextActivity)
- {
- return nextActivity.getActivityTypeId()!=null && nextActivity.getActivityTypeId().intValue()==ParallelWaitActivity.PARALLEL_WAIT_ACTIVITY_TYPE;
+ private boolean isParallelWaitActivity(Activity nextActivity) {
+ return nextActivity.getActivityTypeId() != null
+ && nextActivity.getActivityTypeId().intValue() == ParallelWaitActivity.PARALLEL_WAIT_ACTIVITY_TYPE;
}
- public void setActivityDAO(IActivityDAO activityDAO) {
- this.activityDAO = activityDAO;
- }
-
+ public void setActivityDAO(IActivityDAO activityDAO) {
+ this.activityDAO = activityDAO;
+ }
-
-
}
\ No newline at end of file