Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/GateActivity.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/GateActivity.java,v diff -u -r1.5 -r1.6 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/GateActivity.java 6 Apr 2005 05:02:57 -0000 1.5 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/GateActivity.java 6 Apr 2005 07:34:45 -0000 1.6 @@ -2,9 +2,12 @@ import java.io.Serializable; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.apache.commons.lang.builder.ToStringBuilder; +import org.lamsfoundation.lams.learningdesign.strategy.GateActivityStrategy; +import org.lamsfoundation.lams.usermanagement.User; /** @@ -25,6 +28,9 @@ /** persistent field */ private Boolean gateOpen; + /** + * The learners who are waiting at the gate. + */ private Set waitingLearners; /** full constructor */ @@ -138,13 +144,6 @@ this.waitingLearners = waitingLearners; } - public String toString() - { - return new ToStringBuilder(this) - .append("activityId", getActivityId()) - .toString(); - } - public Boolean getGateOpen() { return gateOpen; @@ -155,9 +154,47 @@ this.gateOpen = gateOpen; } - public boolean shouldOpen() + //--------------------------------------------------------------------- + // Domain service methods + //--------------------------------------------------------------------- + + /** + * Add a learner into the waiting list. + * @param learner the new waiting learner. + */ + public void addWaitingLeaner(User learner) { - return false; + if(this.waitingLearners == null) + this.setWaitingLearners(new HashSet()); + + //only add the learner if we have never added him before. + if(!this.waitingLearners.contains(learner)) + this.waitingLearners.add(learner); } + + /** + * Delegate to strategy class to calculate whether we should open the + * gate for this learner. + * @param learner the learner who wants to go through the gate. + * @return the gate should be open or closed. + */ + public boolean shouldOpenGateFor(User learner, List lessonLearners) + { + //by default, we close the gate + if(getGateOpen()==null) + this.setGateOpen(new Boolean(false)); + + return ((GateActivityStrategy)simpleActivityStrategy).shouldOpenGateFor(learner,lessonLearners,this); + } + + //--------------------------------------------------------------------- + // Helper methods + //--------------------------------------------------------------------- + public String toString() + { + return new ToStringBuilder(this) + .append("activityId", getActivityId()) + .toString(); + } } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ScheduleGateActivity.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/ScheduleGateActivity.java,v diff -u -r1.11 -r1.12 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ScheduleGateActivity.java 6 Apr 2005 05:02:57 -0000 1.11 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ScheduleGateActivity.java 6 Apr 2005 07:34:45 -0000 1.12 @@ -5,6 +5,7 @@ import java.util.Set; import org.apache.commons.lang.builder.ToStringBuilder; +import org.lamsfoundation.lams.learningdesign.strategy.ScheduleGateActivityStrategy; /** @@ -110,10 +111,12 @@ waitingLearners); this.gateStartTimeOffset = gateStartTimeOffset; this.gateEndTimeOffset = gateEndTimeOffset; + this.simpleActivityStrategy = new ScheduleGateActivityStrategy(); } /** default constructor */ public ScheduleGateActivity() { + this.simpleActivityStrategy = new ScheduleGateActivityStrategy(); } /** minimal constructor */ @@ -145,6 +148,7 @@ waitingLearners); this.gateStartTimeOffset = gateStartTimeOffset; this.gateEndTimeOffset = gateEndTimeOffset; + this.simpleActivityStrategy = new ScheduleGateActivityStrategy(); } /** * Makes a copy of the ScheduleGateActivity for authoring, preview and monitoring enviornment Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/SynchGateActivity.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/SynchGateActivity.java,v diff -u -r1.10 -r1.11 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/SynchGateActivity.java 6 Apr 2005 05:02:57 -0000 1.10 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/SynchGateActivity.java 6 Apr 2005 07:34:45 -0000 1.11 @@ -5,6 +5,7 @@ import java.util.Set; import org.apache.commons.lang.builder.ToStringBuilder; +import org.lamsfoundation.lams.learningdesign.strategy.SynchGateActivityStrategy; /** @@ -55,10 +56,12 @@ transitionFrom, gateActivityLevelId, waitingLearners); + super.simpleActivityStrategy = new SynchGateActivityStrategy(); } /** default constructor */ public SynchGateActivity() { + super.simpleActivityStrategy = new SynchGateActivityStrategy(); } /** minimal constructor */ @@ -87,6 +90,7 @@ transitionFrom, gateActivityLevelId, waitingLearners); + super.simpleActivityStrategy = new SynchGateActivityStrategy(); } /** Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/GateActivityStrategy.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/GateActivityStrategy.java,v diff -u -r1.1 -r1.2 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/GateActivityStrategy.java 5 Apr 2005 23:59:22 -0000 1.1 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/GateActivityStrategy.java 6 Apr 2005 07:34:45 -0000 1.2 @@ -23,8 +23,11 @@ package org.lamsfoundation.lams.learningdesign.strategy; import java.util.ArrayList; +import java.util.List; import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.GateActivity; +import org.lamsfoundation.lams.usermanagement.User; /** @@ -38,9 +41,48 @@ */ public abstract class GateActivityStrategy extends SimpleActivityStrategy { + //--------------------------------------------------------------------- + // Template methods + //--------------------------------------------------------------------- + /** + * Returns wether we should open the gate or close the gate. It's + * implementation depends on the type of the gate we are dealing with. + * Generally, it needs the check up the current gate status. If the gate + * is already opened, we will keep it open for current learner. Otherwise, + * we need to validate the open condition for this learner. + * + * @param learner the learner who just arrived at the gate. + * @param activity the gate activity. + * @param lessonLearners all learners who are currently in the lesson. + * @return whether we should open it or not. + */ + public boolean shouldOpenGateFor(User learner,List lessonLearners,GateActivity activity) + { + activity.addWaitingLeaner(learner); + + if(!activity.getGateOpen().booleanValue()) + { + if( isOpenConditionMet(activity, lessonLearners)) + { + activity.setGateOpen(new Boolean(true)); + activity.getWaitingLearners().clear(); + } + + } + + return activity.getGateOpen().booleanValue(); + } - //--------------------------------------------------------------------- + // Abstract methods + //--------------------------------------------------------------------- + /** + * Check up the open condition according the gate type. + * @return return true if the condition is met. + */ + protected abstract boolean isOpenConditionMet(GateActivity activity, + List lessonLearners); + //--------------------------------------------------------------------- // Overidden methods //--------------------------------------------------------------------- /** Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/PermissionGateActivityStrategy.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/PermissionGateActivityStrategy.java,v diff -u -r1.2 -r1.3 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/PermissionGateActivityStrategy.java 5 Apr 2005 23:59:22 -0000 1.2 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/PermissionGateActivityStrategy.java 6 Apr 2005 07:34:45 -0000 1.3 @@ -21,8 +21,10 @@ package org.lamsfoundation.lams.learningdesign.strategy; import java.util.ArrayList; +import java.util.List; import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.GateActivity; /** * Activity strategy that deals with the calculation specific to gate activity. @@ -46,4 +48,16 @@ contributionTypes.add(PERMISSION_GATE); } + /** + * Regarding permission gate, we don't validate the open condition for the + * learner because the decision of opening the gate or not comes from the + * teacher. The teacher may open or close the gate at monitoring interface. + * + * @see org.lamsfoundation.lams.learningdesign.strategy.GateActivityStrategy#isOpenConditionMet() + */ + protected boolean isOpenConditionMet(GateActivity activity,List lessonLearners) + { + return activity.getGateOpen().booleanValue(); + } + } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/ScheduleGateActivityStrategy.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/ScheduleGateActivityStrategy.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/ScheduleGateActivityStrategy.java 6 Apr 2005 07:34:45 -0000 1.1 @@ -0,0 +1,72 @@ +/*************************************************************************** + * 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.ArrayList; +import java.util.List; + +import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.GateActivity; + + +/** + * Activity strategy that deals with the calculation specific to schedule gate + * activity. The major part of this strategy will be overiding the methods that + * defined in the abstract level. + * + * @author Jacky Fang + * @since 2005-4-6 + * @version 1.1 + * + */ +public class ScheduleGateActivityStrategy extends GateActivityStrategy +{ + //--------------------------------------------------------------------- + // Overriden methods + //--------------------------------------------------------------------- + + /** + * @see org.lamsfoundation.lams.learningdesign.strategy.GateActivityStrategy#setUpContributionType(org.lamsfoundation.lams.learningdesign.Activity, java.util.ArrayList) + */ + protected void setUpContributionType(Activity activity, + ArrayList contributionTypes) + { + contributionTypes.add(SCHEDULE_GATE); + } + + /** + * Regarding schedule gate, we don't validate the open condition for the + * learner because the decision of opening the gate or not comes from the + * system scheduler. Lams open the gate when the start time is reached and + * closed the gate when the end time is reached. + * + * @see org.lamsfoundation.lams.learningdesign.strategy.GateActivityStrategy#isOpenConditionMet() + */ + protected boolean isOpenConditionMet(GateActivity activity, + List lessonLearners) + { + return activity.getGateOpen().booleanValue(); + } + + +} Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/SynchGateActivityStrategy.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/SynchGateActivityStrategy.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/strategy/SynchGateActivityStrategy.java 6 Apr 2005 07:34:45 -0000 1.1 @@ -0,0 +1,85 @@ +/*************************************************************************** + * 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.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.GateActivity; +import org.lamsfoundation.lams.usermanagement.User; + + +/** + * Activity strategy that deals with the calculation specific to schedule gate + * activity. The major part of this strategy will be overiding the methods that + * defined in the abstract level. + * + * @author Jacky Fang + * @since 2005-4-6 + * @version 1.1 + * + */ +public class SynchGateActivityStrategy extends GateActivityStrategy +{ + //--------------------------------------------------------------------- + // Overriden methods + //--------------------------------------------------------------------- + /** + *
Check up the waiting learners list and lesson learner list. If all + * lesson learner appears in the waiting list, we assume the open condition + * for the sync gate is met.
+ * + *Note, simply compares the size of two list might be proper. Waiting + * learners might not want to wait any more and exit the lesson, who will + * be removed from current lesson learner list. Therefore, it is possible + * that the waiting learner list is larger than the current lesson learner + * list.
+ * + * @see org.lamsfoundation.lams.learningdesign.strategy.GateActivityStrategy#isOpenConditionMet() + */ + protected boolean isOpenConditionMet(GateActivity activity, + List lessonLearners) + { + for(Iterator i = lessonLearners.iterator();i.hasNext();) + { + User learner = (User)i.next(); + if (!activity.getWaitingLearners().contains(learner)) + return false; + } + return true; + } + + /** + * @see org.lamsfoundation.lams.learningdesign.strategy.SimpleActivityStrategy#setUpContributionType(org.lamsfoundation.lams.learningdesign.Activity, java.util.ArrayList) + */ + protected void setUpContributionType(Activity activity, + ArrayList contributionTypes) + { + contributionTypes.add(SYNC_GATE); + } + + + +} Index: lams_common/test/java/org/lamsfoundation/lams/learningdesign/TestGateActivityStrategy.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/test/java/org/lamsfoundation/lams/learningdesign/Attic/TestGateActivityStrategy.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_common/test/java/org/lamsfoundation/lams/learningdesign/TestGateActivityStrategy.java 6 Apr 2005 07:34:45 -0000 1.1 @@ -0,0 +1,116 @@ +/*************************************************************************** + * 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 java.util.ArrayList; +import java.util.List; + +import org.lamsfoundation.lams.usermanagement.User; + +import junit.framework.TestCase; + + +/** + * + * @author Jacky Fang + * @since 2005-4-6 + * @version + * + */ +public class TestGateActivityStrategy extends TestCase +{ + private GateActivity schduleGate = new ScheduleGateActivity(); + private GateActivity permissionGate = new PermissionGateActivity(); + private GateActivity synchGate = new SynchGateActivity(); + + private static List testLessonUsers = new ArrayList(); + private static final int NUM_OF_TEST_USERS = 5; + private static final int TEST_USER_ID = 1; + + /* + * @see AbstractLamsTestCase#setUp() + */ + protected void setUp() throws Exception + { + + //initialize lesson users + for(int i =0; i