Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/Lesson.hbm.xml =================================================================== diff -u -r95574f488cd396cd8e0e246a091a23dca4190e4f -rc85eeb30f32d1551d97688e0153f5c81839f03d3 --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/Lesson.hbm.xml (.../Lesson.hbm.xml) (revision 95574f488cd396cd8e0e246a091a23dca4190e4f) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/lesson/Lesson.hbm.xml (.../Lesson.hbm.xml) (revision c85eeb30f32d1551d97688e0153f5c81839f03d3) @@ -154,114 +154,33 @@ - - - SELECT DISTINCT {lesson.*} - FROM lams_lesson {lesson}, - lams_grouping, - lams_group, - lams_user_group, - lams_learning_design - WHERE ({lesson}.class_grouping_id = lams_grouping.grouping_id) - AND (lams_grouping.staff_group_id = lams_group.group_id) - AND (lams_group.group_id = lams_user_group.group_id) - AND NOT ({lesson}.lesson_state_id = 7) - AND (lams_user_group.user_id = :userId) - AND ({lesson}.learning_design_id = lams_learning_design.learning_design_id) - AND (lams_learning_design.copy_type_id=2) - - UNION - - SELECT DISTINCT {lesson.*} - FROM lams_lesson {lesson} - WHERE ({lesson}.user_id = :userId) - AND ({lesson}.class_grouping_id IS NULL) - AND NOT ({lesson}.lesson_state_id = 7) - - SELECT DISTINCT {user.*} - FROM lams_lesson, - lams_grouping, - lams_group, - lams_user_group, - lams_learning_design, - lams_tool_session, - lams_user {user} - WHERE (lams_lesson.class_grouping_id = lams_grouping.grouping_id) - AND (lams_grouping.staff_group_id = lams_group.group_id) - AND (lams_group.group_id = lams_user_group.group_id) - AND ({user}.user_id = lams_user_group.user_id) - AND (lams_tool_session.tool_session_id = :sessionId) - AND (lams_tool_session.lesson_id = lams_lesson.lesson_id) - AND (lams_lesson.learning_design_id = lams_learning_design.learning_design_id) - AND (lams_learning_design.copy_type_id=2) + FROM lams_lesson AS l + JOIN lams_grouping AS ging ON l.class_grouping_id = ging.grouping_id + JOIN lams_group AS g ON ging.staff_group_id = g.group_id + JOIN lams_user_group AS ug ON g.group_id = ug.group_id + JOIN lams_user AS {user} ON {user}.user_id = ug.user_id + JOIN lams_learning_design AS ld ON ld.copy_type_id = 2 + AND l.learning_design_id = ld.learning_design_id + JOIN lams_tool_session AS s ON s.tool_session_id = :sessionId + AND s.lesson_id = l.lesson_id - - - SELECT DISTINCT {lesson.*} - FROM lams_lesson {lesson}, - lams_grouping, - lams_group, - lams_user_group, - lams_learning_design - WHERE ({lesson}.class_grouping_id = lams_grouping.grouping_id) - AND (lams_grouping.staff_group_id = lams_group.group_id) - AND (lams_group.group_id = lams_user_group.group_id) - AND NOT ({lesson}.lesson_state_id = 7) - AND (lams_user_group.user_id = :userId) - AND ({lesson}.learning_design_id = lams_learning_design.learning_design_id) - AND (lams_learning_design.copy_type_id=2) - AND ({lesson}.organisation_id = :organisationId) - - - - - SELECT DISTINCT {lesson.*} - FROM lams_lesson {lesson}, - lams_grouping, - lams_group, - lams_user_group, - lams_learning_design - WHERE ({lesson}.class_grouping_id = lams_grouping.grouping_id) - AND (lams_grouping.grouping_id = lams_group.grouping_id) - AND (lams_group.group_id = lams_user_group.group_id) - AND ({lesson}.lesson_state_id IN (3,5)) - AND (lams_user_group.user_id = :userId) - AND ({lesson}.learning_design_id = lams_learning_design.learning_design_id) - AND (lams_learning_design.copy_type_id=2) - AND (lams_group.group_id != lams_grouping.staff_group_id) - AND ({lesson}.organisation_id = :organisationId) - - SELECT DISTINCT {lesson.*} - FROM lams_lesson {lesson}, - lams_grouping, - lams_group, - lams_user_group, - lams_learning_design - WHERE ({lesson}.class_grouping_id = lams_grouping.grouping_id) - AND (lams_grouping.grouping_id = lams_group.grouping_id) - AND (lams_group.group_id = lams_user_group.group_id) - AND ({lesson}.lesson_state_id IN (3,5)) - AND (lams_user_group.user_id = :userId) - AND ({lesson}.learning_design_id = lams_learning_design.learning_design_id) - AND (lams_learning_design.copy_type_id=2) - AND (lams_group.group_id != lams_grouping.staff_group_id) + FROM lams_lesson AS {lesson} + JOIN lams_learning_design AS ld ON ld.copy_type_id = 2 + AND {lesson}.learning_design_id = ld.learning_design_id + JOIN lams_grouping AS ging ON {lesson}.lesson_state_id IN (3,5) + AND {lesson}.class_grouping_id = ging.grouping_id + JOIN lams_group AS g ON ging.grouping_id = g.grouping_id + AND g.group_id != ging.staff_group_id + JOIN lams_user_group AS ug ON ug.user_id = :userId + AND g.group_id = ug.group_id - - - - SELECT DISTINCT {learner.*} - FROM lams_user {learner}, - lams_learner_progress - WHERE ({learner}.user_id = lams_learner_progress.user_id) - AND (lams_learner_progress.lesson_id = :lessonId) - @@ -275,17 +194,18 @@ SELECT l.lesson_id, l.name, l.description, l.lesson_state_id, lp.lesson_completed_flag, l.enable_lesson_notifications, (SELECT TRUE FROM lams_lesson_dependency ld WHERE ld.lesson_id = l.lesson_id LIMIT 1) AS dependent, l.schedule_end_date_time IS NOT NULL OR l.scheduled_number_days_to_lesson_finish IS NOT NULL AS scheduledFinish - FROM (lams_lesson l, lams_learning_design ld, lams_group g, lams_user_group ug, lams_grouping gi) - LEFT JOIN lams_learner_progress lp ON lp.user_id = ug.user_id AND lp.lesson_id = l.lesson_id - WHERE l.learning_design_id = ld.learning_design_id - AND ld.copy_type_id != 3 - AND l.organisation_id = :orgId - AND l.class_grouping_id = g.grouping_id - AND l.lesson_state_id != 7 - AND ug.group_id = g.group_id - AND ug.user_id = :userId - AND gi.grouping_id = g.grouping_id - AND g.group_id != gi.staff_group_id + FROM lams_lesson AS l + JOIN lams_learning_design AS ld ON l.organisation_id = :orgId + AND ld.copy_type_id != 3 + AND l.lesson_state_id != 7 + AND l.learning_design_id = ld.learning_design_id + JOIN lams_group AS g ON l.class_grouping_id = g.grouping_id + JOIN lams_user_group AS ug ON ug.user_id = :userId + AND ug.group_id = g.group_id + JOIN lams_grouping AS gi ON gi.grouping_id = g.grouping_id + AND g.group_id != gi.staff_group_id + LEFT JOIN lams_learner_progress AS lp ON lp.user_id = ug.user_id + AND lp.lesson_id = l.lesson_id @@ -300,17 +220,18 @@ SELECT l.lesson_id, l.name, l.description, l.lesson_state_id, lp.lesson_completed_flag, l.enable_lesson_notifications, (SELECT TRUE FROM lams_lesson_dependency ld WHERE ld.lesson_id = l.lesson_id LIMIT 1) AS dependent, l.schedule_end_date_time IS NOT NULL OR l.scheduled_number_days_to_lesson_finish IS NOT NULL AS scheduledFinish - FROM (lams_lesson l, lams_learning_design ld, lams_group g, lams_user_group ug, lams_grouping gi) - LEFT JOIN lams_learner_progress lp ON lp.user_id = ug.user_id AND lp.lesson_id = l.lesson_id - WHERE l.learning_design_id = ld.learning_design_id - AND ld.copy_type_id != 3 - AND l.organisation_id = :orgId - AND l.class_grouping_id = g.grouping_id - AND l.lesson_state_id != 7 - AND ug.group_id = g.group_id - AND ug.user_id = :userId - AND gi.grouping_id = g.grouping_id - AND g.group_id = gi.staff_group_id + FROM lams_lesson AS l + JOIN lams_learning_design AS ld ON l.organisation_id = :orgId + AND ld.copy_type_id != 3 + AND l.lesson_state_id != 7 + AND l.learning_design_id = ld.learning_design_id + JOIN lams_group AS g ON l.class_grouping_id = g.grouping_id + JOIN lams_user_group AS ug ON ug.user_id = :userId + AND ug.group_id = g.group_id + JOIN lams_grouping AS gi ON gi.grouping_id = g.grouping_id + AND g.group_id = gi.staff_group_id + LEFT JOIN lams_learner_progress AS lp ON lp.user_id = ug.user_id + AND lp.lesson_id = l.lesson_id @@ -325,26 +246,27 @@ SELECT l.lesson_id, l.name, l.description, l.lesson_state_id, lp.lesson_completed_flag, l.enable_lesson_notifications, (SELECT TRUE FROM lams_lesson_dependency ld WHERE ld.lesson_id = l.lesson_id LIMIT 1) AS dependent, l.schedule_end_date_time IS NOT NULL OR l.scheduled_number_days_to_lesson_finish IS NOT NULL AS scheduledFinish - FROM (lams_lesson l, lams_learning_design ld) - LEFT JOIN lams_learner_progress lp ON lp.user_id = :userId AND lp.lesson_id = l.lesson_id - WHERE l.learning_design_id = ld.learning_design_id - AND ld.copy_type_id != 3 - AND l.organisation_id = :orgId - AND l.lesson_state_id != 7 + FROM lams_lesson AS l + JOIN lams_learning_design AS ld ON ld.copy_type_id != 3 + AND l.lesson_state_id != 7 + AND l.organisation_id = :orgId + AND l.learning_design_id = ld.learning_design_id + LEFT JOIN lams_learner_progress lp ON lp.user_id = :userId + AND lp.lesson_id = l.lesson_id SELECT DISTINCT {lesson.*} - FROM (lams_lesson {lesson}, lams_learning_design ld, lams_group g, lams_user_group ug, lams_organisation lo) - WHERE {lesson}.learning_design_id = ld.learning_design_id - AND ld.copy_type_id != 3 - AND ({lesson}.organisation_id = lo.organisation_id) - AND (lo.organisation_id = :orgId or lo.parent_organisation_id = :orgId) - AND {lesson}.class_grouping_id = g.grouping_id - AND {lesson}.lesson_state_id != 7 - AND ug.group_id = g.group_id - AND ug.user_id = :userId + FROM lams_lesson AS {lesson} + JOIN lams_learning_design AS ld ON ld.copy_type_id != 3 + AND {lesson}.lesson_state_id != 7 + AND {lesson}.learning_design_id = ld.learning_design_id + JOIN lams_organisation AS lo ON {lesson}.organisation_id = lo.organisation_id + AND (lo.organisation_id = :orgId OR lo.parent_organisation_id = :orgId) + JOIN lams_group AS g ON {lesson}.class_grouping_id = g.grouping_id + JOIN lams_user_group AS ug ON ug.user_id = :userId + AND ug.group_id = g.group_id Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ChosenGrouper.java =================================================================== diff -u -rb25a6d2d1cebe3c69d4af018aa14198533a0d4c5 -rc85eeb30f32d1551d97688e0153f5c81839f03d3 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ChosenGrouper.java (.../ChosenGrouper.java) (revision b25a6d2d1cebe3c69d4af018aa14198533a0d4c5) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ChosenGrouper.java (.../ChosenGrouper.java) (revision c85eeb30f32d1551d97688e0153f5c81839f03d3) @@ -33,128 +33,137 @@ import org.lamsfoundation.lams.learningdesign.exception.GroupingException; import org.lamsfoundation.lams.usermanagement.User; - /** - * The chosen grouper algorithm implementation. It creates a new group for - * the learners that the teacher requested. + * The chosen grouper algorithm implementation. It creates a new group for the learners that the teacher requested. * * @author Jacky Fang - * @since 2005-3-24 + * @since 2005-3-24 * @version 1.1 * */ -public class ChosenGrouper extends Grouper implements Serializable -{ +public class ChosenGrouper extends Grouper implements Serializable { - private static final long serialVersionUID = -8498560084860150033L; - private static Logger log = Logger.getLogger(ChosenGrouper.class); + private static final long serialVersionUID = -8498560084860150033L; + private static Logger log = Logger.getLogger(ChosenGrouper.class); - /** - * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping,java.lang.String, org.lamsfoundation.lams.usermanagement.User) + /** + * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping,java.lang.String, + * org.lamsfoundation.lams.usermanagement.User) */ - public void doGrouping(Grouping chosenGrouping, String groupName, User learner) - { - //convert the single user into a list. - List learners = new ArrayList(); - learners.add(learner); - //delegate to do grouping for a list of learners. - doGrouping(chosenGrouping,groupName,learners); + @Override + public void doGrouping(Grouping chosenGrouping, String groupName, User learner) { + // convert the single user into a list. + List learners = new ArrayList(); + learners.add(learner); + // delegate to do grouping for a list of learners. + doGrouping(chosenGrouping, groupName, learners); } - + /** - * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping,java.lang.String, java.util.List) + * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping,java.lang.String, + * java.util.List) */ - public void doGrouping(Grouping chosenGrouping,String groupName, List learners) - { - Group selectedGroup = null; + @Override + public void doGrouping(Grouping chosenGrouping, String groupName, List learners) { + Group selectedGroup = null; - String trimmedName = groupName != null ? groupName.trim() : null; - if ( trimmedName == null || trimmedName.length() == 0 ) { - trimmedName = generateGroupName(chosenGrouping); - } else { - Iterator iter = chosenGrouping.getGroups().iterator(); - while (iter.hasNext() && selectedGroup==null) { - Group group = (Group) iter.next(); - if ( trimmedName.equals(group.getGroupName()) ) { - selectedGroup = group; - } - } - } - doGrouping(chosenGrouping, selectedGroup, trimmedName, learners); + String trimmedName = groupName != null ? groupName.trim() : null; + if ((trimmedName == null) || (trimmedName.length() == 0)) { + trimmedName = generateGroupName(chosenGrouping); + } else { + Iterator iter = chosenGrouping.getGroups().iterator(); + while (iter.hasNext() && (selectedGroup == null)) { + Group group = (Group) iter.next(); + if (trimmedName.equals(group.getGroupName())) { + selectedGroup = group; + } + } + } + doGrouping(chosenGrouping, selectedGroup, trimmedName, learners); } - /** - * @param chosenGrouping - * @return - */ - private String generateGroupName(Grouping chosenGrouping) { - String trimmedName; - String prefix = getPrefix(); - trimmedName = prefix+" "+System.currentTimeMillis(); - log.info("Chosen grouper for grouping "+chosenGrouping.toString()+" did not get a group name. Selecting default name of "+trimmedName); - return trimmedName; - } - /** - * @throws GroupingException - * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping,java.lang.Long, java.util.List) + * @param chosenGrouping + * @return */ - public void doGrouping(Grouping chosenGrouping,Long groupId, List learners) throws GroupingException - { - if ( groupId != null ) { - Iterator iter = chosenGrouping.getGroups().iterator(); - Group selectedGroup = null; - while (iter.hasNext() && selectedGroup==null) { - Group group = (Group) iter.next(); - if ( group.getGroupId().equals(groupId) ) { - selectedGroup = group; - } - } - if ( selectedGroup == null ) { - String error = "Tried to add users to group "+groupId+" but group cannot be found."; - log.error(error); - throw new GroupingException(error); - } - doGrouping(chosenGrouping, selectedGroup, null, learners); - } else { - String groupName = generateGroupName(chosenGrouping); - doGrouping(chosenGrouping, null, groupName, learners); - } + private String generateGroupName(Grouping chosenGrouping) { + String trimmedName; + String prefix = getPrefix(); + trimmedName = prefix + " " + System.currentTimeMillis(); + ChosenGrouper.log.info("Chosen grouper for grouping " + chosenGrouping.toString() + + " did not get a group name. Selecting default name of " + trimmedName); + return trimmedName; } - /** If the group exists add them to the group, otherwise creates a new group. If group is not supplied, then groupName must - * be supplied. - * @param chosenGrouping (Mandatory) - * @param group (Optional) - * @param groupName (Optional) - * @param learners (Mandatory) + /** + * @throws GroupingException + * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping,java.lang.Long, + * java.util.List) */ - private void doGrouping(Grouping chosenGrouping, Group group, String groupName, List learners) - { - if ( group != null ) { - group.getUsers().addAll(learners); - } else { - chosenGrouping.getGroups().add(Group.createLearnerGroup(chosenGrouping,groupName, - new HashSet(learners))); - } + @Override + public void doGrouping(Grouping chosenGrouping, Long groupId, List learners) throws GroupingException { + if (groupId != null) { + Iterator iter = chosenGrouping.getGroups().iterator(); + Group selectedGroup = null; + while (iter.hasNext() && (selectedGroup == null)) { + Group group = (Group) iter.next(); + if (group.getGroupId().equals(groupId)) { + selectedGroup = group; + } + } + if (selectedGroup == null) { + String error = "Tried to add users to group " + groupId + " but group cannot be found."; + ChosenGrouper.log.error(error); + throw new GroupingException(error); + } + doGrouping(chosenGrouping, selectedGroup, null, learners); + } else { + String groupName = generateGroupName(chosenGrouping); + doGrouping(chosenGrouping, null, groupName, learners); + } } - - /** Create an empty group for the given grouping. If the current number of groups = max number of - * groups then a grouping exception is thrown. + + /** + * If the group exists add them to the group, otherwise creates a new group. If group is not supplied, then + * groupName must be supplied. * - * @param grouping (mandatory) - * @param groupName (mandatory) + * @param chosenGrouping + * (Mandatory) + * @param group + * (Optional) + * @param groupName + * (Optional) + * @param learners + * (Mandatory) */ - public Group createGroup(Grouping grouping, String name) throws GroupingException - { - int currentSize = grouping.getGroups().size(); - if ( grouping.getMaxNumberOfGroups()!=null && currentSize == grouping.getMaxNumberOfGroups() ) { - String error = "Tried to add group "+name+" to grouping "+grouping+". Exceeded max number of groups - current size is "+currentSize; - log.error(error); - throw new GroupingException(error); - } - return super.createGroup(grouping, name); + private void doGrouping(Grouping chosenGrouping, Group group, String groupName, List learners) { + if (group != null) { + group.getUsers().addAll(learners); + } else { + chosenGrouping.getGroups().add(Group.createLearnerGroup(chosenGrouping, groupName, new HashSet(learners))); + } + } + /** + * Create an empty group for the given grouping. If the current number of groups = max number of groups then a + * grouping exception is thrown. + * + * @param grouping + * (mandatory) + * @param groupName + * (mandatory) + */ + @Override + public Group createGroup(Grouping grouping, String name) throws GroupingException { + int currentSize = grouping.getGroups().size(); + if ((grouping.getMaxNumberOfGroups() != null) && (currentSize == grouping.getMaxNumberOfGroups())) { + String error = "Tried to add group " + name + " to grouping " + grouping + + ". Exceeded max number of groups - current size is " + currentSize; + ChosenGrouper.log.error(error); + throw new GroupingException(error); } + return super.createGroup(grouping, name); + } + } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/Grouper.java =================================================================== diff -u -rb25a6d2d1cebe3c69d4af018aa14198533a0d4c5 -rc85eeb30f32d1551d97688e0153f5c81839f03d3 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/Grouper.java (.../Grouper.java) (revision b25a6d2d1cebe3c69d4af018aa14198533a0d4c5) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/Grouper.java (.../Grouper.java) (revision c85eeb30f32d1551d97688e0153f5c81839f03d3) @@ -33,210 +33,234 @@ import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.util.MessageService; - - - /** - * This is interface that defines the contract for performing grouping - * algorithm. + * This is interface that defines the contract for performing grouping algorithm. * - * It would be nicer to get the message service directly from within the classes, rather than have a setter. - * But can't think of a way to directly access it when the grouper object doesn't - * have any link to the Spring context. (Fiona Malikoff) + * It would be nicer to get the message service directly from within the classes, rather than have a setter. But can't + * think of a way to directly access it when the grouper object doesn't have any link to the Spring context. (Fiona + * Malikoff) * * @author Jacky Fang - * @since 2005-3-24 + * @since 2005-3-24 * @version 1.1 * */ -public abstract class Grouper -{ - - private static Logger log = Logger.getLogger(Grouper.class); +public abstract class Grouper { - String DEFAULT_GROUP_NAME_PREFIX_I18N = "group.name.prefix"; - private MessageService commonMessageService; + private static Logger log = Logger.getLogger(Grouper.class); - /** Set the message service, needed for the I18N of the default group name prefix. - * Should call this method before calling doGrouping() or getPrefix() */ - public void setCommonMessageService(MessageService commonMessageService) { - this.commonMessageService = commonMessageService; - } - - protected MessageService getCommonMessageService() { - return commonMessageService; - } + String DEFAULT_GROUP_NAME_PREFIX_I18N = "group.name.prefix"; + private MessageService commonMessageService; - /** - * Do the grouping for a list of learners that the teacher requested. If you don't supply a name, you may get a system - * generated name. - * @param grouping the grouping that is used to perform groups creation. - * @param name for this group (optional) - * @param learners the list of learners that the teacher requested. + /** + * Set the message service, needed for the I18N of the default group name prefix. Should call this method before + * calling doGrouping() or getPrefix() */ - public abstract void doGrouping(Grouping grouping, String groupName, List learners) throws GroupingException; - - /** - * Do the grouping for a single learner. Should call setCommonMessageService() before calling this method. - * If you don't supply a name, you may get a system generated name. - * @param grouping the grouping that is used to perform groups creation. - * @param name for this group (optional) - * @param learner the learner teacher want to add. - */ - public abstract void doGrouping(Grouping grouping, String groupName, User learner) throws GroupingException; + public void setCommonMessageService(MessageService commonMessageService) { + this.commonMessageService = commonMessageService; + } - /** - * Do the grouping for a list of learners that the teacher requested. If you don't supply an id, you may get a group with a - * system generated name. - * @param grouping the grouping that is used to perform groups creation. - * @param id of the group (optional) - * @param learner the learner teacher want to add. - * @throws GroupingException if the group does not exist. + protected MessageService getCommonMessageService() { + return commonMessageService; + } + + /** + * Do the grouping for a list of learners that the teacher requested. If you don't supply a name, you may get a + * system generated name. + * + * @param grouping + * the grouping that is used to perform groups creation. + * @param name + * for this group (optional) + * @param learners + * the list of learners that the teacher requested. */ - public abstract void doGrouping(Grouping chosenGrouping,Long groupId, List learners) throws GroupingException; + public abstract void doGrouping(Grouping grouping, String groupName, List learners) throws GroupingException; - /** - * Get the default group name prefix - * @return default group name prefix - */ - public String getPrefix() { - String prefix = commonMessageService != null ? commonMessageService.getMessage(DEFAULT_GROUP_NAME_PREFIX_I18N) : ""; - prefix = prefix.trim(); - return prefix.length()>0 ? prefix : "Group"; - } - - /** - * Remove the give learners from the given group. Cannot remove learners if the group is already in use (i.e. - * a tool session exists) + /** + * Do the grouping for a single learner. Should call setCommonMessageService() before calling this method. If you + * don't supply a name, you may get a system generated name. * + * @param grouping + * the grouping that is used to perform groups creation. + * @param name + * for this group (optional) + * @param learner + * the learner teacher want to add. + */ + public abstract void doGrouping(Grouping grouping, String groupName, User learner) throws GroupingException; + + /** + * Do the grouping for a list of learners that the teacher requested. If you don't supply an id, you may get a group + * with a system generated name. + * + * @param grouping + * the grouping that is used to perform groups creation. + * @param id + * of the group (optional) + * @param learner + * the learner teacher want to add. + * @throws GroupingException + * if the group does not exist. + */ + public abstract void doGrouping(Grouping chosenGrouping, Long groupId, List learners) + throws GroupingException; + + /** + * Get the default group name prefix + * + * @return default group name prefix + */ + public String getPrefix() { + String prefix = commonMessageService != null ? commonMessageService.getMessage(DEFAULT_GROUP_NAME_PREFIX_I18N) + : ""; + prefix = prefix.trim(); + return prefix.length() > 0 ? prefix : "Group"; + } + + /** + * Remove the give learners from the given group. Cannot remove learners if the group is already in use (i.e. a tool + * session exists) + * * Trims the name of the group before checking if it is null or before matching to a group. * - * @param grouping (mandatory) - * @param groupID if not null only remove user from this group, if null remove learner from any group. - * @param learner the learner to be removed (mandatory) + * @param grouping + * (mandatory) + * @param groupID + * if not null only remove user from this group, if null remove learner from any group. + * @param learner + * the learner to be removed (mandatory) */ - public void removeLearnersFromGroup(Grouping grouping, Long groupID, List learners) throws GroupingException - { - Set groups = grouping.getGroups(); - Iterator iter = groups.iterator(); - boolean groupFound = false; - - while (iter.hasNext() && ! groupFound ) { - Group group = (Group) iter.next(); + public void removeLearnersFromGroup(Grouping grouping, Long groupID, List learners) throws GroupingException { + Set groups = grouping.getGroups(); + Iterator iter = groups.iterator(); + boolean groupFound = false; - if ( groupID == null || groupID.equals(group.getGroupId()) ) { - - groupFound = groupID != null; + while (iter.hasNext() && !groupFound) { + Group group = (Group) iter.next(); - if ( group.mayBeDeleted() ) { - - boolean removed = group.getUsers().removeAll(learners); - if ( removed ) { - if ( log.isDebugEnabled() ) { - log.debug("Removed "+learners.size()+" users from group "+group.getGroupName()); - } - } - - } else { - String error = "Tried to remove a group which cannot be removed (tool sessions probably exist). Group "+group+" grouping "+grouping+". Not removing the group."; - log.error(error); - throw new GroupingException(error); - } - + if (groupID == null || groupID.equals(group.getGroupId())) { + + groupFound = groupID != null; + + if (group.mayBeDeleted()) { + + boolean removed = group.getUsers().removeAll(learners); + if (removed) { + if (log.isDebugEnabled()) { + log.debug("Removed " + learners.size() + " users from group " + group.getGroupName()); } + } + + } else { + String error = "Tried to remove a group which cannot be removed (tool sessions probably exist). Group " + + group + " grouping " + grouping + ". Not removing the group."; + log.error(error); + throw new GroupingException(error); } + + } + } } - /** - * Create an empty group for the given grouping. Trims the name of the group before creating the group. - * If the group name group name already exists then it appends a datetime string to make the name unique. Gives - * it 5 attempts to make it unique then gives up. + /** + * Create an empty group for the given grouping. Trims the name of the group before creating the group. If the group + * name group name already exists then it appends a datetime string to make the name unique. Gives it 5 attempts to + * make it unique then gives up. * * Throws a GroupingException if name is null or blank. * - * @param grouping (mandatory) - * @param name (mandatory) - * @param forceName (mandatory) + * @param grouping + * (mandatory) + * @param name + * (mandatory) + * @param forceName + * (mandatory) */ - public Group createGroup(Grouping grouping, String name) throws GroupingException - { - String trimmedName = name.trim(); - if ( trimmedName == null || trimmedName.length()==0 ) { - log.warn("Tried to add a group with no name to grouping "+grouping+". Not creating group."); - return null; - } - Set emptySet = new HashSet(); - Group newGroup = Group.createLearnerGroup(grouping,trimmedName,emptySet); - - if ( newGroup == null ) { - trimmedName = trimmedName + " " + new Long(System.currentTimeMillis()).toString(); - newGroup = Group.createLearnerGroup(grouping, trimmedName, emptySet); - } + public Group createGroup(Grouping grouping, String name) throws GroupingException { + String trimmedName = name.trim(); + if (trimmedName == null || trimmedName.length() == 0) { + log.warn("Tried to add a group with no name to grouping " + grouping + ". Not creating group."); + return null; + } + Set emptySet = new HashSet(); + Group newGroup = Group.createLearnerGroup(grouping, trimmedName, emptySet); - if ( newGroup == null ) { - // what, still not unique? Okay try sticking a number on the end. Try 5 times then give up - log.warn("Having trouble creating a unique name for a group. Have tried "+trimmedName); - int attempt = 1; - while ( newGroup == null && attempt < 5) { - newGroup = Group.createLearnerGroup(grouping, trimmedName+" "+new Integer(attempt).toString(), emptySet); - } - if ( newGroup == null ) { - String error = "Unable to create a unique name for a group. Tried 5 variations on "+trimmedName+" now giving up."; - log.error(error); - throw new GroupingException(error); + if (newGroup == null) { + trimmedName = trimmedName + " " + new Long(System.currentTimeMillis()).toString(); + newGroup = Group.createLearnerGroup(grouping, trimmedName, emptySet); + } - } - } + if (newGroup == null) { + // what, still not unique? Okay try sticking a number on the end. Try 5 times then give up + log.warn("Having trouble creating a unique name for a group. Have tried " + trimmedName); + int attempt = 1; + while (newGroup == null && attempt < 5) { + newGroup = Group.createLearnerGroup(grouping, trimmedName + " " + new Integer(attempt).toString(), + emptySet); + } + if (newGroup == null) { + String error = "Unable to create a unique name for a group. Tried 5 variations on " + trimmedName + + " now giving up."; + log.error(error); + throw new GroupingException(error); - if ( newGroup != null ) - grouping.getGroups().add(newGroup); - - return newGroup; - + } } - /** - * Remove a group for the given grouping. If the group is already used (e.g. a tool session exists) - * then it throws a GroupingException. If the group does not exist, nothing happens. + if (newGroup != null) + grouping.getGroups().add(newGroup); + + return newGroup; + + } + + /** + * Remove a group for the given grouping. If the group is already used (e.g. a tool session exists) then it throws a + * GroupingException. If the group does not exist, nothing happens. * * Trims the name of the group before selecting the group. * * When a group is removed all the users in the group become ungrouped. * * Also throws a GroupingException if groupName is null or blank. - * - * @param grouping (mandatory) - * @param groupID (mandatory) + * + * @param grouping + * (mandatory) + * @param groupID + * (mandatory) */ public void removeGroup(Grouping grouping, Long groupID) throws GroupingException { - - Iterator iter = grouping.getGroups().iterator(); - boolean groupDeleted = false; - - while (!groupDeleted && iter.hasNext()) { - Group group = (Group) iter.next(); - if ( group.getGroupId().equals(groupID) ) { - - if ( group.mayBeDeleted() ) { - - // all okay so we can delete - if ( log.isDebugEnabled() ) { - log.warn("Deleting group "+group.getGroupName()+" for grouping "+grouping); - } - iter.remove(); - groupDeleted = true; - - } else { - String error = "Tried to remove a group which cannot be removed (tool sessions probably exist). Group "+group+" grouping "+grouping+". Not removing the group."; - log.error(error); - throw new GroupingException(error); - } - } + + Iterator iter = grouping.getGroups().iterator(); + boolean groupDeleted = false; + + while (!groupDeleted && iter.hasNext()) { + Group group = (Group) iter.next(); + if (group.getGroupId().equals(groupID)) { + + if (group.mayBeDeleted()) { + + // all okay so we can delete + if (log.isDebugEnabled()) { + log.warn("Deleting group " + group.getGroupName() + " for grouping " + grouping); + } + iter.remove(); + groupDeleted = true; + + } else { + String error = "Tried to remove a group which cannot be removed (tool sessions probably exist). Group " + + group + " grouping " + grouping + ". Not removing the group."; + log.error(error); + throw new GroupingException(error); } - - if ( !groupDeleted ) { - log.warn("Tried to remove a group "+groupID+" but the group does not exist for grouping "+grouping+"."); - } + } } + if (!groupDeleted) { + log.warn("Tried to remove a group " + groupID + " but the group does not exist for grouping " + grouping + + "."); + } + } + } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/RandomGrouper.java =================================================================== diff -u -r62d0bb09a4512210d42ebd60885c7e1834c0cc5e -rc85eeb30f32d1551d97688e0153f5c81839f03d3 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/RandomGrouper.java (.../RandomGrouper.java) (revision 62d0bb09a4512210d42ebd60885c7e1834c0cc5e) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/RandomGrouper.java (.../RandomGrouper.java) (revision c85eeb30f32d1551d97688e0153f5c81839f03d3) @@ -32,235 +32,236 @@ import org.lamsfoundation.lams.learningdesign.exception.GroupingException; import org.lamsfoundation.lams.usermanagement.User; - /** - *

The random grouping algorithm implementation. It allocates user into the - * groups according to the attributes accepted from user interface: - * numberOfGroups and learnersPerGroup. If any of - * these two attribute has be set, the random grouping will be done - * correspondently.

+ *

+ * The random grouping algorithm implementation. It allocates user into the groups according to the attributes accepted + * from user interface: numberOfGroups and learnersPerGroup. If any of these two attribute has + * be set, the random grouping will be done correspondently. + *

* - *

In the case of random grouping by number of groups, the number of groups - * will be fixed, and learners are evenly allocated into the groups. For - * example, there are 10 users and numberOfGroups=3, the number - * of learners in three groups will 4,3,3. And if there are 1 user and - * numberOfGroups=3, all three groups still will be created - * with learner number 1,0,0.

+ *

+ * In the case of random grouping by number of groups, the number of groups will be fixed, and learners are evenly + * allocated into the groups. For example, there are 10 users and numberOfGroups=3, the number of learners + * in three groups will 4,3,3. And if there are 1 user and numberOfGroups=3, all three groups still will be + * created with learner number 1,0,0. + *

* - *

In the case of random grouping by learners per group, groups are only - * created if the total learner number exceeds the existing group capacity. - * Learners are also evenly allocated into the groups.For example, if there is - * 5 users and learnerPerGroup=3, only 2 groups will be created. + *

+ * In the case of random grouping by learners per group, groups are only created if the total learner number exceeds the + * existing group capacity. Learners are also evenly allocated into the groups.For example, if there is 5 users and + * learnerPerGroup=3, only 2 groups will be created. *

* * @author Jacky Fang - * @since 2005-3-24 + * @since 2005-3-24 * @version 1.1 * */ -public class RandomGrouper extends Grouper implements Serializable -{ - private static final long serialVersionUID = -3696368461795411181L; +public class RandomGrouper extends Grouper implements Serializable { + private static final long serialVersionUID = -3696368461795411181L; - private static Logger log = Logger.getLogger(RandomGrouper.class); - - //--------------------------------------------------------------------- + private static Logger log = Logger.getLogger(RandomGrouper.class); + + // --------------------------------------------------------------------- // Grouping algorithm Implementation Method - //--------------------------------------------------------------------- + // --------------------------------------------------------------------- /** * Do the grouping for single new learner. - * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping, java.lang.String,org.lamsfoundation.lams.usermanagement.User) + * + * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping, + * java.lang.String,org.lamsfoundation.lams.usermanagement.User) */ - public void doGrouping(Grouping randomGrouping,String groupName, User learner) - { - //convert the single user into a list. - List learners = new ArrayList(); - learners.add(learner); - //delegate to do grouping for a list of learners. - doGrouping(randomGrouping,groupName,learners); + @Override + public void doGrouping(Grouping randomGrouping, String groupName, User learner) { + // convert the single user into a list. + List learners = new ArrayList(); + learners.add(learner); + // delegate to do grouping for a list of learners. + doGrouping(randomGrouping, groupName, learners); } /** * Do the grouping for a list of new learners. - * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping,java.lang.String, java.util.List) + * + * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping,java.lang.String, + * java.util.List) */ - public void doGrouping(Grouping randomGrouping, String groupName, List learners) - { - //calculate how many new groups needs to be created. - int numOfGroupsTobeCreated =0; - if(randomGrouping.getGroups().size()==0) - numOfGroupsTobeCreated = calculateNumOfNewGroups((RandomGrouping)randomGrouping, - learners, - true); - else - numOfGroupsTobeCreated = calculateNumOfNewGroups((RandomGrouping)randomGrouping, - learners, - false); - //create new groups - createGroups((RandomGrouping)randomGrouping, numOfGroupsTobeCreated); - //join the new learners into these groups. - joinGroups(randomGrouping, learners); + @Override + public void doGrouping(Grouping randomGrouping, String groupName, List learners) { + // calculate how many new groups needs to be created. + int numOfGroupsTobeCreated = 0; + if (randomGrouping.getGroups().size() == 0) { + numOfGroupsTobeCreated = calculateNumOfNewGroups((RandomGrouping) randomGrouping, learners, true); + } else { + numOfGroupsTobeCreated = calculateNumOfNewGroups((RandomGrouping) randomGrouping, learners, false); + } + // create new groups + createGroups((RandomGrouping) randomGrouping, numOfGroupsTobeCreated); + // join the new learners into these groups. + joinGroups(randomGrouping, learners); } - + /** - * Need to be able to force a user into a particular group for group based branching in preview. - * So this is a non-random random. Bleah! - * @throws GroupingException - * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping,java.lang.Long, java.util.List) + * Need to be able to force a user into a particular group for group based branching in preview. So this is a + * non-random random. Bleah! + * + * @throws GroupingException + * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping,java.lang.Long, + * java.util.List) */ - public void doGrouping(Grouping randomGrouping,Long groupId, List learners) throws GroupingException - { - if ( groupId != null ) { - Iterator iter = randomGrouping.getGroups().iterator(); - Group selectedGroup = null; - while (iter.hasNext() && selectedGroup==null) { - Group group = (Group) iter.next(); - if ( group.getGroupId().equals(groupId) ) { - selectedGroup = group; - } - } - if ( selectedGroup == null ) { - String error = "Tried to add users to group "+groupId+" but group cannot be found."; - log.error(error); - throw new GroupingException(error); - } - selectedGroup.getUsers().addAll(learners); - } else { - // normal random !!! - doGrouping(randomGrouping, (String)null, learners); - } + @Override + public void doGrouping(Grouping randomGrouping, Long groupId, List learners) throws GroupingException { + if (groupId != null) { + Iterator iter = randomGrouping.getGroups().iterator(); + Group selectedGroup = null; + while (iter.hasNext() && (selectedGroup == null)) { + Group group = (Group) iter.next(); + if (group.getGroupId().equals(groupId)) { + selectedGroup = group; + } + } + if (selectedGroup == null) { + String error = "Tried to add users to group " + groupId + " but group cannot be found."; + RandomGrouper.log.error(error); + throw new GroupingException(error); + } + selectedGroup.getUsers().addAll(learners); + } else { + // normal random !!! + doGrouping(randomGrouping, (String) null, learners); + } } - - //--------------------------------------------------------------------- + + // --------------------------------------------------------------------- // Helper Methods - doGrouping - //--------------------------------------------------------------------- + // --------------------------------------------------------------------- /** - * Compute the number of new groups needs to be created based on passed - * in grouping. It figures out group by number of groups or group by - * learner per group automatically. + * Compute the number of new groups needs to be created based on passed in grouping. It figures out group by number + * of groups or group by learner per group automatically. * - * @param randomGrouping the grouping we used to group learner - * @param learners the list of learners need to be grouped + * @param randomGrouping + * the grouping we used to group learner + * @param learners + * the list of learners need to be grouped * @return the number required new group. */ - private int calculateNumOfNewGroups(RandomGrouping randomGrouping, - List learners, - boolean isInitialization) - { - if(randomGrouping.getNumberOfGroups()!=null && randomGrouping.getNumberOfGroups().intValue()>0) { - return getNewGroupsByNumberOfGroups(randomGrouping, randomGrouping.getNumberOfGroups(), isInitialization); - } else if(randomGrouping.getLearnersPerGroup()!=null && randomGrouping.getLearnersPerGroup().intValue()>0) { - return getNewGroupsByLearnerPerGroup(randomGrouping,learners); - } else { - log.warn("Random Grouping id="+randomGrouping.getGroupingId()+" is missing both the number of groups and learners per group. Defaulting to two groups."); - return getNewGroupsByNumberOfGroups(randomGrouping, 2, isInitialization); - } + private int calculateNumOfNewGroups(RandomGrouping randomGrouping, List learners, boolean isInitialization) { + if ((randomGrouping.getNumberOfGroups() != null) && (randomGrouping.getNumberOfGroups().intValue() > 0)) { + return getNewGroupsByNumberOfGroups(randomGrouping, randomGrouping.getNumberOfGroups(), isInitialization); + } else if ((randomGrouping.getLearnersPerGroup() != null) + && (randomGrouping.getLearnersPerGroup().intValue() > 0)) { + return getNewGroupsByLearnerPerGroup(randomGrouping, learners); + } else { + RandomGrouper.log.warn("Random Grouping id=" + randomGrouping.getGroupingId() + + " is missing both the number of groups and learners per group. Defaulting to two groups."); + return getNewGroupsByNumberOfGroups(randomGrouping, 2, isInitialization); + } } /** - * Create new groups and insert them into the grouping. Group names - * are Group 1, Group 2, etc. - * @param randomGrouping the requested grouping. - * @param numOfGroupsTobeCreated the number new groups need to be created. + * Create new groups and insert them into the grouping. Group names are Group 1, Group 2, etc. + * + * @param randomGrouping + * the requested grouping. + * @param numOfGroupsTobeCreated + * the number new groups need to be created. */ - private void createGroups(RandomGrouping randomGrouping, - int numOfGroupsTobeCreated) - { - String prefix = getPrefix(); - int size = randomGrouping.getGroups().size(); - for(int numCreated=0,groupIndex=size+1;numCreated0?numberOfNewGroups:0; - } + private int getNewGroupsByNumberOfGroups(RandomGrouping randomGrouping, int numberOfGroups, + boolean isInitialization) { + if (isInitialization) { + return numberOfGroups; + } else { + int numberOfNewGroups = numberOfGroups - randomGrouping.getGroups().size(); + + return numberOfNewGroups > 0 ? numberOfNewGroups : 0; + } } } Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILessonDAO.java =================================================================== diff -u -r509d15bcc570bff483a13152ef8c45cbae767e78 -rc85eeb30f32d1551d97688e0153f5c81839f03d3 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILessonDAO.java (.../ILessonDAO.java) (revision 509d15bcc570bff483a13152ef8c45cbae767e78) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/ILessonDAO.java (.../ILessonDAO.java) (revision c85eeb30f32d1551d97688e0153f5c81839f03d3) @@ -47,9 +47,6 @@ */ Lesson getLesson(Long lessonId); - /** Get all the lessons in the database. This includes the disabled lessons. */ - List getAllLessons(); - Lesson getLessonWithJoinFetchedProgress(Long lessonId); /** @@ -62,17 +59,6 @@ List getActiveLessonsForLearner(User learner); /** - * Gets all lessons that are active for a learner, in a given organisation - * - * @param learnerId - * a User that identifies the learner. - * @param organisationId - * the desired organisation . - * @return a List with all active lessons in it. - */ - List getActiveLessonsForLearner(Integer learnerId, Integer organisationID); - - /** * Saves or Updates a Lesson. * * @param lesson @@ -106,16 +92,6 @@ List getLessonsCreatedByUser(Integer userID); /** - * Gets all lessons in the given organisation, for which this user is in the staff group. Does not return disabled - * 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. - * @return a List with all appropriate lessons in it. - */ - List getLessonsForMonitoring(int userID, int organisationID); - - /** * Returns the all the learners that have started the requested lesson. * * @param lessonId @@ -216,12 +192,4 @@ * @return list of teachers that monitor the lesson which contains the tool with given session ID */ List getMonitorsByToolSessionId(Long sessionId); - - /** - * Gets lesson for tools based on toolSessionID - * - * @param sessionID - * @return - */ - Lesson getLessonFromSessionID(Long toolSessionID); -} +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LessonDAO.java =================================================================== diff -u -r509d15bcc570bff483a13152ef8c45cbae767e78 -rc85eeb30f32d1551d97688e0153f5c81839f03d3 --- lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LessonDAO.java (.../LessonDAO.java) (revision 509d15bcc570bff483a13152ef8c45cbae767e78) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/dao/hibernate/LessonDAO.java (.../LessonDAO.java) (revision c85eeb30f32d1551d97688e0153f5c81839f03d3) @@ -59,6 +59,8 @@ + "and lesson.startDateTime is not null and lesson.startDateTime < ?"; private final static String COUNT_ACTIVE_LEARNERS = "select count(distinct progress.user.id)" + " from " + LearnerProgress.class.getName() + " progress" + " where progress.lesson.id = :lessonId"; + private final static String LOAD_ACTIVE_LEARNERS = "select distinct progress.user from " + + LearnerProgress.class.getName() + " progress where progress.lesson.id = :lessonId"; private final static String FIND_LESSON_FOR_ACTIVITY = "select lesson from " + Lesson.class.getName() + " lesson, " + Activity.class.getName() + " activity " + " where activity.activityId=:activityId and activity.learningDesign=lesson.learningDesign"; @@ -110,12 +112,6 @@ }); } - /** Get all the lessons in the database. This includes the disabled lessons. */ - @Override - public List getAllLessons() { - return getHibernateTemplate().loadAll(Lesson.class); - } - /** * Gets all lessons that are active for a learner. * @@ -141,50 +137,17 @@ } /** - * Gets all lessons that are active for a learner, in a given organisation - * - * @param learnerId - * a User that identifies the learner. - * @param organisationId - * the desired organisation. - * @return a List with all active lessons in it. - */ - @Override - public List getActiveLessonsForLearner(final Integer learnerId, final Integer organisationId) { - List lessons = null; - - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - lessons = (List) hibernateTemplate.execute(new HibernateCallback() { - @Override - public Object doInHibernate(Session session) throws HibernateException { - Query query = session.getNamedQuery("activeLessons"); - query.setInteger("userId", learnerId); - query.setInteger("organisationId", organisationId); - List result = query.list(); - return result; - } - }); - return lessons; - } - - /** * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getActiveLearnerByLesson(long) */ + @SuppressWarnings("unchecked") @Override - public List getActiveLearnerByLesson(final long lessonId) { - List learners = null; - - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - learners = (List) hibernateTemplate.execute(new HibernateCallback() { + public List getActiveLearnerByLesson(final long lessonId) { + return (List) new HibernateTemplate(this.getSessionFactory()).execute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException { - Query query = session.getNamedQuery("activeLearners"); - query.setLong("lessonId", lessonId); - List result = query.list(); - return result; + return session.createQuery(LessonDAO.LOAD_ACTIVE_LEARNERS).setLong("lessonId", lessonId).list(); } }); - return learners; } /** @@ -309,32 +272,6 @@ } /** - * Gets all lessons in the given organisation, for which this user is in the staff group. Does not return disabled - * 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. - * @return a List with all appropriate lessons in it. - */ - @Override - public List getLessonsForMonitoring(final int userID, final int organisationID) { - List lessons = null; - - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - lessons = (List) hibernateTemplate.execute(new HibernateCallback() { - @Override - public Object doInHibernate(Session session) throws HibernateException { - Query query = session.getNamedQuery("lessonsForMonitoring"); - query.setInteger("userId", userID); - query.setInteger("organisationId", organisationID); - List result = query.list(); - return result; - } - }); - return lessons; - } - - /** * Get all the preview lessons more with the creation date before the given date. * * @param startDate @@ -436,29 +373,14 @@ /** * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getMonitorsByToolSessionId(Long) */ + @SuppressWarnings("unchecked") @Override public List getMonitorsByToolSessionId(Long sessionId) { return this.getHibernateTemplate().findByNamedQueryAndNamedParam("monitorsByToolSessionId", "sessionId", sessionId); } /** - * @see org.lamsfoundation.lams.lesson.dao.ILessonDAO#getLessonDetailsFromSessionID(java.lang.Long) - */ - @Override - public Lesson getLessonFromSessionID(final Long toolSessionID) { - HibernateTemplate hibernateTemplate = new HibernateTemplate(this.getSessionFactory()); - return (Lesson) hibernateTemplate.execute(new HibernateCallback() { - @Override - public Object doInHibernate(Session session) throws HibernateException { - Query query = session.createQuery(LessonDAO.LESSON_BY_SESSION_ID); - query.setLong("toolSessionID", toolSessionID); - return query.uniqueResult(); - } - }); - } - - /** * Maps users from an organisation with the given role to a boolean value saying whether they participate in the * given lesson. */ Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java =================================================================== diff -u -r509d15bcc570bff483a13152ef8c45cbae767e78 -rc85eeb30f32d1551d97688e0153f5c81839f03d3 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision 509d15bcc570bff483a13152ef8c45cbae767e78) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision c85eeb30f32d1551d97688e0153f5c81839f03d3) @@ -414,25 +414,6 @@ List getMonitorsByToolSessionId(Long sessionId); /** - * Gets all lessons that are active for a learner, in a given organisation - * - * @param learnerId - * a User that identifies the learner. - * @param organisationId - * the desired organisation. - * @return a List with all active lessons in it. - */ - List getActiveLessonsForLearner(final Integer learnerId, final Integer organisationId); - - /** - * Gets lesson details for tools based on toolSessionID - * - * @param sessionID - * @return - */ - LessonDetailsDTO getLessonDetailsFromSessionID(Long toolSessionID); - - /** * Check if preceding lessons have been completed and the given lesson is available to the user. */ boolean checkLessonReleaseConditions(Long lessonId, Integer learnerId); Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java =================================================================== diff -u -r509d15bcc570bff483a13152ef8c45cbae767e78 -rc85eeb30f32d1551d97688e0153f5c81839f03d3 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision 509d15bcc570bff483a13152ef8c45cbae767e78) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision c85eeb30f32d1551d97688e0153f5c81839f03d3) @@ -672,20 +672,6 @@ } @Override - public List getActiveLessonsForLearner(Integer learnerId, Integer organisationId) { - return lessonDAO.getActiveLessonsForLearner(learnerId, organisationId); - } - - @Override - public LessonDetailsDTO getLessonDetailsFromSessionID(Long toolSessionID) { - Lesson lesson = this.lessonDAO.getLessonFromSessionID(toolSessionID); - if (lesson != null) { - return lesson.getLessonDetails(); - } - return null; - } - - @Override public boolean checkLessonReleaseConditions(Long lessonId, Integer learnerId) { Lesson lesson = getLesson(lessonId); if (lesson != null) {