Index: lams_learning/src/java/org/lamsfoundation/lams/learning/LearningResources.properties
===================================================================
RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/Attic/LearningResources.properties,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/LearningResources.properties 28 Jan 2005 02:17:16 -0000 1.1
@@ -0,0 +1,14 @@
+# Resources for parameter 'com.lamsinternational.lams.learning.LearningResources'
+# Project P/lams_learning
+message.activity.loading=The next task is loading. Please wait....
+message.lesson.finished=Congratulations, you have finished.
+message.lesson.finishedCont=You have now completed your learning activity. Please log out or select a new session from the Available Sessions Panel
+message.activity.parallel.partialComplete=You have to complete the other task before progressing to the next activity....
+message.activity.parallel.noFrames=Your browser does not handle frames!
+message.activity.options.noActivitySelected=Please select an activity from the list
+message.activity.options.activityCount=You must complete at least {0} of these {1} activities.
+message.activity.options.note=Note: Once you finish any of the above activities you can revisit them by using the progress bar on the left.
+
+label.activity.options.choose=Choose
+label.activity.finish=Finish
+
Index: lams_learning/src/java/org/lamsfoundation/lams/learning/progress/Progress.java
===================================================================
RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/progress/Attic/Progress.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/progress/Progress.java 28 Jan 2005 02:17:16 -0000 1.1
@@ -0,0 +1,21 @@
+/*
+ * Progress.java
+ *
+ * Created on 07 December 2004, 10:48
+ */
+
+package org.lamsfoundation.lams.learning.progress;
+
+/**
+ * Value object holds progress data for a learner.
+ * @author chris
+ */
+public class Progress
+{
+
+ /** Creates a new instance of Progress */
+ public Progress()
+ {
+ }
+
+}
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
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressEngine.java 28 Jan 2005 02:17:16 -0000 1.1
@@ -0,0 +1,90 @@
+/*
+ * ProgressEngine.java
+ *
+ * Created on 07 December 2004, 10:42
+ */
+
+package org.lamsfoundation.lams.learning.progress;
+
+
+import com.lamsinternational.lams.learningdesign.*;
+import com.lamsinternational.lams.lesson.*;
+import com.lamsinternational.lams.usermanagement.User;
+
+/**
+ * The Progress Engine controls how a learner progresses
+ * through a sequence.
+ *
+ * @author chris
+ */
+public class ProgressEngine
+{
+
+ /**
+ * Creates a new instance of ProgressEngine.
+ */
+ public ProgressEngine()
+ {
+ }
+
+ /**
+ * Method determines next step for a learner based on the activity
+ * they have just completed.
+ * @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.
+ * @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 Progress calculateProgress(User learner, Lesson lesson, Activity completedActivity) throws ProgressException
+ {
+ //mark activity as complete for user
+
+ //if activity has transition
+
+ //follow transition to get next activity
+
+ //mark next activit as current act for user
+
+ //fill in VO with right data for next act.
+
+ //else if activity has a parent activity
+
+ //get parent
+
+ //notify parent activity that child is complete
+
+ //if parent is now complete
+
+ //recurse
+
+ //else (if no parent and no transtions)
+
+ //mark learner as having finished sequence
+
+ //fill in VO with right data for the end of sequence
+
+ return null;
+ }
+
+ /**
+ * Method determines the start point for a learner when they begin a Lesson.
+ * @param learner the User
who is starting the Lesson
.
+ * @param lesson the Lesson
the learner is starting.
+ * @return Progress - the VO that contains the data needed to send
+ * @throws ProgressException if the start point cannot be calculated successfully.
+ */
+ public Progress getStartPoint(User learner, Lesson lesson) throws ProgressException
+ {
+
+ //get lD from lesson
+
+ //get first activity from ld
+
+ //fill in VO based on first activity
+
+ return null;
+ }
+
+}
Index: lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressException.java
===================================================================
RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressException.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressException.java 28 Jan 2005 02:17:16 -0000 1.1
@@ -0,0 +1,32 @@
+/*
+ * ProgressException.java
+ *
+ * Created on 07 December 2004, 10:59
+ */
+
+package org.lamsfoundation.lams.learning.progress;
+
+/**
+ * The type of exception thrown by the ProgressEngine.
+ * @author chris
+ */
+public class ProgressException extends java.lang.Exception
+{
+
+ /**
+ * Creates a new instance of ProgressException
without detail message.
+ */
+ public ProgressException()
+ {
+ }
+
+
+ /**
+ * Constructs an instance of ProgressException
with the specified detail message.
+ * @param msg the detail message.
+ */
+ public ProgressException(String msg)
+ {
+ super(msg);
+ }
+}
Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java 28 Jan 2005 02:17:16 -0000 1.1
@@ -0,0 +1,100 @@
+/*
+ * ILearnerService.java
+ *
+ * Created on 18 January 2005, 15:23
+ */
+
+package org.lamsfoundation.lams.learning.service;
+
+import java.util.List;
+
+import com.lamsinternational.lams.lesson.Lesson;
+import com.lamsinternational.lams.lesson.LearnerProgress;
+import com.lamsinternational.lams.usermanagement.User;
+/**
+ *
+ * @author chris
+ */
+public interface ILearnerService
+{
+
+
+
+ /**
+ * Returns a list of all the active Lessons a User is a Learner in.
+ * @param User the learner
+ * @return List of Lessons
+ * @throws LearnerServiceException in case of problems.
+ */
+ public List getActiveLessons(User learner);
+
+
+ /**
+ * Used to allow a User to resume a Lesson they have already started
+ * @param learner the Learner
+ * @param the lesson to resume
+ * @throws LearnerServiceException in case of problems.
+ */
+ public LearnerProgress resumeLesson(User learner, Lesson lesson);
+
+
+ /**
+ * Gets the lesson object for the given key.
+ *
+ */
+ public Lesson getLesson(long lessonID);
+
+
+
+ /**
+ * Joins a User to a a new lesson as a learner
+ * @param learner the Learner
+ * @param lessionID identifies the Lesson to start
+ * @throws LearnerServiceException in case of problems.
+ */
+ public LearnerProgress startLesson(User learner, Lesson lesson);
+
+
+
+ /**
+ * Used to view a completed activity (read only?).
+ * @param activityID identifies the activity to view
+ * @param learner the Learner in the activity
+ * @param lesson the Lesson in which the activity took place
+ * @throws LearnerServiceException in case of problems.
+ * @return bean containing Learner Display data for the activity.
+ */
+ //public Bean viewFinishedActivity(long activityID, User learner, Lesson lesson);
+
+
+
+ /**
+ * Used to indicate when a Learner leaves a lesson.
+ * @param learner the Learner
+ * @param lesson the Lesson to exit from.
+ */
+ public void exitLesson(User learner, Lesson lesson);
+
+
+
+ /**
+ * Returns the current progress data of the User.
+ * @param learner the Learner
+ * @param lesson the Lesson to get progress from.
+ * @return LearnerProgess contains the learner's progress for the lesson.
+ * @throws LearnerServiceException in case of problems.
+ */
+ public LearnerProgress getProgress(User learner, Lesson lesson);
+
+
+ /**
+ * Calculates learner progress and returns the data required to be displayed to the learner (including URL(s)).
+ * @param completedActivityID identifies the activity just completed
+ * @param learner the Learner
+ * @param lesson the Lesson in progress.
+ * @return the bean containing the display data for the Learner
+ * @throws LearnerServiceException in case of problems.
+ */
+ public LearnerProgress calculateProgress(long completedActivityID, User learner, Lesson lesson);
+
+}
Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java 28 Jan 2005 02:17:16 -0000 1.1
@@ -0,0 +1,123 @@
+/*
+ * LearnerService.java
+ *
+ * Created on 11 January 2005, 15:42
+ */
+package org.lamsfoundation.lams.learning.service;
+
+import java.util.List;
+
+import org.lamsfoundation.lams.learning.progress.ProgressEngine;
+import org.lamsfoundation.lams.learning.progress.dao.IProgressDAO;
+
+
+import com.lamsinternational.lams.lesson.Lesson;
+import com.lamsinternational.lams.lesson.dao.ILessonDAO;
+import com.lamsinternational.lams.lesson.LearnerProgress;
+import com.lamsinternational.lams.usermanagement.User;
+/**
+ * This class is a facade over the Learning middle tier.
+ * @author chris
+ */
+public class LearnerService implements ILearnerService
+{
+ private IProgressDAO progressDAO = null;
+ private ILessonDAO lessonDAO = null;
+
+ /** Creates a new instance of LearnerService */
+ public LearnerService()
+ {
+ }
+
+ /**
+ * Returns a list of all the active Lessons a User is a Learner in.
+ * @param User the learner
+ * @return List of Lessons
+ * @throws LearnerServiceException in case of problems.
+ */
+ public List getActiveLessons(User learner)
+ {
+
+ return lessonDAO.getActiveLessons(learner);
+
+ }
+
+ /**
+ * Used to allow a User to resume a Lesson they have already started
+ * @param learner the Learner
+ * @param the lesson to resume
+ * @throws LearnerServiceException in case of problems.
+ */
+ public LearnerProgress resumeLesson(User learner, Lesson lesson)
+ {
+ return ProgressEngine.resumeLesson(learner, lesson);
+ }
+
+ public Lesson getLesson(long lessonID)
+ {
+ return lessonDAO.getLession(lessionID);
+ }
+
+
+ /**
+ * Joins a User to a a new lesson as a learner
+ * @param learner the Learner
+ * @param lessionID identifies the Lesson to start
+ * @throws LearnerServiceException in case of problems.
+ */
+ public LearnerProgress startLesson(User learner, Lesson lesson)
+ {
+ return ProgressEngine.startLesson(leaner, lesson);
+ }
+
+
+ /**
+ * Used to view a completed activity (read only?).
+ * @param activityID identifies the activity to view
+ * @param learner the Learner in the activity
+ * @param lesson the Lesson in which the activity took place
+ * @throws LearnerServiceException in case of problems.
+ * @return bean containing Learner Display data for the activity.
+ */
+// public Bean viewFinishedActivity(long activityID, User learner, Lesson lesson)
+// {
+// return ProgressEngine.viewFinishedActivity(activityID, learner, lesson);
+// }
+
+
+ /**
+ * Used to indicate when a Learner leaves a lesson.
+ * @param learner the Learner
+ * @param lesson the Lesson to exit from.
+ */
+ public void exitLesson(User learner, Lesson lesson)
+ {
+ ProgressEngine.exitLesson(learner, lesson);
+ }
+
+
+ /**
+ * Returns the current progress data of the User.
+ * @param learner the Learner
+ * @param lesson the Lesson to get progress from.
+ * @return LearnerProgess contains the learner's progress for the lesson.
+ * @throws LearnerServiceException in case of problems.
+ */
+ public LearnerProgress getProgress(User learner, Lesson lesson)
+ {
+ return progressDAO.getProgress(learner, lesson);
+ }
+
+ /**
+ * Calculates learner progress and returns the data required to be displayed to the learner (including URL(s)).
+ * @param completedActivityID identifies the activity just completed
+ * @param learner the Learner
+ * @param lesson the Lesson in progress.
+ * @return the bean containing the display data for the Learner
+ * @throws LearnerServiceException in case of problems.
+ */
+ public LearnerProgress calculateProgress(long completedActivityID, User learner, Lesson lesson)
+ {
+ return ProgressEngine.getNextActivity(completedActivityID, learner, lesson);
+ }
+}
Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerServiceException.java
===================================================================
RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerServiceException.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerServiceException.java 28 Jan 2005 02:17:16 -0000 1.1
@@ -0,0 +1,32 @@
+/*
+ * LearnerServiceException.java
+ *
+ * Created on 12 January 2005, 10:46
+ */
+package org.lamsfoundation.lams.learning.service;
+
+
+/**
+ * Type of exception thrown by the learning service.
+ * @author chris
+ */
+public class LearnerServiceException extends java.lang.RuntimeException
+{
+
+ /**
+ * Creates a new instance of LearnerServiceException
without detail message.
+ */
+ public LearnerServiceException()
+ {
+ }
+
+
+ /**
+ * Constructs an instance of LearnerServiceException
with the specified detail message.
+ * @param msg the detail message.
+ */
+ public LearnerServiceException(String msg)
+ {
+ super(msg);
+ }
+}
Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerServiceProxy.java
===================================================================
RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerServiceProxy.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerServiceProxy.java 28 Jan 2005 02:17:16 -0000 1.1
@@ -0,0 +1,43 @@
+package org.lamsfoundation.lams.learning.service;
+
+import javax.servlet.ServletContext;
+
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+
+/**
+ *
This class act as the proxy between web layer and service layer. It is + * designed to decouple the presentation logic and business logic completely. + * In this way, the presentation tier will no longer be aware of the changes in + * service layer. Therefore we can feel free to switch the business logic + * implementation.
+ * + */ +public class LearnerServiceProxy +{ + + /** + * Return the learner domain service object. It will delegate to the Spring + * helper method to retrieve the proper bean from Spring bean factory. + * @param servletContext the servletContext for current application + * @return survey service object. + */ + public static final ILearnerService getLearnerService(ServletContext servletContext) + { + return (ILearnerService)getLearnerDomainService(servletContext); + } + + /** + * Retrieve the proper Spring bean from bean factory. + * @param servletContext the servletContext for current application + * @return the Spring service bean. + */ + private static Object getLearnerDomainService(ServletContext servletContext) + { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); + return wac.getBean("learnerService"); + } + + +} \ No newline at end of file Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/TestLearnerService.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/service/Attic/TestLearnerService.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/TestLearnerService.java 28 Jan 2005 02:17:16 -0000 1.1 @@ -0,0 +1,269 @@ +/* + * Created on 18/01/2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.lamsfoundation.lams.learning.service; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import com.lamsinternational.lams.learningdesign.Activity; +import com.lamsinternational.lams.learningdesign.ComplexActivity; +import com.lamsinternational.lams.learningdesign.LearningDesign; +import com.lamsinternational.lams.learningdesign.OptionsActivity; +import com.lamsinternational.lams.learningdesign.ParallelActivity; +import com.lamsinternational.lams.learningdesign.ToolActivity; +import com.lamsinternational.lams.lesson.LearnerProgress; +import com.lamsinternational.lams.lesson.Lesson; +import com.lamsinternational.lams.lesson.dao.ILessonDAO; +import com.lamsinternational.lams.usermanagement.User; + +/** + * @author kevin + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class TestLearnerService implements ILearnerService { + + private HttpServletRequest request; + private static String NAME = "lams.learning.testlearnerservice"; + + private ILessonDAO lessonDAO; + + public void setLessonDAO(ILessonDAO lessonDAO) { + this.lessonDAO = lessonDAO; + } + + + public TestLearnerService() { + } + + public void setRequest(HttpServletRequest request) { + this.request = request; + } + + private LearnerProgress getProgress() { + HttpSession session = request.getSession(true); + LearnerProgress progress = (LearnerProgress)session.getAttribute(NAME); + if (progress == null) { + // create new progress + progress = createProgress(); + // store progress + session.setAttribute(NAME, progress); + } + return progress; + } + + private void setProgress(LearnerProgress progress) { + HttpSession session = request.getSession(true); + session.setAttribute(NAME, progress); + } + + public void clearProgress() { + setProgress(null); + } + + + public List getActiveLessons(User learner) { + return null; + } + + public LearnerProgress resumeLesson(User learner, Lesson lesson) { + return null; + } + + public Lesson getLesson(long lessonID) { + return null; + } + + public LearnerProgress startLesson(User learner, Lesson lesson) { + return null; + } + + public void exitLesson(User learner, Lesson lesson) { + } + + public LearnerProgress getProgress(User learner, Lesson lesson) { + return getProgress(); + } + + public LearnerProgress calculateProgress(long completedActivityId, User learner, Lesson lesson) { + LearnerProgress progress = getProgress(learner, lesson); + setComplete(completedActivityId, progress); + Activity currentActivity = calculateCurrent(progress); + progress.setCurrentActivity(currentActivity); + setProgress(progress); + + progress = createNextProgress(completedActivityId, progress); + + return progress; + } + + + private void setComplete(long activityId, LearnerProgress progress) { + Activity activity = getActivity(activityId, progress); + progress.getAttemptedActivities().remove(activity); + progress.getCompletedActivities().add(activity); + + if ((activityId == 4) && + progress.getProgressState(getActivity(5, progress)) == LearnerProgress.ACTIVITY_COMPLETED) { + setComplete(3, progress); + } + else if ((activityId == 5) && + progress.getProgressState(getActivity(4, progress)) == LearnerProgress.ACTIVITY_COMPLETED) { + setComplete(3, progress); + } + else if ((activityId == 7) || (activityId == 8) || (activityId == 9)) { + if ((progress.getProgressState(getActivity(7, progress)) == LearnerProgress.ACTIVITY_COMPLETED) && + (progress.getProgressState(getActivity(8, progress)) == LearnerProgress.ACTIVITY_COMPLETED) && + (progress.getProgressState(getActivity(9, progress)) == LearnerProgress.ACTIVITY_COMPLETED)) { + setComplete(6, progress); + } + } + else if ((activityId == 10) && + progress.getProgressState(getActivity(10, progress)) == LearnerProgress.ACTIVITY_COMPLETED) { + progress.setLessonComplete(true); + } + } + + private Activity getActivity(long activityId, LearnerProgress progress) { + Lesson lesson = progress.getLesson(); + if (lesson == null) return null; + LearningDesign learningDesign = lesson.getLearningDesign(); + if (learningDesign == null) return null; + Set activities = learningDesign.getActivities(); + if (activities == null) return null; + Iterator i = activities.iterator(); + while (i.hasNext()) { + Activity activity = (Activity)i.next(); + if (activity.getActivityId().longValue() == activityId) { + return activity; + } + } + return null; + } + + + private Activity calculateCurrent(LearnerProgress progress) { + Activity activity = null; + if (progress.getProgressState(getActivity(1, progress)) != LearnerProgress.ACTIVITY_COMPLETED) activity = getActivity(1, progress); + else if (progress.getProgressState(getActivity(2, progress)) != LearnerProgress.ACTIVITY_COMPLETED) activity = getActivity(2, progress); + else if (progress.getProgressState(getActivity(3, progress)) != LearnerProgress.ACTIVITY_COMPLETED) activity = getActivity(3, progress); + else if (progress.getProgressState(getActivity(6, progress)) != LearnerProgress.ACTIVITY_COMPLETED) activity = getActivity(6, progress); + else if (progress.getProgressState(getActivity(10, progress)) != LearnerProgress.ACTIVITY_COMPLETED) activity = getActivity(10, progress); + + return activity; + } + + + private LearnerProgress createProgress() { + + LearnerProgress progress = new LearnerProgress(); + Set attempted = new HashSet(); + Set complete = new HashSet(); + + Lesson lesson = new Lesson(); + //Lesson lesson = lessonDAO.getLesson(new Long(1)); + progress.setLesson(lesson); + + LearningDesign learningDesign = new LearningDesign(); + lesson.setLearningDesign(learningDesign); + Set activities = new HashSet(); + learningDesign.setActivities(activities); + + Activity activity = new ToolActivity(); + activity.setActivityId(new Long(1)); + activities.add(activity); + activity = new ToolActivity(); + activity.setActivityId(new Long(2)); + activities.add(activity); + activity = new ParallelActivity(); + activity.setActivityId(new Long(3)); + Set subActivities = new HashSet(); + ((ComplexActivity)activity).setActivities(subActivities); + activities.add(activity); + + activity = new ToolActivity(); + activity.setActivityId(new Long(4)); + subActivities.add(activity); + activities.add(activity); + activity = new ToolActivity(); + activity.setActivityId(new Long(5)); + subActivities.add(activity); + activities.add(activity); + + activity = new OptionsActivity(); + activity.setActivityId(new Long(6)); + activity.setTitle("foo"); + activity.setDescription("activities for foo"); + ((OptionsActivity)activity).setMinNumberOfOptions(new Integer(2)); + ((OptionsActivity)activity).setMaxNumberOfOptions(new Integer(3)); + subActivities = new HashSet(); + ((ComplexActivity)activity).setActivities(subActivities); + activities.add(activity); + + activity = new ToolActivity(); + activity.setActivityId(new Long(7)); + subActivities.add(activity); + activities.add(activity); + activity = new ToolActivity(); + activity.setActivityId(new Long(8)); + subActivities.add(activity); + activities.add(activity); + activity = new ToolActivity(); + activity.setActivityId(new Long(9)); + subActivities.add(activity); + activities.add(activity); + + activity = new ToolActivity(); + activity.setActivityId(new Long(10)); + activities.add(activity); + + progress.setAttemptedActivities(attempted); + progress.setCompletedActivities(complete); + + progress.setCurrentActivity(getActivity(1, progress)); + + return progress; + } + + private LearnerProgress createNextProgress(long completedId, LearnerProgress oldProgress) { + LearnerProgress progress = new LearnerProgress(); + progress.setLesson(oldProgress.getLesson()); + progress.setLessonComplete(oldProgress.isLessonComplete()); + progress.setAttemptedActivities(oldProgress.getAttemptedActivities()); + progress.setCompletedActivities(oldProgress.getCompletedActivities()); + progress.setCurrentActivity(oldProgress.getCurrentActivity()); + + // nextActivity is the next activity to be attempted after completedId, + // usually this will be whatever is now the current + Activity nextActivity = oldProgress.getCurrentActivity(); + + if ((completedId == 4) || (completedId == 5)) { + nextActivity = null; + } + else if ((completedId == 7) || + (completedId == 8) || + (completedId == 9)) { + nextActivity = null; + } + + if (completedId == 10) { + nextActivity = null; + } + + // this is the completed activity specific progress + progress.setNextActivity(nextActivity); + + return progress; + } + +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/ActivityAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/ActivityAction.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/ActivityAction.java 28 Jan 2005 02:17:15 -0000 1.1 @@ -0,0 +1,347 @@ +//Created by MyEclipse Struts +// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.2/xslt/JavaClass.xsl + +package org.lamsfoundation.lams.learning.web.action; + +import javax.servlet.http.*; + +import java.util.*; + +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.actions.DispatchAction; +import org.lamsfoundation.lams.learning.service.LearnerServiceException; +import org.lamsfoundation.lams.learning.service.LearnerServiceProxy; +import org.lamsfoundation.lams.learning.service.TestLearnerService; +import org.lamsfoundation.lams.learning.web.bean.SessionBean; +import org.lamsfoundation.lams.learning.web.form.ActivityForm; + +import com.lamsinternational.lams.usermanagement.*; +import com.lamsinternational.lams.lesson.*; +import com.lamsinternational.lams.learningdesign.*; + +/** + * MyEclipse Struts + * Creation date: 01-12-2005 + * + * XDoclet definition: + * + * @struts:action path="/Activity" name="activityForm" parameter="method" + * validate="false" scope="request" + * + * -- Load one or more URLs to display an activity + * @struts:action-forward name="displayToolActivity" path="/DisplayToolActivity.do" + * @struts:action-forward name="displayParallelActivity" path="/DisplayParallelActivity.do" + * @struts:action-forward name="displayOptionsActivity" path="/DisplayOptionsActivity.do" + * -- Wait message for gate activity + * @struts:action-forward name="displayGateActivity" path="/DisplayGateActivity.do" + * + * -- Tell browser to request next activity. Needed because the parallel + * -- activity frames need to be cleared by the client. + * @struts:action-forward name="requestDisplay" path=".requestDisplay" + * + * -- "Complete other activity" message + * @struts:action-forward name="parallelWait" path=".parallelWait" redirect="true" + * -- Sequence complete message + * @struts:action-forward name="lessonComplete" path=".lessonComplete" redirect="true" + * + */ +public class ActivityAction extends DispatchAction { + + /** + * Gets the session bean from session. + * @return SessionBean for this request, null if no session. + */ + protected SessionBean getSessionBean(HttpServletRequest request) { + HttpSession session = request.getSession(false); + if (session == null) { + return null; + } + SessionBean sessionBean = (SessionBean)session.getAttribute(SessionBean.NAME); + return sessionBean; + } + + /** + * Sets the session bean for this session. + */ + protected void setSessionBean(SessionBean sessionBean, HttpServletRequest request) { + HttpSession session = request.getSession(false); + if (session == null) { + return; + } + session.setAttribute(SessionBean.NAME, sessionBean); + } + + /** + * Temporary method for testing. To use point the browser to /Activity.do?method=test + */ + public ActionForward test( + ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) { + ActivityForm activityForm = (ActivityForm) form; + + SessionBean sessionBean = new SessionBean(); + setSessionBean(sessionBean, request); + + TestLearnerService learnerService = (TestLearnerService)LearnerServiceProxy.getLearnerService(this.getServlet().getServletContext()); + learnerService.setRequest(request); + learnerService.clearProgress(); + //activityForm.setActivityId(new Long(1)); + + return displayCurrent(mapping, form, request, response); + } + + /** + * Loads an activity using the activityId and forwards onto the required display + * action (displayToolActivity, displayParallelActivity, etc.). + */ + public ActionForward display( + ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) { + ActivityForm activityForm = (ActivityForm) form; + + // TODO: should we use a page forward or throw an exception for no session? + SessionBean sessionBean = getSessionBean(request); + if (sessionBean == null) { + // forward to the no session error page + return mapping.findForward("noSessionError"); + } + + TestLearnerService learnerService = (TestLearnerService)LearnerServiceProxy.getLearnerService(this.getServlet().getServletContext()); + learnerService.setRequest(request); + + // Get learner + User learner = sessionBean.getLeaner(); + // Get lesson + Lesson lesson = sessionBean.getLesson(); + // Get learnerProgress + LearnerProgress progress = sessionBean.getLearnerProgress(); + if (progress == null) { + progress = learnerService.getProgress(learner, lesson); + sessionBean.setLearnerProgress(progress); + setSessionBean(sessionBean, request); + } + + // Find requested activity + Long activityId = activityForm.getActivityId(); + Activity activity = getActivity(activityId.longValue(), progress); + if (activity == null) { + // TODO: log error + return mapping.findForward("error"); + } + + ActionForward forward = displayActivity(activity, progress, mapping, activityForm, request, response); + + return forward; + } + + /** + * Loads the current activity and forwards onto the required display + * action (same as for display method). + */ + public ActionForward displayCurrent( + ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) { + ActivityForm activityForm = (ActivityForm) form; + + // TODO: should we use a page forward or throw an exception for no session? + SessionBean sessionBean = getSessionBean(request); + if (sessionBean == null) { + // forward to the no session error page + return mapping.findForward("noSessionError"); + } + + TestLearnerService learnerService = (TestLearnerService)LearnerServiceProxy.getLearnerService(this.getServlet().getServletContext()); + learnerService.setRequest(request); + + // Get learner + User learner = sessionBean.getLeaner(); + // Get lesson + Lesson lesson = sessionBean.getLesson(); + // Get learnerProgress + LearnerProgress progress = sessionBean.getLearnerProgress(); + if (progress == null) { + progress = learnerService.getProgress(learner, lesson); + sessionBean.setLearnerProgress(progress); + setSessionBean(sessionBean, request); + } + + // Get current activity + Activity activity = progress.getCurrentActivity(); + + ActionForward forward = null; + // TODO: If null need to check for lesson complete or not started + if (activity == null) { + if (progress.isLessonComplete()) { + forward = mapping.findForward("lessonComplete"); + } + else { + // TODO: log error + return mapping.findForward("error"); + } + } + else { + forward = displayActivity(activity, progress, mapping, activityForm, request, response); + } + + return forward; + } + + /** + * Sets the current activity as complete and uses the progress engine to find + * the next activity (may be null). Note that the activity being completed may be + * part of a parallel activity. + * Forwards onto the required display action (displayToolActivity, + * displayParallelActivity, etc.). + */ + public ActionForward complete( + ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) throws LearnerServiceException { + ActivityForm activityForm = (ActivityForm) form; + + // TODO: should we use a page forward or throw an exception for no session? + SessionBean sessionBean = getSessionBean(request); + if (sessionBean == null) { + // forward to the no session error page + return mapping.findForward("noSessionError"); + } + + TestLearnerService learnerService = (TestLearnerService)LearnerServiceProxy.getLearnerService(this.getServlet().getServletContext()); + learnerService.setRequest(request); + + // Get learner + User learner = sessionBean.getLeaner(); + // Get lesson + Lesson lesson = sessionBean.getLesson(); + // Get learnerProgress + LearnerProgress progress = sessionBean.getLearnerProgress(); + if (progress == null) { + progress = learnerService.getProgress(learner, lesson); + } + + // Find requested activity + // The activity must be a current activity + // TODO: or can the activity be non-current and not complete? + Long activityId = activityForm.getActivityId(); + Activity activity = getActivity(activityId.longValue(), progress); + + // if not current then error + if (activity == null) { + // TODO: log error + return mapping.findForward("error"); + } + + // Set activity as complete + LearnerProgress nextProgress = learnerService.calculateProgress(activity.getActivityId().longValue(), learner, lesson); + + //ActionForward forward = displayNextActivity(activity, nextProgress, mapping, activityForm, request, response); + ActionForward forward = displayNextActivity(progress, nextProgress, mapping, activityForm, request, response); + sessionBean.setLearnerProgress(nextProgress); + setSessionBean(sessionBean, request); + + return forward; + } + + + /** + * Display the next activity in progress. + * The just finished activity is needed to display the current progress because + * ParallelActivity may require that the client re-request the activity or display + * a "patially complete" message. + * @param previousProgress, the progress before the activity was completed + * @param progress, the current progress + */ + private ActionForward displayNextActivity(LearnerProgress previousProgress, LearnerProgress progress, + ActionMapping mapping, ActivityForm activityForm, HttpServletRequest request, HttpServletResponse response) throws LearnerServiceException { + + ActionForward forward = null; + + if (progress.isLessonComplete()) { + forward = mapping.findForward("lessonComplete"); + } + else { + Activity nextActivity = progress.getNextActivity(); + Activity currentActivity = progress.getCurrentActivity(); + Activity previousActivity = previousProgress.getCurrentActivity(); + if (nextActivity == null) { + if (previousActivity == currentActivity) { + if (previousActivity instanceof ParallelActivity) { + forward = mapping.findForward("parallelWait"); + } + else { + nextActivity = currentActivity; + forward = displayActivity(nextActivity, progress, mapping, activityForm, request, response); + } + } + else { + if (previousActivity instanceof ParallelActivity) { + nextActivity = currentActivity; + forward = mapping.findForward("requestDisplay"); + } + else { + nextActivity = currentActivity; + forward = displayActivity(nextActivity, progress, mapping, activityForm, request, response); + } + } + } + else { + forward = displayActivity(nextActivity, progress, mapping, activityForm, request, response); + } + if (nextActivity != null) request.setAttribute("activityId", nextActivity.getActivityId()); + } + + return forward; + } + + + /** + * Returns an ActionForward to display an activity. The forward returned is + * displayToolActivity for a ToolActivity, displayParallelActivity for a + * ParallelActivity and displayOptionsActivity for an OptionsActivity. The + * activity ID is also set as a request attribute (read by DisplayActivity). + */ + private ActionForward displayActivity(Activity activity, LearnerProgress progress, + ActionMapping mapping, ActivityForm activityForm, HttpServletRequest request, HttpServletResponse response) { + String forwardName = null; + + // This should not be done with instanceof, perhaps should use the class name + if (activity instanceof ComplexActivity) { + if (activity instanceof OptionsActivity) forwardName = "displayOptionsActivity"; + else if (activity instanceof ParallelActivity) forwardName = "displayParallelActivity"; + } + else if (activity instanceof SimpleActivity) { + forwardName = "displayToolActivity"; + } + + Long activityId = activity.getActivityId(); + request.setAttribute("activityId", activityId); + + ActionForward forward = mapping.findForward(forwardName); + return forward; + } + + /** A quick method to get an activity from within a progress. This method is + * temporary. + */ + private Activity getActivity(long activityId, LearnerProgress progress) { + Set activities = progress.getLesson().getLearningDesign().getActivities(); + Iterator i = activities.iterator(); + while (i.hasNext()) { + Activity activity = (Activity)i.next(); + if (activity.getActivityId().longValue() == activityId) { + return activity; + } + } + return null; + } + +} \ No newline at end of file Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayActivity.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/Attic/DisplayActivity.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayActivity.java 28 Jan 2005 02:17:15 -0000 1.1 @@ -0,0 +1,97 @@ +//Created by MyEclipse Struts +// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.2/xslt/JavaClass.xsl + +package org.lamsfoundation.lams.learning.web.action; + +import javax.servlet.http.*; +import java.util.*; + +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.Action; +import org.lamsfoundation.lams.learning.web.bean.SessionBean; +import org.lamsfoundation.lams.learning.web.form.ActivityForm; + +import com.lamsinternational.lams.usermanagement.*; +import com.lamsinternational.lams.learningdesign.*; +import com.lamsinternational.lams.lesson.*; + +/** + * MyEclipse Struts + * Creation date: 01-12-2005 + * + */ +public abstract class DisplayActivity extends Action { + + protected SessionBean getSessionBean(HttpServletRequest request) { + HttpSession session = request.getSession(false); + if (session == null) { + return null; + } + SessionBean sessionBean = (SessionBean)session.getAttribute(SessionBean.NAME); + return sessionBean; + } + + /** display + * Gets an activity from the request (attribute) and forwards onto the required + * jsp (SingleActivity or ParallelActivity). + */ + public ActionForward execute( + ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) { + ActivityForm displayForm = (ActivityForm) form; + + // TODO: should we use a page forward or throw an exception for no session? + SessionBean sessionBean = getSessionBean(request); + if (sessionBean == null) { + // forward to the no session error page + return mapping.findForward("noSessionError"); + } + + // Get learner + User learner = sessionBean.getLeaner(); + // Get learnerProgress + LearnerProgress progress = sessionBean.getLearnerProgress(); + + Long activityId = (Long)request.getAttribute("activityId"); + if (activityId == null) { + // check the request for an activityId + activityId = displayForm.getActivityId(); + if (activityId == null) { + return mapping.findForward("error"); + } + } + + // Find requested activity + // May need special processing if activity is not current + Activity activity = getActivity(activityId.longValue(), progress); + + ActionForward forward = displayActivity(activity, progress, mapping, displayForm, request, response); + return forward; + } + + /** + * Returns an ActionForward to display an activity based on its type. The form bean + * also has its values set for display. Note that this method is over-ridden by the + * DisplayOptionsActivity sub-class. + */ + protected abstract ActionForward displayActivity(Activity activity, LearnerProgress progress, + ActionMapping mapping, ActivityForm form, HttpServletRequest request, HttpServletResponse response); + + + private Activity getActivity(long activityId, LearnerProgress progress) { + Set activities = progress.getLesson().getLearningDesign().getActivities(); + Iterator i = activities.iterator(); + while (i.hasNext()) { + Activity activity = (Activity)i.next(); + if (activity.getActivityId().longValue() == activityId) { + return activity; + } + } + return null; + } + +} \ No newline at end of file Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayOptionsActivity.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/Attic/DisplayOptionsActivity.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayOptionsActivity.java 28 Jan 2005 02:17:15 -0000 1.1 @@ -0,0 +1,89 @@ +/* + * Created on 14/01/2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.lamsfoundation.lams.learning.web.action; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.learning.web.bean.ActivityURL; +import org.lamsfoundation.lams.learning.web.form.ActivityForm; +import org.lamsfoundation.lams.learning.web.form.OptionsActivityForm; +import org.lamsfoundation.lams.learning.web.util.Utils; + +import com.lamsinternational.lams.learningdesign.Activity; +import com.lamsinternational.lams.learningdesign.OptionsActivity; +import com.lamsinternational.lams.lesson.LearnerProgress; + +/** + * @author daveg + * + * XDoclet definition: + * + * @struts:action path="/DisplayOptionsActivity" name="optionsActivityForm" + * input="/Activity.do" validate="false" scope="request" + * + * @struts:action-forward name="displayOptions" path=".optionsActivity" + * + */ +public class DisplayOptionsActivity extends DisplayActivity { + + /** + * Returns an ActionForward to display an activity and sets the form bean values. + */ + protected ActionForward displayActivity(Activity activity, LearnerProgress progress, + ActionMapping mapping, ActivityForm activityForm, HttpServletRequest request, HttpServletResponse response) { + String forward = null; + + if (!(activity instanceof OptionsActivity)) { + // error + return mapping.findForward("error"); + } + + OptionsActivityForm form = (OptionsActivityForm)activityForm; + + forward = "displayOptions"; + + OptionsActivity optionsActivity = (OptionsActivity)activity; + form.setActivityId(activity.getActivityId()); + form.setTitle(activity.getTitle()); + form.setDescription(activity.getDescription()); + form.setMinimum(optionsActivity.getMinNumberOfOptions().intValue()); + form.setMaximum(optionsActivity.getMaxNumberOfOptions().intValue()); + + List activityURLs = new ArrayList(); + // TODO: Need to get order somehow + Set subActivities = optionsActivity.getActivities(); + Iterator i = subActivities.iterator(); + int completedCount = 0; + while (i.hasNext()) { + Activity subActivity = (Activity)i.next(); + ActivityURL url = Utils.generateActivityURL(subActivity, progress); + activityURLs.add(url); + if (progress.getProgressState(subActivity) == LearnerProgress.ACTIVITY_COMPLETED) { + completedCount++; + } + } + form.setActivityURLs(activityURLs); + if (completedCount >= optionsActivity.getMinNumberOfOptions().intValue()) { + form.setFinished(true); + } + + if (activityURLs.size() == 0) { + // TODO: error + } + + return mapping.findForward(forward); + } + +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayParallelActivity.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/Attic/DisplayParallelActivity.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayParallelActivity.java 28 Jan 2005 02:17:15 -0000 1.1 @@ -0,0 +1,69 @@ +//Created by MyEclipse Struts +// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.2/xslt/JavaClass.xsl + +package org.lamsfoundation.lams.learning.web.action; + +import javax.servlet.http.*; +import java.util.*; + +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.learning.web.bean.ActivityURL; +import org.lamsfoundation.lams.learning.web.form.ActivityForm; +import org.lamsfoundation.lams.learning.web.util.Utils; + +import com.lamsinternational.lams.learningdesign.*; +import com.lamsinternational.lams.lesson.*; + +/** + * MyEclipse Struts + * Creation date: 01-12-2005 + * + * XDoclet definition: + * + * @struts:action path="/DisplayParallelActivity" name="activityForm" + * validate="false" scope="request" + * + * @struts:action-forward name="displayParallel" path=".parallelActivity" + * + */ +public class DisplayParallelActivity extends DisplayActivity { + + /** + * Returns an ActionForward to display an activity based on its type. The form bean + * also has its values set for display. Note that this method is over-ridden by the + * DisplayOptionsActivity sub-class. + */ + protected ActionForward displayActivity(Activity activity, LearnerProgress progress, + ActionMapping mapping, ActivityForm form, HttpServletRequest request, HttpServletResponse response) { + String forward = null; + + if (!(activity instanceof ParallelActivity)) { + // error + return mapping.findForward("error"); + } + + ParallelActivity parallelActivity = (ParallelActivity)activity; + + forward = "displayParallel"; + + form.setActivityId(activity.getActivityId()); + List activityURLs = new ArrayList(); + // TODO: Need to get order somehow + Set subActivities = parallelActivity.getActivities(); + Iterator i = subActivities.iterator(); + while (i.hasNext()) { + Activity subActivity = (Activity)i.next(); + ActivityURL url = Utils.generateActivityURL(subActivity, progress); + activityURLs.add(url); + } + form.setActivityURLs(activityURLs); + + if (activityURLs.size() == 0) { + // TODO: error + } + + return mapping.findForward(forward); + } + +} \ No newline at end of file Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayToolActivity.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/Attic/DisplayToolActivity.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/DisplayToolActivity.java 28 Jan 2005 02:17:15 -0000 1.1 @@ -0,0 +1,61 @@ +//Created by MyEclipse Struts +// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.2/xslt/JavaClass.xsl + +package org.lamsfoundation.lams.learning.web.action; + +import javax.servlet.http.*; +import java.util.*; + +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.learning.web.bean.ActivityURL; +import org.lamsfoundation.lams.learning.web.form.ActivityForm; +import org.lamsfoundation.lams.learning.web.util.Utils; + +import com.lamsinternational.lams.learningdesign.*; +import com.lamsinternational.lams.lesson.*; + +/** + * MyEclipse Struts + * Creation date: 01-12-2005 + * + * XDoclet definition: + * + * @struts:action path="/DisplayToolActivity" name="activityForm" + * validate="false" scope="request" + * + * -- Load one or more URLs to display an activity + * @struts:action-forward name="displayTool" path=".toolActivity" + * + */ +public class DisplayToolActivity extends DisplayActivity { + + /** + * Returns an ActionForward to display an activity based on its type. The form bean + * also has its values set for display. Note that this method is over-ridden by the + * DisplayOptionsActivity sub-class. + */ + protected ActionForward displayActivity(Activity activity, LearnerProgress progress, + ActionMapping mapping, ActivityForm form, HttpServletRequest request, HttpServletResponse response) { + + if (!(activity instanceof ToolActivity)) { + // error + return mapping.findForward("error"); + } + ToolActivity toolActivity = (ToolActivity)activity; + + List activityURLs = new ArrayList(); + String forward = null; + + forward = "displayTool"; + + form.setActivityId(activity.getActivityId()); + //ActivityURL url = Utils.generateActivityURL(activity, progress); + ActivityURL url = Utils.getToolURL(toolActivity, progress); + activityURLs.add(url); + form.setActivityURLs(activityURLs); + + return mapping.findForward(forward); + } + +} \ No newline at end of file Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/TestAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/Attic/TestAction.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/TestAction.java 28 Jan 2005 02:17:15 -0000 1.1 @@ -0,0 +1,40 @@ +/* + * Created on 27/01/2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.lamsfoundation.lams.learning.web.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.learning.service.ILearnerService; +import org.lamsfoundation.lams.learning.service.LearnerServiceProxy; + + +/** + * + * XDoclet definition: + * + * @struts:action path="/test" name="testForm" + * validate="false" scope="request" + * + */ +public class TestAction extends Action { + + public ActionForward execute( + ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) { + ILearnerService learnerService = LearnerServiceProxy.getLearnerService(this.getServlet().getServletContext()); + //LearnerProgress progress = learnerService.getProgress(null, null); + return null; + } + +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/bean/ActivityURL.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/bean/ActivityURL.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/bean/ActivityURL.java 28 Jan 2005 02:17:16 -0000 1.1 @@ -0,0 +1,53 @@ +/* + * Created on 13/01/2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.lamsfoundation.lams.learning.web.bean; + +/** + * @author kevin + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class ActivityURL { + + private Long activityId; + private String url; + private String title; + private String description; + private boolean complete; + + public boolean isComplete() { + return complete; + } + public void setComplete(boolean complete) { + this.complete = complete; + } + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public Long getActivityId() { + return activityId; + } + public void setActivityId(Long activityId) { + this.activityId = activityId; + } + public String getUrl() { + return url; + } + public void setUrl(String url) { + this.url = url; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/bean/SessionBean.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/bean/Attic/SessionBean.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/bean/SessionBean.java 28 Jan 2005 02:17:16 -0000 1.1 @@ -0,0 +1,44 @@ +/* + * Created on 14/01/2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.lamsfoundation.lams.learning.web.bean; + +import com.lamsinternational.lams.usermanagement.*; +import com.lamsinternational.lams.lesson.*; + +/** + * @author kevin + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class SessionBean implements java.io.Serializable { + + public static String NAME = "lams.learning.session"; + + private User leaner; + private Lesson lesson; + private LearnerProgress progress; + + public User getLeaner() { + return leaner; + } + public void setLeaner(User leaner) { + this.leaner = leaner; + } + public Lesson getLesson() { + return lesson; + } + public void setLesson(Lesson lesson) { + this.lesson = lesson; + } + public LearnerProgress getLearnerProgress() { + return progress; + } + public void setLearnerProgress(LearnerProgress progress) { + this.progress = progress; + } +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/form/ActivityForm.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/form/ActivityForm.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/form/ActivityForm.java 28 Jan 2005 02:17:15 -0000 1.1 @@ -0,0 +1,66 @@ +//Created by MyEclipse Struts +// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.2/xslt/JavaClass.xsl + +package org.lamsfoundation.lams.learning.web.form; + +import javax.servlet.http.HttpServletRequest; +import java.util.*; + +import org.apache.struts.action.ActionErrors; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionMapping; + +/** + * MyEclipse Struts + * Creation date: 01-12-2005 + * + * XDoclet definition: + * @struts:form name="activityForm" + */ +public class ActivityForm extends ActionForm { + + /** List of ActivityURL, will only contain one if a simple activity */ + private List activityURLs; + /** Unique identifier specifying the session for this activity, maps back to + * LearnerProgress (or Learner) and Activity. Note that the activity may already + * be complete. + */ + private Long activityId; + + + /** + * Method validate + * @param mapping + * @param request + * @return ActionErrors + */ + public ActionErrors validate( + ActionMapping mapping, + HttpServletRequest request) { + + throw new UnsupportedOperationException("Generated method 'validate(...)' not implemented."); + } + + /** + * Method reset + * @param mapping + * @param request + */ + public void reset(ActionMapping mapping, HttpServletRequest request) { + activityURLs = null; + //throw new UnsupportedOperationException("Generated method 'reset(...)' not implemented."); + } + + public List getActivityURLs() { + return activityURLs; + } + public void setActivityURLs(List activityURLs) { + this.activityURLs = activityURLs; + } + public Long getActivityId() { + return activityId; + } + public void setActivityId(Long activityId) { + this.activityId = activityId; + } +} \ No newline at end of file Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/form/OptionsActivityForm.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/form/OptionsActivityForm.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/form/OptionsActivityForm.java 28 Jan 2005 02:17:15 -0000 1.1 @@ -0,0 +1,53 @@ +/* + * Created on 14/01/2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.lamsfoundation.lams.learning.web.form; + +/** + * @author daveg + * + * XDoclet definition: + * @struts:form name="optionsActivityForm" + */ +public class OptionsActivityForm extends ActivityForm { + + private String title; + private String description; + private int minimum; + private int maximum; + private boolean finished; + + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public int getMinimum() { + return minimum; + } + public void setMinimum(int minimum) { + this.minimum = minimum; + } + public int getMaximum() { + return maximum; + } + public void setMaximum(int maximum) { + this.maximum = maximum; + } + public boolean isFinished() { + return finished; + } + public void setFinished(boolean finished) { + this.finished = finished; + } +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/form/TestForm.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/form/Attic/TestForm.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/form/TestForm.java 28 Jan 2005 02:17:15 -0000 1.1 @@ -0,0 +1,18 @@ +/* + * Created on 27/01/2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.lamsfoundation.lams.learning.web.form; + +import org.apache.struts.action.ActionForm; + +/** + * + * XDoclet definition: + * @struts:form name="testForm" + */ +public class TestForm extends ActionForm { + +} Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/Utils.java =================================================================== RCS file: /usr/local/cvsroot/lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/Attic/Utils.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/Utils.java 28 Jan 2005 02:17:16 -0000 1.1 @@ -0,0 +1,85 @@ +/* + * Created on 14/01/2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.lamsfoundation.lams.learning.web.util; + +import org.lamsfoundation.lams.learning.web.bean.ActivityURL; + +import com.lamsinternational.lams.lesson.*; +import com.lamsinternational.lams.learningdesign.Activity; +import com.lamsinternational.lams.learningdesign.ComplexActivity; +import com.lamsinternational.lams.learningdesign.GateActivity; +import com.lamsinternational.lams.learningdesign.GroupingActivity; +import com.lamsinternational.lams.learningdesign.SimpleActivity; +import com.lamsinternational.lams.learningdesign.ToolActivity; + +/** + * @author kevin + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class Utils { + + /** + * Generates an ActivityURL for an Activity using it's progress. The URL is for + * the client and so includes hostname etc. + * Note that this method always returns LAMS URLs, if a ToolActivity is passed + * in the URL will be the action for displaying the tool. + */ + public static ActivityURL generateActivityURL(Activity activity, LearnerProgress progress) { + ActivityURL activityURL = new ActivityURL(); + activityURL.setTitle("activity "+activity.getActivityId()); + activityURL.setDescription("description for activity with id "+activity.getActivityId()); + activityURL.setComplete(progress.getProgressState(activity) == LearnerProgress.ACTIVITY_COMPLETED); + // TODO: should not be using instanceof + if (activity instanceof ComplexActivity) { + // if activity is complex need to return a LAMS url + String contextRoot = "/lams_learning"; + String strutsAction = "/Activity.do?method=display"; + String properties = "&activityId="+activity.getActivityId(); + String url = contextRoot+strutsAction+properties; + activityURL.setUrl(url); + } + else if (activity instanceof SimpleActivity) { + //if (progress.activityCompleted(activity)) { + if (activity == null) { + } + else { + if (activity instanceof GroupingActivity) { + // this probably means a wait URL + } + if (activity instanceof GateActivity) { + // not completed so return wait URL + } + if (activity instanceof ToolActivity) { + // get tool URL + activityURL.setActivityId(activity.getActivityId()); + //activityURL.setUrl("toolTest.jsp?activityId="+activity.getActivityId()+"&progressState="+progress.getProgressState(activity)); + String contextRoot = "/lams_learning"; + String strutsAction = "/Activity.do?method=display"; + String properties = "&activityId="+activity.getActivityId(); + String url = contextRoot+strutsAction+properties; + activityURL.setUrl(url); + } + } + } + return activityURL; + } + + public static ActivityURL getToolURL(ToolActivity activity, LearnerProgress progress) { + ActivityURL activityURL = new ActivityURL(); + activityURL.setTitle("activity "+activity.getActivityId()); + activityURL.setDescription("description for activity with id "+activity.getActivityId()); + activityURL.setComplete(progress.getProgressState(activity) == LearnerProgress.ACTIVITY_COMPLETED); + + activityURL.setActivityId(activity.getActivityId()); + activityURL.setUrl("toolTest.jsp?activityId="+activity.getActivityId()+"&progressState="+progress.getProgressState(activity)); + + return activityURL; + } + +}