Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -r1880a97b5b0f4069139be31a76a710740ba992bd -rd4ccb9464e49293dc8d95062ed748d48ed8194d8 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 1880a97b5b0f4069139be31a76a710740ba992bd) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision d4ccb9464e49293dc8d95062ed748d48ed8194d8) @@ -1532,9 +1532,10 @@ } /** - * Moves user to the given activity which he already completed. - * Removes and resets entries in LearnerProgress to achieve it. + * Moves user to the given activity which he already completed. Removes and resets entries in LearnerProgress to + * achieve it. */ + @SuppressWarnings("unchecked") private String forceUncompleteActivity(LearnerProgress learnerProgress, Activity previousActivity) { Activity currentActivity = learnerProgress.getCurrentActivity(); @@ -1547,10 +1548,29 @@ CompletedActivityProgress completedActivityProgress = learnerProgress.getCompletedActivities().get( targetActivity); - learnerProgress.getAttemptedActivities().remove(currentActivity); + learnerProgress.getCompletedActivities().remove(targetActivity); learnerProgress.getAttemptedActivities().put(targetActivity, completedActivityProgress.getStartDate()); do { + if (currentActivity.isComplexActivity()) { + // remove all records within complex activity + for (Activity childActivity : (Set) ((ComplexActivity) currentActivity).getActivities()) { + learnerProgress.getAttemptedActivities().remove(childActivity); + learnerProgress.getCompletedActivities().remove(childActivity); + + if (childActivity.isComplexActivity()) { + for (Activity innerChildActivity : (Set) ((ComplexActivity) childActivity) + .getActivities()) { + learnerProgress.getAttemptedActivities().remove(innerChildActivity); + learnerProgress.getCompletedActivities().remove(innerChildActivity); + } + } + } + } + + learnerProgress.getAttemptedActivities().remove(currentActivity); + learnerProgress.getCompletedActivities().remove(currentActivity); + Transition transitionTo = currentActivity.getTransitionTo(); if (transitionTo == null) { // reached beginning of either sequence or complex activity @@ -1560,21 +1580,18 @@ + targetActivity.getActivityId()); } else { currentActivity = currentActivity.getParentActivity(); - learnerProgress.getAttemptedActivities().remove(currentActivity); - if (currentActivity.getParentActivity() != null) { // for optional sequences, the real complex activity is 2 tiers up, not just one currentActivity = currentActivity.getParentActivity(); - learnerProgress.getAttemptedActivities().remove(currentActivity); } - // now outside the complex activity, carry on with the main sequence - transitionTo = currentActivity.getTransitionTo(); + // now the current activity is the complex one in main sequence } + } else { + // move backwards + currentActivity = transitionTo.getFromActivity(); } - currentActivity = transitionTo.getFromActivity(); - // remove completed activities - learnerProgress.getCompletedActivities().remove(currentActivity); + } while (!currentActivity.equals(targetActivity)); learnerProgressDAO.saveLearnerProgress(learnerProgress);