Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java
===================================================================
diff -u -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb -r1ac030743cfd5c1a1479311197a02821dbc85cbc
--- lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java (.../ILearnerService.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb)
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java (.../ILearnerService.java) (revision 1ac030743cfd5c1a1479311197a02821dbc85cbc)
@@ -103,6 +103,22 @@
public String completeToolSession(Long toolSessionId, User learner);
/**
+ * Complete the activity in the progress engine and delegate to the progress
+ * engine to calculate the next activity in the learning design. This
+ * process might be triggerred by system controlled the activity, such as
+ * grouping and gate. It might also be triggerred by complete tool session
+ * progress from tool. Therefore, the transaction demarcation needs to be
+ * configured as REQURIED
.
+ *
+ *
+ * @param learner the learner who are running this activity in the design.
+ * @param activity the activity is being runned.
+ * @param lesson the lesson this learner is currently in.
+ * @return the url for next activity.
+ */
+ public String completelActivity(User learner,Activity activity,Lesson lesson);
+
+ /**
* Retrieve all lessons that has been started, suspended or finished. All
* finished but archived lesson should not be loaded.
*
@@ -146,4 +162,6 @@
* @param learner the learner needs to be grouped
*/
public void performGrouping(GroupingActivity groupingActivity, User learner);
+
+
}
Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java
===================================================================
diff -u -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb -r1ac030743cfd5c1a1479311197a02821dbc85cbc
--- lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb)
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 1ac030743cfd5c1a1479311197a02821dbc85cbc)
@@ -279,7 +279,6 @@
}
/**
- *
* @see org.lamsfoundation.lams.learning.service.ILearnerService#completeToolSession(long, User)
*/
public String completeToolSession(Long toolSessionId, User learner)
@@ -290,10 +289,19 @@
toolSession.setToolSessionStateId(ToolSession.ENDED_STATE);
lamsCoreToolService.updateToolSession(toolSession);
+
+ return completelActivity(learner, toolSession.getToolActivity(), toolSession.getLesson());
+ }
+
+ /**
+ * @see org.lamsfoundation.lams.learning.service.ILearnerService#completelActivity(org.lamsfoundation.lams.usermanagement.User, org.lamsfoundation.lams.learningdesign.Activity, org.lamsfoundation.lams.lesson.Lesson)
+ */
+ public String completelActivity(User learner,Activity activity,Lesson lesson)
+ {
//build up the url for next activity.
try
{
- LearnerProgress nextLearnerProgress = calculateProgress(toolSession.getToolActivity(), learner, toolSession.getLesson());
+ LearnerProgress nextLearnerProgress = calculateProgress(activity, learner,lesson);
return activityMapping.getProgressURL(nextLearnerProgress);
}
catch (UnsupportedEncodingException e)
Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GroupingAction.java
===================================================================
diff -u -r00814b62109df12f6079c1e88f964e3f12674fbb -r1ac030743cfd5c1a1479311197a02821dbc85cbc
--- lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GroupingAction.java (.../GroupingAction.java) (revision 00814b62109df12f6079c1e88f964e3f12674fbb)
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/action/GroupingAction.java (.../GroupingAction.java) (revision 1ac030743cfd5c1a1479311197a02821dbc85cbc)
@@ -42,6 +42,8 @@
import org.lamsfoundation.lams.learningdesign.Activity;
import org.lamsfoundation.lams.learningdesign.GroupingActivity;
import org.lamsfoundation.lams.lesson.LearnerProgress;
+import org.lamsfoundation.lams.lesson.Lesson;
+import org.lamsfoundation.lams.usermanagement.User;
import org.lamsfoundation.lams.web.action.LamsDispatchAction;
@@ -123,6 +125,10 @@
currentLearners);
request.setAttribute(ActivityAction.ACTIVITY_REQUEST_ATTRIBUTE,learnerProgress.getNextActivity());
+ request.getSession().setAttribute(LearningWebUtil.ATTR_USER_DATA,
+ learnerProgress.getUser());
+ request.getSession().setAttribute(LearningWebUtil.ATTR_LESSON_DATA,
+ learnerProgress.getLesson());
return mapping.findForward(VIEW_GROUPING);
}
@@ -146,16 +152,56 @@
{
//initialize service object
ILearnerService learnerService = LearnerServiceProxy.getLearnerService(getServlet().getServletContext());
-
+ //get current user and lesson data via http. It ensures they are availabe
+ //in the http session. If not, we assume parameters are coming from
+ //request or falsh and we can create learner and lesson objects.
+ User learner = LearningWebUtil.getUserData(request,getServlet().getServletContext());
+ Lesson lesson = LearningWebUtil.getLessonData(request,getServlet().getServletContext());
+
Activity groupingActivity = LearningWebUtil.getActivityFromRequest(request,learnerService);
List groups = new ArrayList(((GroupingActivity)groupingActivity).getCreateGrouping()
.getGroups());
request.getSession().setAttribute(GROUPS,groups);
+ request.setAttribute(LearningWebUtil.PARAM_ACTIVITY_ID,
+ groupingActivity.getActivityId());
return mapping.findForward(SHOW_GROUP);
}
+ /**
+ * Complete the current tool activity and forward to the url of next activity
+ * in the learning design.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws IOException
+ * @throws ServletException
+ */
+ public ActionForward completeActivity(ActionMapping mapping,
+ ActionForm form,
+ HttpServletRequest request,
+ HttpServletResponse response) throws IOException,
+ ServletException
+ {
+ LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgressByUser(request,
+ getServlet().getServletContext());
+ //initialize service object
+ ILearnerService learnerService = LearnerServiceProxy.getLearnerService(getServlet().getServletContext());
+ Activity groupingActivity = LearningWebUtil.getActivityFromRequest(request,learnerService);
+
+
+ String nextActivityUrl = learnerService.completelActivity(learnerProgress.getUser(),
+ groupingActivity,
+ learnerProgress.getLesson());
+
+ response.sendRedirect(nextActivityUrl);
+
+ return null;
+ }
//---------------------------------------------------------------------
// Helper method
//---------------------------------------------------------------------
Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/CustomizedOpenSessionInViewFilter.java
===================================================================
diff -u
--- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/CustomizedOpenSessionInViewFilter.java (revision 0)
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/CustomizedOpenSessionInViewFilter.java (revision 1ac030743cfd5c1a1479311197a02821dbc85cbc)
@@ -0,0 +1,79 @@
+/***************************************************************************
+ * 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.learning.web.util;
+
+import net.sf.hibernate.FlushMode;
+import net.sf.hibernate.Session;
+import net.sf.hibernate.SessionFactory;
+
+import org.springframework.dao.DataAccessResourceFailureException;
+import org.springframework.orm.hibernate.SessionFactoryUtils;
+import org.springframework.orm.hibernate.support.OpenSessionInViewFilter;
+
+
+/**
+ *
+ * @author Jacky Fang
+ * @since 2005-4-4
+ * @version
+ *
+ */
+public class CustomizedOpenSessionInViewFilter extends OpenSessionInViewFilter
+{
+
+ /**
+ * Get a Session for the SessionFactory that this filter uses.
+ * Note that this just applies in single session mode!
+ *
The default implementation delegates to SessionFactoryUtils' + * getSession method and sets the Session's flushMode to NEVER. + *
Can be overridden in subclasses for creating a Session with a custom + * entity interceptor or JDBC exception translator. + * @param sessionFactory the SessionFactory that this filter uses + * @return the Session to use + * @throws DataAccessResourceFailureException if the Session could not be created + * @see org.springframework.orm.hibernate.SessionFactoryUtils#getSession(SessionFactory, boolean) + * @see net.sf.hibernate.FlushMode#NEVER + */ + protected Session getSession(SessionFactory sessionFactory) + throws DataAccessResourceFailureException { + Session session = SessionFactoryUtils.getSession(sessionFactory, true); + session.setFlushMode(FlushMode.AUTO); + return session; + } + + /** + * Close the given Session. + * Note that this just applies in single session mode! + *
The default implementation delegates to SessionFactoryUtils' + * closeSessionIfNecessary method. + *
Can be overridden in subclasses, e.g. for flushing the Session before
+ * closing it. See class-level javadoc for a discussion of flush handling.
+ * Note that you should also override getSession accordingly, to set
+ * the flush mode to something else than NEVER.
+ * @param session the Session used for filtering
+ * @param sessionFactory the SessionFactory that this filter uses
+ */
+ protected void closeSession(Session session, SessionFactory sessionFactory) {
+ SessionFactoryUtils.closeSessionIfNecessary(session, sessionFactory);
+ }
+}
Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LessonLearnerDataManager.java
===================================================================
diff -u -r06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb -r1ac030743cfd5c1a1479311197a02821dbc85cbc
--- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LessonLearnerDataManager.java (.../LessonLearnerDataManager.java) (revision 06dd563d92f6e9e88c76b708f5d9aeb3a61d4dcb)
+++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LessonLearnerDataManager.java (.../LessonLearnerDataManager.java) (revision 1ac030743cfd5c1a1479311197a02821dbc85cbc)
@@ -55,10 +55,10 @@
/**
- *
- * @param context
- * @param lesson
- * @param learner
+ * Cache the user who are running the lesson into the hashmap.
+ * @param context the context of the servlet container.
+ * @param lesson the running lesson.
+ * @param learner the learner who is participating the lesson.
*/
public static void cacheLessonUser(ServletContext context,
Lesson lesson,
@@ -82,10 +82,10 @@
}
/**
- *
- * @param context
- * @param lesson
- * @param learner
+ * Remove the user cache from the hashmap if the learner exit the lesson.
+ * @param context the context of the servlet container.
+ * @param lesson the running lesson.
+ * @param learner the learner who is exitting the lesson.
*/
public static void removeLessonUserFromCache(ServletContext context,
Lesson lesson,
@@ -109,9 +109,10 @@
}
/**
- *
- * @param context
- * @param lessonId
+ * Return all the learners who are doing the requested lesson at the moment.
+ * @param context the context of the servlet container.
+ * @param lessonId the requested lesson.
+ * @param learnerService the learner service object.
*/
public static List getAllLessonLearners(ServletContext context,
long lessonId,
@@ -136,13 +137,12 @@
return lessonUsers;
}
-
/**
- *
- * @param learnerService
- * @param lessonId
- * @param context
- * @return
+ * Restore hashmap by querying active learners from database.
+ * @param learnerService the learner service object.
+ * @param lessonId the requested lesson.
+ * @param context the context of the servlet container.
+ * @return the restored hashmap cache.
*/
private static HashMap restoreMapFromDatabase(ILearnerService learnerService,
long lessonId,
@@ -161,6 +161,5 @@
return learnersMap;
}
-
}
Index: lams_learning/test/java/org/lamsfoundation/lams/learning/web/action/TestGroupingAction.java
===================================================================
diff -u -r00814b62109df12f6079c1e88f964e3f12674fbb -r1ac030743cfd5c1a1479311197a02821dbc85cbc
--- lams_learning/test/java/org/lamsfoundation/lams/learning/web/action/TestGroupingAction.java (.../TestGroupingAction.java) (revision 00814b62109df12f6079c1e88f964e3f12674fbb)
+++ lams_learning/test/java/org/lamsfoundation/lams/learning/web/action/TestGroupingAction.java (.../TestGroupingAction.java) (revision 1ac030743cfd5c1a1479311197a02821dbc85cbc)
@@ -119,6 +119,8 @@
public void testViewGrouping()
{
addRequestParameter("method", "viewGrouping");
+ addRequestParameter(LearningWebUtil.PARAM_USER_ID, TEST_LEARNER_ID);
+ addRequestParameter(LearningWebUtil.PARAM_LESSON_ID, TEST_LESSON_ID);
request.setAttribute(ActivityAction.ACTIVITY_REQUEST_ATTRIBUTE,groupingActivity);
actionPerform();
@@ -131,6 +133,17 @@
assertEquals("verify number of groups",2,groups.size());
}
+ public void testCompleteActivity()
+ {
+ addRequestParameter("method", "completeActivity");
+ addRequestParameter(LearningWebUtil.PARAM_USER_ID, TEST_LEARNER_ID);
+ addRequestParameter(LearningWebUtil.PARAM_LESSON_ID, TEST_LESSON_ID);
+ request.setAttribute(ActivityAction.ACTIVITY_REQUEST_ATTRIBUTE,groupingActivity);
+
+ actionPerform();
+
+ verifyNoActionErrors();
+ }
/**
*
*/
Index: lams_learning/test/web/WEB-INF/spring/applicationContext.xml
===================================================================
diff -u -rccf8e0ceeba756591580b17142823a8eba4d773c -r1ac030743cfd5c1a1479311197a02821dbc85cbc
--- lams_learning/test/web/WEB-INF/spring/applicationContext.xml (.../applicationContext.xml) (revision ccf8e0ceeba756591580b17142823a8eba4d773c)
+++ lams_learning/test/web/WEB-INF/spring/applicationContext.xml (.../applicationContext.xml) (revision 1ac030743cfd5c1a1479311197a02821dbc85cbc)
@@ -112,7 +112,6 @@