Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/Lesson.hbm.xml =================================================================== diff -u -r077455f6c7ce0f7784a308cc66bb62969cf2c68f -rb5558c94121cc60c92ac1e2087110477380602d2 --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/Lesson.hbm.xml (.../Lesson.hbm.xml) (revision 077455f6c7ce0f7784a308cc66bb62969cf2c68f) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/Lesson.hbm.xml (.../Lesson.hbm.xml) (revision b5558c94121cc60c92ac1e2087110477380602d2) @@ -24,10 +24,15 @@ + + + + - @@ -58,13 +63,14 @@ + not-null="false"> Index: lams_common/src/java/org/lamsfoundation/lams/lesson/Lesson.java =================================================================== diff -u -rc44482d534e42cdecb0eefd678fad9cc5d8eb137 -rb5558c94121cc60c92ac1e2087110477380602d2 --- lams_common/src/java/org/lamsfoundation/lams/lesson/Lesson.java (.../Lesson.java) (revision c44482d534e42cdecb0eefd678fad9cc5d8eb137) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/Lesson.java (.../Lesson.java) (revision b5558c94121cc60c92ac1e2087110477380602d2) @@ -107,18 +107,30 @@ /** default constructor */ public Lesson() { } + + /** + * Minimum constructor that initialize the lesson data. It doesn't include + * organization and class information. + * Cain constructor pattern implementation. + */ + public Lesson(Date createDateTime, User user, Integer lessonStateId, LearningDesign learningDesign,Set learnerProgresses) + { + this(null,createDateTime,null,null,user,lessonStateId,learningDesign,null,null,learnerProgresses); + } + /** - * Minimum constructor that includes all not null attributes to create - * a new Lesson object. + * Constructor that creates a new lesson with organization and class + * information. * Chain construtor pattern implementation. */ - public Lesson(Date createDateTime, User user, Integer lessonStateId, LearningDesign learningDesign, LessonClass lessonClass, Organisation organisation, Set learnerProgresses) { - + public Lesson(Date createDateTime, User user, Integer lessonStateId, LearningDesign learningDesign, LessonClass lessonClass, Organisation organisation, Set learnerProgresses) + { this(null,createDateTime,null,null,user,lessonStateId,learningDesign,lessonClass,organisation,learnerProgresses); } /** full constructor */ - public Lesson(Long lessonId, Date createDateTime, Date startDateTime, Date endDateTime, User user, Integer lessonStateId, LearningDesign learningDesign, LessonClass lessonClass, Organisation organisation, Set learnerProgresses) { + public Lesson(Long lessonId, Date createDateTime, Date startDateTime, Date endDateTime, User user, Integer lessonStateId, LearningDesign learningDesign, LessonClass lessonClass, Organisation organisation, Set learnerProgresses) + { this.lessonId = lessonId; this.createDateTime = createDateTime; this.startDateTime = startDateTime; @@ -132,8 +144,8 @@ } /** * Factory method that create a new lesson. It initialized all necessary - * data for a new lesson. It is design for monitor side to create a lesson - * by teacher. + * data for a new lesson with organization and lesson class information. + * It is designed for monitor side to create a lesson by teacher. * * @param user the teacher who created this lesson * @param organisation the organisation associated with this lesson. @@ -156,6 +168,24 @@ new HashSet());//learner progress } + /** + * Factory method that create a new lesson with lesson class and organization. + * It is design to allow user create a lesson first and modify organization + * and lesson class data later. + * + * @param user the user who want to create a lesson. + * @param ld the learning design that this lesson is based on. + * @return the lesson created. + */ + public static Lesson createNewLessonWithoutClass(User user, + LearningDesign ld) + { + return new Lesson(new Date(System.currentTimeMillis()), + user, + Lesson.CREATED, + ld, + new HashSet()); + } //--------------------------------------------------------------------- // Getters and Setters //--------------------------------------------------------------------- @@ -208,7 +238,7 @@ } /** - * @hibernate.property type="java.sql.Timestamp" column="end_date_time" + * @hibernate.property type="java.sql.Timestamp" column="schedule_end_date_time" * length="19" * * @return Returns the scheduleEndDate. @@ -225,6 +255,8 @@ this.scheduleEndDate = scheduleEndDate; } /** + * @hibernate.property type="java.sql.Timestamp" column="schedule_start_date_time" + * length="19" * @return Returns the scheduleStartDate. */ public Date getScheduleStartDate() @@ -275,7 +307,7 @@ } /** - * @hibernate.many-to-one not-null="true" unique="true" + * @hibernate.many-to-one not-null="false" unique="true" * cascade = "save-update" * @hibernate.column name="learning_design_id" */ @@ -288,7 +320,7 @@ } /** - * @hibernate.many-to-one not-null="true" cascade="none" + * @hibernate.many-to-one not-null="false" cascade="none" * @hibernate.column name="organisation_id" */ public Organisation getOrganisation() { Index: lams_common/test/java/org/lamsfoundation/lams/lesson/dao/TestLessonDAO.java =================================================================== diff -u -rcf9eef0a9571555782d02258c6ba8c996865c5ca -rb5558c94121cc60c92ac1e2087110477380602d2 --- lams_common/test/java/org/lamsfoundation/lams/lesson/dao/TestLessonDAO.java (.../TestLessonDAO.java) (revision cf9eef0a9571555782d02258c6ba8c996865c5ca) +++ lams_common/test/java/org/lamsfoundation/lams/lesson/dao/TestLessonDAO.java (.../TestLessonDAO.java) (revision b5558c94121cc60c92ac1e2087110477380602d2) @@ -9,6 +9,7 @@ package org.lamsfoundation.lams.lesson.dao; +import java.util.Date; import java.util.List; import org.lamsfoundation.lams.lesson.Lesson; @@ -75,16 +76,18 @@ public void testUpdateLesson() { Lesson createdLesson = this.lessonDao.getLesson(this.testLesson.getLessonId()); - assertEquals("should be created state now",Lesson.CREATED,createdLesson.getLessonStateId()); - createdLesson.setLessonStateId(Lesson.STARTED_STATE); + assertNull("ensure we are testing right lesson",createdLesson.getScheduleEndDate()); + createdLesson.setLessonStateId(Lesson.STARTED_STATE); + createdLesson.setScheduleEndDate(new Date(System.currentTimeMillis()+60)); lessonDao.updateLesson(createdLesson); Lesson updatedLesson = lessonDao.getLesson(testLesson.getLessonId()); assertEquals("verify the updated lesson state",Lesson.STARTED_STATE,updatedLesson.getLessonStateId()); - + assertNotNull("verify the sechdule end date",updatedLesson.getScheduleEndDate()); + List lessons = this.lessonDao.getActiveLessonsForLearner(this.testUser); assertEquals("verify the number of lesson we get",1,lessons.size());