Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -r56dc9e59c9512b28858b2da10f756103010d9cca -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 Binary files differ Index: lams_common/db/sql/insert_types_data.sql =================================================================== diff -u -rab768712eeeba5d2f03d140fefaa4c856f873508 -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/db/sql/insert_types_data.sql (.../insert_types_data.sql) (revision ab768712eeeba5d2f03d140fefaa4c856f873508) +++ lams_common/db/sql/insert_types_data.sql (.../insert_types_data.sql) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -97,7 +97,9 @@ VALUES (1, 2, 'Grouping', 'All types of grouping including random and chosen.', 'learning/grouping.do?method=performGrouping', 'learning/grouping.do?method=performGrouping', 'learning/grouping.do?method=viewGrouping', 'learning/grouping.do?method=viewGrouping', - null, null, null, now() ); + 'learning/grouping.do?method=viewGrouping', + 'monitoring/grouping.do?method=startGrouping', + 'monitoring/grouping.do?method=startGrouping', now() ); INSERT INTO lams_system_tool (system_tool_id, learning_activity_type_id, tool_display_name, description, learner_url, learner_preview_url, learner_progress_url, export_pfolio_learner_url, Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ChosenGrouper.java =================================================================== diff -u -r56dc9e59c9512b28858b2da10f756103010d9cca -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ChosenGrouper.java (.../ChosenGrouper.java) (revision 56dc9e59c9512b28858b2da10f756103010d9cca) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ChosenGrouper.java (.../ChosenGrouper.java) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -26,11 +26,12 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import org.apache.log4j.Logger; +import org.lamsfoundation.lams.learningdesign.exception.GroupingException; import org.lamsfoundation.lams.usermanagement.User; -import org.lamsfoundation.lams.util.MessageService; /** @@ -65,13 +66,79 @@ */ public void doGrouping(Grouping chosenGrouping,String groupName, List learners) { - String newGroupName = groupName; - if ( newGroupName == null ) { - newGroupName = "Group"+System.currentTimeMillis(); - log.warn("Chosen grouper for grouping "+chosenGrouping.toString()+" didn't get a group name. Selecting default name of "+newGroupName); + String trimmedName = groupName.trim(); + if ( trimmedName == null ) { + String prefix = getPrefix(); + trimmedName = prefix+" "+System.currentTimeMillis(); + log.warn("Chosen grouper for grouping "+chosenGrouping.toString()+" did not get a group name. Selecting default name of "+trimmedName); } - chosenGrouping.getGroups().add(Group.createLearnerGroup(chosenGrouping,newGroupName, + Iterator iter = chosenGrouping.getGroups().iterator(); + Group selectedGroup = null; + while (iter.hasNext() && selectedGroup==null) { + Group group = (Group) iter.next(); + if ( trimmedName.equals(selectedGroup.getGroupName()) ) { + selectedGroup = group; + } + } + doGrouping(chosenGrouping, selectedGroup, trimmedName, learners); + } + + /** + * @throws GroupingException + * @see org.lamsfoundation.lams.learningdesign.Grouper#doGrouping(org.lamsfoundation.lams.learningdesign.Grouping,java.lang.Long, java.util.List) + */ + public void doGrouping(Grouping chosenGrouping,Long groupId, List learners) throws GroupingException + { + 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); + } + + /** If the group exists add them to the group, otherwise creates a new group. Group will always + * exist if called from doGrouping(Grouping chosenGrouping,Long groupId, List learners), but it may or + * may not exist if called from doGrouping(Grouping chosenGrouping,String groupName, List learners). + * @param chosenGrouping + * @param group + * @param groupName + * @param learners + */ + public 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) + */ + public Group createGroup(Grouping grouping, String name) throws GroupingException + { + int currentSize = grouping.getGroups().size(); + if ( 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); + } + } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/Group.java =================================================================== diff -u -r34b959260a0f8f8285793a4481a95ca3580eabc5 -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/Group.java (.../Group.java) (revision 34b959260a0f8f8285793a4481a95ca3580eabc5) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/Group.java (.../Group.java) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -79,20 +79,26 @@ /** * Creation Constructor for initializing learner group without tool sessions - * The order is generated using synchornize method on grouping. + * The order is generated using synchornize method on grouping. If a group of + * this name already exists, returns null. * * @param grouping the grouping this group belongs to. * @param users the users in this group. * @return the new learner group */ public static Group createLearnerGroup(Grouping grouping, String groupName, Set users) { - return new Group(null,groupName,grouping.getNextGroupOrderId(),grouping,users,new HashSet()); + int nextOrderId = grouping.getNextGroupOrderIdCheckName(groupName); + if ( nextOrderId > -1 ) { + return new Group(null,groupName,nextOrderId,grouping,users,new HashSet()); + } + return null; } /** * Creation Constructor for initializing learner group with tool sessions - * The order is generated using synchornize method on grouping. + * The order is generated using synchornize method on grouping. If a group of + * this name already exists, returns null. * * @param grouping the grouping this group belongs to. * @param name of this group @@ -102,7 +108,11 @@ */ public static Group createLearnerGroupWithToolSession(Grouping grouping, String groupName, Set users,Set toolSessions) { - return new Group(null,groupName,grouping.getNextGroupOrderId(),grouping,users,toolSessions); + int nextOrderId = grouping.getNextGroupOrderIdCheckName(groupName); + if ( nextOrderId > -1 ) { + return new Group(null,groupName,nextOrderId,grouping,users,toolSessions); + } + return null; } /** @@ -284,4 +294,10 @@ public GroupDTO getGroupDTO(){ return new GroupDTO(this); } + + /** May this group be deleted or a user from this group deleted? It should not be + * deleted if there are tool sessions attached */ + public boolean mayBeDeleted() { + return getToolSessions().size() == 0; + } } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/Grouper.java =================================================================== diff -u -r56dc9e59c9512b28858b2da10f756103010d9cca -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/Grouper.java (.../Grouper.java) (revision 56dc9e59c9512b28858b2da10f756103010d9cca) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/Grouper.java (.../Grouper.java) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -23,8 +23,13 @@ /* $$Id$$ */ package org.lamsfoundation.lams.learningdesign; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; +import java.util.Set; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.learningdesign.exception.GroupingException; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.util.MessageService; @@ -46,6 +51,9 @@ */ public abstract class Grouper { + + private static Logger log = Logger.getLogger(Grouper.class); + String DEFAULT_GROUP_NAME_PREFIX_I18N = "group.name.prefix"; private MessageService commonMessageService; @@ -65,18 +73,26 @@ * @param name for this group * @param learners the list of learners that the teacher requested. */ - public abstract void doGrouping(Grouping grouping, String groupName, List learners); + 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. * @param grouping the grouping that is used to perform groups creation. * @param name for this group * @param learner the learner teacher want to add. - * @param commonMessageService the message service from lams.jar. Needed for prefix for the group names. */ - public abstract void doGrouping(Grouping grouping, String groupName, User learnere); + public abstract void doGrouping(Grouping grouping, String groupName, User learner) throws GroupingException; /** + * Do the grouping for a list of learners that the teacher requested. + * @param grouping the grouping that is used to perform groups creation. + * @param id of the group + * @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 */ @@ -85,5 +101,114 @@ 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) + */ + 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(); -} + 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. If the group name is not supplied + * or the group name already exists then nothing happens. Trims the name of the group before creating + * the group. + * + * Throws a GroupingException if name is null or blank. + * + * @param grouping (mandatory) + * @param name (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; + } + Group newGroup = Group.createLearnerGroup(grouping,trimmedName,new HashSet()); + 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) + */ + 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); + } + } + } + + 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/Grouping.java =================================================================== diff -u -r56dc9e59c9512b28858b2da10f756103010d9cca -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/Grouping.java (.../Grouping.java) (revision 56dc9e59c9512b28858b2da10f756103010d9cca) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/Grouping.java (.../Grouping.java) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -228,18 +228,24 @@ // Service methods //--------------------------------------------------------------------- /** - * Return the next group order id. + * Return the next group order id. Can't do it on size as groups may have been deleted. + * Returns -1 if the proposed name is the same as existing name * @return the next order id. */ - public synchronized int getNextGroupOrderId() + public synchronized int getNextGroupOrderIdCheckName(String proposedName) { - int order =0; - if(this.groups!=null) - { - order = groups.size(); - return ++order; - } - else return ++order; + int maxOrderId = 0; + + if ( this.getGroups() != null ) { + Iterator iter = this.getGroups().iterator(); + while (iter.hasNext()) { + Group element = (Group) iter.next(); + maxOrderId = element.getOrderId() > maxOrderId ? element.getOrderId() : maxOrderId; + if ( proposedName.equals(element.getGroupName()) ) + return -1; + } + } + return ++maxOrderId; } /** Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/RandomGrouper.java =================================================================== diff -u -r56dc9e59c9512b28858b2da10f756103010d9cca -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/RandomGrouper.java (.../RandomGrouper.java) (revision 56dc9e59c9512b28858b2da10f756103010d9cca) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/RandomGrouper.java (.../RandomGrouper.java) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -27,8 +27,10 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import org.apache.log4j.Logger; +import org.lamsfoundation.lams.learningdesign.exception.GroupingException; import org.lamsfoundation.lams.usermanagement.User; @@ -100,6 +102,16 @@ //join the new learners into these groups. joinGroups(randomGrouping, learners); } + + /** + * @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 + { + doGrouping(randomGrouping, (String)null, learners); + } + //--------------------------------------------------------------------- // Helper Methods - doGrouping //--------------------------------------------------------------------- Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/exception/GroupingException.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/exception/GroupingException.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/exception/GroupingException.java (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -0,0 +1,54 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.learningdesign.exception; + +public class GroupingException extends LearningDesignException { + + public GroupingException(){ + + } + public GroupingException(String message){ + super(message); + } + /** + * Constructor for wrapping the throwable object + * @param cause + */ + public GroupingException(Throwable cause) + { + super(cause); + } + + /** + * Constructor for wrapping both the customized error message and + * throwable exception object. + * @param message + * @param cause + */ + public GroupingException(String message, Throwable cause) + { + super(message, cause); + } +} Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/exception/LearningDesignException.java =================================================================== diff -u -r34b959260a0f8f8285793a4481a95ca3580eabc5 -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/exception/LearningDesignException.java (.../LearningDesignException.java) (revision 34b959260a0f8f8285793a4481a95ca3580eabc5) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/exception/LearningDesignException.java (.../LearningDesignException.java) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -26,7 +26,7 @@ /** * @author Manpreet Minhas */ -public class LearningDesignException extends Exception { +public class LearningDesignException extends RuntimeException { public LearningDesignException(){ Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/exception/LearningDesignProcessorException.java =================================================================== diff -u -r3f60ecf7d3a92231a1089191ae75c68bc66e9595 -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/exception/LearningDesignProcessorException.java (.../LearningDesignProcessorException.java) (revision 3f60ecf7d3a92231a1089191ae75c68bc66e9595) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/exception/LearningDesignProcessorException.java (.../LearningDesignProcessorException.java) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -23,7 +23,7 @@ /* $Id$ */ package org.lamsfoundation.lams.learningdesign.exception; -public class LearningDesignProcessorException extends Exception { +public class LearningDesignProcessorException extends RuntimeException { public LearningDesignProcessorException(){ Index: lams_common/src/java/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml =================================================================== diff -u -r56dc9e59c9512b28858b2da10f756103010d9cca -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml (.../lessonApplicationContext.xml) (revision 56dc9e59c9512b28858b2da10f756103010d9cca) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml (.../lessonApplicationContext.xml) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -36,9 +36,11 @@ PROPAGATION_REQUIRED - PROPAGATION_REQUIRED - PROPAGATION_REQUIRED PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java =================================================================== diff -u -r56dc9e59c9512b28858b2da10f756103010d9cca -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision 56dc9e59c9512b28858b2da10f756103010d9cca) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -27,16 +27,14 @@ import java.util.Collection; import java.util.List; -import org.lamsfoundation.lams.learningdesign.Grouper; -import org.lamsfoundation.lams.learningdesign.Grouping; import org.lamsfoundation.lams.learningdesign.GroupingActivity; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.lesson.dto.LessonDTO; import org.lamsfoundation.lams.lesson.dto.LessonDetailsDTO; import org.lamsfoundation.lams.usermanagement.User; /** - * Access the general lesson details. + * Access the general lesson details and access to grouping. * * A lesson has three different "lists" of learners. *
    @@ -93,6 +91,7 @@ /** * If the supplied learner is not already in a group, then perform grouping for * the learners who have started the lesson, based on the grouping activity. + * Currently used for random grouping. * This method should be used when we do have an grouping activity and learner that is * already part of the Hibernate session. (e.g. from the ForceComplete) * @@ -104,9 +103,46 @@ /** * Perform grouping for all the learners who have started the lesson, based on the grouping activity. + * Currently used for chosen grouping. * @param lessonId lesson id (mandatory) + * @param groupName group name (mandatory) * @param groupingActivityId the activity that has create grouping. (mandatory) */ - public void performChosenGrouping(GroupingActivity groupingActivity, List learners) throws LessonServiceException; + public void performGrouping(GroupingActivity groupingActivity, String groupName, List learners) throws LessonServiceException; + /** + * Perform grouping for all the learners who have started the lesson, based on the grouping activity. + * Currently used for chosen grouping. + * @param lessonId lesson id (mandatory) + * @param groupId group id (mandatory) + * @param groupingActivityId the activity that has create grouping. (mandatory) + */ + public void performGrouping(GroupingActivity groupingActivity, Long groupId, List learners) throws LessonServiceException; + + /** + * Remove learners from the given group. + * @param groupingActivity the activity that has create grouping. (mandatory) + * @param groupName if not null only remove user from this group, if null remove learner from any group. + * @param learners the learners to be removed (mandatory) + */ + public void removeLearnersFromGroup(GroupingActivity groupingActivity, Long groupId, List learners) throws LessonServiceException; + + + /** Create an empty group for the given grouping. If the group name is not supplied + * or the group name already exists then nothing happens. + * + * @param groupingActivity the activity that has create grouping. (mandatory) + * @param groupName (mandatory) + */ + public void createGroup(GroupingActivity groupingActivity, String name) throws LessonServiceException; + + /** + * Remove a group for the given grouping. If the group is already used (e.g. a tool session exists) + * then it throws a GroupingException. + * + * @param groupingActivity the activity that has create grouping. (mandatory) + * @param groupName (mandatory) + */ + public void removeGroup(GroupingActivity groupingActivity, Long groupId) throws LessonServiceException; + } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java =================================================================== diff -u -r56dc9e59c9512b28858b2da10f756103010d9cca -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision 56dc9e59c9512b28858b2da10f756103010d9cca) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -27,14 +27,18 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Set; import org.apache.log4j.Logger; +import org.lamsfoundation.lams.learningdesign.Group; import org.lamsfoundation.lams.learningdesign.Grouper; import org.lamsfoundation.lams.learningdesign.Grouping; import org.lamsfoundation.lams.learningdesign.GroupingActivity; import org.lamsfoundation.lams.learningdesign.dao.IActivityDAO; import org.lamsfoundation.lams.learningdesign.dao.IGroupingDAO; +import org.lamsfoundation.lams.learningdesign.exception.GroupingException; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.lesson.dao.ILessonDAO; import org.lamsfoundation.lams.lesson.dto.LessonDTO; @@ -199,18 +203,24 @@ // get the real objects, not the CGLIB version grouping = groupingDAO.getGroupingById(grouping.getGroupingId()); Grouper grouper = grouping.getGrouper(); + if ( grouper != null ) { grouper.setCommonMessageService(messageService); - if ( grouping.getGroups().size() == 0 ) { - // no grouping done yet - do everyone already in the lesson. - List usersInLesson = getActiveLessonLearners(lessonId); - grouper.doGrouping(grouping, null, usersInLesson); - } else if ( ! grouping.doesLearnerExist(learner) ) { - // done the others, just do the one user - grouper.doGrouping(grouping, null, learner); + try { + if ( grouping.getGroups().size() == 0 ) { + // no grouping done yet - do everyone already in the lesson. + List usersInLesson = getActiveLessonLearners(lessonId); + grouper.doGrouping(grouping, (String)null, usersInLesson); + } else if ( ! grouping.doesLearnerExist(learner) ) { + // done the others, just do the one user + grouper.doGrouping(grouping, null, learner); + } + } catch ( GroupingException e ) { + throw new LessonServiceException(e); } groupingDAO.update(grouping); } + } else { String error = "The method performGrouping supports only grouping methods where the grouper decides the groups (currently only RandomGrouping). Called with a groupingActivity with the wrong grouper "+groupingActivity.getActivityId(); log.error(error); @@ -219,26 +229,127 @@ } /** - * Perform the grouping, setting the given list of learners as one group. - * @param groupingActivityId the activity that has create grouping. (mandatory) + * Perform the grouping, setting the given list of learners as one group. Not used initially. + * @param groupingActivity the activity that has create grouping. (mandatory) * @param learners to form one group */ - public void performChosenGrouping(GroupingActivity groupingActivity, List learners) throws LessonServiceException { + public void performGrouping(GroupingActivity groupingActivity, String groupName, List learners) throws LessonServiceException { Grouping grouping = groupingActivity.getCreateGrouping(); if ( grouping != null && grouping.isChosenGrouping() ) { Grouper grouper = grouping.getGrouper(); if ( grouper != null ) { grouper.setCommonMessageService(messageService); - grouper.doGrouping(grouping, null, learners); + try { + grouper.doGrouping(grouping, groupName, learners); + } catch ( GroupingException e ) { + throw new LessonServiceException(e); + } groupingDAO.update(grouping); } } else { String error = "The method performChosenGrouping supports only grouping methods where the supplied list should be used as a single group (currently only ChosenGrouping). Called with a groupingActivity with the wrong grouper "+groupingActivity.getActivityId(); log.error(error); throw new LessonServiceException(error); } - } + } + /** + * Perform the grouping, setting the given list of learners as one group. Currently used for chosen grouping. + * @param groupingActivity the activity that has create grouping. (mandatory) + * @param learners to form one group + */ + public void performGrouping(GroupingActivity groupingActivity, Long groupId, List learners) throws LessonServiceException { + Grouping grouping = groupingActivity.getCreateGrouping(); + if ( grouping != null && grouping.isChosenGrouping() ) { + Grouper grouper = grouping.getGrouper(); + if ( grouper != null ) { + grouper.setCommonMessageService(messageService); + try { + grouper.doGrouping(grouping, groupId, learners); + } catch ( GroupingException e ) { + throw new LessonServiceException(e); + } + groupingDAO.update(grouping); + } + } else { + String error = "The method performChosenGrouping supports only grouping methods where the supplied list should be used as a single group (currently only ChosenGrouping). Called with a groupingActivity with the wrong grouper "+groupingActivity.getActivityId(); + log.error(error); + throw new LessonServiceException(error); + } + } + /** + * Remove learners from the given group. + * @param groupingActivity the activity that has create grouping. (mandatory) + * @param groupID if not null only remove user from this group, if null remove learner from any group. + * @param learners the learners to be removed (mandatory) + */ + public void removeLearnersFromGroup(GroupingActivity groupingActivity, Long groupID, List learners) throws LessonServiceException + { + Grouping grouping = groupingActivity.getCreateGrouping(); + if ( grouping != null ) { + // get the real objects, not the CGLIB version + grouping = groupingDAO.getGroupingById(grouping.getGroupingId()); + Grouper grouper = grouping.getGrouper(); + if ( grouper != null ) { + try { + grouper.removeLearnersFromGroup(grouping, groupID, learners); + } catch ( GroupingException e ) { + throw new LessonServiceException(e); + } + } + groupingDAO.update(grouping); + } + } + + /** Create an empty group for the given grouping. If the group name is not supplied + * or the group name already exists then nothing happens. + * + * @param groupingActivity the activity that has create grouping. (mandatory) + * @param groupName (mandatory) + */ + public void createGroup(GroupingActivity groupingActivity, String name) throws LessonServiceException + { + Grouping grouping = groupingActivity.getCreateGrouping(); + if ( grouping != null ) { + // get the real objects, not the CGLIB version + grouping = groupingDAO.getGroupingById(grouping.getGroupingId()); + Grouper grouper = grouping.getGrouper(); + if ( grouper != null ) { + try { + grouper.createGroup(grouping, name); + } catch ( GroupingException e ) { + throw new LessonServiceException(e); + } + } + groupingDAO.update(grouping); + } + } + + /** + * Remove a group for the given grouping. If the group is already used (e.g. a tool session exists) + * then it throws a GroupingException. + * + * @param groupingActivity the activity that has create grouping. (mandatory) + * @param groupID (mandatory) + */ + public void removeGroup(GroupingActivity groupingActivity, Long groupID) throws LessonServiceException { + Grouping grouping = groupingActivity.getCreateGrouping(); + if ( grouping != null ) { + // get the real objects, not the CGLIB version + grouping = groupingDAO.getGroupingById(grouping.getGroupingId()); + Grouper grouper = grouping.getGrouper(); + if ( grouper != null ) { + try { + grouper.removeGroup(grouping, groupID); + } catch ( GroupingException e ) { + throw new LessonServiceException(e); + } + } + groupingDAO.update(grouping); + } + } + + } Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonServiceException.java =================================================================== diff -u -r56dc9e59c9512b28858b2da10f756103010d9cca -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonServiceException.java (.../LessonServiceException.java) (revision 56dc9e59c9512b28858b2da10f756103010d9cca) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonServiceException.java (.../LessonServiceException.java) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -23,11 +23,7 @@ /* $$Id$$ */ package org.lamsfoundation.lams.lesson.service; -/** - * Type of exception thrown by Tool operations and interfaces. - * @author chris - */ -public class LessonServiceException extends java.lang.Exception +public class LessonServiceException extends java.lang.RuntimeException { /** Index: lams_common/src/java/org/lamsfoundation/lams/tool/exception/ToolException.java =================================================================== diff -u -r34b959260a0f8f8285793a4481a95ca3580eabc5 -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/tool/exception/ToolException.java (.../ToolException.java) (revision 34b959260a0f8f8285793a4481a95ca3580eabc5) +++ lams_common/src/java/org/lamsfoundation/lams/tool/exception/ToolException.java (.../ToolException.java) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -27,7 +27,7 @@ * Type of exception thrown by Tool operations and interfaces. * @author chris */ -public class ToolException extends java.lang.Exception +public class ToolException extends java.lang.RuntimeException { /** Index: lams_common/src/java/org/lamsfoundation/lams/web/util/AttributeNames.java =================================================================== diff -u -r8d7fbb9d04178c47476596b238655bf8ce2214ca -r5009e72ce26a04aa0654d6a6a53eb177c99f42d8 --- lams_common/src/java/org/lamsfoundation/lams/web/util/AttributeNames.java (.../AttributeNames.java) (revision 8d7fbb9d04178c47476596b238655bf8ce2214ca) +++ lams_common/src/java/org/lamsfoundation/lams/web/util/AttributeNames.java (.../AttributeNames.java) (revision 5009e72ce26a04aa0654d6a6a53eb177c99f42d8) @@ -47,6 +47,7 @@ public static final String PARAM_ACTIVITY_ID = "activityID"; public static final String PARAM_COURSE_ID = "courseID"; public static final String PARAM_CLASS_ID = "classID"; + public static final String PARAM_GROUP_ID = "groupID"; public static final String PARAM_LEARNINGDESIGN_ID = "learningDesignID"; public static final String PARAM_ORGANISATION_ID = "organisationID";