Index: lams_central/src/java/org/lamsfoundation/lams/web/outcome/OutcomeController.java =================================================================== diff -u -re6dc4db4137cfd6b07a4aa79711b9d12b39fb78e -rb8e54021b464f3abf023581e819cee4d4a54f26e --- lams_central/src/java/org/lamsfoundation/lams/web/outcome/OutcomeController.java (.../OutcomeController.java) (revision e6dc4db4137cfd6b07a4aa79711b9d12b39fb78e) +++ lams_central/src/java/org/lamsfoundation/lams/web/outcome/OutcomeController.java (.../OutcomeController.java) (revision b8e54021b464f3abf023581e819cee4d4a54f26e) @@ -23,7 +23,6 @@ package org.lamsfoundation.lams.web.outcome; import java.util.Date; -import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -36,7 +35,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; -import org.lamsfoundation.lams.learningdesign.ToolActivity; +import org.lamsfoundation.lams.lesson.service.ILessonService; import org.lamsfoundation.lams.outcome.Outcome; import org.lamsfoundation.lams.outcome.OutcomeMapping; import org.lamsfoundation.lams.outcome.OutcomeResult; @@ -54,7 +53,6 @@ import org.lamsfoundation.lams.util.FileUtil; import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.WebUtil; -import org.lamsfoundation.lams.util.excel.ExcelCell; import org.lamsfoundation.lams.util.excel.ExcelSheet; import org.lamsfoundation.lams.util.excel.ExcelUtil; import org.lamsfoundation.lams.web.session.SessionManager; @@ -87,6 +85,9 @@ @Autowired private IOutcomeService outcomeService; @Autowired + private ILessonService lessonService; + + @Autowired @Qualifier("centralMessageService") private MessageService messageService; @@ -348,9 +349,7 @@ mappingId); Long lessonId = outcomeMapping.getLessonId(); if (lessonId == null) { - ToolActivity toolActivity = ((List) userManagementService.findByProperty(ToolActivity.class, - "toolContentId", outcomeMapping.getToolContentId())).get(0); - lessonId = toolActivity.getLearningDesign().getLessons().iterator().next().getLessonId(); + lessonId = lessonService.getLessonByToolContentId(outcomeMapping.getToolContentId()).getLessonId(); } Integer userId = getUserDTO().getUserID(); securityService.isLessonMonitor(lessonId, userId, "set outcome result", true); Index: lams_common/src/java/org/lamsfoundation/lams/events/EventNotificationService.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -rb8e54021b464f3abf023581e819cee4d4a54f26e --- lams_common/src/java/org/lamsfoundation/lams/events/EventNotificationService.java (.../EventNotificationService.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_common/src/java/org/lamsfoundation/lams/events/EventNotificationService.java (.../EventNotificationService.java) (revision b8e54021b464f3abf023581e819cee4d4a54f26e) @@ -60,7 +60,7 @@ public void createLessonEvent(String scope, String name, Long toolContentId, String defaultSubject, String defaultMessage, boolean isHtmlFormat, AbstractDeliveryMethod deliveryMethod) throws InvalidParameterException { - Lesson lesson = getLessonByToolContentId(toolContentId); + Lesson lesson = lessonService.getLessonByToolContentId(toolContentId); if (!eventExists(scope, name, lesson.getLessonId())) { Event event = new Event(scope, name, lesson.getLessonId(), defaultSubject, defaultMessage, isHtmlFormat); Set users = null; @@ -125,7 +125,7 @@ return; } - ArrayList monitoringUsersIds = new ArrayList(); + ArrayList monitoringUsersIds = new ArrayList<>(); for (Map.Entry entry : monitoringUsers.entrySet()) { if (entry.getValue()) { monitoringUsersIds.add(entry.getKey().getUserId()); @@ -304,7 +304,7 @@ throw new InvalidParameterException("Delivery method can not be null."); } boolean substriptionFound = false; - List subscriptionList = new ArrayList(event.getSubscriptions()); + List subscriptionList = new ArrayList<>(event.getSubscriptions()); for (int index = 0; index < subscriptionList.size(); index++) { Subscription subscription = subscriptionList.get(index); if (subscription.getUserId().equals(userId) && subscription.getDeliveryMethod().equals(deliveryMethod)) { @@ -367,7 +367,7 @@ @Override public void triggerInternal(Event eventData, String subject, String message) { // fetch the event again so it is associated with current session - Event event = (Event) eventDAO.find(Event.class, eventData.getUid()); + Event event = eventDAO.find(Event.class, eventData.getUid()); Event eventFailCopy = null; Iterator subscriptionIterator = event.getSubscriptions().iterator(); while (subscriptionIterator.hasNext()) { @@ -444,7 +444,7 @@ @Override public void triggerLessonEvent(String scope, String name, Long toolContentId, String subject, String message) { - Lesson lesson = getLessonByToolContentId(toolContentId); + Lesson lesson = lessonService.getLessonByToolContentId(toolContentId); trigger(scope, name, lesson.getLessonId(), subject, message); } @@ -474,7 +474,7 @@ @Override public void triggerForSingleUser(Long subscriptionUid, String subject, String message) { - Subscription subscription = (Subscription) eventDAO.find(Subscription.class, subscriptionUid); + Subscription subscription = eventDAO.find(Subscription.class, subscriptionUid); Event event = subscription.getEvent(); String subjectToSend = subject == null ? event.getSubject() : subject; String messageToSend = message == null ? event.getMessage() : message; @@ -640,10 +640,4 @@ } unsubscribe(event, userId, deliveryMethod); } - - private Lesson getLessonByToolContentId(Long toolContentId) { - ToolActivity activity = (ToolActivity) eventDAO - .findByProperty(ToolActivity.class, "toolContentId", toolContentId).get(0); - return (Lesson) activity.getLearningDesign().getLessons().iterator().next(); - } } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java =================================================================== diff -u -r1ba40605c8e5fff683288c9c72f5ab2a981ba98a -rb8e54021b464f3abf023581e819cee4d4a54f26e --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision 1ba40605c8e5fff683288c9c72f5ab2a981ba98a) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision b8e54021b464f3abf023581e819cee4d4a54f26e) @@ -103,6 +103,8 @@ */ Lesson getLesson(Long lessonId); + Lesson getLessonByToolContentId(long toolContentId); + /** * 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 @@ -342,7 +344,7 @@ /** Gets the count of the users who are currently in an activity */ Integer getCountLearnersInCurrentActivity(Activity activity); - + /** * Returns map of lessons in an organisation for a particular learner or staff user. * @@ -436,9 +438,10 @@ * Finds IDs of preview lessons. */ List getPreviewLessons(Integer limit); - + /** - * Finds IDs of all lessons in an organisation. When calling MonitoringService.removeLessonPermanently() you cannot load the Lessons + * Finds IDs of all lessons in an organisation. When calling MonitoringService.removeLessonPermanently() you cannot + * load the Lessons * or a Hibernate error occurs. So we need a way to get the ids withouth calling Organisation.getLessons() */ List getOrganisationLessons(Integer organisationId); Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java =================================================================== diff -u -r1ba40605c8e5fff683288c9c72f5ab2a981ba98a -rb8e54021b464f3abf023581e819cee4d4a54f26e --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision 1ba40605c8e5fff683288c9c72f5ab2a981ba98a) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision b8e54021b464f3abf023581e819cee4d4a54f26e) @@ -40,6 +40,7 @@ import org.lamsfoundation.lams.learningdesign.Grouper; import org.lamsfoundation.lams.learningdesign.Grouping; import org.lamsfoundation.lams.learningdesign.GroupingActivity; +import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.learningdesign.dao.IGroupingDAO; import org.lamsfoundation.lams.learningdesign.exception.GroupingException; import org.lamsfoundation.lams.lesson.LearnerProgress; @@ -148,6 +149,11 @@ return lessonDAO.getLesson(lessonId); } + public Lesson getLessonByToolContentId(long toolContentId) { + ToolActivity toolActivity = baseDAO.findByProperty(ToolActivity.class, "toolContentId", toolContentId).get(0); + return toolActivity.getLearningDesign().getLessons().iterator().next(); + } + @Override public void performGrouping(Long lessonId, GroupingActivity groupingActivity, User learner) throws LessonServiceException { @@ -218,7 +224,7 @@ if (grouper != null) { grouper.setCommonMessageService(messageService); try { - List learners = new ArrayList(1); + List learners = new ArrayList<>(1); learners.add(learner); grouper.doGrouping(grouping, groupId, learners); } catch (GroupingException e) { @@ -267,10 +273,9 @@ groupingDAO.update(grouping); } } - + @Override - public void removeAllLearnersFromGrouping(Grouping grouping) - throws LessonServiceException { + public void removeAllLearnersFromGrouping(Grouping grouping) throws LessonServiceException { if (grouping != null) { // get the real objects, not the CGLIB version grouping = groupingDAO.getGroupingById(grouping.getGroupingId()); @@ -344,7 +349,7 @@ lessonDAO.initialize(learnersGroup); } - User user = (User) baseDAO.find(User.class, userId); + User user = baseDAO.find(User.class, userId); boolean ret = lessonClass.addLearner(user); if (ret) { lessonClassDAO.updateLessonClass(lessonClass); @@ -356,7 +361,7 @@ public boolean removeLearner(Long lessonId, Integer userId) { Lesson lesson = lessonDAO.getLesson(lessonId); LessonClass lessonClass = lesson.getLessonClass(); - User user = (User) baseDAO.find(User.class, userId); + User user = baseDAO.find(User.class, userId); Group learnerGroup = lessonClass.getGroupBy(user); boolean result = learnerGroup.getUsers().remove(user); @@ -388,9 +393,9 @@ lessonDAO.initialize(learnersGroup); } - Set users = new HashSet(); + Set users = new HashSet<>(); for (Integer userId : userIds) { - User user = (User) baseDAO.find(User.class, userId); + User user = baseDAO.find(User.class, userId); users.add(user); } addLearners(lesson, users); @@ -436,7 +441,7 @@ } lessonDAO.initialize(lessonClass.getStaffGroup()); - User user = (User) baseDAO.find(User.class, userId); + User user = baseDAO.find(User.class, userId); boolean ret = lessonClass.addStaffMember(user); if (ret) { @@ -449,7 +454,7 @@ public boolean removeStaffMember(Long lessonId, Integer userId) { Lesson lesson = lessonDAO.getLesson(lessonId); LessonClass lessonClass = lesson.getLessonClass(); - User user = (User) baseDAO.find(User.class, userId); + User user = baseDAO.find(User.class, userId); Group staffGroup = lessonClass.getStaffGroup(); boolean result = staffGroup.getUsers().remove(user); @@ -478,9 +483,9 @@ // yes this is a bit of a hack! lessonDAO.initialize(lessonClass.getStaffGroup()); - Set users = new HashSet(); + Set users = new HashSet<>(); for (Integer userId : userIds) { - User user = (User) baseDAO.find(User.class, userId); + User user = baseDAO.find(User.class, userId); users.add(user); } addStaffMembers(lesson, users); @@ -584,7 +589,7 @@ int count = 0; List progresses = learnerProgressDAO.getCompletedLearnerProgressForLesson(lessonId, null, null, true); - Activity firstAddedActivity = (Activity) baseDAO.find(Activity.class, firstAddedActivityId); + Activity firstAddedActivity = baseDAO.find(Activity.class, firstAddedActivityId); for (LearnerProgress progress : progresses) { if (progress.getLessonComplete() == LearnerProgress.LESSON_END_OF_DESIGN_COMPLETE) { @@ -614,13 +619,15 @@ return learnerProgressDAO.getNumUsersAttemptedActivity(activity); } - public Integer getCountLearnersInCurrentActivity(Activity activity){ + @Override + public Integer getCountLearnersInCurrentActivity(Activity activity) { return learnerProgressDAO.getNumUsersCurrentActivity(activity); } + @Override public Map getLessonsByOrgAndUserWithCompletedFlag(Integer userId, Integer orgId, Integer userRole) { - TreeMap map = new TreeMap(); + TreeMap map = new TreeMap<>(); List list = lessonDAO.getLessonsByOrgAndUserWithCompletedFlag(userId, orgId, userRole); if (list != null) { Iterator iterator = list.iterator(); @@ -690,10 +697,10 @@ } @Override - public List getOrganisationLessons(Integer organisationId) { - return lessonDAO.getOrganisationLessons(organisationId) ; + public List getOrganisationLessons(Integer organisationId) { + return lessonDAO.getOrganisationLessons(organisationId); } - + @Override public boolean checkLessonReleaseConditions(Long lessonId, Integer learnerId) { Lesson lesson = getLesson(lessonId); @@ -710,7 +717,7 @@ @Override public Set getReleasedSucceedingLessons(Long completedLessonId, Integer learnerId) { - Set releasedSucceedingLessons = new HashSet(); + Set releasedSucceedingLessons = new HashSet<>(); Lesson lesson = getLesson(completedLessonId); if (lesson != null) { for (Lesson succeedingLesson : lesson.getSucceedingLessons()) { Index: lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/GradebookService.java =================================================================== diff -u -rbe35a3f2bf2414f299ca74f4ea8c3e2555b16d8e -rb8e54021b464f3abf023581e819cee4d4a54f26e --- lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/GradebookService.java (.../GradebookService.java) (revision be35a3f2bf2414f299ca74f4ea8c3e2555b16d8e) +++ lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/GradebookService.java (.../GradebookService.java) (revision b8e54021b464f3abf023581e819cee4d4a54f26e) @@ -771,39 +771,39 @@ /* * TODO Method is not in use. Remove it? - * + * * private void updateUserActivityGradebookMark(Lesson lesson, Activity activity, User learner) { * ToolSession toolSession = toolService.getToolSessionByLearner(learner, activity); - * + * * if ((toolSession == null) || (toolSession == null) || (learner == null) || (lesson == null) * || (activity == null) || !(activity instanceof ToolActivity) * || (((ToolActivity) activity).getEvaluation() == null)) { * return; * } * ToolActivity toolActivity = (ToolActivity) activity; - * + * * // Getting the first activity evaluation * ActivityEvaluation eval = toolActivity.getEvaluation(); - * + * * try { * ToolOutput toolOutput = toolService.getOutputFromTool(eval.getToolOutputDefinition(), toolSession, * learner.getUserId()); - * + * * if (toolOutput != null) { * ToolOutputValue outputVal = toolOutput.getValue(); * if (outputVal != null) { * Double outputDouble = outputVal.getDouble(); - * + * * GradebookUserActivity gradebookUserActivity = getGradebookUserActivity(toolActivity.getActivityId(), * learner.getUserId()); - * + * * // Only set the mark if it hasnt previously been set by a teacher * if ((gradebookUserActivity == null) || !gradebookUserActivity.getMarkedInGradebook()) { * updateGradebookUserActivityMark(lesson, learner, toolActivity, outputDouble, false, false); * } * } * } - * + * * } catch (ToolException e) { * logger.debug( * "Runtime exception when attempted to get outputs for activity: " + toolActivity.getActivityId(), e); @@ -1884,15 +1884,15 @@ /* * TODO Method is not in use. Remove it? - * + * * public void updateActivityMark(Double mark, String feedback, Integer userID, Long toolSessionID, * Boolean markedInGradebook) { * ToolSession toolSession = toolService.getToolSessionById(toolSessionID); * User learner = (User) userService.findById(User.class, userID); * if ((learner != null) && (toolSession != null)) { * ToolActivity activity = toolSession.getToolActivity(); * GradebookUserActivity gradebookUserActivity = getGradebookUserActivity(activity.getActivityId(), userID); - * + * * // If gradebook user activity is null or the mark is set by teacher or was set previously by user - save the * // mark and feedback * if ((gradebookUserActivity == null) || markedInGradebook || !gradebookUserActivity.getMarkedInGradebook()) { Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java =================================================================== diff -u -ra61b6ad192148c0ae514f37a9b488c3a15535ee9 -rb8e54021b464f3abf023581e819cee4d4a54f26e --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision a61b6ad192148c0ae514f37a9b488c3a15535ee9) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision b8e54021b464f3abf023581e819cee4d4a54f26e) @@ -628,7 +628,7 @@ new Object[] { progress.getUser().getLogin(), progress.getUser().getUserId(), activity.getTitle(), activity.getActivityId() })); } - + /** * "Complete" an activity from the web layer's perspective. Used for CompleteActivityAction and the Gate and * Grouping actions. Calls the learningService to actually complete the activity and progress. @@ -646,13 +646,13 @@ if (currentActivity == null) { progress = joinLesson(learnerId, lesson.getLessonId()); - + } else if (progress.getCompletedActivities().containsKey(currentActivity)) { // recalculate activity mark and pass it to gradebook updateGradebookMark(currentActivity, progress); return activityMapping.getCloseForward(currentActivity, lesson.getLessonId()); - + } else { completeActivity(learnerId, currentActivity, progress.getLearnerProgressId()); } @@ -1434,14 +1434,11 @@ @Override public void createCommandForLearners(Long toolContentId, Collection userIds, String jsonCommand) { // find lesson for given tool content ID - ToolActivity activity = activityDAO.getToolActivityByToolContentId(toolContentId); - LearningDesign learningDesign = activity.getLearningDesign(); - Lesson lesson = learningDesign.getLessons().iterator().next(); - Long lessonId = lesson.getLessonId(); + Long lessonId = lessonService.getLessonByToolContentId(toolContentId).getLessonId(); // go through each user, find his user name and add a command for him for (Integer userId : userIds) { - User user = (User) activityDAO.find(User.class, userId); + User user = activityDAO.find(User.class, userId); Command command = new Command(lessonId, user.getLogin(), jsonCommand); commandDAO.insert(command); }