Index: lams_learning/lib/hibernate/hibernate2.jar =================================================================== diff -u -r29932d4b94bba030634340a4e4548626d1a694f7 -r0e9942a1cb3517b16f9cf75267fbea94371b621f Binary files differ Index: lams_learning/lib/jfreechart/gnujaxp.jar =================================================================== diff -u -r29932d4b94bba030634340a4e4548626d1a694f7 -r0e9942a1cb3517b16f9cf75267fbea94371b621f Binary files differ Index: lams_learning/lib/jfreechart/jcommon-0.9.6.jar =================================================================== diff -u -r29932d4b94bba030634340a4e4548626d1a694f7 -r0e9942a1cb3517b16f9cf75267fbea94371b621f Binary files differ Index: lams_learning/lib/jfreechart/jfreechart-0.9.21.jar =================================================================== diff -u -r29932d4b94bba030634340a4e4548626d1a694f7 -r0e9942a1cb3517b16f9cf75267fbea94371b621f Binary files differ Index: lams_learning/lib/lams/lams.jar =================================================================== diff -u -r11c5be112ae49dc43d2bd32e7d9556921a0cff64 -r0e9942a1cb3517b16f9cf75267fbea94371b621f Binary files differ Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java =================================================================== diff -u -r11c5be112ae49dc43d2bd32e7d9556921a0cff64 -r0e9942a1cb3517b16f9cf75267fbea94371b621f --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 11c5be112ae49dc43d2bd32e7d9556921a0cff64) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 0e9942a1cb3517b16f9cf75267fbea94371b621f) @@ -56,7 +56,7 @@ private ProgressEngine progressEngine; private IToolSessionDAO toolSessionDAO; - private ActionMappings actionMappings; + private ActionMappings actionMappings; //--------------------------------------------------------------------- // Inversion of Control Methods - Constructor injection //--------------------------------------------------------------------- @@ -122,7 +122,7 @@ { LearnerProgress learnerProgress = learnerProgressDAO.getLearnerProgressByLearner(learner,lesson); - if(learnerProgress!=null) + if(learnerProgress==null) { //create a new learner progress for new learner learnerProgress = new LearnerProgress(learner,lesson); @@ -137,7 +137,70 @@ } + /** + * 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 learnerProgressDAO.getLearnerProgressByLearner(learner, lesson); + } + + + public LearnerProgress chooseActivity(User learner, Lesson lesson, Activity activity) { + LearnerProgress progress = learnerProgressDAO.getLearnerProgressByLearner(learner, lesson); + progress.setProgressState(activity, LearnerProgress.ACTIVITY_ATTEMPTED); + learnerProgressDAO.saveLearnerProgress(progress); + return progress; + } + + + /** + * 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(Activity completedActivity, User learner, Lesson lesson) throws ProgressException + { + return progressEngine.calculateProgress(learner, lesson, completedActivity); + } + + + public String completeToolActivity(long toolSessionId) { + // get learner, lesson and activity using toolSessionId + User learner = null; + Lesson lesson = null; + Activity activity = null; + + String url = null; + try { + LearnerProgress nextLearnerProgress = calculateProgress(activity, learner, lesson); + Activity nextActivity = nextLearnerProgress.getNextActivity(); + url = actionMappings.getActivityURL(nextActivity, nextLearnerProgress); + } + catch (ProgressException e) { + // log e + throw new LearnerServiceException(e.getMessage()); + } + + return url; + } + + public void setActionMappings(ActionMappings actionMappings) { + this.actionMappings = actionMappings; + } + + //--------------------------------------------------------------------- + // Helper Methods + //--------------------------------------------------------------------- + /** * This method navigate through all the tool activities included inside * the next activity. For each tool activity, we look up the database * to check up the existance of correspondent tool session. If the tool @@ -200,63 +263,4 @@ toolSessionDAO.saveToolSession(toolSession); } - /** - * 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 learnerProgressDAO.getLearnerProgressByLearner(learner, lesson); - } - - - public LearnerProgress chooseActivity(User learner, Lesson lesson, Activity activity) { - LearnerProgress progress = learnerProgressDAO.getLearnerProgressByLearner(learner, lesson); - progress.setProgressState(activity, LearnerProgress.ACTIVITY_ATTEMPTED); - learnerProgressDAO.saveLearnerProgress(progress); - return progress; - } - - - /** - * 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(Activity completedActivity, User learner, Lesson lesson) throws ProgressException - { - return progressEngine.calculateProgress(learner, lesson, completedActivity); - } - - - public String completeToolActivity(long toolSessionId) { - // get learner, lesson and activity using toolSessionId - User learner = null; - Lesson lesson = null; - Activity activity = null; - - String url = null; - try { - LearnerProgress nextLearnerProgress = calculateProgress(activity, learner, lesson); - Activity nextActivity = nextLearnerProgress.getNextActivity(); - url = actionMappings.getActivityURL(nextActivity, nextLearnerProgress); - } - catch (ProgressException e) { - // log e - throw new LearnerServiceException(e.getMessage()); - } - - return url; - } - - public void setActionMappings(ActionMappings actionMappings) { - this.actionMappings = actionMappings; - } - } Index: lams_learning/test/java/log4j.properties =================================================================== diff -u --- lams_learning/test/java/log4j.properties (revision 0) +++ lams_learning/test/java/log4j.properties (revision 0e9942a1cb3517b16f9cf75267fbea94371b621f) @@ -0,0 +1,4 @@ +log4j.rootLogger=INFO,stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %5p (%F:%L) - %m%n \ No newline at end of file Index: lams_learning/test/java/org/lamsfoundation/lams/learning/service/TestLearnerService.java =================================================================== diff -u -r11c5be112ae49dc43d2bd32e7d9556921a0cff64 -r0e9942a1cb3517b16f9cf75267fbea94371b621f --- lams_learning/test/java/org/lamsfoundation/lams/learning/service/TestLearnerService.java (.../TestLearnerService.java) (revision 11c5be112ae49dc43d2bd32e7d9556921a0cff64) +++ lams_learning/test/java/org/lamsfoundation/lams/learning/service/TestLearnerService.java (.../TestLearnerService.java) (revision 0e9942a1cb3517b16f9cf75267fbea94371b621f) @@ -22,20 +22,46 @@ import org.lamsfoundation.lams.AbstractLamsTestCase; +import org.lamsfoundation.lams.learning.progress.ProgressException; +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.lesson.dao.ILessonDAO; +import org.lamsfoundation.lams.lesson.dao.hibernate.LessonDAO; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; + + /** * * @author Jacky Fang 2005-2-22 * */ public class TestLearnerService extends AbstractLamsTestCase { - + private ILearnerService learnerService; + private IUserManagementService usermanageService; + private ILessonDAO lessonDao; + //--------------------------------------------------------------------- + // Testing Data - Constants + //--------------------------------------------------------------------- + private final Integer TEST_USER_ID = new Integer(1); + private final Long Test_Lesson_ID = new Long(1); + //--------------------------------------------------------------------- + // Testing Data - Instance Variables + //--------------------------------------------------------------------- + private User testUser; + private Lesson testLesson; /* * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); + learnerService = (ILearnerService)this.context.getBean("learnerService"); + usermanageService = (IUserManagementService)this.context.getBean("userManagementService"); + lessonDao = (LessonDAO)this.context.getBean("lessonDAO"); + + testUser = usermanageService.getUserById(TEST_USER_ID); + testLesson = lessonDao.getLesson(Test_Lesson_ID); } /* @@ -57,10 +83,14 @@ protected String[] getContextConfigLocation() { return new String[] { "/WEB-INF/spring/learningApplicationContext.xml", - "/WEB-INF/spring/applicationContext.xml"}; + "/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml", + "/org/lamsfoundation/lams/tool/toolApplicationContext.xml", + "applicationContext.xml"}; } - public void testJoinLesson() + public void testJoinLesson() throws ProgressException { + learnerService.joinLesson(testUser,testLesson); + assertTrue(true); } }