Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/BranchDTO.java
===================================================================
diff -u
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/BranchDTO.java (revision 0)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/BranchDTO.java (revision 7651b7a24448e75a74e89ed815d8f9f1d7328636)
@@ -0,0 +1,72 @@
+package org.lamsfoundation.lams.monitoring;
+
+import java.io.Serializable;
+import java.util.SortedSet;
+
+import org.apache.commons.lang.builder.CompareToBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.lamsfoundation.lams.learningdesign.Group;
+import org.lamsfoundation.lams.learningdesign.SequenceActivity;
+
+/** Represents a single branch within a branching activity. Used by the Teacher Chosen Grouping screen for
+ * allocating learners to branches, and on the other branching screens to view the current branch -> group mappings
+ *
+ * A branch is equivalent to a SequenceActivity within a BranchingActivity
+ */
+public class BranchDTO implements Serializable, Comparable {
+
+ private Long branchId;
+ private String branchName;
+ private SortedSet groups;
+
+ public BranchDTO(SequenceActivity activity, SortedSet groups) {
+ this.branchId = activity.getActivityId();
+ this.branchName = activity.getTitle();
+ this.groups = groups;
+ }
+ /** Get the activity id for the sequence activity that is equivalent to this branch */
+ public Long getBranchId() {
+ return branchId;
+ }
+ public void setBranchId(Long branchId) {
+ this.branchId = branchId;
+ }
+ /** The branch name is the title of the sequence activity that is equivalent to this branch */
+ public String getBranchName() {
+ return branchName;
+ }
+ public void setBranchName(String branchName) {
+ this.branchName = branchName;
+ }
+ /** Get the groups currently assigned to this branch. For a teacher chosen branching activity,
+ * there will be one group per branch.
+ * @return
+ */
+ public SortedSet getGroups() {
+ return groups;
+ }
+ public void setGroups(SortedSet groups) {
+ this.groups = groups;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("branchName", branchName)
+ .append("branchId", branchId)
+ .append("groups", groups)
+ .toString();
+ }
+
+ public int compareTo(Object other) {
+ BranchDTO otherBranch = (BranchDTO) other;
+ return new CompareToBuilder()
+ .append(branchName, otherBranch.branchName)
+ .append(branchId, otherBranch.branchId)
+ .toComparison();
+ }
+
+
+
+
+
+}
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/BranchingDTO.java
===================================================================
diff -u
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/BranchingDTO.java (revision 0)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/BranchingDTO.java (revision 7651b7a24448e75a74e89ed815d8f9f1d7328636)
@@ -0,0 +1,86 @@
+package org.lamsfoundation.lams.monitoring;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.commons.lang.builder.CompareToBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.lamsfoundation.lams.learningdesign.BranchingActivity;
+import org.lamsfoundation.lams.learningdesign.Group;
+import org.lamsfoundation.lams.learningdesign.GroupBranchActivityEntry;
+import org.lamsfoundation.lams.learningdesign.SequenceActivity;
+
+/** Represents an overall branching activity. Used by the Teacher Chosen Grouping screen for
+ * allocating learners to branches, and on the other branching screens to view the current branch -> group mappings
+ */
+public class BranchingDTO implements Serializable, Comparable {
+
+ private Long branchActivityId;
+ private String branchActivityName;
+ private SortedSet branches;
+
+ public BranchingDTO(BranchingActivity activity) {
+ this.branchActivityId = activity.getActivityId();
+ this.branchActivityName = activity.getTitle();
+
+ branches = new TreeSet();
+ Iterator iter = activity.getActivities().iterator();
+ while (iter.hasNext()) {
+ SequenceActivity branch = (SequenceActivity) iter.next();
+ Set mappingEntries = branch.getBranchEntries();
+ SortedSet groups = new TreeSet();
+ for ( GroupBranchActivityEntry entry : mappingEntries ) {
+ Group group = entry.getGroup();
+ groups.add(group);
+ }
+ branches.add(new BranchDTO(branch, groups));
+ }
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this)
+ .append("branchActivityId", branchActivityId)
+ .append("branchActivityName", branchActivityName)
+ .append("branches", branches)
+ .toString();
+ }
+
+ public int compareTo(Object other) {
+ BranchingDTO otherBranch = (BranchingDTO) other;
+ return new CompareToBuilder()
+ .append(branchActivityId, otherBranch.branchActivityId)
+ .append(branchActivityName, otherBranch.branchActivityName)
+ .toComparison();
+ }
+
+ public Long getBranchActivityId() {
+ return branchActivityId;
+ }
+
+ public void setBranchActivityId(Long branchActivityId) {
+ this.branchActivityId = branchActivityId;
+ }
+
+ public String getBranchActivityName() {
+ return branchActivityName;
+ }
+
+ public void setBranchActivityName(String branchActivityName) {
+ this.branchActivityName = branchActivityName;
+ }
+
+ public SortedSet getBranches() {
+ return branches;
+ }
+
+ public void setBranches(SortedSet branches) {
+ this.branches = branches;
+ }
+
+
+
+
+}
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/ContributeActivityDTO.java
===================================================================
diff -u -r08950e1090443c3423a3d1c587416a2fccd8bbdf -r7651b7a24448e75a74e89ed815d8f9f1d7328636
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/ContributeActivityDTO.java (.../ContributeActivityDTO.java) (revision 08950e1090443c3423a3d1c587416a2fccd8bbdf)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/ContributeActivityDTO.java (.../ContributeActivityDTO.java) (revision 7651b7a24448e75a74e89ed815d8f9f1d7328636)
@@ -125,8 +125,9 @@
this.contributionType = contributionType;
boolean isReq = contributionType!=null &&
( contributionType.equals(ContributionTypes.DEFINE_LATER) ||
- contributionType.equals(ContributionTypes.PERMISSION_GATE)||
- contributionType.equals(ContributionTypes.CHOSEN_GROUPING) );
+ contributionType.equals(ContributionTypes.PERMISSION_GATE) ||
+ contributionType.equals(ContributionTypes.CHOSEN_GROUPING) ||
+ contributionType.equals(ContributionTypes.CHOSEN_BRANCHING));
this.isRequired = new Boolean(isReq);
}
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/ContributeDTOFactory.java
===================================================================
diff -u -r08950e1090443c3423a3d1c587416a2fccd8bbdf -r7651b7a24448e75a74e89ed815d8f9f1d7328636
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/ContributeDTOFactory.java (.../ContributeDTOFactory.java) (revision 08950e1090443c3423a3d1c587416a2fccd8bbdf)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/ContributeDTOFactory.java (.../ContributeDTOFactory.java) (revision 7651b7a24448e75a74e89ed815d8f9f1d7328636)
@@ -24,10 +24,15 @@
/* $Id$ */
package org.lamsfoundation.lams.monitoring;
+import java.util.Vector;
+
+import org.lamsfoundation.lams.learningdesign.Activity;
import org.lamsfoundation.lams.learningdesign.ComplexActivity;
import org.lamsfoundation.lams.learningdesign.ContributionTypes;
import org.lamsfoundation.lams.learningdesign.SimpleActivity;
import org.lamsfoundation.lams.learningdesign.ToolActivity;
+import org.lamsfoundation.lams.learningdesign.strategy.ComplexActivityStrategy;
+import org.lamsfoundation.lams.learningdesign.strategy.IContributionTypeStrategy;
import org.lamsfoundation.lams.learningdesign.strategy.SimpleActivityStrategy;
import org.lamsfoundation.lams.tool.exception.LamsToolServiceException;
import org.lamsfoundation.lams.tool.service.ILamsCoreToolService;
@@ -45,20 +50,26 @@
ContributeActivityDTO dto = null;
SimpleActivityStrategy strategy = activity.getSimpleActivityStrategy();
if ( strategy != null ) {
- Integer[] contributionType = activity.getSimpleActivityStrategy().getContributionType();
- if ( contributionType.length > 0 ) {
- dto = new ContributeActivityDTO(activity);
- for(int i=0;i 0 ) {
+ dto = new ContributeActivityDTO(activity);
+ for(int i=0;i childActivities)
{
- return new ContributeActivityDTO(activity);
+ ContributeActivityDTO dto = null;
+ ComplexActivityStrategy strategy = activity.getComplexActivityStrategy();
+ if ( strategy != null ) {
+ dto = addContributionURLS(lessonID, activity, strategy, toolService);
+ if ( childActivities != null && childActivities.size() > 0 ) {
+ if ( dto == null ) {
+ dto = new ContributeActivityDTO(activity);
+ }
+ dto.setChildActivities(childActivities);
+ }
+ }
+ return dto;
}
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/ContributeActivitiesProcessor.java
===================================================================
diff -u -r08950e1090443c3423a3d1c587416a2fccd8bbdf -r7651b7a24448e75a74e89ed815d8f9f1d7328636
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/ContributeActivitiesProcessor.java (.../ContributeActivitiesProcessor.java) (revision 08950e1090443c3423a3d1c587416a2fccd8bbdf)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/ContributeActivitiesProcessor.java (.../ContributeActivitiesProcessor.java) (revision 7651b7a24448e75a74e89ed815d8f9f1d7328636)
@@ -98,13 +98,11 @@
public void endComplexActivity(ComplexActivity activity) {
ContributeActivityDTO dto = null;
- if ( currentActivityList.size()>0 ) {
- dto = ContributeDTOFactory.getContributeActivityDTO(activity);
- dto.setChildActivities(currentActivityList);
- }
+ // always attempt to get a dto, as some branching activities require contribution.
+ dto = ContributeDTOFactory.getContributeActivityDTO(lessonID, activity, toolService, currentActivityList);
currentActivityList = (Vector) activityListStack.pop();
- if ( dto != null ) {
+ if ( dto != null) {
currentActivityList.add(dto);
}
}
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java
===================================================================
diff -u -r7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15 -r7651b7a24448e75a74e89ed815d8f9f1d7328636
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 7651b7a24448e75a74e89ed815d8f9f1d7328636)
@@ -735,7 +735,7 @@
for (Iterator i = activities.iterator(); i.hasNext();)
{
Activity activity = (Activity) i.next();
- // if it is a non-grouped Tool Activity, create the tool sessions now
+ // if it is a non-grouped and non-branched Tool Activity, create the tool sessions now
if ( activity.isToolActivity() ) {
ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId());
initToolSessionIfSuitable(toolActivity, requestedLesson);
@@ -745,6 +745,19 @@
ScheduleGateActivity gateActivity = (ScheduleGateActivity) activityDAO.getActivityByActivityId(activity.getActivityId());
activity = runGateScheduler(gateActivity,lessonStartTime,requestedLesson.getLessonName());
}
+ if ( activity.isBranchingActivity() && activity.getGrouping() == null) {
+ // all branching activities must have a grouping, as the learner will be allocated to a group linked to a sequence (branch)
+ Grouping grouping = new ChosenGrouping(null, null, null);
+ grouping.getActivities().add(activity);
+ activity.setGrouping(grouping);
+ groupingDAO.insert(grouping);
+
+ activity.setGrouping(grouping);
+ if ( log.isDebugEnabled() ) {
+ log.debug( "startLesson: Created chosen grouping "+grouping+" for branching activity "+activity);
+ }
+ }
+
activity.setInitialised(Boolean.TRUE);
activityDAO.update(activity);
@@ -1609,6 +1622,22 @@
//---------------------------------------------------------------------
// Helper Methods - start lesson
//---------------------------------------------------------------------
+ /**
+ * Is this activity inside a branch?
+ */
+ private boolean isInBranch(Activity activity) {
+
+ Activity parent = activity.getParentActivity();
+
+ if ( parent == null )
+ return false;
+
+ if ( parent.isBranchingActivity() )
+ return true;
+
+ return isInBranch(parent);
+ }
+
/**
* If the activity is not grouped, then it create lams tool session for
* all the learners in the lesson. After the creation of lams tool session,
@@ -1620,7 +1649,9 @@
*/
private void initToolSessionIfSuitable(ToolActivity activity, Lesson lesson)
{
- if ( ! activity.getApplyGrouping().booleanValue() ) {
+ // TODO: also need to check if it is inside a branch. If so, don't create
+ // the tool session as it will only apply to some users in the lesson.
+ if ( ! activity.getApplyGrouping().booleanValue() || isInBranch(activity) ) {
activity.setToolSessions(new HashSet());
try {
@@ -1815,8 +1846,8 @@
}
- /* ************** Grouping related calls ***************************************/
- /** Get all the active learners in the lesson who are not in a group.
+ /* ************** Grouping and branching related calls ***************************************/
+ /** Get all the active learners in the lesson who are not in a group/branch
*
* If the activity is a grouping activity, then set useCreatingGrouping = true to
* base the list on the create grouping. Otherwise leave it false and it will use the
@@ -1889,15 +1920,6 @@
grouping = groupingActivity.getCreateGrouping();
} else {
grouping = activity.getGrouping();
- if ( grouping == null && activity.isChosenBranchingActivity() ) {
- // for chosen, create one on the fly the first time required
- grouping = new ChosenGrouping(null, null, null);
- grouping.getActivities().add(activity);
- groupingDAO.insert(grouping);
- if ( log.isDebugEnabled() ) {
- log.debug( methodName+": Created chosen grouping "+grouping+" for branching activity "+activity);
- }
- }
}
if ( grouping == null ) {
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/ChosenBranchingAJAXAction.java
===================================================================
diff -u -r7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15 -r7651b7a24448e75a74e89ed815d8f9f1d7328636
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/ChosenBranchingAJAXAction.java (.../ChosenBranchingAJAXAction.java) (revision 7f65c5834b2d8aaee5e26b1f49a1c634c1c6cb15)
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/ChosenBranchingAJAXAction.java (.../ChosenBranchingAJAXAction.java) (revision 7651b7a24448e75a74e89ed815d8f9f1d7328636)
@@ -41,15 +41,19 @@
import org.apache.struts.action.ActionMapping;
import org.lamsfoundation.lams.learning.web.util.LearningWebUtil;
import org.lamsfoundation.lams.learningdesign.Activity;
+import org.lamsfoundation.lams.learningdesign.ActivityTitleComparator;
import org.lamsfoundation.lams.learningdesign.BranchingActivity;
import org.lamsfoundation.lams.learningdesign.ChosenBranchingActivity;
import org.lamsfoundation.lams.learningdesign.ChosenGrouping;
import org.lamsfoundation.lams.learningdesign.Group;
+import org.lamsfoundation.lams.learningdesign.GroupBranchActivityEntry;
import org.lamsfoundation.lams.learningdesign.GroupComparator;
import org.lamsfoundation.lams.learningdesign.Grouping;
import org.lamsfoundation.lams.learningdesign.GroupingActivity;
import org.lamsfoundation.lams.learningdesign.SequenceActivity;
import org.lamsfoundation.lams.lesson.service.LessonServiceException;
+import org.lamsfoundation.lams.monitoring.BranchDTO;
+import org.lamsfoundation.lams.monitoring.BranchingDTO;
import org.lamsfoundation.lams.monitoring.service.IMonitoringService;
import org.lamsfoundation.lams.monitoring.service.MonitoringServiceException;
import org.lamsfoundation.lams.monitoring.service.MonitoringServiceProxy;
@@ -86,13 +90,11 @@
private static final String CHOSEN_SELECTION_SCREEN = "chosenSelection";
private static final String VIEW_BRANCHES_SCREEN = "viewBranches";
- private static final String PARAM_ACTIVITY_DESCRIPTION = "description";
public static final String PARAM_TYPE = "type";
-// public static final String PARAM_MAX_NUM_GROUPS = "maxNumberOfGroups";
- public static final String PARAM_NAME = "name";
- public static final String PARAM_BRANCHES = "branches";
- public static final String PARAM_MEMBERS = "members";
+ public static final String PARAM_BRANCHING_DTO = "branching";
+ public static final String PARAM_BRANCH_ID = "branchID";
public static final String PARAM_MAY_DELETE = "mayDelete";
+ public static final String PARAM_MEMBERS = "members";
private Integer getUserId(HttpServletRequest request) {
HttpSession ss = SessionManager.getSession();
@@ -144,87 +146,107 @@
log.error(error);
throw new MonitoringServiceException(error);
}
- Grouping grouping = activity.getGrouping();
- if ( grouping == null ) {
- // need to create the grouping for a chosen branching activity
- String error = "Grouping for branching activity missing. Activity was "+activity;
- log.error(error);
- throw new MonitoringServiceException(error);
- }
+ // in general the progress engine expects the activity and lesson id to be in the request,
+ // so follow that standard.
request.setAttribute(AttributeNames.PARAM_ACTIVITY_ID, activityID);
request.setAttribute(AttributeNames.PARAM_LESSON_ID, lessonId);
request.setAttribute(AttributeNames.PARAM_TITLE, activity.getTitle());
- request.setAttribute(PARAM_ACTIVITY_DESCRIPTION, activity.getDescription());
-
- if ( activity.isBranchingActivity() ) {
-// request.setAttribute(PARAM_MAX_NUM_GROUPS, grouping.getMaxNumberOfGroups());
- // can I remove groups/users - can't if tool sessions have been created
- Set groups = grouping.getGroups();
- Iterator iter = groups.iterator();
- boolean mayDelete = true;
- while (mayDelete && iter.hasNext()) {
- Group group = (Group) iter.next();
- mayDelete = group.mayBeDeleted();
+
+ if ( activity.isChosenBranchingActivity() ) {
+
+ // can we still move users? check each group for tool sessions.
+ Iterator iter = ((BranchingActivity)activity).getActivities().iterator();
+ boolean mayMoveUser = true;
+ while (iter.hasNext()) {
+ SequenceActivity branch = (SequenceActivity) iter.next();
+ Set mappingEntries = branch.getBranchEntries();
+ for ( GroupBranchActivityEntry entry : mappingEntries ) {
+ mayMoveUser = mayMoveUser && entry.getGroup().mayBeDeleted();
+ }
}
- request.setAttribute(PARAM_MAY_DELETE, mayDelete);
+ request.setAttribute(PARAM_MAY_DELETE, mayMoveUser);
+
return mapping.findForward(CHOSEN_SELECTION_SCREEN);
} else {
-
// go to a view only screen for group based and tool based grouping
- // view all the branches, along with the groups for each branch and each groups members
- SortedSet branches = new TreeSet();
- branches.addAll(((BranchingActivity)activity).getActivities());
- request.setAttribute(PARAM_BRANCHES,branches);
+ BranchingDTO dto = new BranchingDTO((BranchingActivity) activity);
+ request.setAttribute(PARAM_BRANCHING_DTO, dto);
+ if ( log.isDebugEnabled() ) {
+ log.debug("assignBranch: Branching activity "+dto);
+ }
return mapping.findForward(VIEW_BRANCHES_SCREEN);
}
}
/**
- * Get a list of group names and the number of users in each group. Designed to respond to an AJAX call.
+ * Get a list of branch names, their associated group id and the number of users in the group. Designed to respond to an AJAX call.
*
- * Input parameters: activityID
+ * Input parameters: activityID (which is the branching activity id)
*
- * Output format: "groupid,name,num users;groupid,name,num users"
+ * Output format: "branchid,name,num users;branchid,groupid,name,num users"
*/
- public ActionForward getGroups(ActionMapping mapping,
+ public ActionForward getBranches(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
- // get the grouping data and sort it.
+ // get the branching data and sort it.
Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID);
IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- ChosenBranchingActivity activity = (ChosenBranchingActivity) monitoringService.getActivityById(activityID);
- Grouping grouping = getGrouping(activity);
- Set sortedGroups = new TreeSet(new GroupComparator());
- sortedGroups.addAll(grouping.getGroups());
+ BranchingActivity activity = (BranchingActivity) monitoringService.getActivityById(activityID);
+
+ TreeSet sortedBranches = new TreeSet(new ActivityTitleComparator());
+ sortedBranches.addAll(activity.getActivities());
- // build the output string to return to the chosen grouping page.
- String groupOutput = "";
+ // build the output string to return to the chosen branching page.
+ // there should only ever be one group for each branch in chosen branching
+ String branchesOutput = "";
+
boolean first = true;
- for ( Group group: sortedGroups ) {
- Long groupId = group.getGroupId();
- String name = group.getGroupName();
- Integer numberOfMembers = group.getUsers().size();
+ for ( SequenceActivity branch : sortedBranches ) {
+ Long branchId = branch.getActivityId();
+ String name = branch.getTitle();
+ Integer numberOfMembers = null;
+
+ Set mappingEntries = branch.getBranchEntries();
+ if ( mappingEntries != null ) {
+ if ( mappingEntries.size() > 0 ) {
+ log.warn("Branch "+branch+" for branching activity "+activity+" has more than one group. This should not happen. Using only the first group.");
+ mappingEntries = new TreeSet();
+ }
+
+ Iterator mappingIter = mappingEntries.iterator();
+ if ( mappingIter.hasNext() ) {
+ Group group = ((GroupBranchActivityEntry) mappingIter.next()).getGroup();
+ numberOfMembers = group.getUsers().size();
+ }
+ }
+
if ( ! first ) {
- groupOutput=groupOutput+";";
+ branchesOutput=branchesOutput+";";
} else {
first = false;
}
- groupOutput=groupOutput+groupId+","+name+","+numberOfMembers;
+
+ branchesOutput=branchesOutput+branchId+","+name+","+numberOfMembers;
}
- writeAJAXResponse(response, groupOutput);
+
+ if ( log.isDebugEnabled() ) {
+ log.debug("getBranches activity id "+activityID+" returning "+branchesOutput);
+ }
+
+ writeAJAXResponse(response, branchesOutput);
return null;
}
/**
* Get a list of all the class members who aren't grouped yet. Designed to respond to an AJAX call.
*
- * Input parameters: activityID
+ * Input parameters: activityID (which is the branching activity id)
*
- * Output format: "groupid,name,num users;groupid,name,num users"
+ * Output format: "userid,lastname,firstname;userid,lastname,firstname;"
*/
public ActionForward getClassMembersNotGrouped(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
@@ -244,39 +266,44 @@
/**
* Get a list of group names and the number of users in each group. Designed to respond to an AJAX call.
*
- * Input parameters: activityID, groupID
+ * Input parameters: branchID which is sequence activity id
*
* Output format: "userid,lastname,firstname;"
*/
- public ActionForward getGroupMembers(ActionMapping mapping,
+ public ActionForward getBranchMembers(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
- // TODO optimise this call - we don't really need the activity and the grouping - go straight to the group in the db
- // get the group, and from there the user data and sort the user data.
- Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID);
- Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID);
+ Long branchID = WebUtil.readLongParam(request, PARAM_BRANCH_ID);
IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- ChosenBranchingActivity activity = (ChosenBranchingActivity) monitoringService.getActivityById(activityID);
- Grouping grouping = getGrouping(activity);
- Set groups = grouping.getGroups();
- Iterator iter = groups.iterator();
- Group group = null;
- while (group==null && iter.hasNext()) {
- Group candidateGroup = (Group) iter.next();
- if ( groupID.equals(candidateGroup.getGroupId()) )
- group = candidateGroup;
+ SequenceActivity branch = (SequenceActivity) monitoringService.getActivityById(branchID);
+
+ Set mappingEntries = branch.getBranchEntries();
+ Group group = null;
+
+ if ( mappingEntries != null ) {
+ if ( mappingEntries.size() > 0 ) {
+ log.warn("Branch "+branch+" for branching activity "+branch+" has more than one group. This should not happen. Using only the first group.");
+ mappingEntries = new TreeSet();
+ }
+
+ Iterator mappingIter = mappingEntries.iterator();
+ if ( mappingIter.hasNext() ) {
+ group = ((GroupBranchActivityEntry) mappingIter.next()).getGroup();
+ }
}
- if ( group == null ) {
- String error = "Group cannot be found. Activity was "+activity+" Grouping was "+grouping+" Grouping ID was "+groupID;
- log.error(error);
- throw new MonitoringServiceException(error);
+
+ String userOutput = null;
+ if ( group != null ) {
+ SortedSet sortedUsers = new TreeSet(new LastNameAlphabeticComparator());
+ sortedUsers.addAll(group.getUsers());
+ userOutput = buildUserString(sortedUsers);
}
+
+ if ( log.isDebugEnabled() ) {
+ log.debug("getBranchMembers branch id "+branchID+" returning "+userOutput);
+ }
- Set users = group.getUsers();
- SortedSet sortedUsers = new TreeSet(new LastNameAlphabeticComparator());
- sortedUsers.addAll(users);
- String userOutput = buildUserString(sortedUsers);
writeAJAXResponse(response, userOutput);
return null;
}
@@ -305,64 +332,42 @@
}
/**
- * Add a new group. Designed to respond to an AJAX call.
+ * Add learners to a group. Designed to respond to an AJAX call.
*
- * Input parameters: activityID, name (group name)
+ * Input parameters: branchID, name: group name, members: comma separated list of users
*
* Output format: no data returned - just the header
*/
- public ActionForward addGroup(ActionMapping mapping,
+ public ActionForward addMembers(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException, LessonServiceException {
- Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID);
- String name = WebUtil.readStrParam(request, PARAM_NAME);
+ Long branchID = WebUtil.readLongParam(request, PARAM_BRANCH_ID);
IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- monitoringService.addGroup(activityID, name, false);
- writeAJAXResponse(response,"");
- return null;
- }
+ SequenceActivity branch = (SequenceActivity) monitoringService.getActivityById(branchID);
- /**
- * Remove a group. Cannot remove the group if it is in use (tool session ids exist). Designed to respond to an AJAX call.
- *
- * Input parameters: activityID, name: group name
- *
- * Output format: no data returned - just the header
- */
- public ActionForward removeGroup(ActionMapping mapping,
- ActionForm form, HttpServletRequest request,
- HttpServletResponse response) throws IOException, ServletException, LessonServiceException {
+ Set mappingEntries = branch.getBranchEntries();
+ Group group = null;
+
+ if ( mappingEntries != null ) {
+ if ( mappingEntries.size() > 0 ) {
+ log.warn("Branch "+branch+" for branching activity "+branch+" has more than one group. This should not happen. Using only the first group.");
+ mappingEntries = new TreeSet();
+ }
+
+ Iterator mappingIter = mappingEntries.iterator();
+ if ( mappingIter.hasNext() ) {
+ group = ((GroupBranchActivityEntry) mappingIter.next()).getGroup();
+ }
+ }
- Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID);
- Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID);
-
- IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- monitoringService.removeGroup(activityID, groupID, false);
- writeAJAXOKResponse(response);
- return null;
- }
-
- /**
- * Add learners to a group. Designed to respond to an AJAX call.
- *
- * Input parameters: activityID, name: group name, members: comma separated list of users
- *
- * Output format: no data returned - just the header
- */
- public ActionForward addMembers(ActionMapping mapping,
- ActionForm form, HttpServletRequest request,
- HttpServletResponse response) throws IOException, ServletException, LessonServiceException {
-
- Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID);
- Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID);
String members = WebUtil.readStrParam(request, PARAM_MEMBERS, true);
if ( members != null ) {
String[] membersSplit = members.split(",");
- IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- monitoringService.addUsersToGroup(activityID, groupID, membersSplit, false);
+// monitoringService.addUsersToGroup(activityID, groupID, membersSplit, false);
}
- writeAJAXOKResponse(response);
+
+ writeAJAXOKResponse(response);
return null;
}
@@ -377,15 +382,15 @@
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException, LessonServiceException {
- Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID);
- Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID);
- String members = WebUtil.readStrParam(request, PARAM_MEMBERS, true);
- if ( members != null ) {
- String[] membersSplit = members.split(",");
- IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
- monitoringService.removeUsersFromGroup(activityID, groupID, membersSplit, false);
- }
- writeAJAXOKResponse(response);
+// Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID);
+// Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID);
+// String members = WebUtil.readStrParam(request, PARAM_MEMBERS, true);
+// if ( members != null ) {
+// String[] membersSplit = members.split(",");
+// IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext());
+// monitoringService.removeUsersFromGroup(activityID, groupID, membersSplit, false);
+// }
+// writeAJAXOKResponse(response);
return null;
}