Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -r8482164570cc9e8db87a1419dc6944c58553b327 -r62b97a5e0fd88110e023f00793a983713296f9b6 Binary files differ Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILearnerProgressDAO.java =================================================================== diff -u -r9357467901bacb28df24a695ec35e99434ebbea9 -r62b97a5e0fd88110e023f00793a983713296f9b6 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILearnerProgressDAO.java (.../ILearnerProgressDAO.java) (revision 9357467901bacb28df24a695ec35e99434ebbea9) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILearnerProgressDAO.java (.../ILearnerProgressDAO.java) (revision 62b97a5e0fd88110e023f00793a983713296f9b6) @@ -54,7 +54,7 @@ * the lesson for which the progress data applies * @return the user's progress data */ - LearnerProgress getLearnerProgressByLearner(final Integer learnerId, final Long lessonId); + LearnerProgress getLearnerProgressByLearner(Integer learnerId, Long lessonId); /** * Saves or Updates learner progress data. @@ -84,40 +84,56 @@ * @param activity * @return List */ - List getLearnerProgressReferringToActivity(final Activity activity); + List getLearnerProgressReferringToActivity(Activity activity); /** + * Get learners who most recently entered the activity. + */ + List getLearnersLatestByActivity(Long activityId, Integer limit, Integer offset); + + /** + * Get learners who are at the given activities at the moment. + */ + List getLearnersByActivities(Long[] activityIds, Integer limit, Integer offset); + + /** + * Get learners who most recently finished the lesson. + */ + List getLearnersLatestCompletedForLesson(Long lessonId, Integer limit, Integer offset); + + /** * Get all the learner progress records for a lesson where the progress is marked as completed. * * @param lessonId * @return List */ - List getCompletedLearnerProgressForLesson(final Long lessonId); - + List getCompletedLearnerProgressForLesson(Long lessonId); + /** * Get all the learner progress records for a lesson. * * @param lessonId * @return */ - List getLearnerProgressForLesson(final Long lessonId); - + List getLearnerProgressForLesson(Long lessonId); + /** * Get all the learner progress records for a lesson restricted by list of these user ids. * * @param lessonId - * @param userIds return progresses for only these users + * @param userIds + * return progresses for only these users * @return */ - List getLearnerProgressForLesson(final Long lessonId, final List userIds); - + List getLearnerProgressForLesson(Long lessonId, List userIds); + /** * Get all the learner progresses for a lesson list. * * @param lessonIds * @return */ - List getLearnerProgressForLessons(final List lessonIds); + List getLearnerProgressForLessons(List lessonIds); /** * Get all the users records where the user has attempted the given activity. Uses the progress records to determine @@ -126,25 +142,16 @@ * @param activityId * @return List */ - List getLearnersHaveAttemptedActivity(final Activity activity); + List getLearnersHaveAttemptedActivity(Activity activity); /** - * Get all the users records where the user has completed the given activity. Uses the progress records to determine - * the users. - * - * @param activityId - * @return List - */ - List getLearnersHaveCompletedActivity(final Activity activity); - - /** * Count of the number of users that have attempted or completed an activity. Useful for activities that don't have * tool sessions. * * @param activityId * @return List */ - Integer getNumUsersAttemptedActivity(final Activity activity); + Integer getNumUsersAttemptedActivity(Activity activity); /** * Count of the number of users that have completed an activity. Useful for activities that don't have tool @@ -153,24 +160,15 @@ * @param activityId * @return List */ - Integer getNumUsersCompletedActivity(final Activity activity); + Integer getNumUsersCompletedActivity(Activity activity); /** - * Get the count of all learner progress records for an lesson without loading the records. - * - * @return Number of learner progress records for this lesson + * Get number of learners who finished the given lesson. */ - Integer getNumAllLearnerProgress(final Long lessonId); + Integer getNumUsersCompletedLesson(Long lessonId); /** - * Get a batch of learner progress records (size batchSize) for an lesson, sorted by surname and the first name. - * Start at the beginning of the table if no previousUserId is given, otherwise get the batch after lastUserId. - * - * @param lessonId - * @param lastUserId - * @param batchSize - * @return List + * Get number of learners who are at the given activity at the moment. */ - List getBatchLearnerProgress(final Long lessonId, final User lastUser, final int batchSize); - + Integer getNumUsersCurrentActivity(Activity activity); } Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILessonDAO.java =================================================================== diff -u -r4020e48e252d3a5a9ace181e62bb78900f05128b -r62b97a5e0fd88110e023f00793a983713296f9b6 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILessonDAO.java (.../ILessonDAO.java) (revision 4020e48e252d3a5a9ace181e62bb78900f05128b) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILessonDAO.java (.../ILessonDAO.java) (revision 62b97a5e0fd88110e023f00793a983713296f9b6) @@ -28,7 +28,6 @@ import org.lamsfoundation.lams.dao.IBaseDAO; import org.lamsfoundation.lams.lesson.Lesson; -import org.lamsfoundation.lams.lesson.dto.LessonDetailsDTO; import org.lamsfoundation.lams.usermanagement.User; /** @@ -42,7 +41,7 @@ * Retrieves the Lesson * * @param lessonId - * identifies the lesson to get + * identifies the lesson to get * @return the lesson */ public Lesson getLesson(Long lessonId); @@ -56,7 +55,7 @@ * Gets all lessons that are active for a learner. TODO to be removed when the dummy interface is no longer needed * * @param learner - * a User that identifies the learner. + * a User that identifies the learner. * @return a Set with all active lessons in it. */ public List getActiveLessonsForLearner(User learner); @@ -65,26 +64,26 @@ * Gets all lessons that are active for a learner, in a given organisation * * @param learnerId - * a User that identifies the learner. + * a User that identifies the learner. * @param organisationId - * the desired organisation . + * the desired organisation . * @return a List with all active lessons in it. */ - public List getActiveLessonsForLearner(final Integer learnerId, final Integer organisationID); + public List getActiveLessonsForLearner(Integer learnerId, Integer organisationID); /** * Saves or Updates a Lesson. * * @param lesson - * the Lesson to save + * the Lesson to save */ public void saveLesson(Lesson lesson); /** * Deletes a Lesson permanently. * * @param lesson - * the Lesson to remove. + * the Lesson to remove. */ public void deleteLesson(Lesson lesson); @@ -100,7 +99,7 @@ * lessons. * * @param userID - * The user_id of the user + * The user_id of the user * @return List The list of Lessons for the given user */ public List getLessonsCreatedByUser(Integer userID); @@ -110,101 +109,112 @@ * lessons or preview lessons. This is the list of lessons that a user may monitor/moderate/manage. * * @param user - * a User that identifies the teacher/staff member. + * a User that identifies the teacher/staff member. * @return a List with all appropriate lessons in it. */ - public List getLessonsForMonitoring(final int userID, final int organisationID); + public List getLessonsForMonitoring(int userID, int organisationID); /** * Returns the all the learners that have started the requested lesson. * * @param lessonId - * the id of the requested lesson. + * the id of the requested lesson. * @return the list of learners. */ - public List getActiveLearnerByLesson(final long lessonId); + public List getActiveLearnerByLesson(long lessonId); /** * Returns the all the learners that have started the requested lesson and are in the given group. * * @param lessonId - * the id of the requested lesson. + * the id of the requested lesson. * @param groupId - * the id of the requested group. + * the id of the requested group. * @return the list of learners. */ - public List getActiveLearnerByLessonAndGroup(final long lessonId, final long groupId); + public List getActiveLearnerByLessonAndGroup(long lessonId, long groupId); /** * Returns the count of all the learners that have started the requested lesson. * * @param lessonId - * the id of the requested lesson. + * the id of the requested lesson. * @return the count of the learners. */ - public Integer getCountActiveLearnerByLesson(final long lessonId); + public Integer getCountActiveLearnerByLesson(long lessonId); /** + * Returns the count of all the learners that are a part of the lesson class. + */ + public Integer getCountLearnerByLesson(long lessonId); + + /** * Get all the preview lessons more with the creation date before the given date. * * @param startDate - * UTC date + * UTC date * @return the list of Lessons */ - public List getPreviewLessonsBeforeDate(final Date startDate); + public List getPreviewLessonsBeforeDate(Date startDate); /** * Get the lesson that applies to this activity. Not all activities have an attached lesson. */ - public Lesson getLessonForActivity(final long activityId); + public Lesson getLessonForActivity(long activityId); /** - * Gets all non-removed lessons for a user in an org; set userRole parameter to learner if you want lessons where user is in the - * learner list, or to monitor if in the staff list. + * Gets all non-removed lessons for a user in an org; set userRole parameter to learner if you want lessons where + * user is in the learner list, or to monitor if in the staff list. * - * @param userId a user id that identifies the user. - * @param orgId an org id that identifies the organisation. - * @param userRole return lessons where user is learner or monitor. or returns all lessons in case of group manager + * @param userId + * a user id that identifies the user. + * @param orgId + * an org id that identifies the organisation. + * @param userRole + * return lessons where user is learner or monitor. or returns all lessons in case of group manager * * @return a List containing a list of tuples containing lesson details and the lesson completed flag for the user. */ - public List getLessonsByOrgAndUserWithCompletedFlag(final Integer userId, final Integer orgId, final Integer userRole); - + public List getLessonsByOrgAndUserWithCompletedFlag(Integer userId, Integer orgId, + Integer userRole); + /** - * Gets all non-removed lessons for a user in a group including sub-groups + * Gets all non-removed lessons for a user in a group including sub-groups * - * @param userId a user id that identifies the user. - * @param orgId an org id that identifies the organisation. + * @param userId + * a user id that identifies the user. + * @param orgId + * an org id that identifies the organisation. * @return a List containing a list of tuples containing lesson details and the lesson completed flag for the user. */ - public List getLessonsByGroupAndUser(final Integer userId, final Integer orgId); + public List getLessonsByGroupAndUser(Integer userId, Integer orgId); /** * Gets all non-removed lessons for a group. * * @param orgId * @return */ - public List getLessonsByGroup(final Integer orgId); - + public List getLessonsByGroup(Integer orgId); + /** * Get lessons based on learning designs where the original learning design has the given id. * * @param ldId * @param orgId * @return list of lessons */ - public List getLessonsByOriginalLearningDesign(final Long ldId, final Integer orgId); + public List getLessonsByOriginalLearningDesign(Long ldId, Integer orgId); /** * Finds out which lesson the given tool content belongs to and returns its monitoring users. * * @param sessionId - * tool session ID + * tool session ID * @return list of teachers that monitor the lesson which contains the tool with given session ID */ public List getMonitorsByToolSessionId(Long sessionId); - + /** * Gets lesson for tools based on toolSessionID * Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LearnerProgressDAO.java =================================================================== diff -u -r9357467901bacb28df24a695ec35e99434ebbea9 -r62b97a5e0fd88110e023f00793a983713296f9b6 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LearnerProgressDAO.java (.../LearnerProgressDAO.java) (revision 9357467901bacb28df24a695ec35e99434ebbea9) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LearnerProgressDAO.java (.../LearnerProgressDAO.java) (revision 62b97a5e0fd88110e023f00793a983713296f9b6) @@ -23,9 +23,12 @@ /* $$Id$$ */ package org.lamsfoundation.lams.lesson.dao.hibernate; +import java.math.BigInteger; +import java.util.LinkedList; import java.util.List; import org.apache.log4j.Logger; +import org.hibernate.Query; import org.lamsfoundation.lams.dao.hibernate.LAMSBaseDAO; import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.lesson.LearnerProgress; @@ -44,144 +47,191 @@ protected Logger log = Logger.getLogger(LearnerProgressDAO.class); private final static String LOAD_PROGRESS_BY_LEARNER = "from LearnerProgress p where p.user.id = :learnerId and p.lesson.id = :lessonId"; - private final static String LOAD_PROGRESS_BY_ACTIVITY = "from LearnerProgress p where p.previousActivity = :activity or p.currentActivity = :activity or p.nextActivity = :activity "; - // + - // "or activity in elements(p.previousActivity) or activity in elements(p.completedActivities)"; + + private final static String LOAD_PROGRESS_REFFERING_TO_ACTIVITY = "from LearnerProgress p where p.previousActivity = :activity or p.currentActivity = :activity or p.nextActivity = :activity "; + private final static String LOAD_COMPLETED_PROGRESS_BY_LESSON = "from LearnerProgress p where p.lessonComplete > 0 and p.lesson.id = :lessonId"; + private final static String LOAD_LEARNERS_LATEST_COMPLETED_BY_LESSON = "SELECT p.user FROM LearnerProgress p WHERE " + + "p.lessonComplete > 0 and p.lesson.id = :lessonId ORDER BY p.finishDate DESC"; + + private final static String COUNT_COMPLETED_PROGRESS_BY_LESSON = "select count(*) from LearnerProgress p " + + " where p.lessonComplete > 0 and p.lesson.id = :lessonId"; + private final static String COUNT_ATTEMPTED_ACTIVITY = "select count(*) from LearnerProgress prog, " + " Activity act join prog.attemptedActivities attAct " + " where act.id = :activityId and " + " index(attAct) = act"; private final static String COUNT_COMPLETED_ACTIVITY = "select count(*) from LearnerProgress prog, " + " Activity act join prog.completedActivities compAct " + " where act.id = :activityId and " + " index(compAct) = act"; - private final static String COUNT_PROGRESS_BY_LESSON = "select count(*) from LearnerProgress p where p.lesson.id = :lessonId"; - + private final static String COUNT_CURRENT_ACTIVITY = "select count(*) from LearnerProgress prog WHERE " + + " prog.currentActivity = :activity"; + private final static String LOAD_PROGRESS_BY_LESSON = "from LearnerProgress p " + " where p.lesson.id = :lessonId order by p.user.lastName, p.user.firstName, p.user.userId"; - + private final static String LOAD_PROGRESS_BY_LESSON_AND_USER_IDS = "from LearnerProgress p " + " where p.lesson.id = :lessonId AND p.user.userId IN (:userIds) order by p.user.lastName, p.user.firstName, p.user.userId"; - private final String LOAD_PROGRESSES_BY_LESSON_LIST = "FROM LearnerProgress progress WHERE " + private final static String LOAD_PROGRESSES_BY_LESSON_LIST = "FROM LearnerProgress progress WHERE " + " progress.lesson.lessonId IN (:lessonIds)"; - - private final static String LOAD_NEXT_BATCH_PROGRESS_BY_LESSON = "from LearnerProgress p where p.lesson.id = :lessonId " - + " and (( p.user.lastName > :lastUserLastName)" - + " or ( p.user.lastName = :lastUserLastName and p.user.firstName > :lastUserFirstName) " - + " or ( p.user.lastName = :lastUserLastName and p.user.firstName = :lastUserFirstName and p.user.userId > :lastUserId))" - + " order by p.user.lastName, p.user.firstName, p.user.userId"; + private final static String LOAD_LEARNERS_LATEST_BY_ACTIVITY = "SELECT prog.user_id FROM lams_learner_progress AS prog " + + "JOIN lams_progress_attempted AS att USING (learner_progress_id) " + + "WHERE prog.current_activity_id = :activityId AND att.activity_id = :activityId " + + "ORDER BY att.start_date_time DESC"; + + private final static String LOAD_LEARNERS_BY_ACTIVITIES = "SELECT p.user FROM LearnerProgress p WHERE " + + " p.currentActivity.id IN (:activityIds)"; + @Override public LearnerProgress getLearnerProgress(Long learnerProgressId) { return (LearnerProgress) getSession().get(LearnerProgress.class, learnerProgressId); } @Override public void saveLearnerProgress(LearnerProgress learnerProgress) { - getSession().save(learnerProgress); + getSession().save(learnerProgress); } @Override public void deleteLearnerProgress(LearnerProgress learnerProgress) { - getSession().delete(learnerProgress); + getSession().delete(learnerProgress); } @Override - public LearnerProgress getLearnerProgressByLearner(final Integer learnerId, final Long lessonId) { + public LearnerProgress getLearnerProgressByLearner(final Integer learnerId, final Long lessonId) { - return (LearnerProgress) getSession().createQuery(LOAD_PROGRESS_BY_LEARNER).setInteger("learnerId", learnerId) - .setLong("lessonId", lessonId).uniqueResult(); - } + return (LearnerProgress) getSession().createQuery(LearnerProgressDAO.LOAD_PROGRESS_BY_LEARNER) + .setInteger("learnerId", learnerId).setLong("lessonId", lessonId).uniqueResult(); + } @Override public void updateLearnerProgress(LearnerProgress learnerProgress) { this.getSession().update(learnerProgress); } + @SuppressWarnings("unchecked") @Override - public List getLearnerProgressReferringToActivity(final Activity activity) { - return (List) getSession().createQuery(LOAD_PROGRESS_BY_ACTIVITY).setEntity("activity", activity).list(); + public List getLearnerProgressReferringToActivity(final Activity activity) { + return getSession().createQuery(LearnerProgressDAO.LOAD_PROGRESS_REFFERING_TO_ACTIVITY) + .setEntity("activity", activity).list(); + } + + @SuppressWarnings("unchecked") + @Override + public List getLearnersLatestByActivity(final Long activityId, final Integer limit, final Integer offset) { + Query query = getSession().createSQLQuery(LearnerProgressDAO.LOAD_LEARNERS_LATEST_BY_ACTIVITY) + .setLong("activityId", activityId); + if (limit != null) { + query.setMaxResults(limit); } + if (offset != null) { + query.setFirstResult(offset); + } + // first query fetches only progress IDs + List result = query.list(); + // fetch user objects and return them + List learners = new LinkedList(); + for (BigInteger userId : result) { + learners.add((User) getSession().get(User.class, userId.intValue())); + } + return learners; + } - @Override - public List getCompletedLearnerProgressForLesson(final Long lessonId) { + @SuppressWarnings("unchecked") + @Override + public List getLearnersByActivities(final Long[] activityIds, final Integer limit, final Integer offset) { + Query query = getSession().createQuery(LearnerProgressDAO.LOAD_LEARNERS_BY_ACTIVITIES) + .setParameterList("activityIds", activityIds); + if (limit != null) { + query.setMaxResults(limit); + } + if (offset != null) { + query.setFirstResult(offset); + } + return query.list(); + } - return (List) getSession().createQuery(LOAD_COMPLETED_PROGRESS_BY_LESSON).setLong("lessonId", lessonId).list(); + @SuppressWarnings("unchecked") + @Override + public List getLearnersLatestCompletedForLesson(final Long lessonId, final Integer limit, + final Integer offset) { + Query query = getSession().createQuery(LearnerProgressDAO.LOAD_LEARNERS_LATEST_COMPLETED_BY_LESSON) + .setLong("lessonId", lessonId); + if (limit != null) { + query.setMaxResults(limit); } - - @Override - public List getLearnerProgressForLesson(final Long lessonId) { - return (List) getSession().createQuery(LOAD_PROGRESS_BY_LESSON).setLong("lessonId", lessonId).list(); + if (offset != null) { + query.setFirstResult(offset); } - + return query.list(); + } + + @SuppressWarnings("unchecked") @Override - public List getLearnerProgressForLesson(final Long lessonId, final List userIds) { - return getSession().createQuery(LOAD_PROGRESS_BY_LESSON_AND_USER_IDS).setLong("lessonId", lessonId) - .setParameterList("userIds", userIds).list(); + public List getCompletedLearnerProgressForLesson(final Long lessonId) { + return getSession().createQuery(LearnerProgressDAO.LOAD_COMPLETED_PROGRESS_BY_LESSON) + .setLong("lessonId", lessonId).list(); } + @SuppressWarnings("unchecked") @Override + public List getLearnerProgressForLesson(final Long lessonId) { + return getSession().createQuery(LearnerProgressDAO.LOAD_PROGRESS_BY_LESSON).setLong("lessonId", lessonId) + .list(); + } + + @SuppressWarnings("unchecked") + @Override + public List getLearnerProgressForLesson(final Long lessonId, final List userIds) { + return getSession().createQuery(LearnerProgressDAO.LOAD_PROGRESS_BY_LESSON_AND_USER_IDS) + .setLong("lessonId", lessonId).setParameterList("userIds", userIds).list(); + } + + @SuppressWarnings("unchecked") + @Override public List getLearnerProgressForLessons(final List lessonIds) { - return getSession().createQuery(LOAD_PROGRESSES_BY_LESSON_LIST).setParameterList("lessonIds", lessonIds).list(); + return getSession().createQuery(LearnerProgressDAO.LOAD_PROGRESSES_BY_LESSON_LIST) + .setParameterList("lessonIds", lessonIds).list(); } @Override @SuppressWarnings("unchecked") - public List getLearnersHaveAttemptedActivity(final Activity activity) { - List learners = (List) getSession().getNamedQuery("usersAttemptedActivity") - .setLong("activityId", activity.getActivityId().longValue()).list(); + public List getLearnersHaveAttemptedActivity(final Activity activity) { + List learners = getSession().getNamedQuery("usersAttemptedActivity") + .setLong("activityId", activity.getActivityId().longValue()).list(); - return learners; - } + return learners; + } @Override public Integer getNumUsersAttemptedActivity(final Activity activity) { - Object value = getSession().createQuery(COUNT_ATTEMPTED_ACTIVITY) - .setLong("activityId", activity.getActivityId().longValue()).uniqueResult(); - Integer attempted = new Integer(((Number) value).intValue()); - return new Integer(attempted.intValue() + getNumUsersCompletedActivity(activity).intValue()); + Object value = getSession().createQuery(LearnerProgressDAO.COUNT_ATTEMPTED_ACTIVITY) + .setLong("activityId", activity.getActivityId().longValue()).uniqueResult(); + Integer attempted = new Integer(((Number) value).intValue()); + return new Integer(attempted.intValue() + getNumUsersCompletedActivity(activity).intValue()); } - @Override - @SuppressWarnings("unchecked") - public List getLearnersHaveCompletedActivity(final Activity activity) { - List learners = null; + @Override + public Integer getNumUsersCompletedActivity(final Activity activity) { + Object value = getSession().createQuery(LearnerProgressDAO.COUNT_COMPLETED_ACTIVITY) + .setLong("activityId", activity.getActivityId().longValue()).uniqueResult(); + return new Integer(((Number) value).intValue()); + } - learners = (List) getSession().getNamedQuery("usersCompletedActivity") - .setLong("activityId", activity.getActivityId().longValue()).list(); - return learners; - } - - @Override - public Integer getNumUsersCompletedActivity(final Activity activity) { - Object value = getSession().createQuery(COUNT_COMPLETED_ACTIVITY) - .setLong("activityId", activity.getActivityId().longValue()).uniqueResult(); - return new Integer(((Number) value).intValue()); - } - @Override - public Integer getNumAllLearnerProgress(final Long lessonId) { - Object value = getSession().createQuery(COUNT_PROGRESS_BY_LESSON).setLong("lessonId", lessonId.longValue()) - .uniqueResult(); - return new Integer(((Number) value).intValue()); + public Integer getNumUsersCompletedLesson(final Long lessonId) { + Object value = getSession().createQuery(LearnerProgressDAO.COUNT_COMPLETED_PROGRESS_BY_LESSON) + .setLong("lessonId", lessonId).uniqueResult(); + return ((Number) value).intValue(); } - @Override - @SuppressWarnings("unchecked") - public List getBatchLearnerProgress(final Long lessonId, final User lastUser, final int batchSize) { - - if (lastUser == null) { - return (List) getSession().createQuery(LOAD_PROGRESS_BY_LESSON) - .setLong("lessonId", lessonId.longValue()).setMaxResults(batchSize).list(); - - } else { - return (List) getSession().createQuery(LOAD_NEXT_BATCH_PROGRESS_BY_LESSON) - .setLong("lessonId", lessonId.longValue()).setString("lastUserLastName", lastUser.getLastName()) - .setString("lastUserFirstName", lastUser.getFirstName()) - .setInteger("lastUserId", lastUser.getUserId().intValue()).setMaxResults(batchSize).list(); - } - } - -} + @Override + public Integer getNumUsersCurrentActivity(final Activity activity) { + Object value = getSession().createQuery(LearnerProgressDAO.COUNT_CURRENT_ACTIVITY) + .setEntity("activity", activity).uniqueResult(); + return ((Number) value).intValue(); + } +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LessonDAO.java =================================================================== diff -u -r4d65537fb74ec9a261ccb55520fe28c1253e9b13 -r62b97a5e0fd88110e023f00793a983713296f9b6 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LessonDAO.java (.../LessonDAO.java) (revision 4d65537fb74ec9a261ccb55520fe28c1253e9b13) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LessonDAO.java (.../LessonDAO.java) (revision 62b97a5e0fd88110e023f00793a983713296f9b6) @@ -62,29 +62,36 @@ + "and l.learningDesign.copyTypeID != " + LearningDesign.COPY_TYPE_PREVIEW + " " + "and l.lessonStateId = " + Lesson.STARTED_STATE + " " + "and l.organisation.organisationId = ? " + " order by l.lessonName"; private final static String LESSONS_BY_GROUP = "from " + Lesson.class.getName() - + " where organisation.organisationId=? and lessonStateId <= 6"; - private final static String LESSON_BY_SESSION_ID = "select lesson from Lesson lesson, ToolSession session where " + - "session.lesson=lesson and session.toolSessionId=:toolSessionID"; + + " where organisation.organisationId=? and lessonStateId <= 6"; + private final static String LESSON_BY_SESSION_ID = "select lesson from Lesson lesson, ToolSession session where " + + "session.lesson=lesson and session.toolSessionId=:toolSessionID"; + private final static String COUNT_LEARNERS_CLASS = "SELECT COUNT(*) FROM lams_lesson AS lesson " + + "JOIN lams_grouping AS grouping ON lesson.class_grouping_id = grouping.grouping_id " + + "JOIN lams_group AS gr USING (grouping_id) JOIN lams_user_group AS ug USING (group_id) " + + "WHERE lesson_id = :lessonId"; /** * Retrieves the Lesson. Used in instances where it cannot be lazy loaded so it forces an initialize. * * @param lessonId - * identifies the lesson to get + * identifies the lesson to get * @return the lesson */ + @Override public Lesson getLesson(Long lessonId) { Lesson lesson = (Lesson) getSession().get(Lesson.class, lessonId); return lesson; } - public Lesson getLessonWithJoinFetchedProgress(final Long lessonId) { + @Override + public Lesson getLessonWithJoinFetchedProgress(final Long lessonId) { - return (Lesson) getSession().createCriteria(Lesson.class).add(Restrictions.like("lessonId", lessonId)) - .setFetchMode("learnerProgresses", FetchMode.JOIN).uniqueResult(); - } + return (Lesson) getSession().createCriteria(Lesson.class).add(Restrictions.like("lessonId", lessonId)) + .setFetchMode("learnerProgresses", FetchMode.JOIN).uniqueResult(); + } /** Get all the lessons in the database. This includes the disabled lessons. */ + @Override public List getAllLessons() { return loadAll(Lesson.class); } @@ -93,103 +100,120 @@ * Gets all lessons that are active for a learner. * * @param learner - * a User that identifies the learner. + * a User that identifies the learner. * @return a List with all active lessons in it. */ - public List getActiveLessonsForLearner(final User learner) { + @Override + public List getActiveLessonsForLearner(final User learner) { - Query query = getSession().getNamedQuery("activeLessonsAllOrganisations"); - query.setInteger("userId", learner.getUserId().intValue()); - List result = query.list(); - return result; - } + Query query = getSession().getNamedQuery("activeLessonsAllOrganisations"); + query.setInteger("userId", learner.getUserId().intValue()); + List result = query.list(); + return result; + } /** * Gets all lessons that are active for a learner, in a given organisation * * @param learnerId - * a User that identifies the learner. + * a User that identifies the learner. * @param organisationId - * the desired organisation. + * the desired organisation. * @return a List with all active lessons in it. */ - public List getActiveLessonsForLearner(final Integer learnerId, final Integer organisationId) { + @Override + public List getActiveLessonsForLearner(final Integer learnerId, final Integer organisationId) { - Query query = getSession().getNamedQuery("activeLessons"); - query.setInteger("userId", learnerId); - query.setInteger("organisationId", organisationId); - List result = query.list(); - return result; - } + Query query = getSession().getNamedQuery("activeLessons"); + query.setInteger("userId", learnerId); + query.setInteger("organisationId", organisationId); + List result = query.list(); + return result; + } /** * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getActiveLearnerByLesson(long) */ + @Override public List getActiveLearnerByLesson(final long lessonId) { - Query query = getSession().getNamedQuery("activeLearners"); - query.setLong("lessonId", lessonId); - List result = query.list(); - return result; + Query query = getSession().getNamedQuery("activeLearners"); + query.setLong("lessonId", lessonId); + List result = query.list(); + return result; } /** * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getActiveLearnerByLessonAndGroup(long, long) */ + @Override public List getActiveLearnerByLessonAndGroup(final long lessonId, final long groupId) { - Query query = getSession().getNamedQuery("activeLearnersByGroup"); - query.setLong("lessonId", lessonId); - query.setLong("groupId", groupId); - List result = query.list(); - return result; + Query query = getSession().getNamedQuery("activeLearnersByGroup"); + query.setLong("lessonId", lessonId); + query.setLong("groupId", groupId); + List result = query.list(); + return result; } /** * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getActiveLearnerByLesson(long) Note: Hibernate 3.1 * query.uniqueResult() returns Integer, Hibernate 3.2 query.uniqueResult() returns Long */ + @Override public Integer getCountActiveLearnerByLesson(final long lessonId) { - Query query = getSession().createQuery(LessonDAO.COUNT_ACTIVE_LEARNERS); - query.setLong("lessonId", lessonId); - Object value = query.uniqueResult(); - return new Integer(((Number) value).intValue()); + Query query = getSession().createQuery(LessonDAO.COUNT_ACTIVE_LEARNERS); + query.setLong("lessonId", lessonId); + Object value = query.uniqueResult(); + return new Integer(((Number) value).intValue()); } + @Override + public Integer getCountLearnerByLesson(final long lessonId) { + Query query = getSession().createSQLQuery(LessonDAO.COUNT_LEARNERS_CLASS); + query.setLong("lessonId", lessonId); + Object value = query.uniqueResult(); + return ((Number) value).intValue(); + } + /** - * f Saves or Updates a Lesson. + * Saves or Updates a Lesson. * * @param lesson */ + @Override public void saveLesson(Lesson lesson) { - getSession().save(lesson); + getSession().save(lesson); } /** * Deletes a Lesson permanently. * * @param lesson */ + @Override public void deleteLesson(Lesson lesson) { - getSession().delete(lesson); + getSession().delete(lesson); } /** * Update the lesson data * * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#updateLesson(org.lamsfoundation.lams.lesson.Lesson) */ + @Override public void updateLesson(Lesson lesson) { - getSession().update(lesson); + getSession().update(lesson); } /** * Returns the list of available Lessons created by a given user. Does not return disabled lessons or preview * lessons. * * @param userID - * The user_id of the user + * The user_id of the user * @return List The list of Lessons for the given user */ + @Override public List getLessonsCreatedByUser(Integer userID) { List lessons = this.doFind(LessonDAO.FIND_LESSON_BY_CREATOR, userID); return lessons; @@ -200,24 +224,26 @@ * lessons or preview lessons. This is the list of lessons that a user may monitor/moderate/manage. * * @param user - * a User that identifies the teacher/staff member. + * a User that identifies the teacher/staff member. * @return a List with all appropriate lessons in it. */ + @Override public List getLessonsForMonitoring(final int userID, final int organisationID) { - Query query = getSession().getNamedQuery("lessonsForMonitoring"); - query.setInteger("userId", userID); - query.setInteger("organisationId", organisationID); - List result = query.list(); - return result; + Query query = getSession().getNamedQuery("lessonsForMonitoring"); + query.setInteger("userId", userID); + query.setInteger("organisationId", organisationID); + List result = query.list(); + return result; } /** * Get all the preview lessons more with the creation date before the given date. * * @param startDate - * UTC date + * UTC date * @return the list of Lessons */ + @Override public List getPreviewLessonsBeforeDate(final Date startDate) { List lessons = this.doFind(LessonDAO.FIND_PREVIEW_BEFORE_START_DATE, startDate); return lessons; @@ -226,54 +252,60 @@ /** * Get the lesson that applies to this activity. Not all activities have an attached lesson. */ + @Override public Lesson getLessonForActivity(final long activityId) { - Query query = getSession().createQuery(LessonDAO.FIND_LESSON_FOR_ACTIVITY); - query.setLong("activityId", activityId); - return (Lesson) query.uniqueResult(); + Query query = getSession().createQuery(LessonDAO.FIND_LESSON_FOR_ACTIVITY); + query.setLong("activityId", activityId); + return (Lesson) query.uniqueResult(); } /** * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getLessonsByOrgAndUserWithCompletedFlag(Integer, Integer, * boolean) */ - public List getLessonsByOrgAndUserWithCompletedFlag(final Integer userId, final Integer orgId, final Integer userRole) { + @Override + public List getLessonsByOrgAndUserWithCompletedFlag(final Integer userId, final Integer orgId, + final Integer userRole) { - String queryName; - if (Role.ROLE_MONITOR.equals(userRole)) { - queryName = "staffLessonsByOrgAndUserWithCompletedFlag"; - } else if (Role.ROLE_LEARNER.equals(userRole)) { - queryName = "learnerLessonsByOrgAndUserWithCompletedFlag"; - } else { - // in case of Role.ROLE_GROUP_MANAGER - queryName = "allLessonsByOrgAndUserWithCompletedFlag"; - } - - Query query = getSession().getNamedQuery(queryName); - query.setInteger("userId", userId.intValue()); - query.setInteger("orgId", orgId.intValue()); - List result = query.list(); - return result; + String queryName; + if (Role.ROLE_MONITOR.equals(userRole)) { + queryName = "staffLessonsByOrgAndUserWithCompletedFlag"; + } else if (Role.ROLE_LEARNER.equals(userRole)) { + queryName = "learnerLessonsByOrgAndUserWithCompletedFlag"; + } else { + // in case of Role.ROLE_GROUP_MANAGER + queryName = "allLessonsByOrgAndUserWithCompletedFlag"; + } + + Query query = getSession().getNamedQuery(queryName); + query.setInteger("userId", userId.intValue()); + query.setInteger("orgId", orgId.intValue()); + List result = query.list(); + return result; } - + /** * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getLessonsByOrgAndUserWithCompletedFlag(Integer, Integer, * boolean) */ + @Override public List getLessonsByGroupAndUser(final Integer userId, final Integer orgId) { - Query query = getSession().getNamedQuery("lessonsByOrgAndUserWithChildOrgs"); - query.setInteger("userId", userId.intValue()); - query.setInteger("orgId", orgId.intValue()); - List result = query.list(); - return result; + Query query = getSession().getNamedQuery("lessonsByOrgAndUserWithChildOrgs"); + query.setInteger("userId", userId.intValue()); + query.setInteger("orgId", orgId.intValue()); + List result = query.list(); + return result; } - + + @Override public List getLessonsByGroup(final Integer orgId) { return this.doFind(LessonDAO.LESSONS_BY_GROUP, orgId); } /** * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getLessonsByOriginalLearningDesign(Integer) */ + @Override public List getLessonsByOriginalLearningDesign(final Long ldId, final Integer orgId) { Object[] args = { ldId.longValue(), orgId.intValue() }; List lessons = this.doFind(LessonDAO.LESSONS_WITH_ORIGINAL_LEARNING_DESIGN, args); @@ -283,18 +315,19 @@ /** * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getMonitorsByToolSessionId(Long) */ + @Override @SuppressWarnings("unchecked") public List getMonitorsByToolSessionId(Long sessionId) { - return (List) this.doFindByNamedQueryAndNamedParam("monitorsByToolSessionId", "sessionId", - sessionId); + return (List) this.doFindByNamedQueryAndNamedParam("monitorsByToolSessionId", "sessionId", sessionId); } - + /** * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getLessonDetailsFromSessionID(java.lang.Long) */ + @Override public Lesson getLessonFromSessionID(final Long toolSessionID) { - Query query = getSession().createQuery(LessonDAO.LESSON_BY_SESSION_ID); - query.setLong("toolSessionID", toolSessionID); - return (Lesson) query.uniqueResult(); + Query query = getSession().createQuery(LessonDAO.LESSON_BY_SESSION_ID); + query.setLong("toolSessionID", toolSessionID); + return (Lesson) query.uniqueResult(); } } Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java =================================================================== diff -u -r9357467901bacb28df24a695ec35e99434ebbea9 -r62b97a5e0fd88110e023f00793a983713296f9b6 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision 9357467901bacb28df24a695ec35e99434ebbea9) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision 62b97a5e0fd88110e023f00793a983713296f9b6) @@ -62,35 +62,40 @@ public interface ILessonService { /** Get all the learners who have started the lesson. They may not be currently online. */ - abstract List getActiveLessonLearners(Long lessonId); + List getActiveLessonLearners(Long lessonId); /** * Get all the learners who have started the lesson and are part of a given group. They may not be currently online. */ - abstract List getActiveLessonLearnersByGroup(Long lessonId, Long groupId); + List getActiveLessonLearnersByGroup(Long lessonId, Long groupId); /** * Get the count of all the learners who have started the lesson. They may not be currently online. */ Integer getCountActiveLessonLearners(Long lessonId); /** + * Get the count of all the learners who are a part of the lesson class. + */ + Integer getCountLessonLearners(Long lessonId); + + /** * Get the lesson details for the LAMS client. Suitable for the monitoring client. Contains a count of the total * number of learners in the lesson and the number of active learners. This is a pretty intensive call as it counts * all the learners in the lessons' learner group, and determines the number of active learners. * * @param lessonId * @return lesson details */ - abstract LessonDetailsDTO getLessonDetails(Long lessonId); + LessonDetailsDTO getLessonDetails(Long lessonId); /** * Get the lesson object. * * @param lessonId * @return lesson details */ - abstract Lesson getLesson(Long lessonId); + Lesson getLesson(Long lessonId); /** * Get the lesson details for the LAMS client. Suitable for the learner client. Contains a reduced number of fields @@ -99,7 +104,7 @@ * @param lessonId * @return lesson details */ - abstract LessonDTO getLessonData(Long lessonId); + LessonDTO getLessonData(Long lessonId); /** * If the supplied learner is not already in a group, then perform grouping for the learners who have started the @@ -316,27 +321,13 @@ List getLearnersHaveAttemptedActivity(Activity activity) throws LessonServiceException; /** - * Get the list of users who have completed an activity. This is based on the progress engine records. This will - * give the users in all tool sessions for an activity (if it is a tool activity) or it will give all the users who - * have attempted an activity that doesn't have any tool sessions, i.e. system activities such as branching. - */ - List getLearnersHaveCompletedActivity(Activity activity) throws LessonServiceException; - - /** * Gets the count of the users who have attempted an activity. This is based on the progress engine records. This * will work on all activities, including ones that don't have any tool sessions, i.e. system activities such as * branching. */ Integer getCountLearnersHaveAttemptedActivity(Activity activity) throws LessonServiceException; /** - * Gets the count of the users who have completed an activity. This is based on the progress engine records. This - * will work on all activities, including ones that don't have any tool sessions, i.e. system activities such as - * branching. - */ - Integer getCountLearnersHaveCompletedActivity(Activity activity) throws LessonServiceException; - - /** * Returns map of lessons in an organisation for a particular learner or staff user. * * @param userId @@ -357,7 +348,7 @@ * @param organisationId * @return list of lessons */ - abstract List getLessonsByGroupAndUser(Integer userId, Integer organisationId); + List getLessonsByGroupAndUser(Integer userId, Integer organisationId); /** * Return list of organisation's non-removed lessons. Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java =================================================================== diff -u -r9357467901bacb28df24a695ec35e99434ebbea9 -r62b97a5e0fd88110e023f00793a983713296f9b6 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision 9357467901bacb28df24a695ec35e99434ebbea9) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision 62b97a5e0fd88110e023f00793a983713296f9b6) @@ -122,6 +122,11 @@ } @Override + public Integer getCountLessonLearners(Long lessonId) { + return lessonDAO.getCountLearnerByLesson(lessonId); + } + + @Override public LessonDetailsDTO getLessonDetails(Long lessonId) { Lesson lesson = lessonDAO.getLesson(lessonId); LessonDetailsDTO dto = null; @@ -308,13 +313,14 @@ public boolean addLearner(Long lessonId, Integer userId) throws LessonServiceException { Lesson lesson = lessonDAO.getLesson(lessonId); if (lesson == null) { - throw new LessonServiceException("Lesson " + lessonId + " does not exist. Unable to add learner to lesson."); + throw new LessonServiceException( + "Lesson " + lessonId + " does not exist. Unable to add learner to lesson."); } LessonClass lessonClass = lesson.getLessonClass(); if (lessonClass == null) { - throw new LessonServiceException("Lesson class for " + lessonId - + " does not exist. Unable to add learner to lesson."); + throw new LessonServiceException( + "Lesson class for " + lessonId + " does not exist. Unable to add learner to lesson."); } // initialise the lesson group, or we get a lazy loading error when logging in @@ -338,12 +344,13 @@ Lesson lesson = lessonDAO.getLesson(lessonId); if (lesson == null) { - throw new LessonServiceException("Lesson " + lessonId + " does not exist. Unable to add learner to lesson."); + throw new LessonServiceException( + "Lesson " + lessonId + " does not exist. Unable to add learner to lesson."); } LessonClass lessonClass = lesson.getLessonClass(); if (lessonClass == null) { - throw new LessonServiceException("Lesson class for " + lessonId - + " does not exist. Unable to add learner to lesson."); + throw new LessonServiceException( + "Lesson class for " + lessonId + " does not exist. Unable to add learner to lesson."); } // initialise the lesson group, or we might get a lazy loading error in the future @@ -381,24 +388,24 @@ int numberOfLearners = lessonClass.setLearners(users); lessonClassDAO.updateLessonClass(lessonClass); if (LessonService.log.isDebugEnabled()) { - LessonService.log.debug("Set " + numberOfLearners + " learners in lessonClass " - + lessonClass.getGroupingId()); + LessonService.log + .debug("Set " + numberOfLearners + " learners in lessonClass " + lessonClass.getGroupingId()); } } @Override public boolean addStaffMember(Long lessonId, Integer userId) { Lesson lesson = lessonDAO.getLesson(lessonId); if (lesson == null) { - throw new LessonServiceException("Lesson " + lessonId - + " does not exist. Unable to add staff member to lesson."); + throw new LessonServiceException( + "Lesson " + lessonId + " does not exist. Unable to add staff member to lesson."); } LessonClass lessonClass = lesson.getLessonClass(); if (lessonClass == null) { - throw new LessonServiceException("Lesson class for " + lessonId - + " does not exist. Unable to add staff member to lesson."); + throw new LessonServiceException( + "Lesson class for " + lessonId + " does not exist. Unable to add staff member to lesson."); } lessonDAO.initialize(lessonClass.getStaffGroup()); @@ -416,12 +423,13 @@ Lesson lesson = lessonDAO.getLesson(lessonId); if (lesson == null) { - throw new LessonServiceException("Lesson " + lessonId + " does not exist. Unable to add learner to lesson."); + throw new LessonServiceException( + "Lesson " + lessonId + " does not exist. Unable to add learner to lesson."); } LessonClass lessonClass = lesson.getLessonClass(); if (lessonClass == null) { - throw new LessonServiceException("Lesson class for " + lessonId - + " does not exist. Unable to add learner to lesson."); + throw new LessonServiceException( + "Lesson class for " + lessonId + " does not exist. Unable to add learner to lesson."); } // initialise the lesson group, or we might get a lazy loading error in the future @@ -446,8 +454,8 @@ lessonClassDAO.updateLessonClass(lessonClass); } if (LessonService.log.isDebugEnabled()) { - LessonService.log.debug("Added " + numAdded + " staff members to lessonClass " - + lessonClass.getGroupingId()); + LessonService.log + .debug("Added " + numAdded + " staff members to lessonClass " + lessonClass.getGroupingId()); } } @@ -458,8 +466,8 @@ int numberOfStaff = lessonClass.setStaffMembers(users); lessonClassDAO.updateLessonClass(lessonClass); if (LessonService.log.isDebugEnabled()) { - LessonService.log.debug("Set " + numberOfStaff + " staff members in lessonClass " - + lessonClass.getGroupingId()); + LessonService.log + .debug("Set " + numberOfStaff + " staff members in lessonClass " + lessonClass.getGroupingId()); } } @@ -561,21 +569,11 @@ } @Override - public List getLearnersHaveCompletedActivity(Activity activity) throws LessonServiceException { - return learnerProgressDAO.getLearnersHaveCompletedActivity(activity); - } - - @Override public Integer getCountLearnersHaveAttemptedActivity(Activity activity) throws LessonServiceException { return learnerProgressDAO.getNumUsersAttemptedActivity(activity); } @Override - public Integer getCountLearnersHaveCompletedActivity(Activity activity) throws LessonServiceException { - return learnerProgressDAO.getNumUsersCompletedActivity(activity); - } - - @Override public Map getLessonsByOrgAndUserWithCompletedFlag(Integer userId, Integer orgId, Integer userRole) { TreeMap map = new TreeMap(); @@ -591,8 +589,8 @@ Boolean lessonCompleted = (Boolean) tuple[4]; lessonCompleted = lessonCompleted == null ? false : lessonCompleted.booleanValue(); Boolean enableLessonNotifications = (Boolean) tuple[5]; - enableLessonNotifications = enableLessonNotifications == null ? false : enableLessonNotifications - .booleanValue(); + enableLessonNotifications = enableLessonNotifications == null ? false + : enableLessonNotifications.booleanValue(); Boolean dependent = (Boolean) tuple[6]; dependent = dependent == null ? false : dependent.booleanValue(); Boolean scheduledFinish = (Boolean) tuple[7]; Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java =================================================================== diff -u -r093df66baaeb89432c9e5a0351c8fb91cc4a13ac -r62b97a5e0fd88110e023f00793a983713296f9b6 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision 093df66baaeb89432c9e5a0351c8fb91cc4a13ac) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision 62b97a5e0fd88110e023f00793a983713296f9b6) @@ -35,7 +35,6 @@ import org.lamsfoundation.lams.learningdesign.Group; import org.lamsfoundation.lams.learningdesign.GroupingActivity; import org.lamsfoundation.lams.learningdesign.ScheduleGateActivity; -import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.lesson.service.LessonServiceException; @@ -70,8 +69,9 @@ * Create new lesson according to the learning design specified by the user. This involves following major steps: *

* - *
  • 1. Make a runtime copy of static learning design defined in authoring
  • 2. Go through all the tool - * activities defined in the learning design, create a runtime copy of all tool's content.
  • + *
  • 1. Make a runtime copy of static learning design defined in authoring
  • + *
  • 2. Go through all the tool activities defined in the learning design, create a runtime copy of all tool's + * content.
  • * *

    * As a runtime design, it is not copied into any folder. @@ -162,7 +162,7 @@ */ Lesson createLessonClassForLesson(long lessonId, Organisation organisation, String learnerGroupName, List organizationUsers, String staffGroupName, List staffs, Integer userID) - throws UserAccessDeniedException; + throws UserAccessDeniedException; /** * Start the specified the lesson. It must be created before calling this service. @@ -188,8 +188,9 @@ * Runs the system scheduler to start the scheduling for opening gate and closing gate. It invlovs a couple of steps * to start the scheduler: *

    - *
  • 1. Initialize the resource needed by scheduling job by setting them into the job data map.
  • 2. Create - * customized triggers for the scheduling.
  • 3. start the scheduling job
  • + *
  • 1. Initialize the resource needed by scheduling job by setting them into the job data map.
  • + *
  • 2. Create customized triggers for the scheduling.
  • + *
  • 3. start the scheduling job
  • * * @param scheduleGate * the gate that needs to be scheduled. @@ -200,7 +201,8 @@ * the name lesson incorporating this gate - used for the description of the Quartz job. Optional. * @returns An updated gate, that should be saved by the calling code. */ - ScheduleGateActivity runGateScheduler(ScheduleGateActivity scheduleGate, Date schedulingStartTime, String lessonName); + ScheduleGateActivity runGateScheduler(ScheduleGateActivity scheduleGate, Date schedulingStartTime, + String lessonName); /** * Start a lesson on scheduled datetime. @@ -679,6 +681,31 @@ LearnerProgress getLearnerProgress(Integer learnerId, Long lessonId); /** + * Get learners who most recently entered finished the lesson. + */ + List getLearnersLatestCompleted(Long lessonId, Integer limit, Integer offset); + + /** + * Get learners who most recently entered the activity. + */ + List getLearnersLatestByActivity(Long activityId, Integer limit, Integer offset); + + /** + * Get learners who are at the given activities at the moment. + */ + List getLearnersByActivities(Long[] activityIds, Integer limit, Integer offset); + + /** + * Get number of learners who are at the given activity at the moment. + */ + Integer getCountLearnersCurrentActivity(Activity activity); + + /** + * Get number of learners who finished the given lesson. + */ + Integer getCountLearnersCompletedLesson(Long lessonId); + + /** * Set a groups name */ void setGroupName(Long groupID, String name); @@ -701,4 +728,9 @@ */ int cloneLessons(String[] lessonIds, Boolean addAllStaff, Boolean addAllLearners, String[] staffIds, String[] learnerIds, Organisation group) throws MonitoringServiceException; + + /** + * Get list of users who completed the given lesson. + */ + List getUsersCompletedLesson(Long lessonId); } Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -r779cad98782bee132f0716b30c2fc6e59e47e49f -r62b97a5e0fd88110e023f00793a983713296f9b6 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 779cad98782bee132f0716b30c2fc6e59e47e49f) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 62b97a5e0fd88110e023f00793a983713296f9b6) @@ -1666,7 +1666,8 @@ * specified lesson * @return */ - private List getUsersCompletedLesson(Long lessonId) { + @Override + public List getUsersCompletedLesson(Long lessonId) { List usersCompletedLesson = new LinkedList(); List completedLearnerProgresses = learnerProgressDAO @@ -2353,6 +2354,32 @@ } @Override + + public List getLearnersLatestByActivity(Long activityId, Integer limit, Integer offset) { + return learnerProgressDAO.getLearnersLatestByActivity(activityId, limit, offset); + } + + @Override + public List getLearnersByActivities(Long[] activityIds, Integer limit, Integer offset) { + return learnerProgressDAO.getLearnersByActivities(activityIds, limit, offset); + } + + @Override + public List getLearnersLatestCompleted(Long lessonId, Integer limit, Integer offset) { + return learnerProgressDAO.getLearnersLatestCompletedForLesson(lessonId, limit, offset); + } + + @Override + public Integer getCountLearnersCurrentActivity(Activity activity) { + return learnerProgressDAO.getNumUsersCurrentActivity(activity); + } + + @Override + public Integer getCountLearnersCompletedLesson(Long lessonId) { + return learnerProgressDAO.getNumUsersCompletedLesson(lessonId); + } + + @Override public void setGroupName(Long groupID, String name) { Group group = groupDAO.getGroupById(groupID); group.setGroupName(name); Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java =================================================================== diff -u -r3fe7b36b65f07f7a2ea62c371c06cc7a6ba0214f -r62b97a5e0fd88110e023f00793a983713296f9b6 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java (.../MonitoringAction.java) (revision 3fe7b36b65f07f7a2ea62c371c06cc7a6ba0214f) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java (.../MonitoringAction.java) (revision 62b97a5e0fd88110e023f00793a983713296f9b6) @@ -41,6 +41,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -65,6 +66,7 @@ import org.lamsfoundation.lams.learningdesign.LearningDesign; import org.lamsfoundation.lams.learningdesign.OptionsWithSequencesActivity; import org.lamsfoundation.lams.learningdesign.SequenceActivity; +import org.lamsfoundation.lams.learningdesign.Transition; import org.lamsfoundation.lams.learningdesign.exception.LearningDesignException; import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.lesson.Lesson; @@ -88,7 +90,6 @@ import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.CentralConstants; import org.lamsfoundation.lams.util.DateUtil; -import org.lamsfoundation.lams.util.JsonUtil; import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.ValidationUtil; import org.lamsfoundation.lams.util.WebUtil; @@ -139,6 +140,9 @@ private static final String ERROR = "error"; private static final DateFormat LESSON_SCHEDULING_DATETIME_FORMAT = new SimpleDateFormat("MM/dd/yy HH:mm"); + private static final Integer LATEST_LEARNER_PROGRESS_LESSON_DISPLAY_LIMIT = 53; + private static final Integer LATEST_LEARNER_PROGRESS_ACTIVITY_DISPLAY_LIMIT = 7; + private static IAuditService auditService; private static ITimezoneService timezoneService; @@ -147,32 +151,34 @@ private static ISecurityService securityService; + private static IMonitoringService monitoringService; + private Integer getUserId() { HttpSession ss = SessionManager.getSession(); UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); return user != null ? user.getUserID() : null; } - private FlashMessage handleException(Exception e, String methodKey, IMonitoringService monitoringService) { + private FlashMessage handleException(Exception e, String methodKey) { LamsDispatchAction.log.error("Exception thrown " + methodKey, e); MonitoringAction.auditService = getAuditService(); MonitoringAction.auditService.log(MonitoringAction.class.getName() + ":" + methodKey, e.toString()); if (e instanceof UserAccessDeniedException) { return new FlashMessage(methodKey, - monitoringService.getMessageService().getMessage("error.user.noprivilege"), FlashMessage.ERROR); + getMonitoringService().getMessageService().getMessage("error.user.noprivilege"), + FlashMessage.ERROR); } else { String[] msg = new String[1]; msg[0] = e.getMessage(); return new FlashMessage(methodKey, - monitoringService.getMessageService().getMessage("error.system.error", msg), + getMonitoringService().getMessageService().getMessage("error.system.error", msg), FlashMessage.CRITICAL_ERROR); } } - private FlashMessage handleCriticalError(String methodKey, String messageKey, - IMonitoringService monitoringService) { - String message = monitoringService.getMessageService().getMessage(messageKey); + private FlashMessage handleCriticalError(String methodKey, String messageKey) { + String message = getMonitoringService().getMessageService().getMessage(messageKey); LamsDispatchAction.log.error("Error occured " + methodKey + " error "); MonitoringAction.auditService = getAuditService(); MonitoringAction.auditService.log(MonitoringAction.class.getName() + ":" + methodKey, message); @@ -200,9 +206,6 @@ public ActionForward initializeLesson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); - String title = WebUtil.readStrParam(request, "lessonName"); if (title == null) { title = "lesson"; @@ -223,11 +226,11 @@ Lesson newLesson = null; if ((copyType != null) && copyType.equals(LearningDesign.COPY_TYPE_PREVIEW)) { - newLesson = monitoringService.initializeLessonForPreview(title, desc, ldId, getUserId(), customCSV, + newLesson = getMonitoringService().initializeLessonForPreview(title, desc, ldId, getUserId(), customCSV, learnerPresenceAvailable, learnerImAvailable, liveEditEnabled); } else { try { - newLesson = monitoringService.initializeLesson(title, desc, ldId, organisationId, getUserId(), + newLesson = getMonitoringService().initializeLesson(title, desc, ldId, organisationId, getUserId(), customCSV, false, false, learnerExportAvailable, learnerPresenceAvailable, learnerImAvailable, liveEditEnabled, false, learnerRestart, null, null); } catch (SecurityException e) { @@ -263,11 +266,9 @@ */ public ActionForward startLesson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); try { - monitoringService.startLesson(lessonId, getUserId()); + getMonitoringService().startLesson(lessonId, getUserId()); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); return null; @@ -284,8 +285,6 @@ Integer userID = WebUtil.readIntParam(request, AttributeNames.PARAM_USER_ID); long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); IUserManagementService userManagementService = MonitoringServiceProxy .getUserManagementService(getServlet().getServletContext()); @@ -297,7 +296,7 @@ List staff = parseUserList(request, "monitors", allUsers); try { - monitoringService.createLessonClassForLesson(lessonId, organisation, learnerGroupName, learners, + getMonitoringService().createLessonClassForLesson(lessonId, organisation, learnerGroupName, learners, staffGroupName, staff, userID); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the lesson"); @@ -342,9 +341,6 @@ Integer timeLimitIndividual = timeLimitEnable && timeLimitIndividualField ? timeLimitDays : null; Integer timeLimitLesson = timeLimitEnable && !timeLimitIndividualField ? timeLimitDays : null; - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); - IUserManagementService userManagementService = MonitoringServiceProxy .getUserManagementService(getServlet().getServletContext()); @@ -393,11 +389,12 @@ Lesson lesson = null; try { - lesson = monitoringService.initializeLesson(lessonInstanceName, introDescription, ldId, organisationId, - userId, null, introEnable, introImage, portfolioEnable, presenceEnable, imEnable, - enableLiveEdit, notificationsEnable, learnerRestart, timeLimitIndividual, precedingLessonId); + lesson = getMonitoringService().initializeLesson(lessonInstanceName, introDescription, ldId, + organisationId, userId, null, introEnable, introImage, portfolioEnable, presenceEnable, + imEnable, enableLiveEdit, notificationsEnable, learnerRestart, timeLimitIndividual, + precedingLessonId); - monitoringService.createLessonClassForLesson(lesson.getLessonId(), organisation, + getMonitoringService().createLessonClassForLesson(lesson.getLessonId(), organisation, learnerGroupInstanceName, lessonInstanceLearners, staffGroupInstanceName, staff, userId); } catch (SecurityException e) { try { @@ -414,15 +411,15 @@ if (!startMonitor) { try { if (schedulingDatetime == null) { - monitoringService.startLesson(lesson.getLessonId(), userId); + getMonitoringService().startLesson(lesson.getLessonId(), userId); } else { // if lesson should start in few days, set it here - monitoringService.startLessonOnSchedule(lesson.getLessonId(), schedulingDatetime, userId); + getMonitoringService().startLessonOnSchedule(lesson.getLessonId(), schedulingDatetime, userId); } // if lesson should finish in few days, set it here if (timeLimitLesson != null) { - monitoringService.finishLessonOnSchedule(lesson.getLessonId(), timeLimitLesson, userId); + getMonitoringService().finishLessonOnSchedule(lesson.getLessonId(), timeLimitLesson, userId); } } catch (SecurityException e) { try { @@ -441,13 +438,11 @@ public ActionForward startOnScheduleLesson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ParseException, IOException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); String dateStr = WebUtil.readStrParam(request, MonitoringConstants.PARAM_LESSON_START_DATE); Date startDate = MonitoringAction.LESSON_SCHEDULING_DATETIME_FORMAT.parse(dateStr); try { - monitoringService.startLessonOnSchedule(lessonId, startDate, getUserId()); + getMonitoringService().startLessonOnSchedule(lessonId, startDate, getUserId()); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); } @@ -476,13 +471,11 @@ public ActionForward archiveLesson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); try { - monitoringService.unsuspendLesson(lessonId, getUserId()); + getMonitoringService().unsuspendLesson(lessonId, getUserId()); } catch (SecurityException e) { - monitoringService.archiveLesson(lessonId, getUserId()); + getMonitoringService().archiveLesson(lessonId, getUserId()); } return null; } @@ -508,11 +501,9 @@ */ public ActionForward unarchiveLesson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); try { - monitoringService.unarchiveLesson(lessonId, getUserId()); + getMonitoringService().unarchiveLesson(lessonId, getUserId()); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); } @@ -534,11 +525,9 @@ */ public ActionForward suspendLesson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); try { - monitoringService.suspendLesson(lessonId, getUserId()); + getMonitoringService().suspendLesson(lessonId, getUserId()); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); } @@ -559,11 +548,9 @@ */ public ActionForward unsuspendLesson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); try { - monitoringService.unsuspendLesson(lessonId, getUserId()); + getMonitoringService().unsuspendLesson(lessonId, getUserId()); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); } @@ -592,21 +579,20 @@ */ public ActionForward removeLesson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, JSONException, ServletException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); JSONObject jsonObject = new JSONObject(); try { // if this method throws an Exception, there will be no removeLesson=true in the JSON reply - monitoringService.removeLesson(lessonId, getUserId()); + getMonitoringService().removeLesson(lessonId, getUserId()); jsonObject.put("removeLesson", true); } catch (Exception e) { String[] msg = new String[1]; msg[0] = e.getMessage(); - jsonObject.put("removeLesson", monitoringService.getMessageService().getMessage("error.system.error", msg)); + jsonObject.put("removeLesson", + getMonitoringService().getMessageService().getMessage("error.system.error", msg)); } response.setContentType("application/json;charset=utf-8"); @@ -632,9 +618,6 @@ public ActionForward forceComplete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { getAuditService(); - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); - // get parameters Long activityId = null; String actId = request.getParameter(AttributeNames.PARAM_ACTIVITY_ID); @@ -654,7 +637,7 @@ String message = null; try { - message = monitoringService.forceCompleteActivitiesByUser(learnerId, requesterId, lessonId, activityId, + message = getMonitoringService().forceCompleteActivitiesByUser(learnerId, requesterId, lessonId, activityId, removeLearnerContent); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); @@ -669,7 +652,7 @@ // audit log force completion attempt String messageKey = (activityId == null) ? "audit.force.complete.end.lesson" : "audit.force.complete"; Object[] args = new Object[] { learnerId, activityId, lessonId }; - String auditMessage = monitoringService.getMessageService().getMessage(messageKey, args); + String auditMessage = getMonitoringService().getMessageService().getMessage(messageKey, args); MonitoringAction.auditService.log(MonitoringConstants.MONITORING_MODULE_NAME, auditMessage + " " + message); PrintWriter writer = response.getWriter(); @@ -680,13 +663,11 @@ public ActionForward getLessonLearners(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { String wddxPacket; - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); try { Long lessonID = new Long(WebUtil.readLongParam(request, "lessonID")); - wddxPacket = monitoringService.getLessonLearners(lessonID, getUserId()); + wddxPacket = getMonitoringService().getLessonLearners(lessonID, getUserId()); } catch (Exception e) { - wddxPacket = handleException(e, "getLessonLearners", monitoringService).serializeMessage(); + wddxPacket = handleException(e, "getLessonLearners").serializeMessage(); } PrintWriter writer = response.getWriter(); writer.println(wddxPacket); @@ -744,6 +725,47 @@ } /** + * Gets users in JSON format who are at the given activity at the moment or finished the given lesson. + */ + public ActionForward getCurrentLearners(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, JSONException { + JSONArray responseJSON = new JSONArray(); + // if activity ID is provided, lesson ID is ignored + Long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID, true); + if (activityId == null) { + long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); + List learners = getMonitoringService().getUsersCompletedLesson(lessonId); + for (User learner : learners) { + responseJSON.put(WebUtil.userToJSON(learner)); + } + } else { + boolean flaFormat = WebUtil.readBooleanParam(request, "flaFormat", true); + Activity activity = getMonitoringService().getActivityById(activityId); + Set activities = new TreeSet(); + activities.add(activityId); + + // for the Flash format of LD SVGs, children activities are hidden + // and the parent activity shows all learners + if (!flaFormat && (activity.isBranchingActivity() || activity.isOptionsWithSequencesActivity())) { + Set descendants = getDescendants((ComplexActivity) activity); + for (Activity descendat : descendants) { + activities.add(descendat.getActivityId()); + } + } + + List learners = getMonitoringService().getLearnersByActivities(activities.toArray(new Long[] {}), + null, null); + for (User learner : learners) { + responseJSON.put(WebUtil.userToJSON(learner)); + } + } + + response.setContentType("application/json;charset=utf-8"); + response.getWriter().write(responseJSON.toString()); + return null; + } + + /** * Adds/removes learners and monitors to/from lesson class. */ public ActionForward updateLessonClass(ActionMapping mapping, ActionForm form, HttpServletRequest request, @@ -777,13 +799,11 @@ public ActionForward getLessonStaff(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { String wddxPacket; - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); try { Long lessonID = new Long(WebUtil.readLongParam(request, "lessonID")); - wddxPacket = monitoringService.getLessonStaff(lessonID, getUserId()); + wddxPacket = getMonitoringService().getLessonStaff(lessonID, getUserId()); } catch (Exception e) { - wddxPacket = handleException(e, "getLessonStaff", monitoringService).serializeMessage(); + wddxPacket = handleException(e, "getLessonStaff").serializeMessage(); } PrintWriter writer = response.getWriter(); writer.println(wddxPacket); @@ -793,14 +813,12 @@ public ActionForward getLearningDesignDetails(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { String wddxPacket; - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); try { Long lessonID = new Long(WebUtil.readLongParam(request, "lessonID")); getSecurityService().isLessonMonitor(lessonID, getUserId(), "get learning design details", true); - wddxPacket = monitoringService.getLearningDesignDetails(lessonID); + wddxPacket = getMonitoringService().getLearningDesignDetails(lessonID); } catch (Exception e) { - wddxPacket = handleException(e, "getLearningDesignDetails", monitoringService).serializeMessage(); + wddxPacket = handleException(e, "getLearningDesignDetails").serializeMessage(); } PrintWriter writer = response.getWriter(); writer.println(wddxPacket); @@ -810,9 +828,7 @@ public ActionForward getDictionaryXML(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); - MessageService messageService = monitoringService.getMessageService(); + MessageService messageService = getMonitoringService().getMessageService(); String module = WebUtil.readStrParam(request, "module", false); @@ -866,13 +882,11 @@ public ActionForward getLearnerActivityURL(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, LamsToolServiceException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); Integer learnerUserID = new Integer(WebUtil.readIntParam(request, AttributeNames.PARAM_USER_ID)); Long activityID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID)); Long lessonID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID)); try { - String url = monitoringService.getLearnerActivityURL(lessonID, activityID, learnerUserID, getUserId()); + String url = getMonitoringService().getLearnerActivityURL(lessonID, activityID, learnerUserID, getUserId()); return redirectToURL(mapping, response, url); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); @@ -883,13 +897,12 @@ /** Calls the server to bring up the activity's monitoring page. Assumes destination is a new window */ public ActionForward getActivityMonitorURL(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, LamsToolServiceException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); Long activityID = new Long(WebUtil.readLongParam(request, "activityID")); Long lessonID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID)); String contentFolderID = WebUtil.readStrParam(request, "contentFolderID"); try { - String url = monitoringService.getActivityMonitorURL(lessonID, activityID, contentFolderID, getUserId()); + String url = getMonitoringService().getActivityMonitorURL(lessonID, activityID, contentFolderID, + getUserId()); return redirectToURL(mapping, response, url); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); @@ -899,16 +912,14 @@ public ActionForward moveLesson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); String wddxPacket = null; try { Long lessonID = new Long(WebUtil.readLongParam(request, "lessonID")); Integer userID = getUserId(); Integer targetWorkspaceFolderID = new Integer(WebUtil.readIntParam(request, "folderID")); - wddxPacket = monitoringService.moveLesson(lessonID, targetWorkspaceFolderID, userID); + wddxPacket = getMonitoringService().moveLesson(lessonID, targetWorkspaceFolderID, userID); } catch (Exception e) { - FlashMessage flashMessage = handleException(e, "moveLesson", monitoringService); + FlashMessage flashMessage = handleException(e, "moveLesson"); wddxPacket = flashMessage.serializeMessage(); } PrintWriter writer = response.getWriter(); @@ -1040,14 +1051,14 @@ JSONObject responseJSON = new JSONObject(); Lesson lesson = getLessonService().getLesson(lessonId); - LessonDetailsDTO lessonDetails = lesson.getLessonDetails(); - String contentFolderId = lessonDetails.getContentFolderID(); + LearningDesign learningDesign = lesson.getLearningDesign(); + String contentFolderId = learningDesign.getContentFolderID(); Locale userLocale = new Locale(user.getLocaleLanguage(), user.getLocaleCountry()); - responseJSON.put(AttributeNames.PARAM_LEARNINGDESIGN_ID, lessonDetails.getLearningDesignID()); - responseJSON.put("numberPossibleLearners", lessonDetails.getNumberPossibleLearners()); - responseJSON.put("lessonStateID", lessonDetails.getLessonStateID()); + responseJSON.put(AttributeNames.PARAM_LEARNINGDESIGN_ID, learningDesign.getLearningDesignId()); + responseJSON.put("numberPossibleLearners", getLessonService().getCountLessonLearners(lessonId)); + responseJSON.put("lessonStateID", lesson.getLessonStateId()); Date startOrScheduleDate = lesson.getStartDateTime() == null ? lesson.getScheduleStartDate() : lesson.getStartDateTime(); @@ -1084,206 +1095,202 @@ Long branchingActivityId = WebUtil.readLongParam(request, "branchingActivityID", true); Lesson lesson = getLessonService().getLesson(lessonId); - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); - LessonDetailsDTO lessonDetails = lesson.getLessonDetails(); - String contentFolderId = lessonDetails.getContentFolderID(); - - // few details for each activity - Map activitiesMap = new TreeMap(); LearningDesign learningDesign = lesson.getLearningDesign(); + String contentFolderId = learningDesign.getContentFolderID(); + + // find out if the LD SVG is in new Flashless (exploded) format + JSONObject responseJSON = new JSONObject(); + boolean flaFormat = false; for (Activity activity : (Set) learningDesign.getActivities()) { - if ((branchingActivityId == null) || MonitoringAction.isBranchingChild(branchingActivityId, activity)) { - Long activityId = activity.getActivityId(); - JSONObject activityJSON = new JSONObject(); - activityJSON.put("id", activityId); - activityJSON.put("uiid", activity.getActivityUIID()); - activityJSON.put("title", activity.getTitle()); + if ((activity.isBranchingActivity() || activity.isOptionsWithSequencesActivity()) + && (((ComplexActivity) activity).getXcoord() == null)) { + // if a single activity is in FLA format, all of them are + flaFormat = true; + break; + } + } + responseJSON.put("flaFormat", flaFormat); - int activityType = activity.getActivityTypeId(); - activityJSON.put("type", activityType); - Activity parentActivity = activity.getParentActivity(); - if (activity.isBranchingActivity() && (((BranchingActivity) activity).getXcoord() == null)) { - // old branching is just a rectangle like Tool - // new branching has start and finish points, it's exploded - activityJSON.put("flaFormat", true); - activityJSON.put("x", - MonitoringAction.getActivityCoordinate(((BranchingActivity) activity).getStartXcoord())); - activityJSON.put("y", - MonitoringAction.getActivityCoordinate(((BranchingActivity) activity).getStartYcoord())); - } else if (activity.isOptionsWithSequencesActivity() - && (((OptionsWithSequencesActivity) activity).getXcoord() == null)) { - // old optional sequences is just a long rectangle - // new optional sequences has start and finish points, it's exploded - activityJSON.put("flaFormat", true); - activityJSON.put("x", MonitoringAction - .getActivityCoordinate(((OptionsWithSequencesActivity) activity).getStartXcoord())); - activityJSON.put("y", MonitoringAction - .getActivityCoordinate(((OptionsWithSequencesActivity) activity).getStartYcoord())); - } else if ((parentActivity != null) - && ((Activity.OPTIONS_ACTIVITY_TYPE == parentActivity.getActivityTypeId()) - || (Activity.PARALLEL_ACTIVITY_TYPE == parentActivity.getActivityTypeId()) - || (Activity.FLOATING_ACTIVITY_TYPE == parentActivity.getActivityTypeId()))) { - // Optional Activity children had coordinates relative to parent - activityJSON.put("x", MonitoringAction.getActivityCoordinate(parentActivity.getXcoord()) - + MonitoringAction.getActivityCoordinate(activity.getXcoord())); - activityJSON.put("y", MonitoringAction.getActivityCoordinate(parentActivity.getYcoord()) - + MonitoringAction.getActivityCoordinate(activity.getYcoord())); - } else { - activityJSON.put("x", MonitoringAction.getActivityCoordinate(activity.getXcoord())); - activityJSON.put("y", MonitoringAction.getActivityCoordinate(activity.getYcoord())); - } + Set activities = new HashSet(); + List contributeActivities = getContributeActivities(lessonId, true); + Map> parentToChildren = new TreeMap>(); + // filter activities that are interesting for further processing + for (Activity activity : (Set) learningDesign.getActivities()) { + if (activity.isSequenceActivity()) { + // skip sequence activities as they are just for grouping + continue; + } - String monitorUrl = monitoringService.getActivityMonitorURL(lessonId, activityId, contentFolderId, - monitorUserId); - if (monitorUrl != null) { - // whole activity monitor URL - activityJSON.put("url", monitorUrl); - } + if (flaFormat) { + // in FLA format everything is exploded so there are no hidden child activities + activities.add(activity); + continue; + } - activitiesMap.put(activityId, activityJSON); + Activity parentActivity = activity.getParentActivity(); + Activity parentParentActivity = parentActivity == null ? null : parentActivity.getParentActivity(); + if (parentParentActivity == null) { + activities.add(activity); + continue; } - } - JSONObject responseJSON = new JSONObject(); - for (LearnerProgress learnerProgress : (Set) lesson.getLearnerProgresses()) { - User learner = learnerProgress.getUser(); - if (learnerProgress.isComplete()) { - JSONObject learnerJSON = WebUtil.userToJSON(learner); - // no more details are needed for learners who completed the lesson - responseJSON.append("completedLearners", learnerJSON); + if (!parentParentActivity.isOptionsWithSequencesActivity() && (!parentParentActivity.isBranchingActivity() + || parentParentActivity.getActivityId().equals(branchingActivityId))) { + activities.add(activity); } else { - Activity currentActivity = learnerProgress.getCurrentActivity(); - if ((currentActivity != null) && ((branchingActivityId == null) - || MonitoringAction.isBranchingChild(branchingActivityId, currentActivity))) { - JSONObject learnerJSON = WebUtil.userToJSON(learner); + // branching and options with sequences in Flash format have hidden activities + // map the children to their parent for further processing + Set children = parentToChildren.get(parentParentActivity.getActivityId()); + if (children == null) { + children = new HashSet(); + parentToChildren.put(parentParentActivity.getActivityId(), children); + } + children.add(activity); - // assign learners to child activity or parent branching/options with sequences? - Activity parentActivity = currentActivity.getParentActivity(); - Long targetActivityId = (branchingActivityId != null) || (parentActivity == null) - || (parentActivity.getParentActivity() == null) - || !(parentActivity.getParentActivity().isBranchingActivity() - || parentActivity.getParentActivity().isOptionsWithSequencesActivity()) - ? currentActivity.getActivityId() - : parentActivity.getParentActivity().getActivityId(); - - JSONObject targetActivityJSON = activitiesMap.get(targetActivityId); - if (Boolean.TRUE.equals(JsonUtil.opt(targetActivityJSON, "flaFormat"))) { - // for new format, we always set learners to child activity, not parent - targetActivityJSON = activitiesMap.get(currentActivity.getActivityId()); + // skip hidden contribute activities + if (contributeActivities != null) { + Iterator contributeActivityIterator = contributeActivities.iterator(); + while (contributeActivityIterator.hasNext()) { + if (activity.getActivityId().equals(contributeActivityIterator.next().getActivityID())) { + contributeActivityIterator.remove(); + } } - targetActivityJSON.append("learners", learnerJSON); } } } - responseJSON.put("activities", new JSONArray(activitiesMap.values())); - responseJSON.put("numberPossibleLearners", lessonDetails.getNumberPossibleLearners()); - - List contributeActivities = getContributeActivities(lessonId, true); - // remove "attention required" marker for hidden activities in Flash Authoring if (contributeActivities != null) { - Iterator activityIterator = contributeActivities.iterator(); - while (activityIterator.hasNext()) { - ContributeActivityDTO contributeActivityDTO = activityIterator.next(); - Activity contributeActivity = monitoringService.getActivityById(contributeActivityDTO.getActivityID()); - Activity topParentActivity = contributeActivity.getParentActivity() == null ? null - : contributeActivity.getParentActivity().getParentActivity(); - - if ((branchingActivityId == null) && (topParentActivity != null) - && (topParentActivity.isBranchingActivity() - || topParentActivity.isOptionsWithSequencesActivity())) { - JSONObject topContributeActivityJSON = activitiesMap.get(topParentActivity.getActivityId()); - if (!Boolean.TRUE.equals(JsonUtil.opt(topContributeActivityJSON, "flaFormat"))) { - activityIterator.remove(); - } - } - } Gson gson = new GsonBuilder().create(); responseJSON.put("contributeActivities", new JSONArray(gson.toJson(contributeActivities))); } - response.setContentType("application/json;charset=utf-8"); - response.getWriter().write(responseJSON.toString()); + JSONArray activitiesJSON = new JSONArray(); + for (Activity activity : activities) { + Long activityId = activity.getActivityId(); + JSONObject activityJSON = new JSONObject(); + activityJSON.put("id", activityId); + activityJSON.put("uiid", activity.getActivityUIID()); + activityJSON.put("title", activity.getTitle()); + activityJSON.put("type", activity.getActivityTypeId()); - return null; - } + Activity parentActivity = activity.getParentActivity(); + if (activity.isBranchingActivity() && (((BranchingActivity) activity).getXcoord() == null)) { + // old branching is just a rectangle like Tool + // new branching has start and finish points, it's exploded + activityJSON.put("x", + MonitoringAction.getActivityCoordinate(((BranchingActivity) activity).getStartXcoord())); + activityJSON.put("y", + MonitoringAction.getActivityCoordinate(((BranchingActivity) activity).getStartYcoord())); + } else if (activity.isOptionsWithSequencesActivity() + && (((OptionsWithSequencesActivity) activity).getXcoord() == null)) { + // old optional sequences is just a long rectangle + // new optional sequences has start and finish points, it's exploded + activityJSON.put("x", MonitoringAction + .getActivityCoordinate(((OptionsWithSequencesActivity) activity).getStartXcoord())); + activityJSON.put("y", MonitoringAction + .getActivityCoordinate(((OptionsWithSequencesActivity) activity).getStartYcoord())); + } else if ((parentActivity != null) && (parentActivity.isOptionsActivity() + || parentActivity.isParallelActivity() || parentActivity.isFloatingActivity())) { + // Optional Activity children had coordinates relative to parent + activityJSON.put("x", MonitoringAction.getActivityCoordinate(parentActivity.getXcoord()) + + MonitoringAction.getActivityCoordinate(activity.getXcoord())); + activityJSON.put("y", MonitoringAction.getActivityCoordinate(parentActivity.getYcoord()) + + MonitoringAction.getActivityCoordinate(activity.getYcoord())); + } else { + activityJSON.put("x", MonitoringAction.getActivityCoordinate(activity.getXcoord())); + activityJSON.put("y", MonitoringAction.getActivityCoordinate(activity.getYcoord())); + } - /** - * Checks if activity A is before activity B in a sequence. - */ - public ActionForward isActivityPreceding(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws Exception { - long activityAid = WebUtil.readLongParam(request, "activityA"); - long activityBid = WebUtil.readLongParam(request, "activityB"); - boolean result = false; + String monitorUrl = getMonitoringService().getActivityMonitorURL(lessonId, activityId, contentFolderId, + monitorUserId); + if (monitorUrl != null) { + // whole activity monitor URL + activityJSON.put("url", monitorUrl); + } - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); - Activity precedingActivity = monitoringService.getActivityById(activityBid); - - // move back an look for activity A - while (!result && (precedingActivity != null)) { - if (precedingActivity.getTransitionTo() != null) { - precedingActivity = precedingActivity.getTransitionTo().getFromActivity(); - } else if (precedingActivity.getParentActivity() != null) { - // this is a nested activity; move up - precedingActivity = precedingActivity.getParentActivity(); - continue; + // find few latest users and count of all users for each activity + int learnerCount = 0; + if (activity.isBranchingActivity() || activity.isOptionsWithSequencesActivity()) { + // go through hidden children of complex activities and take them into account + learnerCount += getMonitoringService().getCountLearnersCurrentActivity(activity); + Set children = parentToChildren.get(activityId); + if (children != null) { + for (Activity child : children) { + learnerCount += getMonitoringService().getCountLearnersCurrentActivity(child); + } + } } else { - precedingActivity = null; - } + List latestLearners = getMonitoringService().getLearnersLatestByActivity(activity.getActivityId(), + MonitoringAction.LATEST_LEARNER_PROGRESS_ACTIVITY_DISPLAY_LIMIT, null); + if (latestLearners.size() < MonitoringAction.LATEST_LEARNER_PROGRESS_ACTIVITY_DISPLAY_LIMIT) { + // if there are less learners than the limit, we already know the size + learnerCount = latestLearners.size(); + } else { + learnerCount = getMonitoringService().getCountLearnersCurrentActivity(activity); + } - if ((precedingActivity != null) && !precedingActivity.isSequenceActivity()) { - if (precedingActivity.getActivityId().equals(activityAid)) { - // found it - result = true; - } else if (precedingActivity.isComplexActivity()) { - // check descendants of a complex activity - ComplexActivity complexActivity = (ComplexActivity) monitoringService - .getActivityById(precedingActivity.getActivityId()); - if (containsActivity(complexActivity, activityAid, monitoringService)) { - result = true; + // parse learners into JSON format + if (!latestLearners.isEmpty()) { + JSONArray learnersJSON = new JSONArray(); + for (User learner : latestLearners) { + learnersJSON.put(WebUtil.userToJSON(learner)); } + + activityJSON.put("learners", learnersJSON); } } + activityJSON.put("learnerCount", learnerCount); + + activitiesJSON.put(activityJSON); } + responseJSON.put("activities", activitiesJSON); - response.setContentType("text/plain;charset=utf-8"); - response.getWriter().write(Boolean.toString(result)); - return null; - } + // find learners who completed the lesson + List completedLearners = getMonitoringService().getLearnersLatestCompleted(lessonId, + MonitoringAction.LATEST_LEARNER_PROGRESS_LESSON_DISPLAY_LIMIT, null); + for (User learner : completedLearners) { + JSONObject learnerJSON = WebUtil.userToJSON(learner); + // no more details are needed for learners who completed the lesson + responseJSON.append("completedLearners", learnerJSON); + } + Integer completedLearnerCount = null; + if (completedLearners.size() < MonitoringAction.LATEST_LEARNER_PROGRESS_LESSON_DISPLAY_LIMIT) { + completedLearnerCount = completedLearners.size(); + } else { + completedLearnerCount = getMonitoringService().getCountLearnersCompletedLesson(lessonId); + } + responseJSON.put("completedLearnerCount", completedLearnerCount); + responseJSON.put("numberPossibleLearners", getLessonService().getCountLessonLearners(lessonId)); - /** - * Checks if a complex activity or its descendats contain an activity with the given ID. - */ - private boolean containsActivity(ComplexActivity complexActivity, long targetActivityId, - IMonitoringService monitoringService) { - for (Activity childActivity : (Set) complexActivity.getActivities()) { - if (childActivity.getActivityId().equals(targetActivityId)) { - return true; + // on first fetch get transitions metadata so Monitoring can set their SVG elems IDs + if (WebUtil.readBooleanParam(request, "getTransitions", false)) { + JSONArray transitions = new JSONArray(); + for (Transition transition : (Set) learningDesign.getTransitions()) { + JSONObject transitionJSON = new JSONObject(); + transitionJSON.put("uiid", transition.getTransitionUIID()); + transitionJSON.put("fromID", transition.getFromActivity().getActivityId()); + transitionJSON.put("toID", transition.getToActivity().getActivityId()); + + transitions.put(transitionJSON); } - if (childActivity.isComplexActivity()) { - ComplexActivity childComplexActivity = (ComplexActivity) monitoringService - .getActivityById(childActivity.getActivityId()); - if (containsActivity(childComplexActivity, targetActivityId, monitoringService)) { - return true; - } - } + responseJSON.put("transitions", transitions); } - return false; + + response.setContentType("application/json;charset=utf-8"); + response.getWriter().write(responseJSON.toString()); + + return null; + } public ActionForward releaseGate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); String wddxPacket = null; try { Long activityID = new Long(WebUtil.readLongParam(request, "activityID")); - wddxPacket = monitoringService.releaseGate(activityID); + wddxPacket = getMonitoringService().releaseGate(activityID); } catch (Exception e) { - FlashMessage flashMessage = handleException(e, "releaseGate", monitoringService); + FlashMessage flashMessage = handleException(e, "releaseGate"); wddxPacket = flashMessage.serializeMessage(); } PrintWriter writer = response.getWriter(); @@ -1293,8 +1300,6 @@ public ActionForward startPreviewLesson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); FlashMessage flashMessage = null; try { @@ -1308,16 +1313,16 @@ */ try { - monitoringService.createPreviewClassForLesson(userID, lessonID); - monitoringService.startLesson(lessonID, getUserId()); + getMonitoringService().createPreviewClassForLesson(userID, lessonID); + getMonitoringService().startLesson(lessonID, getUserId()); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the lesson"); return null; } flashMessage = new FlashMessage("startPreviewSession", new Long(lessonID)); } catch (Exception e) { - flashMessage = handleException(e, "startPreviewSession", monitoringService); + flashMessage = handleException(e, "startPreviewSession"); } PrintWriter writer = response.getWriter(); @@ -1379,6 +1384,15 @@ return MonitoringAction.lessonService; } + private IMonitoringService getMonitoringService() { + if (MonitoringAction.monitoringService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + MonitoringAction.monitoringService = (IMonitoringService) ctx.getBean("monitoringService"); + } + return MonitoringAction.monitoringService; + } + private ISecurityService getSecurityService() { if (MonitoringAction.securityService == null) { WebApplicationContext ctx = WebApplicationContextUtils @@ -1394,13 +1408,11 @@ */ public ActionForward learnerExportPortfolioAvailable(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); Long lessonID = new Long(WebUtil.readLongParam(request, "lessonID")); Integer userID = getUserId(); Boolean learnerExportPortfolioAvailable = WebUtil.readBooleanParam(request, "learnerExportPortfolio", false); try { - monitoringService.setLearnerPortfolioAvailable(lessonID, userID, learnerExportPortfolioAvailable); + getMonitoringService().setLearnerPortfolioAvailable(lessonID, userID, learnerExportPortfolioAvailable); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); } @@ -1413,18 +1425,16 @@ */ public ActionForward presenceAvailable(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); Long lessonID = new Long(WebUtil.readLongParam(request, "lessonID")); Integer userID = getUserId(); Boolean presenceAvailable = WebUtil.readBooleanParam(request, "presenceAvailable", false); try { - monitoringService.setPresenceAvailable(lessonID, userID, presenceAvailable); + getMonitoringService().setPresenceAvailable(lessonID, userID, presenceAvailable); if (!presenceAvailable) { - monitoringService.setPresenceImAvailable(lessonID, userID, false); + getMonitoringService().setPresenceImAvailable(lessonID, userID, false); } } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); @@ -1438,14 +1448,12 @@ */ public ActionForward presenceImAvailable(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); Long lessonID = new Long(WebUtil.readLongParam(request, "lessonID")); Integer userID = getUserId(); Boolean presenceImAvailable = WebUtil.readBooleanParam(request, "presenceImAvailable", false); try { - monitoringService.setPresenceImAvailable(lessonID, userID, presenceImAvailable); + getMonitoringService().setPresenceImAvailable(lessonID, userID, presenceImAvailable); } catch (SecurityException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); } @@ -1455,10 +1463,6 @@ /** Open Time Chart display */ public ActionForward viewTimeChart(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); - try { long lessonID = WebUtil.readLongParam(request, "lessonID"); @@ -1505,26 +1509,9 @@ return result; } - private static boolean isBranchingChild(Long branchingActivityId, Activity activity) { - if ((branchingActivityId == null) || (activity == null)) { - return false; - } - - Activity parentActivity = activity.getParentActivity(); - while (parentActivity != null) { - if (parentActivity.isBranchingActivity()) { - return parentActivity.getActivityId().equals(branchingActivityId); - } - parentActivity = parentActivity.getParentActivity(); - } - return false; - } - @SuppressWarnings("unchecked") private List getContributeActivities(Long lessonId, boolean skipCompletedBranching) { - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); - List contributeActivities = monitoringService.getAllContributeActivityDTO(lessonId); + List contributeActivities = getMonitoringService().getAllContributeActivityDTO(lessonId); Lesson lesson = getLessonService().getLesson(lessonId); if (contributeActivities != null) { @@ -1540,7 +1527,7 @@ if (skipCompletedBranching && ContributionTypes.CHOSEN_BRANCHING.equals(contributeEntry.getContributionType())) { Set learners = new HashSet(lesson.getLessonClass().getLearners()); - ChosenBranchingActivity branching = (ChosenBranchingActivity) monitoringService + ChosenBranchingActivity branching = (ChosenBranchingActivity) getMonitoringService() .getActivityById(contributeActivity.getActivityID()); for (SequenceActivity branch : (Set) branching.getActivities()) { Group group = branch.getSoleGroupForBranch(); @@ -1569,4 +1556,21 @@ private static int getActivityCoordinate(Integer coord) { return (coord == null) || (coord < 0) ? ObjectExtractor.DEFAULT_COORD : coord; } + + /** + * Gets all children and their childre etc. of the given complex activity. + */ + @SuppressWarnings("unchecked") + private Set getDescendants(ComplexActivity complexActivity) { + Set result = new HashSet(); + for (Activity child : (Set) complexActivity.getActivities()) { + child = getMonitoringService().getActivityById(child.getActivityId()); + if (child.isComplexActivity()) { + result.addAll(getDescendants((ComplexActivity) child)); + } else { + result.add(child); + } + } + return result; + } } \ No newline at end of file