Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolActivity.java =================================================================== diff -u -rc135649b64e98c9233da20bdcfb7689598116314 -r42844312f7e8f8330c1b4892a8e036ff6b0813d8 --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolActivity.java (.../ToolActivity.java) (revision c135649b64e98c9233da20bdcfb7689598116314) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/ToolActivity.java (.../ToolActivity.java) (revision 42844312f7e8f8330c1b4892a8e036ff6b0813d8) @@ -41,6 +41,7 @@ import org.lamsfoundation.lams.tool.NonGroupedToolSession; import org.lamsfoundation.lams.tool.Tool; import org.lamsfoundation.lams.tool.ToolSession; +import org.lamsfoundation.lams.tool.exception.LamsToolServiceException; import org.lamsfoundation.lams.usermanagement.User; /** @@ -163,68 +164,64 @@ } /** - * Factory method to create a new tool session for a single user when he is - * running current activity. Does not check to see if a tool session already - * exists. + * Factory method to create a new tool session for a single user when he is running current activity. Does not check + * to see if a tool session already exists. *

- * If the activity has groupingSupportType = GROUPING_SUPPORT_NONE then a - * new tool session is created for each learner. + * If the activity has groupingSupportType = GROUPING_SUPPORT_NONE then a new tool session is created for each + * learner. *

- * If the activity has groupingSupportType = GROUPING_SUPPORT_REQUIRED then - * a new tool session is created for each group of learners. It will fall - * back to a class group if no grouping is found - the user interface should - * not have allowed this! + * If the activity has groupingSupportType = GROUPING_SUPPORT_REQUIRED then a new tool session is created for each + * group of learners. It will fall back to a class group if no grouping is found - the user interface should not + * have allowed this! *

- * If the activity has groupingSupportType = GROUPING_SUPPORT_OPTIONAL then - * a new tool session is created for each group of learners. If no grouping - * is available then a whole of class group is created. + * If the activity has groupingSupportType = GROUPING_SUPPORT_OPTIONAL then a new tool session is created for each + * group of learners. If no grouping is available then a whole of class group is created. *

- * If groupingSupportType is not set then defaults to GROUPING_SUPPORT_NONE. - * If for some reason a grouped session if also does the equivalent of - * GROUPING_SUPPORT_NONE. This way the system will still function, if not as - * expected! + * If groupingSupportType is not set then defaults to GROUPING_SUPPORT_NONE. If for some reason a grouped session if + * also does the equivalent of GROUPING_SUPPORT_NONE. This way the system will still function, if not as expected! *

* * @param learner - * the user who should be using this tool session. + * the user who should be using this tool session. * @return the new tool session. */ + @SuppressWarnings("unchecked") public ToolSession createToolSessionForActivity(User learner, Lesson lesson) { Date now = new Date(System.currentTimeMillis()); Integer supportType = getGroupingSupportType(); ToolSession session = null; if (supportType != null - && (supportType.intValue() == GROUPING_SUPPORT_REQUIRED || supportType.intValue() == GROUPING_SUPPORT_OPTIONAL)) { + && (supportType.equals(GROUPING_SUPPORT_REQUIRED) || supportType.equals(GROUPING_SUPPORT_OPTIONAL))) { // Both cases create a small group if a grouping exists, otherwise creates a class group. - Group learners = null; + Group group = null; if (getApplyGrouping().booleanValue()) { - learners = this.getGroupFor(learner); - } + group = this.getGroupFor(learner); + if (group == null || group.isNull()) { + throw new LamsToolServiceException("Activity " + getActivityId() + + " requires existing grouping but no group for user " + learner.getUserId() + + " exists yet."); + } - if (supportType.intValue() == GROUPING_SUPPORT_REQUIRED && learners == null) { - log - .error("Activity " - + getActivityId() - + " requires grouping (groupingSupportType=GROUPING_SUPPORT_REQUIRED) but no grouping was available. " - + " applyGrouping = " + getApplyGrouping() + " grouping = " + getGrouping() - + ". Falling back to a class grouping."); - } + for (ToolSession toolSession : (Set) group.getToolSessions()) { + if (this.equals(toolSession.getToolActivity())) { + session = toolSession; + break; + } + } + } else { + LessonClass lessonClassGrouping = lesson.getLessonClass(); + group = this.getGroupFor(learner, lessonClassGrouping); - if (learners == null || learners.isNull()) { - LessonClass lessonClass = lesson.getLessonClass(); - learners = this.getGroupFor(learner, lessonClass); + if (group != null && !group.isNull()) { + session = new GroupedToolSession(this, now, ToolSession.STARTED_STATE, group, lesson); + } else { + log.error("Unable to get a lesson class group for a new tool session for activity " + + getActivityId() + " and user " + learner + + ". Falling back to one learner per session."); + } } - - if (learners != null && !learners.isNull()) { - session = new GroupedToolSession(this, now, ToolSession.STARTED_STATE, learners, lesson); - } else { - log - .error("Unable to get the group for a new tool session for Activity " + getActivityId() - + " Falling back to one learner per session." + " Learner " + learner + ", lesson is " - + lesson); - } } if (session == null) { Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -r79add7aa4fc06ca2cc260306f2e33f987a0b4bcb -r42844312f7e8f8330c1b4892a8e036ff6b0813d8 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 79add7aa4fc06ca2cc260306f2e33f987a0b4bcb) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 42844312f7e8f8330c1b4892a8e036ff6b0813d8) @@ -1346,9 +1346,6 @@ String stopReason = forceCompleteActivity(learner, lessonId, learnerProgress, currentActivity, stopPreviousActivity, new ArrayList()); - // without this, there are errors when target is in branching - learnerService.createToolSessionsIfNecessary(stopActivity, learnerProgress); - return stopReason != null ? stopReason : messageService .getMessage(MonitoringService.FORCE_COMPLETE_STOP_MESSAGE_STOPPED_UNEXPECTEDLY); } @@ -1490,7 +1487,9 @@ stopReason = messageService.getMessage( MonitoringService.FORCE_COMPLETE_STOP_MESSAGE_COMPLETED_TO_ACTIVITY, new Object[] { activity.getTitle() }); - + + // without this, there are errors when target is in branching + learnerService.createToolSessionsIfNecessary(stopActivity, learnerProgress); } else { Activity nextActivity = learnerProgress.getNextActivity();