Index: lams_build/lib/lams/lams-central.jar =================================================================== diff -u -r9bd21433617c6dbccfacfb09752344c640570966 -rdded08ea618c437f0f0f6424c6b1bbf54abe5bd7 Binary files differ Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -r15045d0b9b0dbb930f42a9da7757207e7a325341 -rdded08ea618c437f0f0f6424c6b1bbf54abe5bd7 Binary files differ Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java =================================================================== diff -u -r9bd21433617c6dbccfacfb09752344c640570966 -rdded08ea618c437f0f0f6424c6b1bbf54abe5bd7 --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision 9bd21433617c6dbccfacfb09752344c640570966) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision dded08ea618c437f0f0f6424c6b1bbf54abe5bd7) @@ -478,60 +478,37 @@ } /** - * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#isLearningDesignAvailable(LearningDesign, - * java.lang.Integer) - */ - @Override - public boolean isLearningDesignAvailable(LearningDesign design, Integer userID) throws LearningDesignException, - IOException { - if (design == null) { - throw new LearningDesignException(FlashMessage.getNoSuchLearningDesignExists("getLearningDesignDetails", - design.getLearningDesignId()).serializeMessage()); - } - - if ((design.getEditOverrideUser() != null) && (design.getEditOverrideLock() != null)) { - return design.getEditOverrideUser().getUserId().equals(userID) ? true : !design.getEditOverrideLock(); - } else { - return true; - } - } - - private void setLessonLock(LearningDesign design, boolean lock) { - Lesson lesson = null; - - // lock active lesson - Set lessons = design.getLessons(); - Iterator it = lessons.iterator(); - - while (it.hasNext()) { - lesson = (Lesson) it.next(); - lesson.setLockedForEdit(lock); - } - } - - /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#setupEditOnFlyLock(LearningDesign, * java.lang.Integer) */ + @SuppressWarnings("unchecked") @Override public boolean setupEditOnFlyLock(Long learningDesignID, Integer userID) throws LearningDesignException, UserException, IOException { User user = (User) baseDAO.find(User.class, userID); + if (user == null) { + throw new UserException(messageService.getMessage("no.such.user.exist", new Object[] { userID })); + } - LearningDesign design = learningDesignID != null ? getLearningDesign(learningDesignID) : null; + LearningDesign design = learningDesignID == null ? null : getLearningDesign(learningDesignID); - if (isLearningDesignAvailable(design, userID)) { + if (design == null) { + throw new LearningDesignException(FlashMessage.getNoSuchLearningDesignExists("getLearningDesignDetails", + learningDesignID).serializeMessage()); + } + boolean learningDesignAvailable = design.getEditOverrideUser() == null || design.getEditOverrideLock() == null + || design.getEditOverrideUser().getUserId().equals(userID) || !design.getEditOverrideLock(); + + if (learningDesignAvailable) { if (design.getLessons().isEmpty()) { - throw new LearningDesignException("There are no lessons attached to the design."); // TODO: - // add - // error - // msg - } else if (user == null) { - throw new UserException(messageService.getMessage("no.such.user.exist", new Object[] { userID })); + // TODO: add error msg + throw new LearningDesignException("There are no lessons attached to the design."); } - setLessonLock(design, true); + for (Lesson lesson : (Set) design.getLessons()) { + lesson.setLockedForEdit(true); + } // lock Learning Design design.setEditOverrideLock(true); @@ -540,125 +517,113 @@ learningDesignDAO.update(design); return true; - } else { - return false; } + return false; } /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#setupEditOnFlyGate(java.lang.Long, * java.lang.Integer) */ + @Override public String setupEditOnFlyGate(Long learningDesignID, Integer userID) throws UserException, IOException { User user = (User) baseDAO.find(User.class, userID); - LearningDesign design = learningDesignID != null ? getLearningDesign(learningDesignID) : null; - if (user == null) { throw new UserException(messageService.getMessage("no.such.user.exist", new Object[] { userID })); } - // parse Learning Design to find last read - only Activity + LearningDesign design = learningDesignID == null ? null : getLearningDesign(learningDesignID); + + // parse Learning Design to find last read-only Activity EditOnFlyProcessor processor = new EditOnFlyProcessor(design, activityDAO); processor.parseLearningDesign(); Activity lastReadOnlyActivity = processor.getLastReadOnlyActivity(); - // add new System Gate after last read-only Activity - addSystemGateAfterActivity(lastReadOnlyActivity, design); + // check if system gate already exists + if (lastReadOnlyActivity == null || !lastReadOnlyActivity.isGateActivity() + || !((GateActivity) lastReadOnlyActivity).isSystemGate()) { + // add new System Gate after last read-only Activity + addSystemGateAfterActivity(lastReadOnlyActivity, design); + learningDesignDAO.update(design); + } - setLessonLock(design, false); - - learningDesignDAO.update(design); - return new FlashMessage("setupEditOnFlyGate", true).serializeMessage(); } /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#finishEditOnFly(java.lang.Long, * java.lang.Integer) */ + @SuppressWarnings("unchecked") @Override public String finishEditOnFly(Long learningDesignID, Integer userID, boolean cancelled) throws IOException { FlashMessage flashMessage = null; - Lesson lesson = null; - LearningDesign design = learningDesignID != null ? learningDesignDAO.getLearningDesignById(learningDesignID) - : null; - User user = (User) baseDAO.find(User.class, userID); if (user == null) { flashMessage = FlashMessage.getNoSuchUserExists("finishEditOnFly", userID); } - if (design != null) { /* - * only the user who is editing the design may - * unlock it - */ + LearningDesign design = learningDesignID == null ? null : learningDesignDAO + .getLearningDesignById(learningDesignID); + + if (design == null) { + flashMessage = FlashMessage.getNoSuchLearningDesignExists("finishEditOnFly", learningDesignID); + } else { + // only the user who is editing the design may unlock it if (design.getEditOverrideUser().equals(user)) { design.setEditOverrideLock(false); design.setEditOverrideUser(null); - Set lessons = design.getLessons(); /* unlock lesson */ + // parse Learning Design to find last read - only Activity + // (hopefully the system gate in this case ) - Iterator it = lessons.iterator(); - while (it.hasNext()) { - lesson = (Lesson) it.next(); - lesson.setLockedForEdit(false); - } - - /* - * parse Learning Design to find last read - only Activity ( - * hopefully the system gate in this case ) - */ EditOnFlyProcessor processor = new EditOnFlyProcessor(design, activityDAO); processor.parseLearningDesign(); Activity lastReadOnlyActivity = processor.getLastReadOnlyActivity(); // open and release waiting list on system gate - GateActivity gate = null; - - if (lastReadOnlyActivity != null && lastReadOnlyActivity.isGateActivity() + if ((lastReadOnlyActivity != null) && lastReadOnlyActivity.isGateActivity() && ((GateActivity) lastReadOnlyActivity).isSystemGate()) { - gate = (GateActivity) lastReadOnlyActivity; + // remove previously inserted system gate + design = removeTempSystemGate(lastReadOnlyActivity.getActivityId(), design.getLearningDesignId()); } - if (gate != null) { - // remove inputted system gate - design = removeTempSystemGate(gate.getActivityId(), design.getLearningDesignId()); - } + for (Lesson lesson : (Set) design.getLessons()) { + lesson.setLockedForEdit(false); - // LDEV-1899 only mark learners uncompleted if a change was - // saved - if (!cancelled) { - // the lesson may now have additional activities on the end, - // so clear any completed flags - lessonService.performMarkLessonUncompleted(lesson.getLessonId()); - } + // LDEV-1899 only mark learners uncompleted if a change was saved + if (!cancelled) { + // the lesson may now have additional activities on the end, + // so clear any completed flags + lessonService.performMarkLessonUncompleted(lesson.getLessonId()); + } - initialiseToolActivityForRuntime(design, lesson); - learningDesignDAO.insertOrUpdate(design); + initialiseToolActivityForRuntime(design, lesson); - flashMessage = new FlashMessage("finishEditOnFly", lesson.getLessonId()); + if (flashMessage == null) { + flashMessage = new FlashMessage("finishEditOnFly", lesson.getLessonId()); + } + } + learningDesignDAO.update(design); } else { flashMessage = FlashMessage.getNoSuchUserExists("finishEditOnFly", userID); } - } else { - - flashMessage = FlashMessage.getNoSuchLearningDesignExists("finishEditOnFly", learningDesignID); } return flashMessage.serializeMessage(); } /** - * Remove a temp. System Gate from the design. Requires removing the gate from any learner progress entries - should - * only be a current activity but remove it from previous and next, just in case. + * Remove a temporary System Gate from the design. Requires removing the gate from any learner progress entries - + * should only be a current activity but remove it from previous and next, just in case. * * This will leave a "hole" in the learner progress, but the progress engine can take care of that. * @@ -674,14 +639,12 @@ // rearrange to-transition and/or delete redundant transition if ((toTransition != null) && (fromTransition != null)) { - toTransition.setToActivity(fromTransition.getToActivity()); fromTransition.getToActivity().setTransitionTo(toTransition); toTransition.setToUIID(toTransition.getToActivity().getActivityUIID()); design.getTransitions().remove(fromTransition); transitionDAO.update(toTransition); - } else if ((toTransition != null) && (fromTransition == null)) { toTransition.getFromActivity().setTransitionFrom(null); design.getTransitions().remove(toTransition); @@ -691,6 +654,9 @@ design.getTransitions().remove(fromTransition); } + // need to remove it from any learner progress entries + lessonService.removeProgressReferencesToActivity(gate); + // remove temp system gate design.getActivities().remove(gate); gate.setTransitionFrom(null); @@ -699,206 +665,157 @@ // increment design version field design.setDesignVersion(design.getDesignVersion() + 1); - // need to remove it from any learner progress entries - lessonService.removeProgressReferencesToActivity(gate); - return design; } /** - * Add a temp. System Gate. to the design. - * - * @param activities - * @param design + * Add a temporary System Gate to the design. */ - public void addSystemGateAfterActivity(Activity activity, LearningDesign design) { + @SuppressWarnings("unchecked") + private void addSystemGateAfterActivity(Activity activity, LearningDesign design) { GateActivity gate = null; - - Integer syncType = new Integer(Activity.SYSTEM_GATE_ACTIVITY_TYPE); - Integer activityType = new Integer(Activity.SYSTEM_GATE_ACTIVITY_TYPE); Integer maxId = design.getMaxID(); - // messageService.getMessage(MSG_KEY_SYNC_GATE ); String title = "System Gate"; - SystemTool systemTool = systemToolDAO.getSystemToolByID(SystemTool.SYSTEM_GATE); - try { /* create new System Gate Activity */ - gate = (GateActivity) Activity.getActivityInstance(syncType.intValue()); - gate.setActivityTypeId(activityType.intValue()); - gate.setActivityCategoryID(Activity.CATEGORY_SYSTEM); - gate.setSystemTool(systemTool); - gate.setActivityUIID(++maxId); - gate.setTitle(title != null ? title : "Gate"); - gate.setGateOpen(false); - gate.setWaitingLearners(null); - gate.setGateActivityLevelId(GateActivity.LEARNER_GATE_LEVEL); - gate.setApplyGrouping(false); // not nullable so default to false - gate.setGroupingSupportType(Activity.GROUPING_SUPPORT_OPTIONAL); - gate.setOrderId(null); - gate.setCreateDateTime(new Date()); - gate.setReadOnly(Boolean.TRUE); - gate.setLearningDesign(design); + /* create new System Gate Activity */ + gate = (GateActivity) Activity.getActivityInstance(Activity.SYSTEM_GATE_ACTIVITY_TYPE); + gate.setActivityTypeId(Activity.SYSTEM_GATE_ACTIVITY_TYPE); + gate.setActivityCategoryID(Activity.CATEGORY_SYSTEM); + gate.setSystemTool(systemTool); + gate.setActivityUIID(++maxId); + gate.setTitle(title); + gate.setGateOpen(false); + gate.setWaitingLearners(null); + gate.setGateActivityLevelId(GateActivity.LEARNER_GATE_LEVEL); + gate.setApplyGrouping(false); // not nullable so default to false + gate.setGroupingSupportType(Activity.GROUPING_SUPPORT_OPTIONAL); + gate.setOrderId(null); + gate.setCreateDateTime(new Date()); + gate.setReadOnly(Boolean.TRUE); + gate.setLearningDesign(design); - design.getActivities().add(gate); - baseDAO.insert(gate); + design.getActivities().add(gate); + baseDAO.insert(gate); - Transition fromTransition; - Transition newTransition = new Transition(); - Activity toActivity = null; + Transition fromTransition = null; + Activity toActivity = null; - if (activity != null) { - // update transitions - fromTransition = activity.getTransitionFrom(); + Transition newTransition = new Transition(); + newTransition.setTransitionUIID(++maxId); + newTransition.setLearningDesign(design); - if (fromTransition != null) { - toActivity = fromTransition.getToActivity(); + if (activity == null) { + // no read-only activities, insert gate at start of sequence + fromTransition = newTransition; - fromTransition.setToActivity(gate); + toActivity = design.getFirstActivity(); - fromTransition.setToUIID(gate.getActivityUIID()); - newTransition.setTransitionUIID(++maxId); - newTransition.setFromActivity(gate); - newTransition.setFromUIID(gate.getActivityUIID()); - newTransition.setToActivity(toActivity); - newTransition.setToUIID(toActivity.getActivityUIID()); - newTransition.setLearningDesign(design); + newTransition.setToActivity(toActivity); + newTransition.setToUIID(toActivity.getActivityUIID()); + newTransition.setFromActivity(gate); + newTransition.setFromUIID(gate.getActivityUIID()); - gate.setTransitionFrom(newTransition); - toActivity.setTransitionTo(newTransition); - gate.setTransitionTo(fromTransition); + gate.setTransitionFrom(fromTransition); + toActivity.setTransitionTo(fromTransition); - // set x / y position for Gate - Integer x1 = activity.getXcoord() != null ? activity.getXcoord() : 0; + // set gate as first activity in sequence + design.setFirstActivity(gate); - Integer x2 = toActivity.getXcoord() != null ? toActivity.getXcoord() : 0; + // set x / y position for Gate + Integer x1 = toActivity.getXcoord() == null ? 0 : toActivity.getXcoord(); - gate.setXcoord(new Integer(((x1.intValue() + 123 + x2.intValue()) / 2) - 13)); + Integer x2 = toActivity.getTransitionFrom() == null ? null : toActivity.getTransitionFrom().getToActivity() + .getXcoord(); - Integer y1 = activity.getYcoord() != null ? activity.getYcoord() : 0; - Integer y2 = toActivity.getYcoord() != null ? toActivity.getYcoord() : 0; + if ((x1 != null) && (x2 != null)) { + gate.setXcoord(x2 >= x1 ? (x1.intValue() - 13 - 20) : (x1.intValue() + 123 + 13 + 20)); + } else { + gate.setXcoord(x1.intValue() - 13 - 20); + } - gate.setYcoord(new Integer((y1.intValue() + 50 + y2.intValue()) / 2)); + gate.setYcoord(toActivity.getYcoord() + 25); - } else { - // fromTransition = newTransition; + } else { + // update transitions + fromTransition = activity.getTransitionFrom(); - newTransition.setTransitionUIID(++maxId); - newTransition.setFromActivity(activity); - newTransition.setFromUIID(activity.getActivityUIID()); - newTransition.setToActivity(gate); - newTransition.setToUIID(gate.getActivityUIID()); - newTransition.setLearningDesign(design); + if (fromTransition == null) { + newTransition.setFromActivity(activity); + newTransition.setFromUIID(activity.getActivityUIID()); + newTransition.setToActivity(gate); + newTransition.setToUIID(gate.getActivityUIID()); - activity.setTransitionFrom(newTransition); - gate.setTransitionTo(newTransition); + activity.setTransitionFrom(newTransition); + gate.setTransitionTo(newTransition); - Integer x1 = activity.getTransitionTo() != null ? activity.getTransitionTo().getFromActivity() - .getXcoord() : 0; /* set x/y position for Gate */ - Integer x2 = activity.getXcoord() != null ? activity.getXcoord() : 0; + Integer x1 = activity.getTransitionTo() == null ? 0 : activity.getTransitionTo().getFromActivity() + .getXcoord(); /* set x/y position for Gate */ + Integer x2 = activity.getXcoord() == null ? null : activity.getXcoord(); - if ((x1 != null) && (x2 != null)) { - gate.setXcoord(x2 >= x1 ? new Integer(x2.intValue() + 123 + 13 + 20) : new Integer(x2 - .intValue() - 13 - 20)); - } else { - gate.setXcoord(new Integer(x2.intValue() + 123 + 13 + 20)); - } - - gate.setYcoord(activity.getYcoord() + 25); + if ((x1 != null) && (x2 != null)) { + gate.setXcoord(x2 >= x1 ? (x2.intValue() + 123 + 13 + 20) : (x2.intValue() - 13 - 20)); + } else { + gate.setXcoord(x2.intValue() + 123 + 13 + 20); } + gate.setYcoord(activity.getYcoord() + 25); + } else { - // no read-only activities insert gate at start of sequence - fromTransition = newTransition; - toActivity = design.getFirstActivity(); + toActivity = fromTransition.getToActivity(); - newTransition.setTransitionUIID(++maxId); - newTransition.setToActivity(toActivity); - newTransition.setToUIID(toActivity.getActivityUIID()); + fromTransition.setToActivity(gate); + fromTransition.setToUIID(gate.getActivityUIID()); + newTransition.setFromActivity(gate); newTransition.setFromUIID(gate.getActivityUIID()); - newTransition.setLearningDesign(design); + newTransition.setToActivity(toActivity); + newTransition.setToUIID(toActivity.getActivityUIID()); - gate.setTransitionFrom(fromTransition); - toActivity.setTransitionTo(fromTransition); + gate.setTransitionFrom(newTransition); + toActivity.setTransitionTo(newTransition); + gate.setTransitionTo(fromTransition); - // keep gate door closed to stop learner's from going past this - // point - gate.setGateOpen(false); - - // set gate as first activity in sequence - design.setFirstActivity(gate); - // set x / y position for Gate - Integer x1 = toActivity.getXcoord() != null ? toActivity.getXcoord() : 0; + Integer x1 = activity.getXcoord() == null ? 0 : activity.getXcoord(); + Integer x2 = toActivity.getXcoord() == null ? 0 : toActivity.getXcoord(); + gate.setXcoord(((x1.intValue() + 123 + x2.intValue()) / 2) - 13); - Integer x2 = toActivity.getTransitionFrom() != null ? toActivity.getTransitionFrom().getToActivity() - .getXcoord() : null; - - if ((x1 != null) && (x2 != null)) { - gate.setXcoord(x2 >= x1 ? new Integer(x1.intValue() - 13 - 20) : new Integer( - x1.intValue() + 123 + 13 + 20)); - } else { - gate.setXcoord(new Integer(x1.intValue() - 13 - 20)); - } - - gate.setYcoord(toActivity.getYcoord() + 25); + Integer y1 = activity.getYcoord() == null ? 0 : activity.getYcoord(); + Integer y2 = toActivity.getYcoord() == null ? 0 : toActivity.getYcoord(); + gate.setYcoord((y1.intValue() + 50 + y2.intValue()) / 2); } - - design.getTransitions().add(newTransition); - design.setMaxID(maxId); - - // increment design version field - design.setDesignVersion(design.getDesignVersion() + 1); - - if (gate != null) { - activityDAO.update(gate); - } - if (activity != null) { - activityDAO.update(activity); - } - if (toActivity != null) { - activityDAO.update(toActivity); - } - - if ((fromTransition != null) && !fromTransition.equals(newTransition)) { - baseDAO.update(fromTransition); - } - if (newTransition != null) { - baseDAO.insert(newTransition); - } - if (design != null) { - learningDesignDAO.insertOrUpdate(design); - } - - } catch (NullPointerException npe) { - log.error(npe.getMessage(), npe); } - } + design.getTransitions().add(newTransition); + design.setMaxID(maxId); - /** - * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#getFirstUnattemptedActivity(org.lamsfoundation.lams.learningdesign.LearningDesign) - */ - @Override - public Activity getFirstUnattemptedActivity(LearningDesign design) throws LearningDesignException { - Activity activity = design.getFirstActivity(); + // increment design version field + design.setDesignVersion(design.getDesignVersion() + 1); - while (activity.getReadOnly() && (activity.getTransitionFrom() != null)) { - activity = activity.getTransitionFrom().getToActivity(); + if (gate != null) { + activityDAO.update(gate); } - - return activity; + if (activity != null) { + activityDAO.update(activity); + } + if (toActivity != null) { + activityDAO.update(toActivity); + } + if (fromTransition != null) { + baseDAO.update(fromTransition); + } + baseDAO.insert(newTransition); + learningDesignDAO.update(design); } + @SuppressWarnings("unchecked") private void initialiseToolActivityForRuntime(LearningDesign design, Lesson lesson) throws MonitoringServiceException { Date now = new Date(); - Set activities = design.getActivities(); - for (Iterator i = activities.iterator(); i.hasNext();) { - Activity activity = (Activity) i.next(); - + for (Activity activity : (Set) design.getActivities()) { if (!activity.isInitialised()) { // this is a new activity - need to set up the content, do any // scheduling, etc @@ -931,6 +848,8 @@ activityDAO.update(activity); } } + + learningDesignDAO.update(design); } @Override Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java =================================================================== diff -u -r9bd21433617c6dbccfacfb09752344c640570966 -rdded08ea618c437f0f0f6424c6b1bbf54abe5bd7 --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java (.../IAuthoringService.java) (revision 9bd21433617c6dbccfacfb09752344c640570966) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java (.../IAuthoringService.java) (revision dded08ea618c437f0f0f6424c6b1bbf54abe5bd7) @@ -358,25 +358,6 @@ public String finishEditOnFly(Long learningDesignID, Integer userID, boolean cancelled) throws IOException; /** - * - * @param design - * @return - * @throws LearningDesignException - */ - public Activity getFirstUnattemptedActivity(LearningDesign design) throws LearningDesignException; - - /** - * - * @param design - * @param userID - * @return - * @throws LearningDesignException - * @throws IOException - */ - public boolean isLearningDesignAvailable(LearningDesign design, Integer userID) throws LearningDesignException, - IOException; - - /** * Returns the generic help url from configuration * * @return String Generic help url Index: lams_central/src/java/org/lamsfoundation/lams/authoring/web/EditOnFlyServlet.java =================================================================== diff -u -r1feb16a101c9bfb25d6d738acf9d14858c451950 -rdded08ea618c437f0f0f6424c6b1bbf54abe5bd7 --- lams_central/src/java/org/lamsfoundation/lams/authoring/web/EditOnFlyServlet.java (.../EditOnFlyServlet.java) (revision 1feb16a101c9bfb25d6d738acf9d14858c451950) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/EditOnFlyServlet.java (.../EditOnFlyServlet.java) (revision dded08ea618c437f0f0f6424c6b1bbf54abe5bd7) @@ -1,26 +1,22 @@ package org.lamsfoundation.lams.authoring.web; - import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; - import org.apache.log4j.Logger; import org.lamsfoundation.lams.authoring.service.IAuthoringService; -import org.lamsfoundation.lams.util.audit.IAuditService; -import org.lamsfoundation.lams.util.WebUtil; -import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.usermanagement.exception.UserException; -import org.lamsfoundation.lams.learningdesign.LearningDesign; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.util.audit.IAuditService; import org.lamsfoundation.lams.util.wddx.FlashMessage; -import org.lamsfoundation.lams.web.servlet.AbstractStoreWDDXPacketServlet; +import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -29,137 +25,112 @@ * Edit a learning design (Edit-On-The-Fly) * * @author Mitch Seaton - * + * * @web:servlet name="editLD" * @web:servlet-mapping url-pattern="/eof/authoring/editLearningDesign" */ public class EditOnFlyServlet extends HttpServlet { - private static Logger log = Logger.getLogger(EditOnFlyServlet.class); - private static IAuditService auditService; - - private Integer userID = null; - private Long learningDesignID = null; - - public IAuthoringService getAuthoringService(){ - WebApplicationContext webContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); - return (IAuthoringService) webContext.getBean(AuthoringConstants.AUTHORING_SERVICE_BEAN_NAME); + private static Logger log = Logger.getLogger(EditOnFlyServlet.class); + + private static IAuthoringService authoringService; + private static IAuditService auditService; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String returnPacket = null; + + // Set to expire far in the past. + response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT"); + + // Set standard HTTP/1.1 no-cache headers. + response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); + + // Set IE extended HTTP/1.1 no-cache headers (use addHeader). + response.addHeader("Cache-Control", "post-check=0, pre-check=0"); + + // Set standard HTTP/1.0 no-cache header. + response.setHeader("Pragma", "no-cache"); + + // TODO: Check roles/permissions on the User to see if they have access to edit this design + Integer userID = getUserID(request); + Long learningDesignID = WebUtil.readLongParam(request, AttributeNames.PARAM_LEARNINGDESIGN_ID); + PrintWriter writer = response.getWriter(); + + try { + returnPacket = doSetup(learningDesignID, userID, request, response); + writer.println(returnPacket); + } catch (Exception e) { + // Don't want exceptions flowing back to Flash if we can help it. + + FlashMessage flashMessage = FlashMessage.getExceptionOccured( + IAuthoringService.START_EDIT_ON_FLY_MESSAGE_KEY, e.getMessage() == null ? e.getClass().getName() + : e.getMessage()); + + writer.write(flashMessage.serializeMessage()); + + getAuditService().log(EditOnFlyServlet.class.getName(), "Exception triggered: " + e.toString()); + + return; } - - /** - * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest, HttpServletResponse) - */ - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - String returnPacket = null; - PrintWriter writer = null; - - auditService = getAuditService(); - - // Set to expire far in the past. - response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT"); + } - // Set standard HTTP/1.1 no-cache headers. - response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); + /** + * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest, HttpServletResponse) + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { + doGet(request, response); - // Set IE extended HTTP/1.1 no-cache headers (use addHeader). - response.addHeader("Cache-Control", "post-check=0, pre-check=0"); + } - // Set standard HTTP/1.0 no-cache header. - response.setHeader("Pragma", "no-cache"); - - // TODO: Check roles/permissions on the User to see if they have access to edit this design - userID = getUserID(request); - learningDesignID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_LEARNINGDESIGN_ID)); - - try { - writer = response.getWriter(); - - returnPacket = doSetup(request, response); - - } catch ( Exception e ) { - // Don't want exceptions flowing back to Flash if we can help it. - - FlashMessage flashMessage = FlashMessage.getExceptionOccured(getMessageKey(), - e.getMessage()!=null?e.getMessage():e.getClass().getName()); - - if(writer == null) - writer = response.getWriter(); - - writer.write(flashMessage.serializeMessage()); - - auditService.log(EditOnFlyServlet.class.getName(),"Exception triggered: "+e.toString()); - - return; - } - - // can't inform Flash if an exception occurs now... - if ( writer != null && returnPacket != null) - writer.println(returnPacket); + private String doSetup(Long learningDesignID, Integer userID, HttpServletRequest request, + HttpServletResponse response) throws ServletException, UserException, IOException { + String packet = null; + + try { + boolean lockSetup = getAuthoringService().setupEditOnFlyLock(learningDesignID, userID); + if (lockSetup) { + packet = getAuthoringService().setupEditOnFlyGate(learningDesignID, userID); + } else { + packet = new FlashMessage("setupEditOnFlyLock", false, FlashMessage.OBJECT_MESSAGE).serializeMessage(); + } + } catch (Exception e) { + packet = FlashMessage.getExceptionOccured("doSetup", e.getMessage()).serializeMessage(); } - /** - * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest, HttpServletResponse) - */ - protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException - { - doGet(request, response); - + return packet; + } + + private Integer getUserID(HttpServletRequest request) { + Integer userId = WebUtil.readIntParam(request, AttributeNames.PARAM_USER_ID, true); + if (userId == null) { + HttpSession session = SessionManager.getSession(); + UserDTO userDto = (UserDTO) session.getAttribute(AttributeNames.USER); + userId = userDto.getUserID(); } - - /** - * - */ - private String doSetup(HttpServletRequest request, HttpServletResponse response) - throws ServletException, UserException, IOException { - String packet = null; - - IAuthoringService service = getAuthoringService(); - - try { - if(service.setupEditOnFlyLock(learningDesignID, userID)) - packet = service.setupEditOnFlyGate(learningDesignID, userID); - else - packet = new FlashMessage("setupEditOnFlyLock", false, FlashMessage.OBJECT_MESSAGE).serializeMessage(); - } catch(Exception e) { - packet = FlashMessage.getExceptionOccured("doSetup", e.getMessage()).serializeMessage(); - } - - return packet; + return userId; + } + + private IAuthoringService getAuthoringService() { + if (EditOnFlyServlet.authoringService == null) { + WebApplicationContext webContext = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServletContext()); + + EditOnFlyServlet.authoringService = (IAuthoringService) webContext + .getBean(AuthoringConstants.AUTHORING_SERVICE_BEAN_NAME); } - - /** - * - */ - private Integer getUserID(HttpServletRequest request) { - Integer userId = WebUtil.readIntParam(request, AttributeNames.PARAM_USER_ID, true); - if ( userId == null ) { - HttpSession session = SessionManager.getSession(); - UserDTO userDto = (UserDTO)session.getAttribute(AttributeNames.USER); - userId = userDto.getUserID(); - } - return userId; - } + return EditOnFlyServlet.authoringService; + } - /** - * - * @return - */ - protected String getMessageKey() { - return IAuthoringService.START_EDIT_ON_FLY_MESSAGE_KEY; + private IAuditService getAuditService() { + if (EditOnFlyServlet.auditService == null) { + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(this + .getServletContext()); + EditOnFlyServlet.auditService = (IAuditService) ctx.getBean("auditService"); } - - /** - * Get AuditService bean. - * @return - */ - private IAuditService getAuditService(){ - if(auditService==null){ - WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext()); - auditService = (IAuditService) ctx.getBean("auditService"); - } - return auditService; - } -} + return EditOnFlyServlet.auditService; + } +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java =================================================================== diff -u -r5b633ecc884b7d321a5164af26bfe268629a2d3f -rdded08ea618c437f0f0f6424c6b1bbf54abe5bd7 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision 5b633ecc884b7d321a5164af26bfe268629a2d3f) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision dded08ea618c437f0f0f6424c6b1bbf54abe5bd7) @@ -463,20 +463,54 @@ } } + @SuppressWarnings("unchecked") @Override - public void removeProgressReferencesToActivity(Activity activity) throws LessonServiceException { + public void removeProgressReferencesToActivity(Activity activity) { if (activity != null) { LessonService.log.debug("Processing learner progress for activity " + activity.getActivityId()); - List progresses = learnerProgressDAO.getLearnerProgressReferringToActivity(activity); - if (progresses != null && progresses.size() > 0) { - Iterator iter = progresses.iterator(); - while (iter.hasNext()) { - LearnerProgress progress = (LearnerProgress) iter.next(); - if (removeActivityReference(activity, progress)) { - ; + List progresses = learnerProgressDAO.getLearnerProgressReferringToActivity(activity); + if (progresses != null) { + for (LearnerProgress progress : progresses) { + if (LessonService.log.isDebugEnabled()) { + LessonService.log + .debug("Processing learner progress learner " + progress.getUser().getUserId()); } - learnerProgressDAO.updateLearnerProgress(progress); + + boolean recordUpdated = false; + boolean removed = progress.getAttemptedActivities().remove(activity) != null; + if (removed) { + recordUpdated = true; + LessonService.log.debug("Removed activity from attempted activities"); + } + + removed = progress.getCompletedActivities().remove(activity) != null; + if (removed) { + recordUpdated = true; + LessonService.log.debug("Removed activity from completed activities"); + } + + if (progress.getCurrentActivity() != null && progress.getCurrentActivity().equals(activity)) { + progress.setCurrentActivity(null); + recordUpdated = true; + LessonService.log.debug("Removed activity as current activity"); + } + + if (progress.getNextActivity() != null && progress.getNextActivity().equals(activity)) { + progress.setNextActivity(null); + recordUpdated = true; + LessonService.log.debug("Removed activity as next activity"); + } + + if (progress.getPreviousActivity() != null && progress.getPreviousActivity().equals(activity)) { + progress.setPreviousActivity(null); + recordUpdated = true; + LessonService.log.debug("Removed activity as previous activity"); + } + + if (recordUpdated) { + learnerProgressDAO.updateLearnerProgress(progress); + } } } } @@ -493,47 +527,6 @@ } } - private boolean removeActivityReference(Activity activity, LearnerProgress progress) { - - if (LessonService.log.isDebugEnabled()) { - LessonService.log.debug("Processing learner progress learner " + progress.getUser().getUserId()); - } - - boolean recordUpdated = false; - - boolean removed = (progress.getAttemptedActivities().remove(activity) != null); - if (removed) { - recordUpdated = true; - LessonService.log.debug("Removed activity from attempted activities"); - } - - removed = (progress.getCompletedActivities().remove(activity) != null); - if (removed) { - recordUpdated = true; - LessonService.log.debug("Removed activity from completed activities"); - } - - if (progress.getCurrentActivity() != null && progress.getCurrentActivity().equals(activity)) { - progress.setCurrentActivity(null); - recordUpdated = true; - LessonService.log.debug("Removed activity as current activity"); - } - - if (progress.getNextActivity() != null && progress.getNextActivity().equals(activity)) { - progress.setNextActivity(null); - recordUpdated = true; - LessonService.log.debug("Removed activity as next activity"); - } - - if (progress.getPreviousActivity() != null && progress.getPreviousActivity().equals(activity)) { - progress.setPreviousActivity(null); - recordUpdated = true; - LessonService.log.debug("Removed activity as previous activity"); - } - - return recordUpdated; - } - @Override public void performMarkLessonUncompleted(Long lessonId) throws LessonServiceException { int count = 0;