Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -r1ba40605c8e5fff683288c9c72f5ab2a981ba98a -r66f472a982a10227afd93740142320f4be590c8a --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 1ba40605c8e5fff683288c9c72f5ab2a981ba98a) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 66f472a982a10227afd93740142320f4be590c8a) @@ -1111,7 +1111,7 @@ @SuppressWarnings("unchecked") @Override // For this method to work, the Lesson must not be loaded into the Hibernate cache. If it is, then the call - // lessonDAO.deleteByProperty(Transition.class...) call will trigger a + // lessonDAO.deleteByProperty(Transition.class...) call will trigger a // "deleted object would be re-saved by cascade (remove deleted object from associations)" exception // on the Lesson object. If you only access the lesson id then it will work. You can still load the Organisation, // but do not load the Lesson collection in the Organisation @@ -1121,23 +1121,24 @@ Lesson lesson = lessonDAO.getLesson(lessonId); LearningDesign learningDesign = lesson.getLearningDesign(); + // manually delete transitions as subsequent activity removal does not cascade to them + lessonDAO.deleteByProperty(Transition.class, "learningDesign.learningDesignId", + learningDesign.getLearningDesignId()); + lessonDAO.flush(); + // remove lesson resources lessonDAO.deleteByProperty(LogEvent.class, "lessonId", lessonId); lessonDAO.deleteByProperty(ToolSession.class, "lesson.lessonId", lessonId); - Map notebookProperties = new TreeMap(); + Map notebookProperties = new TreeMap<>(); notebookProperties.put("externalID", lessonId); notebookProperties.put("externalSignature", CoreNotebookConstants.SCRATCH_PAD_SIG); lessonDAO.deleteByProperties(NotebookEntry.class, notebookProperties); lessonDAO.deleteLesson(lesson); - // manually delete transitions as subsequent activity removal does not cascade to them - lessonDAO.deleteByProperty(Transition.class, "learningDesign.learningDesignId", - learningDesign.getLearningDesignId()); - // remove each Tool activity content // It has to be done before removing BranchEntries as fetching Tool content // in its own transaction would re-add connected BranchEntries (Hibernate error) - Set systemActivities = new HashSet(); + Set systemActivities = new HashSet<>(); for (Activity activity : learningDesign.getActivities()) { // get the real object, not the proxy activity = activityDAO.getActivityByActivityId(activity.getActivityId()); @@ -1535,7 +1536,7 @@ Activity currentActivity = learnerProgress.getCurrentActivity(); // list of activities for which "attempted" and "completed" status will be removed // in last-to-first order - List uncompleteActivities = new LinkedList(); + List uncompleteActivities = new LinkedList<>(); if (currentActivity == null) { // Learner has finished the whole lesson. Find the last activity by traversing the transition. @@ -1580,7 +1581,7 @@ learnerProgress.setNextActivity(targetActivity); // grouping and branch activities which need to be reset - Set groupings = new HashSet(); + Set groupings = new HashSet<>(); // remove completed activities step by step, all the way from current to target activity while (!currentActivity.equals(targetActivity)) { @@ -1607,7 +1608,7 @@ // get real instance instead of a lazy loaded proxy Activity sequenceChildActivity = ((SequenceActivity) activityDAO .getActivityByActivityId(childActivity.getActivityId())).getDefaultActivity(); - List sequenceChildActivities = new LinkedList(); + List sequenceChildActivities = new LinkedList<>(); while (sequenceChildActivity != null) { sequenceChildActivities.add(sequenceChildActivity); if (sequenceChildActivity.getTransitionFrom() != null) { @@ -1754,7 +1755,7 @@ lesson = learnerService.getLesson(lessonId); } - Collection users = new LinkedList(); + Collection users = new LinkedList<>(); switch (searchType) { case MonitoringConstants.LESSON_TYPE_ASSIGNED_TO_LESSON: users = lesson.getAllLearners(); @@ -1808,7 +1809,7 @@ case MonitoringConstants.COURSE_TYPE_HAVENT_STARTED_ANY_LESSONS: List allUSers = userManagementService.getUsersFromOrganisation(orgId); - Set usersStartedAtLest1Lesson = new TreeSet(); + Set usersStartedAtLest1Lesson = new TreeSet<>(); Organisation org = getOrganisation(orgId); Set lessons = org.getLessons(); @@ -1837,7 +1838,7 @@ break; case MonitoringConstants.COURSE_TYPE_HAVENT_FINISHED_THESE_LESSONS: - users = new TreeSet(); + users = new TreeSet<>(); // add all available users from selected lessons for (String lessonIdStr : lessonIds) { @@ -1855,7 +1856,7 @@ break; } - Set sortedUsers = new TreeSet(new Comparator() { + Set sortedUsers = new TreeSet<>(new Comparator() { @Override public int compare(User usr0, User usr1) { return ((usr0.getFirstName() + usr0.getLastName() + usr0.getLogin()) @@ -1899,8 +1900,8 @@ EmailNotificationArchive notification = (EmailNotificationArchive) baseDAO.find(EmailNotificationArchive.class, emailNotificationUid); - LinkedHashMap sheets = new LinkedHashMap(); - List rows = new LinkedList(); + LinkedHashMap sheets = new LinkedHashMap<>(); + List rows = new LinkedList<>(); ExcelCell[] row = new ExcelCell[3]; row[0] = new ExcelCell(messageService.getMessage("email.notifications.archived.messages.list.sent.date"), true); row[1] = new ExcelCell( @@ -1950,7 +1951,7 @@ */ @Override public List getUsersCompletedLesson(Long lessonId, Integer limit, Integer offset, boolean orderAscending) { - List usersCompletedLesson = new LinkedList(); + List usersCompletedLesson = new LinkedList<>(); List completedLearnerProgresses = learnerProgressDAO .getCompletedLearnerProgressForLesson(lessonId, limit, offset, orderAscending); @@ -2143,10 +2144,10 @@ } // create the lesson class - add the teacher as the learner and as staff - LinkedList learners = new LinkedList(); + LinkedList learners = new LinkedList<>(); learners.add(user); - LinkedList staffs = new LinkedList(); + LinkedList staffs = new LinkedList<>(); staffs.add(user); createLessonClassForLesson(lessonID, null, "Learner Group", learners, "Staff Group", staffs, userID); @@ -2282,7 +2283,7 @@ private ArrayList createUserList(Long activityIDForErrorMessage, String[] learnerIDs, String addRemoveTextForErrorMessage) { - ArrayList learners = new ArrayList(); + ArrayList learners = new ArrayList<>(); for (String strlearnerID : learnerIDs) { boolean added = false; try { @@ -2307,7 +2308,7 @@ public int addUsersToGroupByLogins(Long activityID, String groupName, Set logins) throws LessonServiceException { - ArrayList learners = new ArrayList(); + ArrayList learners = new ArrayList<>(); for (String login : logins) { User learner = userManagementService.getUserByLogin(login); if (learner == null) { @@ -2323,7 +2324,7 @@ "addUsersToGroupByLogins"); Group group = null; - Set otherGroupNames = new HashSet(); + Set otherGroupNames = new HashSet<>(); for (Group checkGroup : grouping.getGroups()) { if (checkGroup.getGroupName().equalsIgnoreCase(groupName)) { group = checkGroup; @@ -2537,7 +2538,7 @@ throw new MonitoringServiceException(error); } - TreeSet unassignedGroups = new TreeSet(); + TreeSet unassignedGroups = new TreeSet<>(); Grouping grouping = branchingActivity.getGrouping(); Iterator groupIterator = grouping.getGroups().iterator(); @@ -2644,7 +2645,7 @@ public void removeLearnerContent(Long lessonId, Integer learnerId) { User learner = (User) userManagementService.findById(User.class, learnerId); LearnerProgress learnerProgress = getLearnerProgress(learnerId, lessonId); - Set activities = new HashSet(); + Set activities = new HashSet<>(); activities.addAll(learnerProgress.getAttemptedActivities().keySet()); activities.addAll(learnerProgress.getCompletedActivities().keySet()); boolean resetReadOnly = true; @@ -2819,7 +2820,7 @@ * Used in cloneLessons. */ private List createLearnerGroup(Integer groupId, Boolean addAllLearners, String[] learnerIds) { - List learnerUsers = new ArrayList(); + List learnerUsers = new ArrayList<>(); if (addAllLearners) { Vector learnerVector = userManagementService.getUsersFromOrganisationByRole(groupId, Role.LEARNER, true); learnerUsers.addAll(learnerVector); @@ -2841,7 +2842,7 @@ * Used in cloneLessons. */ private List createStaffGroup(Integer groupId, Boolean addAllStaff, String[] staffIds) { - List staffUsers = new ArrayList(); + List staffUsers = new ArrayList<>(); if (addAllStaff) { Vector staffVector = userManagementService.getUsersFromOrganisationByRole(groupId, Role.MONITOR, true); staffUsers.addAll(staffVector);