Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/Activity.java =================================================================== diff -u -r0055799135c002681cf6504a386e061e318df494 -r35d5350252748108494c7cb4bfc2e7d5f2271cba --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/Activity.java (.../Activity.java) (revision 0055799135c002681cf6504a386e061e318df494) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/Activity.java (.../Activity.java) (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba) @@ -34,11 +34,10 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.lamsfoundation.lams.learningdesign.dto.MonitoringActivityDTO; import org.lamsfoundation.lams.learningdesign.dto.ProgressActivityDTO; -import org.lamsfoundation.lams.learningdesign.strategy.SimpleActivityStrategy; +import org.lamsfoundation.lams.learningdesign.strategy.ComplextActivityStrategy; import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.util.Nullable; -import org.lamsfoundation.lams.lesson.ActivityStrategy; /** * @hibernate.class table="lams_learning_activity" */ @@ -190,9 +189,6 @@ public void setGroupingSupportType(Integer groupingSupportType) { this.groupingSupportType = groupingSupportType; } - protected ActivityStrategy activityStrategy; - protected SimpleActivityStrategy simpleActivityStrategy; - /** full constructor */ public Activity( Long activityId, @@ -634,6 +630,7 @@ public boolean isGroupingActivity(){ return getActivityTypeId().intValue()== GROUPING_ACTIVITY_TYPE; } + /** * Delegate to activity strategy to check up the status of all children. * @@ -642,9 +639,10 @@ * @return true if all children are completed. */ - public boolean areChildrenCompleted(LearnerProgress learnerProgress) +/** public boolean areChildrenCompleted(LearnerProgress learnerProgress) { - return activityStrategy.areChildrenCompleted(this,learnerProgress); + //return activityStrategy.areChildrenCompleted(this,learnerProgress); + return ((ComplexActivity)this).areChildrenCompleted(learnerProgress); } /** @@ -658,27 +656,25 @@ * @param currentChild the current child activity in a complex activity. * @return the next activity within a parent activity */ - public Activity getNextActivityByParent(Activity currentChild) +/** public Activity getNextActivityByParent(Activity currentChild) { - return activityStrategy.getNextActivityByParent(this,currentChild); + return ((ComplexActivity)this).getNextActivityByParent(currentChild); } - + */ public Integer getActivityCategoryID() { return activityCategoryID; } public void setActivityCategoryID(Integer activityCategoryID) { this.activityCategoryID = activityCategoryID; } - public Integer[] getContributionType(){ - return simpleActivityStrategy.getContributionType(this); - } + public MonitoringActivityDTO getMonitoringActivityDTO(){ return new MonitoringActivityDTO(this); } public MonitoringActivityDTO getMonitoringActivityDTO(Activity activity){ Integer contributionType[]= null; if(activity.isGateActivity() || activity.isToolActivity() || activity.isGroupingActivity()){ - contributionType = activity.getContributionType(); + contributionType = ((SimpleActivity)activity).getContributionType(); return new MonitoringActivityDTO(activity,contributionType); } else Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ComplexActivity.java =================================================================== diff -u -r0c87ef82b228f2c4e0593ce7884ea252799a114d -r35d5350252748108494c7cb4bfc2e7d5f2271cba --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ComplexActivity.java (.../ComplexActivity.java) (revision 0c87ef82b228f2c4e0593ce7884ea252799a114d) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ComplexActivity.java (.../ComplexActivity.java) (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba) @@ -7,12 +7,16 @@ import java.util.TreeSet; import org.apache.commons.lang.builder.ToStringBuilder; +import org.lamsfoundation.lams.learningdesign.strategy.ComplextActivityStrategy; +import org.lamsfoundation.lams.lesson.LearnerProgress; /** * @hibernate.class */ public abstract class ComplexActivity extends Activity implements Serializable { + + protected ComplextActivityStrategy activityStrategy; /** persistent field */ private Set activities; @@ -113,4 +117,33 @@ } return new NullActivity(); } + + /** + * Delegate to activity strategy to check up the status of all children. + * + * @param learnerProgress the progress data that record what has been + * completed + * @return true if all children are completed. + + */ + public boolean areChildrenCompleted(LearnerProgress learnerProgress) + { + return activityStrategy.areChildrenCompleted(this,learnerProgress); + } + + /** + *
Delegate to activity strategy to calculate what is the next activity + * within the parent activity.
+ * + * Note: The logic of what is the next activity here is progress + * enigne specific now. Please see theActivityStrategy
+ * for details explaination of what is next.
+ *
+ * @param currentChild the current child activity in a complex activity.
+ * @return the next activity within a parent activity
+ */
+ public Activity getNextActivityByParent(Activity currentChild)
+ {
+ return activityStrategy.getNextActivityByParent(this,currentChild);
+ }
}
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/GateActivity.java
===================================================================
diff -u -r7f203b0b0a2e56896f7eee5367b52d1ec4db483e -r35d5350252748108494c7cb4bfc2e7d5f2271cba
--- lams_common/src/java/org/lamsfoundation/lams/learningdesign/GateActivity.java (.../GateActivity.java) (revision 7f203b0b0a2e56896f7eee5367b52d1ec4db483e)
+++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/GateActivity.java (.../GateActivity.java) (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba)
@@ -99,7 +99,7 @@
/**
* @hibernate.many-to-one not-null="true"
- * @hibernate.column name="gate_activity_level_id"
+ * @hibernate.column name="gate_activity_level_id"
*
*/
public Integer getGateActivityLevelId()
@@ -119,10 +119,18 @@
.toString();
}
- public Boolean getGateOpen() {
+ public Boolean getGateOpen()
+ {
return gateOpen;
}
- public void setGateOpen(Boolean gateOpen) {
+
+ public void setGateOpen(Boolean gateOpen)
+ {
this.gateOpen = gateOpen;
}
+
+ public boolean shouldOpen()
+ {
+ return false;
+ }
}
Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/OptionsActivity.java
===================================================================
diff -u -rff0c59d252d1cef65a10cad77374dfe72697ba58 -r35d5350252748108494c7cb4bfc2e7d5f2271cba
--- lams_common/src/java/org/lamsfoundation/lams/learningdesign/OptionsActivity.java (.../OptionsActivity.java) (revision ff0c59d252d1cef65a10cad77374dfe72697ba58)
+++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/OptionsActivity.java (.../OptionsActivity.java) (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba)
@@ -3,7 +3,7 @@
import java.io.Serializable;
import java.util.Date;
import org.apache.commons.lang.builder.ToStringBuilder;
-import org.lamsfoundation.lams.lesson.OptionsActivityStrategy;
+import org.lamsfoundation.lams.learningdesign.strategy.OptionsActivityStrategy;
/**
Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ParallelActivity.java
===================================================================
diff -u -rff0c59d252d1cef65a10cad77374dfe72697ba58 -r35d5350252748108494c7cb4bfc2e7d5f2271cba
--- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ParallelActivity.java (.../ParallelActivity.java) (revision ff0c59d252d1cef65a10cad77374dfe72697ba58)
+++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ParallelActivity.java (.../ParallelActivity.java) (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba)
@@ -4,7 +4,7 @@
import java.util.Date;
import org.apache.commons.lang.builder.ToStringBuilder;
-import org.lamsfoundation.lams.lesson.ParallelActivityStrategy;
+import org.lamsfoundation.lams.learningdesign.strategy.ParallelActivityStrategy;
/**
* @hibernate.class
Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/RandomGrouper.java
===================================================================
diff -u -r85592985e7c0ff8c521939c92f1a3da4639c5f73 -r35d5350252748108494c7cb4bfc2e7d5f2271cba
--- lams_common/src/java/org/lamsfoundation/lams/learningdesign/RandomGrouper.java (.../RandomGrouper.java) (revision 85592985e7c0ff8c521939c92f1a3da4639c5f73)
+++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/RandomGrouper.java (.../RandomGrouper.java) (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba)
@@ -208,7 +208,12 @@
if(isInitialization)
return randomGrouping.getNumberOfGroups().intValue();
else
- return 0;
+ {
+ int numberOfNewGroups = randomGrouping.getNumberOfGroups().intValue()-
+ randomGrouping.getGroups().size();
+
+ return numberOfNewGroups>0?numberOfNewGroups:0;
+ }
}
}
Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ScheduleGateActivity.java
===================================================================
diff -u -rff0c59d252d1cef65a10cad77374dfe72697ba58 -r35d5350252748108494c7cb4bfc2e7d5f2271cba
--- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ScheduleGateActivity.java (.../ScheduleGateActivity.java) (revision ff0c59d252d1cef65a10cad77374dfe72697ba58)
+++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ScheduleGateActivity.java (.../ScheduleGateActivity.java) (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba)
@@ -5,21 +5,47 @@
import org.apache.commons.lang.builder.ToStringBuilder;
-/**
+/**
+ * The hibernate object that wraps the information to schedule a gate in the + * sequence engine. The schedule gate is defined either by offset to the + * lesson start time or by the absolute time set by the teacher.
+ * + *
Interms of gate level, schedule gate only cares about class level at + * the moment. we leaves the complexity of apply schdule gate to group + * and individual level to the future release.
+ * + * @author Chris Perfect + * @author Jacky Fang + * * @hibernate.class -*/ + */ public class ScheduleGateActivity extends GateActivity implements Serializable { - /** nullable persistent field */ + /** + * The relative gate open time from the lesson start time. For example, + * if the lesson starts at 3:00pm and offset is 1, the gate will be opened + * at 4:00pm. + */ private Long gateStartTimeOffset; - /** nullable persistent field */ + /** + *The relative time that gate will be closed from the lesson start time. + * For example, if the lesson starts at 3:00pm and offset is 2, the gate + * will be closed at 5:00pm.
+ * Note it must be larger thangateStartTimeOffset
.
+ */
private Long gateEndTimeOffset;
- /** nullable persistent field */
+ /**
+ * The absolute start time of the gate activity. If this is set, we are
+ * expecting gateStartTimeOffset
is set to null.
+ */
private Date gateStartDateTime;
- /** nullable persistent field */
+ /**
+ * The absolute end time of the gate activity. If this is set, we are
+ * expecting gateEndTimeOffset
is set to null.
+ */
private Date gateEndDateTime;
Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java
===================================================================
diff -u -rff0c59d252d1cef65a10cad77374dfe72697ba58 -r35d5350252748108494c7cb4bfc2e7d5f2271cba
--- lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java (.../SequenceActivity.java) (revision ff0c59d252d1cef65a10cad77374dfe72697ba58)
+++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java (.../SequenceActivity.java) (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba)
@@ -4,7 +4,7 @@
import java.util.Date;
import org.apache.commons.lang.builder.ToStringBuilder;
-import org.lamsfoundation.lams.lesson.SequenceActivityStrategy;
+import org.lamsfoundation.lams.learningdesign.strategy.SequenceActivityStrategy;
/**
Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/SimpleActivity.java
===================================================================
diff -u -r0c87ef82b228f2c4e0593ce7884ea252799a114d -r35d5350252748108494c7cb4bfc2e7d5f2271cba
--- lams_common/src/java/org/lamsfoundation/lams/learningdesign/SimpleActivity.java (.../SimpleActivity.java) (revision 0c87ef82b228f2c4e0593ce7884ea252799a114d)
+++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/SimpleActivity.java (.../SimpleActivity.java) (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba)
@@ -3,13 +3,16 @@
import java.io.Serializable;
import java.util.Date;
import org.apache.commons.lang.builder.ToStringBuilder;
+import org.lamsfoundation.lams.learningdesign.strategy.SimpleActivityStrategy;
/**
* @hibernate.class
*/
public abstract class SimpleActivity extends Activity implements Serializable
{
+ protected SimpleActivityStrategy simpleActivityStrategy;
+
/** full constructor */
public SimpleActivity(Long activityId,
Integer id,
@@ -83,4 +86,9 @@
.append("activityId", getActivityId())
.toString();
}
+
+
+ public Integer[] getContributionType(){
+ return simpleActivityStrategy.getContributionType(this);
+ }
}
Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/ComplextActivityStrategy.java
===================================================================
diff -u
--- lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/ComplextActivityStrategy.java (revision 0)
+++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/ComplextActivityStrategy.java (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba)
@@ -0,0 +1,86 @@
+/*
+ *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.learningdesign.strategy;
+
+import java.io.Serializable;
+import java.util.Iterator;
+
+import org.lamsfoundation.lams.learningdesign.Activity;
+import org.lamsfoundation.lams.learningdesign.ComplexActivity;
+import org.lamsfoundation.lams.lesson.LearnerProgress;
+
+
+/**
+ * Typical implementation of strategy pattern avoid complicated conditional
+ * logic to process activity object hierarchy. It is responsible for all
+ * polymorphism caculation regarding different type of activity.
+ *
+ * @author Jacky Fang 2005-2-23
+ *
+ */
+public abstract class ComplextActivityStrategy implements Serializable
+{
+ /**
+ * Check up all children completion status for a complex activity.
+ * Precondition: the activity should a complex activity that has children. + * + * @param activity the complex activity + * @param learnerProgress the progress data that record what has been + * completed + * @return true if all children are completed. + */ + public boolean areChildrenCompleted(Activity activity, LearnerProgress learnerProgress) + { + ComplexActivity complexActivity = (ComplexActivity)activity; + + int numOfCompletedActivities=0; + for(Iterator i = complexActivity.getActivities().iterator();i.hasNext();) + { + Activity currentActivity = (Activity)i.next(); + if(learnerProgress.getCompletedActivities().contains(currentActivity)) + numOfCompletedActivities++; + } + + return isComplete(numOfCompletedActivities,complexActivity); + + } + + /** + * Check up the children activity completion status against number of + * activities that has been completed within target complex activity. + * @param numOfCompletedActivities the number of completed activities in the + * progress data + * @return true if the completion condition is met. + */ + protected abstract boolean isComplete(int numOfCompletedActivities,ComplexActivity complexActivity); + + + /** + * This method get next activity that should be progressed against the + * requested incomplete parent activity. + * @param parent The requested incomplete parent activity. + * @param currentChild the current children we have just completed. + * + * @return the activity we should progress to. + */ + public abstract Activity getNextActivityByParent(Activity parent, Activity currentChild); + +} Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/OptionsActivityStrategy.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/OptionsActivityStrategy.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/OptionsActivityStrategy.java (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba) @@ -0,0 +1,63 @@ +/* + *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.learningdesign.strategy; + +import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.ComplexActivity; +import org.lamsfoundation.lams.learningdesign.OptionsActivity; + + +/** + * + * Progress calculation strategy for options activity. + * @author Jacky Fang 2005-2-24 + * + */ +public class OptionsActivityStrategy extends ComplextActivityStrategy +{ + + /** + * Return the next activity for a incomplete options activity. In terms of + * incomplete option activity, the next activity will always be the option + * activity itself so as to display the options page again when the user + * finish one option. + * + * @see org.lamsfoundation.lams.learningdesign.strategy.ComplextActivityStrategy#getNextActivityByParent(Activity, Activity) + */ + public Activity getNextActivityByParent(Activity parent, Activity currentChild) + { + return parent; + } + + /** + * Return the completion status of children activities within a options + * activity. A option activity is marked as complete if the maximum + * number of options requirement is met. + * + * @see org.lamsfoundation.lams.learningdesign.strategy.ComplextActivityStrategy#isComplete(int, org.lamsfoundation.lams.learningdesign.ComplexActivity) + */ + protected boolean isComplete(int numOfCompletedActivities, ComplexActivity complexActivity) + { + OptionsActivity optionsActivity = (OptionsActivity)complexActivity; + return numOfCompletedActivities>=optionsActivity.getMaxNumberOfOptions().intValue()?true:false; + } + +} Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/ParallelActivityStrategy.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/ParallelActivityStrategy.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/ParallelActivityStrategy.java (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba) @@ -0,0 +1,62 @@ +/* + *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.learningdesign.strategy; + +import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.ComplexActivity; +import org.lamsfoundation.lams.learningdesign.ParallelActivity; +import org.lamsfoundation.lams.lesson.ParallelWaitActivity; + + +/** + * The progress calculation strategy for parallel activity. + * + * @author Jacky Fang 2005-2-24 + * + */ +public class ParallelActivityStrategy extends ComplextActivityStrategy +{ + /** + * Regarding incomplete parallel activity, the next activity will always + * be a waiting activity, which will finally translated into waiting + * message. + * + * @see org.lamsfoundation.lams.learningdesign.strategy.ComplextActivityStrategy#getNextActivityByParent(Activity, Activity) + */ + public Activity getNextActivityByParent(Activity activity, Activity currentChild) + { + return new ParallelWaitActivity(); + } + + /** + * Return the completion status of children activities within a parallel + * activity. A parallel activity is marked as complete if all children + * activities are completed. + * + * @see org.lamsfoundation.lams.learningdesign.strategy.ComplextActivityStrategy#isComplete(int, org.lamsfoundation.lams.learningdesign.ComplexActivity) + */ + protected boolean isComplete(int numOfCompletedActivities, ComplexActivity complexActivity) + { + ParallelActivity parallelActivity = (ParallelActivity)complexActivity; + return numOfCompletedActivities==parallelActivity.getActivities().size()?true:false; + } + +} Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/SequenceActivityStrategy.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/SequenceActivityStrategy.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/SequenceActivityStrategy.java (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba) @@ -0,0 +1,83 @@ +/* + *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.learningdesign.strategy; + +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; + +import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.ActivityOrderComparator; +import org.lamsfoundation.lams.learningdesign.ComplexActivity; +import org.lamsfoundation.lams.learningdesign.NullActivity; +import org.lamsfoundation.lams.learningdesign.SequenceActivity; + +/** + * Progress calculation strategy for sequence activity. + * + * @author Jacky Fang 2005-2-24 + * + */ +public class SequenceActivityStrategy extends ComplextActivityStrategy +{ + + /** + *Return the next activity for a incomplete options activity. For a + * sequence activity, the activity should be the next activity in the + * children activity set ordered by activity id.
+ * + * Pre-condition: the parent must have some incomplete children + * + * @see org.lamsfoundation.lams.learningdesign.strategy.ComplextActivityStrategy#getNextActivityByParent(Activity, Activity) + */ + public Activity getNextActivityByParent(Activity parent, Activity currentChild) + { + Set children = new TreeSet(new ActivityOrderComparator()); + + children.addAll(((ComplexActivity)parent).getActivities()); + + for(Iterator i=children.iterator();i.hasNext();) + { + Activity curChild = (Activity)i.next(); + //if no current child, we should return the first one. + if(currentChild.isNull()) + return curChild; + + if(curChild.getActivityId().longValue()==currentChild.getActivityId().longValue()) + return (Activity)i.next(); + } + return new NullActivity(); + } + + /** + * Implementation for sequence activity. It returns true if all children + * of this sequence activity appear in the completed activities set from + * current learner progress. + * + * @see org.lamsfoundation.lams.learningdesign.strategy.ComplextActivityStrategy#isComplete(int, org.lamsfoundation.lams.learningdesign.ComplexActivity) + */ + protected boolean isComplete(int numOfCompletedActivities, ComplexActivity complexActivity) + { + SequenceActivity sequenceActivity = (SequenceActivity)complexActivity; + return numOfCompletedActivities==sequenceActivity.getActivities().size()?true:false; + } + +} Fisheye: Tag 35d5350252748108494c7cb4bfc2e7d5f2271cba refers to a dead (removed) revision in file `lams_common/src/java/org/lamsfoundation/lams/lesson/ActivityStrategy.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 35d5350252748108494c7cb4bfc2e7d5f2271cba refers to a dead (removed) revision in file `lams_common/src/java/org/lamsfoundation/lams/lesson/OptionsActivityStrategy.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 35d5350252748108494c7cb4bfc2e7d5f2271cba refers to a dead (removed) revision in file `lams_common/src/java/org/lamsfoundation/lams/lesson/ParallelActivityStrategy.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 35d5350252748108494c7cb4bfc2e7d5f2271cba refers to a dead (removed) revision in file `lams_common/src/java/org/lamsfoundation/lams/lesson/SequenceActivityStrategy.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_common/test/java/org/lamsfoundation/lams/learningdesign/TestComplexActivityStrategy.java =================================================================== diff -u --- lams_common/test/java/org/lamsfoundation/lams/learningdesign/TestComplexActivityStrategy.java (revision 0) +++ lams_common/test/java/org/lamsfoundation/lams/learningdesign/TestComplexActivityStrategy.java (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba) @@ -0,0 +1,174 @@ +/* + *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.learningdesign; + +import org.lamsfoundation.lams.lesson.LearnerProgress; +import org.lamsfoundation.lams.lesson.ParallelWaitActivity; +import org.lamsfoundation.lams.lesson.dao.TestLearnerProgressDAO; + + +/** + * + * @author Jacky Fang 2005-2-24 + * + */ +public class TestComplexActivityStrategy extends TestLearnerProgressDAO +{ + + private Activity testSubOptionsActivityNB; + private Activity testSubOptionsActivityMC; + private Activity testSubParallelActivityQA; + private Activity testSubParallelActivityMB; + private Activity testSubSeuquencActivitySR; + private Activity testSubSeuqenceActivityQNA; + + //this is survey id we inserted in test data sql script + protected static final Long TEST_NB_ACTIVITY_ID = new Long(16); + protected static final Long TEST_MC_ACTIVITY_ID = new Long(17); + protected static final Long TEST_QA_ACTIVITY_ID = new Long(18); + protected static final Long TEST_MB_ACTIVITY_ID = new Long(19); + protected static final Long TEST_SR_ACTIVITY_ID = new Long(22); + protected static final Long TEST_QNA_ACTIVITY_ID = new Long(25); + /* + * @see LessonDataAccessTestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + } + + /* + * @see LessonDataAccessTestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + /** + * Constructor for TestActivityStrategy. + * @param arg0 + */ + public TestComplexActivityStrategy(String name) + { + super(name); + } + + public void testChildrenCompletedForParallelActivity() + { + testSubParallelActivityQA = activityDAO.getActivityByActivityId(TEST_QA_ACTIVITY_ID); + testSubParallelActivityMB = activityDAO.getActivityByActivityId(TEST_MB_ACTIVITY_ID); + + super.testLearnerProgress.setProgressState(testSubParallelActivityQA,LearnerProgress.ACTIVITY_COMPLETED); + super.testLearnerProgress.setProgressState(testSubParallelActivityMB,LearnerProgress.ACTIVITY_COMPLETED); + + assertTrue("should be completed",((ComplexActivity)testParallelActivity).areChildrenCompleted(super.testLearnerProgress)); + } + + public void testChildrenInCompletedForParallelActivity() + { + testSubParallelActivityQA = activityDAO.getActivityByActivityId(TEST_QA_ACTIVITY_ID); + + super.testLearnerProgress.setProgressState(testSubParallelActivityQA,LearnerProgress.ACTIVITY_COMPLETED); + + assertTrue("should not be completed",!((ComplexActivity)testParallelActivity).areChildrenCompleted(super.testLearnerProgress)); + } + + public void testChildrenCompletedForSequenceActivity() + { + testSubSeuquencActivitySR = activityDAO.getActivityByActivityId(TEST_SR_ACTIVITY_ID); + testSubSeuqenceActivityQNA = activityDAO.getActivityByActivityId(TEST_QNA_ACTIVITY_ID); + + + super.testLearnerProgress.setProgressState(testSubSeuquencActivitySR,LearnerProgress.ACTIVITY_COMPLETED); + super.testLearnerProgress.setProgressState(testSubSeuqenceActivityQNA,LearnerProgress.ACTIVITY_COMPLETED); + assertTrue("should be completed",((ComplexActivity)testSequenceActivity).areChildrenCompleted(super.testLearnerProgress)); + } + + public void testChildrenInCompletedForSequenceActivity() + { + testSubSeuquencActivitySR = activityDAO.getActivityByActivityId(TEST_SR_ACTIVITY_ID); + + super.testLearnerProgress.setProgressState(testSubSeuquencActivitySR,LearnerProgress.ACTIVITY_COMPLETED); + assertTrue("should not be completed",!((ComplexActivity)testSequenceActivity).areChildrenCompleted(super.testLearnerProgress)); + } + + public void testChildrenCompletedForOptionsActivity() + { + testSubOptionsActivityNB = activityDAO.getActivityByActivityId(TEST_NB_ACTIVITY_ID); + testSubOptionsActivityMC = activityDAO.getActivityByActivityId(TEST_MC_ACTIVITY_ID); + + super.testLearnerProgress.setProgressState(testSubOptionsActivityNB,LearnerProgress.ACTIVITY_COMPLETED); + assertTrue("should be completed",((ComplexActivity)testOptionsActivity).areChildrenCompleted(super.testLearnerProgress)); + } + + public void testChildrenInCompletedForOptionsActivity() + { + assertTrue("should not be completed",!((ComplexActivity)testOptionsActivity).areChildrenCompleted(super.testLearnerProgress)); + } + + public void testGetNextActivityBySequenceParentActivity() + { + testSubSeuquencActivitySR = activityDAO.getActivityByActivityId(TEST_SR_ACTIVITY_ID); + testSubSeuqenceActivityQNA = activityDAO.getActivityByActivityId(TEST_QNA_ACTIVITY_ID); + + Activity nextActivity = ((ComplexActivity)testSequenceActivity).getNextActivityByParent(testSubSeuquencActivitySR); + + assertNotNull("we should have a next activity",nextActivity); + assertEquals("it should be qna",this.testSubSeuqenceActivityQNA.getActivityId().longValue(),nextActivity.getActivityId().longValue()); + } + + public void testGetFirstActivityWithinSequenceParentActivity() + { + testSubSeuquencActivitySR = activityDAO.getActivityByActivityId(TEST_SR_ACTIVITY_ID); + + Activity nextActivity = ((ComplexActivity)testSequenceActivity).getNextActivityByParent(new NullActivity()); + + assertNotNull("we should have a next activity",nextActivity); + assertEquals("it should be share resource",this.testSubSeuquencActivitySR.getActivityId().longValue(),nextActivity.getActivityId().longValue()); + } + + + public void testGetNextActivityByOptionsParentActivity() + { + testSubOptionsActivityNB = activityDAO.getActivityByActivityId(TEST_NB_ACTIVITY_ID); + + Activity nextActivity = ((ComplexActivity)testOptionsActivity).getNextActivityByParent(testSubOptionsActivityNB); + + assertNotNull("we should have a next activity",nextActivity); + assertEquals("it should be option activity itself", + this.testOptionsActivity.getActivityId().longValue(), + nextActivity.getActivityId().longValue()); + } + + public void testGetNextActivityByParallelParentActivity() + { + testSubParallelActivityQA = activityDAO.getActivityByActivityId(TEST_QA_ACTIVITY_ID); + + Activity nextActivity = ((ComplexActivity)testParallelActivity).getNextActivityByParent(testSubParallelActivityQA); + + assertNotNull("we should have a next activity",nextActivity); + + assertTrue("It should be kind of null activity",nextActivity.isNull()); + assertTrue("It should waiting activity",nextActivity.getActivityTypeId().intValue()==ParallelWaitActivity.PARALLEL_WAIT_ACTIVITY_TYPE); + + } +} Index: lams_common/test/java/org/lamsfoundation/lams/learningdesign/dao/TestActivityDAO.java =================================================================== diff -u -r28d64aab07ef56ac02ca94111b73322d520c967f -r35d5350252748108494c7cb4bfc2e7d5f2271cba --- lams_common/test/java/org/lamsfoundation/lams/learningdesign/dao/TestActivityDAO.java (.../TestActivityDAO.java) (revision 28d64aab07ef56ac02ca94111b73322d520c967f) +++ lams_common/test/java/org/lamsfoundation/lams/learningdesign/dao/TestActivityDAO.java (.../TestActivityDAO.java) (revision 35d5350252748108494c7cb4bfc2e7d5f2271cba) @@ -82,7 +82,7 @@ } public void testGetContributionType(){ activity = activityDAO.getActivityByActivityId(new Long(18)); - Integer as[]=activity.getContributionType(); + Integer as[]=((SimpleActivity)activity).getContributionType(); for(int i=0;i