Index: lams_common/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java =================================================================== diff -u -r471b903caa3365758fbdec0a22440b1b0b3f2947 -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_common/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java (.../ILearnerService.java) (revision 471b903caa3365758fbdec0a22440b1b0b3f2947) +++ lams_common/src/java/org/lamsfoundation/lams/learning/service/ILearnerService.java (.../ILearnerService.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -23,6 +23,7 @@ package org.lamsfoundation.lams.learning.service; +import java.io.UnsupportedEncodingException; import java.util.Collection; import java.util.List; import java.util.Set; @@ -126,6 +127,20 @@ void completeActivity(Integer learnerId, Activity activity, Long progressID); /** + * Complete the activity in the progress engine and delegate to the progress engine to calculate the next activity + * in the learning design. It is currently triggered by various progress engine related action classes, which then + * calculate the url to go to next, based on the ActivityMapping class. + * + * @param learnerId + * the learner who are running this activity in the design. + * @param activity + * the activity is being run. + * @return the updated learner progress + */ + String completeActivity(LearnerProgress progress, Activity currentActivity, Integer learnerId, + boolean redirect) throws UnsupportedEncodingException; + + /** * Retrieve all lessons that has been started, suspended or finished. All finished but archived lesson should not be * loaded. * Index: lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/IUserManagementService.java =================================================================== diff -u -r29a37489a63e5a95f42a5ef5fd8a7daeb65c53c5 -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/IUserManagementService.java (.../IUserManagementService.java) (revision 29a37489a63e5a95f42a5ef5fd8a7daeb65c53c5) +++ lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/IUserManagementService.java (.../IUserManagementService.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -246,6 +246,8 @@ * @return the User */ User getUserByLogin(String login); + + User getUserById(Integer userId); /** * @param login Index: lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java =================================================================== diff -u -r0c4713e27d5f9a122e1f71226dc98f72e7443fb1 -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java (.../UserManagementService.java) (revision 0c4713e27d5f9a122e1f71226dc98f72e7443fb1) +++ lams_common/src/java/org/lamsfoundation/lams/usermanagement/service/UserManagementService.java (.../UserManagementService.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -370,6 +370,11 @@ List results = baseDAO.findByProperty(User.class, "login", login); return results.isEmpty() ? null : (User) results.get(0); } + + @Override + public User getUserById(Integer userId) { + return (User) findById(User.class, userId); + } @Override public void updatePassword(String login, String password) { Index: lams_common/src/java/org/lamsfoundation/lams/util/WebUtil.java =================================================================== diff -u -r3bb7e0141ae1cc15ccd737c95d90b5762a34ad61 -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_common/src/java/org/lamsfoundation/lams/util/WebUtil.java (.../WebUtil.java) (revision 3bb7e0141ae1cc15ccd737c95d90b5762a34ad61) +++ lams_common/src/java/org/lamsfoundation/lams/util/WebUtil.java (.../WebUtil.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -9,19 +9,14 @@ import java.util.HashMap; import java.util.Map.Entry; -import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; -import org.lamsfoundation.lams.learning.service.ILearnerService; -import org.lamsfoundation.lams.learningdesign.dto.ActivityPositionDTO; import org.lamsfoundation.lams.tool.ToolAccessMode; import org.lamsfoundation.lams.tool.exception.ToolException; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.web.util.AttributeNames; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.WebApplicationContextUtils; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -49,63 +44,10 @@ private static final String URL_SHORTENING_CYPHER = "jbdnuteywk"; /** - */ - public static boolean isTokenValid(HttpServletRequest req, String tokenName) { - if (req.getSession() != null) { - String valueSession = (String) req.getSession().getAttribute(tokenName); - String valueRequest = req.getParameter(tokenName); - WebUtil.log.debug("(Session Token) name : " + tokenName + " value : " + valueSession); - WebUtil.log.debug("(Request Token) name : " + tokenName + " value : " + valueRequest); - if ((valueSession != null) && (valueRequest != null)) { - if (valueSession.equals(valueRequest)) { - return true; - } - } - } - return false; - } - - /** - */ - public static void saveTaskURL(HttpServletRequest req, String[] urls) { - if (urls != null) { - if (urls.length == 1) { - req.setAttribute("urlA", urls[0]); - } else if (urls.length == 2) { - req.setAttribute("urlA", urls[0]); - req.setAttribute("urlB", urls[1]); - } - } - } - - /** - */ - public static void saveToken(HttpServletRequest req, String tokenName, String tokenValue) { - if (req.getSession().getAttribute(tokenName) != null) { - WebUtil.resetToken(req, tokenName); - } - req.getSession().setAttribute(tokenName, tokenValue); - WebUtil.log.debug("(Save Session Token) name : " + tokenName + " value : " + tokenValue); - - } - - /** - */ - public static String retrieveToken(HttpServletRequest req, String tokenName) { - return (String) req.getSession().getAttribute(tokenName); - } - - /** - */ - public static void resetToken(HttpServletRequest req, String tokenName) { - req.getSession().removeAttribute(tokenName); - } - - /** * @exception IllegalArgumentException * - if not set */ - public static void checkObject(String paramName, Object paramValue) throws IllegalArgumentException { + private static void checkObject(String paramName, Object paramValue) throws IllegalArgumentException { boolean isNull = paramValue == null; if (!isNull && String.class.isInstance(paramValue)) { String str = (String) paramValue; @@ -128,7 +70,7 @@ WebUtil.checkObject(paramName, paramValue); } String value = paramValue != null ? StringUtils.trimToNull(paramValue) : null; - return value != null ? new Integer(value) : null; + return value != null ? Integer.valueOf(value) : null; } catch (NumberFormatException e) { throw new IllegalArgumentException(paramName + " should be an integer '" + paramValue + "'"); @@ -147,7 +89,7 @@ WebUtil.checkObject(paramName, paramValue); } String value = paramValue != null ? StringUtils.trimToNull(paramValue) : null; - return value != null ? new Long(value) : null; + return value != null ? Long.valueOf(value) : null; } catch (NumberFormatException e) { throw new IllegalArgumentException(paramName + " should be a long '" + paramValue + "'"); @@ -176,7 +118,6 @@ * - if not set or not boolean */ public static boolean checkBoolean(String paramName, String paramValue) throws IllegalArgumentException { - WebUtil.checkObject(paramName, paramValue); return Boolean.valueOf(paramValue.trim()).booleanValue(); } @@ -296,34 +237,6 @@ } /** - * TODO default proper exception at lams level to replace RuntimeException TODO isTesting should be removed when - * login is done properly. - * - * @param req - * - - * @return username from principal object - */ - public static String getUsername(HttpServletRequest req, boolean isTesting) throws RuntimeException { - if (isTesting) { - return "test"; - } - - Principal prin = req.getUserPrincipal(); - if (prin == null) { - throw new RuntimeException( - "Trying to get username but principal object missing. Request is " + req.toString()); - } - - String username = prin.getName(); - if (username == null) { - throw new RuntimeException("Name missing from principal object. Request is " + req.toString() - + " Principal object is " + prin.toString()); - } - - return username; - } - - /** * Retrieve the tool access mode from http request. This is a utility used by the tools that share an implementation * for the learner screen. They use mode=learner, mode=author and mode=teacher for learning, preview and monitoring * respectively. Only used if the tool programmer wants to have one call that supports all three ways of looking at @@ -555,7 +468,6 @@ * @return */ public static String encodeLessonId(Long lessonId) { - String encodedLessonId = lessonId.toString(); encodedLessonId = encodedLessonId.replace('0', URL_SHORTENING_CYPHER.charAt(0)); encodedLessonId = encodedLessonId.replace('1', URL_SHORTENING_CYPHER.charAt(1)); Index: lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/util/GradebookUtil.java =================================================================== diff -u -r62aaf160878735888d077bf28fac3c1989bb8fbd -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/util/GradebookUtil.java (.../GradebookUtil.java) (revision 62aaf160878735888d077bf28fac3c1989bb8fbd) +++ lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/util/GradebookUtil.java (.../GradebookUtil.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -75,7 +75,6 @@ * @param page * @return */ - @SuppressWarnings("unchecked") public static String toGridXML(List gridRows, GBGridView view, String sortBy, boolean isSearch, String searchField, String searchOper, String searchString, String sortOrder, int rowLimit, int page) { @@ -112,7 +111,6 @@ * @param view * @return */ - @SuppressWarnings("unchecked") public static String toGridXML(List gridRows, int page, int totalPages, GBGridView view) { String xml = ""; try { @@ -168,19 +166,15 @@ } public static String niceFormatting(Double mark) { - String markStr = new DecimalFormat("##0.00").format(mark); return markStr; - } public static String niceFormatting(Double mark, boolean displayAsPercentage) { - String markStr = new DecimalFormat("##0.00").format(mark); if ( displayAsPercentage ) markStr += "%"; return markStr; - } public static ExcelCell createPercentageCell(Double mark, boolean markConversionNeeded) { @@ -284,7 +278,6 @@ * @param searchString * @return */ - @SuppressWarnings("unchecked") private static List doRowNameSearch(List gradebookRows, String searchField, String searchOper, String searchString) { List ret = new ArrayList(); Index: lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressBuilder.java =================================================================== diff -u -r4fd363489205116dc8393333f9183ae1a44f0bf4 -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressBuilder.java (.../ProgressBuilder.java) (revision 4fd363489205116dc8393333f9183ae1a44f0bf4) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/progress/ProgressBuilder.java (.../ProgressBuilder.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -176,8 +176,7 @@ log.error(error); throw new LearningDesignProcessorException(error); } - ActivityURL activityURL = LearningWebUtil.getActivityURL(activityMapping, progress, activity, false, - isFloating); + ActivityURL activityURL = activityMapping.getActivityURL(progress, activity, false, isFloating); if (activityURL.getStatus() == LearnerProgress.ACTIVITY_NOT_ATTEMPTED) { activityURL.setUrl((previewMode || isFloating) ? forceLearnerURL + activity.getActivityId() : null); } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerFullService.java =================================================================== diff -u -r471b903caa3365758fbdec0a22440b1b0b3f2947 -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerFullService.java (.../ILearnerFullService.java) (revision 471b903caa3365758fbdec0a22440b1b0b3f2947) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/ILearnerFullService.java (.../ILearnerFullService.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -15,7 +15,6 @@ import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.usermanagement.User; -import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; /** * Contains methods intended for internal usage by lams_learning. @@ -24,9 +23,6 @@ */ public interface ILearnerFullService extends ILearnerService { - /** Get the user service. Used when the action needs the real user object, not just the userId */ - IUserManagementService getUserManagementService(); - /** * Get the last attempt ID for the given learner and lesson. */ @@ -175,6 +171,4 @@ /* Added for RepopulateProgressMarksServlet - can be removed later */ String[] recalcProgressForLearner(Lesson lesson, ArrayList activityList, LearnerProgress learnerProgress, boolean updateGradebookForAll); - - IActivityDAO getActivityDAO(); } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -23,6 +23,7 @@ package org.lamsfoundation.lams.learning.service; +import java.io.UnsupportedEncodingException; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Calendar; @@ -138,26 +139,14 @@ public LearnerService() { } - /** - * @param lessonDAO - * The lessonDAO to set. - */ public void setLessonDAO(ILessonDAO lessonDAO) { this.lessonDAO = lessonDAO; } - /** - * @param learnerProgressDAO - * The learnerProgressDAO to set. - */ public void setLearnerProgressDAO(ILearnerProgressDAO learnerProgressDAO) { this.learnerProgressDAO = learnerProgressDAO; } - /** - * @param lamsToolService - * The lamsToolService to set. - */ public void setLamsCoreToolService(ILamsCoreToolService lamsToolService) { lamsCoreToolService = lamsToolService; } @@ -166,49 +155,18 @@ this.activityMapping = activityMapping; } - /** - * @param activityDAO - * The activityDAO to set. - */ public void setActivityDAO(IActivityDAO activityDAO) { this.activityDAO = activityDAO; } - /** - * @param groupingDAO - * The groupingDAO to set. - */ public void setGroupingDAO(IGroupingDAO groupingDAO) { this.groupingDAO = groupingDAO; } - /** - * @return the groupUserDAO - */ - public IGroupUserDAO getGroupUserDAO() { - return groupUserDAO; - } - - /** - * @param groupUserDAO - * groupUserDAO - */ public void setGroupUserDAO(IGroupUserDAO groupUserDAO) { this.groupUserDAO = groupUserDAO; } - /** - * @return the User Management Service - */ - @Override - public IUserManagementService getUserManagementService() { - return userManagementService; - } - - /** - * @param userService - * User Management Service - */ public void setUserManagementService(IUserManagementService userService) { userManagementService = userService; } @@ -604,22 +562,10 @@ } - /** - * Complete the activity in the progress engine and delegate to the progress engine to calculate the next activity - * in the learning design. It is currently triggered by various progress engine related action classes, which then - * calculate the url to go to next, based on the ActivityMapping class. - * - * @param learnerId - * the learner who are running this activity in the design. - * @param activity - * the activity is being run. - * @return the updated learner progress - */ @Override public void completeActivity(Integer learnerId, Activity activity, Long progressID) { - if (LearnerService.log.isDebugEnabled()) { - LearnerService.log - .debug("Completing activity ID " + activity.getActivityId() + " for learner " + learnerId); + if (log.isDebugEnabled()) { + log.debug("Completing activity ID " + activity.getActivityId() + " for learner " + learnerId); } LearnerProgress progress = learnerProgressDAO.getLearnerProgress(progressID); if (progress.getCompletedActivities().keySet().contains(activity)) { @@ -640,7 +586,7 @@ try { progressEngine.setUpStartPoint(progress); } catch (ProgressException e) { - LearnerService.log.error("error occurred in 'setUpStartPoint':" + e.getMessage(), e); + log.error("error occurred in 'setUpStartPoint':" + e.getMessage(), e); throw new LearnerServiceException(e); } @@ -658,7 +604,43 @@ 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. + * + * @param redirect + * Should this call redirect to the next screen (true) or use a forward (false) + * + * @throws UnsupportedEncodingException + * @throws InterruptedException + */ + @Override + public String completeActivity(LearnerProgress progress, Activity currentActivity, Integer learnerId, + boolean redirect) throws UnsupportedEncodingException { + Lesson lesson = progress.getLesson(); + 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()); + } + + if (currentActivity != null && (currentActivity.isFloating() || (currentActivity.getParentActivity() != null + && progress.getCompletedActivities().containsKey(currentActivity.getParentActivity())))) { + return activityMapping.getCloseForward(currentActivity, lesson.getLessonId()); + } + + return activityMapping.getProgressForward(progress, redirect, false); + } + @Override public void updateGradebookMark(Activity activity, LearnerProgress progress) { User learner = progress.getUser(); @@ -1605,9 +1587,4 @@ return kumalive == null || kumalive.getFinished(); } - @Override - public IActivityDAO getActivityDAO() { - return activityDAO; - } - } \ No newline at end of file Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/BranchingActivityController.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/BranchingActivityController.java (.../BranchingActivityController.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/BranchingActivityController.java (.../BranchingActivityController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -72,12 +72,14 @@ public String performBranching(@ModelAttribute BranchingForm branchingForm, HttpServletRequest request, HttpServletResponse response) { LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgress(request, learnerService); - Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); + Integer learnerId = LearningWebUtil.getUserId(); boolean forceGroup = WebUtil.readBooleanParam(request, BranchingActivityController.PARAM_FORCE_GROUPING, false); String forward = null; + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); if (activity == null) { learnerProgress = learnerService.joinLesson(learnerId, learnerProgress.getLesson().getLessonId()); forward = activityMapping.getActivityForward(activity, learnerProgress, true); @@ -110,8 +112,8 @@ int completedCount = 0; while (i.hasNext()) { Activity nextBranch = i.next(); - ActivityURL activityURL = LearningWebUtil.getActivityURL(activityMapping, learnerProgress, - nextBranch, (branch != null) && branch.equals(nextBranch), false); + ActivityURL activityURL = activityMapping.getActivityURL(learnerProgress, nextBranch, + (branch != null) && branch.equals(nextBranch), false); if (activityURL.isComplete()) { completedCount++; } @@ -158,10 +160,11 @@ public String forceBranching(@ModelAttribute BranchingForm branchingForm, HttpServletRequest request) { LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgress(request, learnerService); - Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); Integer learnerId = LearningWebUtil.getUserId(); String forward = null; + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); if (activity == null) { learnerProgress = learnerService.joinLesson(learnerId, learnerProgress.getLesson().getLessonId()); forward = activityMapping.getActivityForward(activity, learnerProgress, true); @@ -171,7 +174,6 @@ forward = "error"; } else { - BranchingActivity branchingActivity = (BranchingActivity) activity; Long branchId = WebUtil.readLongParam(request, "branchID", false); Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/ChooseActivityController.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/ChooseActivityController.java (.../ChooseActivityController.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/ChooseActivityController.java (.../ChooseActivityController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -33,6 +33,8 @@ import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; @@ -62,8 +64,8 @@ LearnerProgress progress = LearningWebUtil.getLearnerProgress(request, learnerService); Lesson lesson = progress.getLesson(); - Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); - + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); if (activity != null) { progress = learnerService.chooseActivity(learnerId, lesson.getLessonId(), activity, false); } else { Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/CompleteActivityController.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/CompleteActivityController.java (.../CompleteActivityController.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/CompleteActivityController.java (.../CompleteActivityController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -74,7 +74,6 @@ public String execute(@ModelAttribute("messageForm") ActivityForm messageForm, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Integer learnerId = LearningWebUtil.getUserId(); - Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); // This must get the learner progress from the progress id, not cached from the request, // otherwise we may be using an old version of a lesson while a teacher is starting a @@ -101,14 +100,16 @@ } } - String forward = null; // Set activity as complete try { - forward = LearningWebUtil.completeActivity(request, response, activityMapping, progress, activity, learnerId, - learnerService, false); + + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); + //return forward + return learnerService.completeActivity(progress, activity, learnerId, false); + } catch (LearnerServiceException e) { return "error"; } - return forward; } } \ No newline at end of file Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/DisplayActivityController.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/DisplayActivityController.java (.../DisplayActivityController.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/DisplayActivityController.java (.../DisplayActivityController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -80,8 +80,7 @@ boolean displayParallelFrames = WebUtil.readBooleanParam(request, DisplayActivityController.PARAM_INITIAL_DISPLAY, true); - String forward = activityMapping.getProgressForward(learnerProgress, false, displayParallelFrames, request, - learnerService); + String forward = activityMapping.getProgressForward(learnerProgress, false, displayParallelFrames); if (log.isDebugEnabled()) { log.debug(forward); } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/DisplayOptionsActivityController.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/DisplayOptionsActivityController.java (.../DisplayOptionsActivityController.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/DisplayOptionsActivityController.java (.../DisplayOptionsActivityController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -41,6 +41,7 @@ import org.lamsfoundation.lams.learningdesign.dto.ActivityPositionDTO; import org.lamsfoundation.lams.learningdesign.dto.ActivityURL; import org.lamsfoundation.lams.lesson.LearnerProgress; +import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -71,7 +72,9 @@ HttpServletResponse response) { LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgress(request, learnerService); - Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); + + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); if (!(activity instanceof OptionsActivity)) { log.error("activity not OptionsActivity " + activity.getActivityId()); return "error"; @@ -86,8 +89,7 @@ Iterator i = subActivities.iterator(); int completedCount = 0; while (i.hasNext()) { - ActivityURL activityURL = LearningWebUtil.getActivityURL(activityMapping, learnerProgress, i.next(), false, - false); + ActivityURL activityURL = activityMapping.getActivityURL(learnerProgress, i.next(), false, false); if (activityURL.isComplete()) { completedCount++; } Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/DisplayParallelActivityController.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/DisplayParallelActivityController.java (.../DisplayParallelActivityController.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/DisplayParallelActivityController.java (.../DisplayParallelActivityController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -39,6 +39,8 @@ import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.learningdesign.ParallelActivity; import org.lamsfoundation.lams.learningdesign.dto.ActivityURL; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; @@ -65,7 +67,8 @@ public String execute(@ModelAttribute ActivityForm form, HttpServletRequest request, HttpServletResponse response) { activityMapping.setActivityMappingStrategy(new ParallelActivityMappingStrategy()); - Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); if (!(activity instanceof ParallelActivity)) { log.error("activity not ParallelActivity " + activity.getActivityId()); return "error"; Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/DisplayToolActivityController.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/DisplayToolActivityController.java (.../DisplayToolActivityController.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/DisplayToolActivityController.java (.../DisplayToolActivityController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -33,6 +33,8 @@ import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.lesson.LearnerProgress; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -57,8 +59,9 @@ @RequestMapping("/DisplayToolActivity") public String execute(HttpServletRequest request, HttpServletResponse response) { LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgress(request, learnerService); - Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); if (!(activity instanceof ToolActivity)) { log.error("activity not ToolActivity"); return "error"; Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/GateController.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/GateController.java (.../GateController.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/GateController.java (.../GateController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -46,6 +46,7 @@ import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.beans.factory.annotation.Autowired; @@ -79,6 +80,8 @@ @Autowired private ILearnerFullService learnerService; @Autowired + private IUserManagementService userManagementService; + @Autowired private ActivityMapping activityMapping; // --------------------------------------------------------------------- @@ -100,30 +103,20 @@ // --------------------------------------------------------------------- // Struts Dispatch Method // --------------------------------------------------------------------- - /** - * - * @param mapping - * @param form - * @param request - * @param response - * @return - * @throws IOException - * @throws ServletException - */ @RequestMapping("knockGate") public String knockGate(@ModelAttribute GateForm gateForm, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { boolean forceGate = WebUtil.readBooleanParam(request, GateController.PARAM_FORCE_GATE_OPEN, false); Long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); - // initialize service object - Activity activity = learnerService.getActivity(activityId); - User learner = LearningWebUtil.getUser(learnerService); + Integer userId = LearningWebUtil.getUserId(); + User learner = userManagementService.getUserById(userId); Lesson lesson = learnerService.getLesson(lessonId); LearnerProgress learnerProgress = learnerService.getProgress(learner.getUserId(), lessonId); + Activity activity = learnerService.getActivity(activityId); if (activity != null) { // knock the gate GateActivityDTO gateDTO = learnerService.knockGate(activityId, learner, forceGate); @@ -140,9 +133,7 @@ } // gate is open, so let the learner go to the next activity ( updating the cached learner progress on the way ) - return LearningWebUtil.completeActivity(request, response, activityMapping, learnerProgress, activity, - learner.getUserId(), learnerService, true); - + return learnerService.completeActivity(learnerProgress, activity, learner.getUserId(), true); } // --------------------------------------------------------------------- @@ -181,7 +172,8 @@ // so it is in seconds gateForm.setStartOffset(scheduleGate.getGateStartTimeOffset() * 60); - User learner = LearningWebUtil.getUser(learnerService); + Integer userId = LearningWebUtil.getUserId(); + User learner = userManagementService.getUserById(userId); Date reachTime = ScheduleGateActivityStrategy.getPreviousActivityCompletionDate(scheduleGate, learner); gateForm.setReachDate(reachTime); Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/GroupingController.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/GroupingController.java (.../GroupingController.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/GroupingController.java (.../GroupingController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -111,7 +111,9 @@ // initialize service object LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgress(request, learnerService); - Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); + + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); if (!(activity instanceof GroupingActivity)) { log.error("activity not GroupingActivity"); return "error"; @@ -203,12 +205,12 @@ throws IOException, ServletException { // initialize service object LearnerProgress progress = LearningWebUtil.getLearnerProgress(request, learnerService); - Activity groupingActivity = LearningWebUtil.getActivityFromRequest(request, learnerService); + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity groupingActivity = learnerService.getActivity(activityId); Integer learnerId = LearningWebUtil.getUserId(); // so manually resume the progress. The completeActivity code can cope with a missing activity. - return LearningWebUtil.completeActivity(request, response, activityMapping, progress, groupingActivity, - learnerId, learnerService, true); + return learnerService.completeActivity(progress, groupingActivity, learnerId, true); } /** @@ -221,7 +223,8 @@ private void prepareGroupData(HttpServletRequest request) { SortedSet groups = new TreeSet<>(GroupDTO.GROUP_NAME_COMPARATOR); - Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); Grouping grouping = ((GroupingActivity) activity).getCreateGrouping(); if (grouping != null) { @@ -251,7 +254,8 @@ @RequestMapping("/learnerChooseGroup") public String learnerChooseGroup(@ModelAttribute GroupingForm groupingForm, HttpServletRequest request) throws IOException, ServletException { - Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); Long groupId = WebUtil.readLongParam(request, "groupId"); LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgress(request, learnerService); Long lessonId = learnerProgress.getLesson().getLessonId(); Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/LearnerController.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/LearnerController.java (.../LearnerController.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/LearnerController.java (.../LearnerController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -155,17 +155,14 @@ @RequestMapping("/joinLesson") public String joinLesson(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - // initialize service object - Integer learner = null; + // get user and lesson based on request + Integer userId = LearningWebUtil.getUserId(); + long lessonID = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); + try { - - // get user and lesson based on request. - learner = LearningWebUtil.getUserId(); - long lessonID = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); - // security check Lesson lesson = learnerService.getLesson(lessonID); - User user = (User) userManagementService.findById(User.class, learner); + User user = (User) userManagementService.findById(User.class, userId); if ((lesson.getLessonClass() == null) || !lesson.getLessonClass().getLearners().contains(user)) { request.setAttribute("messageKey", "User " + user.getLogin() + " is not a learner in the requested lesson."); @@ -178,23 +175,22 @@ } if (log.isDebugEnabled()) { - log.debug("The learner [" + learner + "] is joining the lesson [" + lessonID + "]"); + log.debug("The learner [" + userId + "] is joining the lesson [" + lessonID + "]"); } // join user to the lesson on the server - LearnerProgress learnerProgress = learnerService.joinLesson(learner, lessonID); + LearnerProgress learnerProgress = learnerService.joinLesson(userId, lessonID); if (log.isDebugEnabled()) { - log.debug("The learner [" + learner + "] joined lesson. The" + "progress data is:" + log.debug("The learner [" + userId + "] joined lesson. The" + "progress data is:" + learnerProgress.toString()); } String url = "learning/" + activityMapping.getDisplayActivityAction(lessonID); redirectToURL(response, url); } catch (Exception e) { - log - .error("An error occurred while learner " + learner + " attempting to join the lesson.", e); + log.error("An error occurred while learner " + userId + " attempting to join the lesson.", e); return "error"; } @@ -209,8 +205,8 @@ throws IOException, ServletException { // fetch necessary parameters long lessonID = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); - User user = LearningWebUtil.getUser(learnerService); - Integer userID = user.getUserId(); + Integer userID = LearningWebUtil.getUserId(); + User user = userManagementService.getUserById(userID); // find number of previous attempts Integer attemptID = learnerService.getProgressArchiveMaxAttemptID(userID, lessonID); Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/LoadToolActivityController.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/LoadToolActivityController.java (.../LoadToolActivityController.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/LoadToolActivityController.java (.../LoadToolActivityController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -38,6 +38,8 @@ import org.lamsfoundation.lams.learningdesign.dto.ActivityURL; import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.tool.exception.RequiredGroupMissingException; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; @@ -59,17 +61,16 @@ public static final String PARAM_ACTIVITY_URL = "activityURL"; public static final String PARAM_IS_BRANCHING = "isBranching"; - private static final Map toolSessionCreationLocks = new TreeMap<>(); - /** * Gets an activity from the request (attribute) and forwards onto a loading page. */ @RequestMapping("/LoadToolActivity") public String execute(@ModelAttribute ActivityForm form, HttpServletRequest request, HttpServletResponse response) { - LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgress(request, learnerService); - Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); + /* * Synchronise calls to the same activity and attempt to create a session, if it does not exist. * Even though the method creating sessions in LamsCoreToolService is synchronised, Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/SequenceActivityController.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/SequenceActivityController.java (.../SequenceActivityController.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/controller/SequenceActivityController.java (.../SequenceActivityController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -37,6 +37,8 @@ import org.lamsfoundation.lams.learningdesign.NullActivity; import org.lamsfoundation.lams.learningdesign.SequenceActivity; import org.lamsfoundation.lams.lesson.LearnerProgress; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -68,26 +70,26 @@ Integer learnerId = LearningWebUtil.getUserId(); LearnerProgress learnerProgress = LearningWebUtil.getLearnerProgress(request, learnerService); - Activity activity = LearningWebUtil.getActivityFromRequest(request, learnerService); + + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); if (!(activity instanceof SequenceActivity)) { log.error("activity not SequenceActivity " + activity.getActivityId()); return "error"; } - String forward = null; SequenceActivity sequenceActivity = (SequenceActivity) activity; Activity firstActivityInSequence = sequenceActivity.getNextActivityByParent(new NullActivity()); if ((firstActivityInSequence != null) && !firstActivityInSequence.isNull()) { // Set the first activity as the current activity and display it learnerProgress = learnerService.chooseActivity(learnerId, learnerProgress.getLesson().getLessonId(), firstActivityInSequence, true); - forward = activityMapping.getActivityForward(firstActivityInSequence, learnerProgress, true); - return forward; + return activityMapping.getActivityForward(firstActivityInSequence, learnerProgress, true); + } else { // No activities exist in the sequence, so go to the next activity. - return LearningWebUtil.completeActivity(request, response, activityMapping, learnerProgress, activity, - learnerId, learnerService, true); + return learnerService.completeActivity(learnerProgress, activity, learnerId, true); } } } \ No newline at end of file Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/servlet/RepopulateProgressMarksServlet.java =================================================================== diff -u -rf2ad75cef0c507a64877942631fee13efbc6ed50 -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/servlet/RepopulateProgressMarksServlet.java (.../RepopulateProgressMarksServlet.java) (revision f2ad75cef0c507a64877942631fee13efbc6ed50) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/servlet/RepopulateProgressMarksServlet.java (.../RepopulateProgressMarksServlet.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -64,6 +64,8 @@ private static Logger log = Logger.getLogger(RepopulateProgressMarksServlet.class); @Autowired + private IActivityDAO activityDAO; + @Autowired private ILogEventService logEventService; @Autowired private ILessonService lessonService; @@ -81,7 +83,6 @@ } @Override - @SuppressWarnings("unchecked") protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -113,7 +114,7 @@ .toString(); ActivitiesToCheckProcessor processor = new ActivitiesToCheckProcessor(lesson.getLearningDesign(), - learnerService.getActivityDAO()); + activityDAO); processor.parseLearningDesign(); ArrayList activityList = processor.getActivityList(); Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMapping.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMapping.java (.../ActivityMapping.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/ActivityMapping.java (.../ActivityMapping.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -33,6 +33,7 @@ import org.lamsfoundation.lams.learning.service.LearnerServiceException; import org.lamsfoundation.lams.learning.web.controller.DisplayActivityController; import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.dto.ActivityURL; import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.tool.exception.LamsToolServiceException; @@ -99,8 +100,8 @@ * @return * @throws UnsupportedEncodingException */ - public String getProgressForward(LearnerProgress progress, boolean redirect, boolean displayParallelFrames, - HttpServletRequest request, ILearnerFullService learnerService) throws UnsupportedEncodingException { + public String getProgressForward(LearnerProgress progress, boolean redirect, boolean displayParallelFrames) + throws UnsupportedEncodingException { String forward = null; if (progress.isComplete()) { @@ -170,6 +171,32 @@ return ActivityMapping.actionToURL(action, activity, true); } + public ActivityURL getActivityURL(LearnerProgress learnerProgress, Activity activity, boolean defaultURL, + boolean isFloating) { + ActivityURL activityURL = new ActivityURL(); + activityURL.setType(activity.getClass().getSimpleName()); + + if (isFloating && activity.isFloatingActivity()) { + // special case - progress engine. Do not want the unknown activity warning + activityURL.setUrl(null); + } else { + activityURL.setUrl(this.getActivityURL(activity)); + } + + activityURL.setActivityId(activity.getActivityId()); + activityURL.setTitle(activity.getTitle()); + activityURL.setDescription(activity.getDescription()); + + byte status = learnerProgress.getProgressState(activity); + activityURL.setStatus(status); + if (status == LearnerProgress.ACTIVITY_COMPLETED) { + activityURL.setComplete(true); + } + activityURL.setFloating(isFloating); + activityURL.setDefaultURL(defaultURL); + return activityURL; + } + /** * Generates an ActivityURL for a Tool Activity or SystemToolActivity. The URL is for the tool and not for the tool * loading page. The URL also includes toolSessionId or toolContentId and all other required data. Index: lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java =================================================================== diff -u -r9b4a3799f9589dbda9a792e10a4ebd649db1e3db -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java (.../LearningWebUtil.java) (revision 9b4a3799f9589dbda9a792e10a4ebd649db1e3db) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/web/util/LearningWebUtil.java (.../LearningWebUtil.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -23,19 +23,13 @@ package org.lamsfoundation.lams.learning.web.util; -import java.io.UnsupportedEncodingException; - import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.lamsfoundation.lams.learning.service.ILearnerFullService; -import org.lamsfoundation.lams.learning.service.LearnerServiceException; import org.lamsfoundation.lams.learningdesign.Activity; -import org.lamsfoundation.lams.learningdesign.dto.ActivityURL; import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.lesson.Lesson; -import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.session.SessionManager; @@ -61,18 +55,6 @@ } /** - * Helper method to retrieve the user data. Gets the id from the user details in the shared session then retrieves - * the real user object. - */ - public static User getUser(ILearnerFullService learnerService) { - HttpSession ss = SessionManager.getSession(); - UserDTO learner = (UserDTO) ss.getAttribute(AttributeNames.USER); - return learner != null - ? (User) learnerService.getUserManagementService().findById(User.class, learner.getUserID()) - : null; - } - - /** * Get the current learner progress. Check the request - in some cases it may be there. * * If not, the learner progress id might be in the request (if we've just come from complete activity). If so, get @@ -95,91 +77,14 @@ } if (learnerProgress == null) { + long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + Activity activity = learnerService.getActivity(activityId); + Lesson lesson = learnerService.getLessonByActivity(activity); + Integer learnerId = LearningWebUtil.getUserId(); - Activity act = LearningWebUtil.getActivityFromRequest(request, learnerService); - Lesson lesson = learnerService.getLessonByActivity(act); learnerProgress = learnerService.getProgress(learnerId, lesson.getLessonId()); } return learnerProgress; } - - /** - * Get the activity from request. We assume there is a parameter coming in. Then the activity id parameter is used - * to retrieve from database. - * - * @param request - * @return - */ - public static Activity getActivityFromRequest(HttpServletRequest request, ILearnerFullService learnerService) { - long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); - Activity activity = learnerService.getActivity(activityId); - return activity; - } - - /** - * "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. - * - * @param redirect - * Should this call redirect to the next screen (true) or use a forward (false) - * @param windowName - * Name of the window that triggered this code. Normally LearnerActivity (the popup window) or lWindow - * (normal learner window) - * @throws UnsupportedEncodingException - * @throws InterruptedException - * - */ - public static String completeActivity(HttpServletRequest request, HttpServletResponse response, - ActivityMapping actionMappings, LearnerProgress progress, Activity currentActivity, Integer learnerId, - ILearnerFullService learnerService, boolean redirect) - throws LearnerServiceException, UnsupportedEncodingException { - - Lesson lesson = progress.getLesson(); - - if (currentActivity == null) { - progress = learnerService.joinLesson(learnerId, lesson.getLessonId()); - } else if (progress.getCompletedActivities().containsKey(currentActivity)) { - - // recalculate activity mark and pass it to gradebook - learnerService.updateGradebookMark(currentActivity, progress); - - return actionMappings.getCloseForward(currentActivity, lesson.getLessonId()); - } else { - learnerService.completeActivity(learnerId, currentActivity, progress.getLearnerProgressId()); - } - - if (currentActivity != null && (currentActivity.isFloating() || (currentActivity.getParentActivity() != null - && progress.getCompletedActivities().containsKey(currentActivity.getParentActivity())))) { - return actionMappings.getCloseForward(currentActivity, lesson.getLessonId()); - } - - return actionMappings.getProgressForward(progress, redirect, false, request, learnerService); - } - - public static ActivityURL getActivityURL(ActivityMapping activityMapping, LearnerProgress learnerProgress, - Activity activity, boolean defaultURL, boolean isFloating) { - ActivityURL activityURL = new ActivityURL(); - activityURL.setType(activity.getClass().getSimpleName()); - - if (isFloating && activity.isFloatingActivity()) { - // special case - progress engine. Do not want the unknown activity warning - activityURL.setUrl(null); - } else { - activityURL.setUrl(activityMapping.getActivityURL(activity)); - } - - activityURL.setActivityId(activity.getActivityId()); - activityURL.setTitle(activity.getTitle()); - activityURL.setDescription(activity.getDescription()); - - byte status = learnerProgress.getProgressState(activity); - activityURL.setStatus(status); - if (status == LearnerProgress.ACTIVITY_COMPLETED) { - activityURL.setComplete(true); - } - activityURL.setFloating(isFloating); - activityURL.setDefaultURL(defaultURL); - return activityURL; - } } \ No newline at end of file Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/service/NbApplicationException.java =================================================================== diff -u --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/service/NbApplicationException.java (revision 0) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/service/NbApplicationException.java (revision be74862925361d836bef1df4c5959105c9695a87) @@ -0,0 +1,68 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + + +package org.lamsfoundation.lams.tool.noticeboard.service; + +/** + * Generic exception class for the noticeboard tool + */ + +public class NbApplicationException extends RuntimeException { + /** + * Default Constructor + */ + public NbApplicationException() { + super(); + } + + /** + * Constructor for customized error message + * + * @param message + */ + public NbApplicationException(String message) { + super(message); + } + + /** + * Constructor for wrapping the throwable object + * + * @param cause + */ + public NbApplicationException(Throwable cause) { + super(cause); + } + + /** + * Constructor for wrapping both the customized error message and + * throwable exception object. + * + * @param message + * @param cause + */ + public NbApplicationException(String message, Throwable cause) { + super(message, cause); + } + +} Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/service/NoticeboardService.java =================================================================== diff -u -r3bb7e0141ae1cc15ccd737c95d90b5762a34ad61 -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/service/NoticeboardService.java (.../NoticeboardService.java) (revision 3bb7e0141ae1cc15ccd737c95d90b5762a34ad61) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/service/NoticeboardService.java (.../NoticeboardService.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -58,7 +58,6 @@ import org.lamsfoundation.lams.tool.noticeboard.model.NoticeboardContent; import org.lamsfoundation.lams.tool.noticeboard.model.NoticeboardSession; import org.lamsfoundation.lams.tool.noticeboard.model.NoticeboardUser; -import org.lamsfoundation.lams.tool.noticeboard.util.NbApplicationException; import org.lamsfoundation.lams.tool.service.ILamsToolService; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.util.JsonUtil; Fisheye: Tag be74862925361d836bef1df4c5959105c9695a87 refers to a dead (removed) revision in file `lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbApplicationException.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag be74862925361d836bef1df4c5959105c9695a87 refers to a dead (removed) revision in file `lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/util/NbWebUtil.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/controller/NbAuthoringController.java =================================================================== diff -u -rb3b03858efeef1c37e36993757f56374a9f2b9f3 -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/controller/NbAuthoringController.java (.../NbAuthoringController.java) (revision b3b03858efeef1c37e36993757f56374a9f2b9f3) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/controller/NbAuthoringController.java (.../NbAuthoringController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -32,8 +32,7 @@ import org.lamsfoundation.lams.tool.noticeboard.NoticeboardConstants; import org.lamsfoundation.lams.tool.noticeboard.model.NoticeboardContent; import org.lamsfoundation.lams.tool.noticeboard.service.INoticeboardService; -import org.lamsfoundation.lams.tool.noticeboard.util.NbApplicationException; -import org.lamsfoundation.lams.tool.noticeboard.util.NbWebUtil; +import org.lamsfoundation.lams.tool.noticeboard.service.NbApplicationException; import org.lamsfoundation.lams.tool.noticeboard.web.form.NbAuthoringForm; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.CommonConstants; @@ -186,7 +185,7 @@ throw new NbApplicationException(error); } - Long content_id = NbWebUtil.convertToLong(nbAuthoringForm.getToolContentID()); + Long content_id = Long.valueOf(nbAuthoringForm.getToolContentID()); //throws exception if the content id does not exist checkContentId(content_id); Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/controller/NbLearnerController.java =================================================================== diff -u -r3bb7e0141ae1cc15ccd737c95d90b5762a34ad61 -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/controller/NbLearnerController.java (.../NbLearnerController.java) (revision 3bb7e0141ae1cc15ccd737c95d90b5762a34ad61) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/controller/NbLearnerController.java (.../NbLearnerController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -43,8 +43,7 @@ import org.lamsfoundation.lams.tool.noticeboard.model.NoticeboardSession; import org.lamsfoundation.lams.tool.noticeboard.model.NoticeboardUser; import org.lamsfoundation.lams.tool.noticeboard.service.INoticeboardService; -import org.lamsfoundation.lams.tool.noticeboard.util.NbApplicationException; -import org.lamsfoundation.lams.tool.noticeboard.util.NbWebUtil; +import org.lamsfoundation.lams.tool.noticeboard.service.NbApplicationException; import org.lamsfoundation.lams.tool.noticeboard.web.form.NbLearnerForm; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.MessageService; @@ -284,7 +283,7 @@ Long userID = getUserID(request); - Long toolSessionID = NbWebUtil.convertToLong(nbLearnerForm.getToolSessionID()); + Long toolSessionID = Long.valueOf(nbLearnerForm.getToolSessionID()); if (toolSessionID == null) { String error = "Unable to continue. The parameters tool session id is missing"; logger.error(error); @@ -350,7 +349,7 @@ @RequestMapping(path = "/reflect", method = RequestMethod.POST) public String reflect(@ModelAttribute NbLearnerForm nbLearnerForm, HttpServletRequest request) { - Long toolSessionID = NbWebUtil.convertToLong(nbLearnerForm.getToolSessionID()); + Long toolSessionID = Long.valueOf(nbLearnerForm.getToolSessionID()); NoticeboardContent nbContent = nbService.retrieveNoticeboardBySessionID(toolSessionID); request.setAttribute("reflectInstructions", nbContent.getReflectInstructions()); request.setAttribute("title", nbContent.getTitle()); Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/controller/NbMonitoringController.java =================================================================== diff -u -rb3b03858efeef1c37e36993757f56374a9f2b9f3 -rbe74862925361d836bef1df4c5959105c9695a87 --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/controller/NbMonitoringController.java (.../NbMonitoringController.java) (revision b3b03858efeef1c37e36993757f56374a9f2b9f3) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/controller/NbMonitoringController.java (.../NbMonitoringController.java) (revision be74862925361d836bef1df4c5959105c9695a87) @@ -41,8 +41,7 @@ import org.lamsfoundation.lams.tool.noticeboard.model.NoticeboardSession; import org.lamsfoundation.lams.tool.noticeboard.model.NoticeboardUser; import org.lamsfoundation.lams.tool.noticeboard.service.INoticeboardService; -import org.lamsfoundation.lams.tool.noticeboard.util.NbApplicationException; -import org.lamsfoundation.lams.tool.noticeboard.util.NbWebUtil; +import org.lamsfoundation.lams.tool.noticeboard.service.NbApplicationException; import org.lamsfoundation.lams.tool.noticeboard.web.form.NbMonitoringForm; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.util.AttributeNames; @@ -69,8 +68,7 @@ @RequestMapping("/monitoring") public String unspecified(@ModelAttribute NbMonitoringForm nbMonitoringForm, HttpServletRequest request) { - - Long toolContentId = NbWebUtil.convertToLong(request.getParameter(NoticeboardConstants.TOOL_CONTENT_ID)); + Long toolContentId = WebUtil.readLongParam(request, NoticeboardConstants.TOOL_CONTENT_ID); String contentFolderID = WebUtil.readStrParam(request, NoticeboardConstants.CONTENT_FOLDER_ID); if (toolContentId == null) { @@ -139,8 +137,8 @@ @RequestMapping("/viewReflection") public String viewReflection(@ModelAttribute NbMonitoringForm nbMonitoringForm, HttpServletRequest request) { - Long userId = NbWebUtil.convertToLong(request.getParameter(NoticeboardConstants.USER_ID)); - Long toolSessionId = NbWebUtil.convertToLong(request.getParameter(NoticeboardConstants.TOOL_SESSION_ID)); + Long userId = WebUtil.readLongParam(request, NoticeboardConstants.USER_ID); + Long toolSessionId = WebUtil.readLongParam(request, NoticeboardConstants.TOOL_SESSION_ID); NoticeboardUser nbUser = nbService.retrieveNoticeboardUser(userId, toolSessionId); NotebookEntry nbEntry = nbService.getEntry(nbUser.getNbSession().getNbSessionId(), CoreNotebookConstants.NOTEBOOK_TOOL, NoticeboardConstants.TOOL_SIGNATURE, userId.intValue());