Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java,v diff -u -r1.41.2.14 -r1.41.2.15 --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java 3 Apr 2007 05:22:39 -0000 1.41.2.14 +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java 5 Apr 2007 03:01:12 -0000 1.41.2.15 @@ -288,68 +288,73 @@ /** * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#isLearningDesignAvailable(LearningDesign, java.lang.Integer) */ - public boolean isLearningDesignAvailable(LearningDesign design, Integer userID) throws LearningDesignException { + public boolean isLearningDesignAvailable(LearningDesign design, Integer userID) throws LearningDesignException, IOException { if(design == null) - throw new LearningDesignException(); + 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; } - /** - * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#setupEditOnFly(java.lang.Long, java.lang.Integer) - */ - public String setupEditOnFly(Long learningDesignID, Integer userID) throws UserException, LearningDesignException, IOException { - FlashMessage flashMessage= null; + private void toogleLessonLock(LearningDesign design) { Lesson lesson = null; - LearningDesign design = learningDesignID!=null ? getLearningDesign(learningDesignID) : null; + // lock active lesson + Set lessons = design.getLessons(); + Iterator it = lessons.iterator(); + + while(it.hasNext()) { + lesson = (Lesson) it.next(); + lesson.setLockedForEdit(!lesson.getLockedForEdit()); + } + } + + /** + * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#setupEditOnFlyLock(LearningDesign, java.lang.Integer) + */ + public boolean setupEditOnFlyLock(Long learningDesignID, Integer userID) throws LearningDesignException, UserException, IOException { User user = (User)baseDAO.find(User.class,userID); + LearningDesign design = learningDesignID!=null ? getLearningDesign(learningDesignID) : null; - if(design == null) { - flashMessage = FlashMessage.getNoSuchLearningDesignExists("setupEditOnFly", learningDesignID); - return flashMessage.serializeMessage(); - } else if(design.getLessons().isEmpty()) - throw new LearningDesignException(); // TODO: add error msg + 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})); - if(isLearningDesignAvailable(design, userID)) { - - // lock active lesson - Set lessons = design.getLessons(); - Iterator it = lessons.iterator(); - while(it.hasNext()) { - lesson = (Lesson) it.next(); - lesson.setLockedForEdit(true); - } + toogleLessonLock(design); - if(lesson != null) - learningDesignDAO.update(design); + // lock Learning Design + design.setEditOverrideLock(true); + design.setEditOverrideUser(user); - // lock Learning Design - design.setEditOverrideLock(true); - design.setEditOverrideUser(user); - - // parse Learning Design to find last read-only Activity - EditOnFlyProcessor processor = new EditOnFlyProcessor(design, activityDAO); - processor.parseLearningDesign(); - - ArrayList activities = processor.getLastReadOnlyActivity(); - - // add new System Gate after last read-only Activity - addSystemGateAfterActivity(activities, design); + learningDesignDAO.update(design); + + return true; + } - learningDesignDAO.update(design); + /** + * @see org.lamsfoundation.lams.authoring.service.IAuthoringService#setupEditOnFlyGate(java.lang.Long, java.lang.Integer) + */ + 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})); + + EditOnFlyProcessor processor = new EditOnFlyProcessor(design, activityDAO); /* parse Learning Design to find last read-only Activity */ + processor.parseLearningDesign(); - flashMessage = new FlashMessage("setupEditOnFly", true); - } else { - // unavailable to edit design - } + ArrayList activities = processor.getLastReadOnlyActivity(); + addSystemGateAfterActivity(activities, design); /* add new System Gate after last read-only Activity */ - return flashMessage.serializeMessage(); + toogleLessonLock(design); + + learningDesignDAO.update(design); + + return new FlashMessage("setupEditOnFlyGate", true).serializeMessage(); } @@ -366,41 +371,34 @@ if(user==null) flashMessage = FlashMessage.getNoSuchUserExists("finishEditOnFly", userID); - // only the user who is editing the design may unlock it - if(design != null) { + if(design != null) { /* only the user who is editing the design may unlock it */ if(design.getEditOverrideUser().equals(user)) { design.setEditOverrideLock(false); design.setEditOverrideUser(null); - //unlock lesson - Set lessons = design.getLessons(); + Set lessons = design.getLessons(); /* unlock lesson */ + 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); + EditOnFlyProcessor processor = new EditOnFlyProcessor(design, activityDAO); /* parse Learning Design to find last read-only Activity (hopefully the system gate in this case) */ processor.parseLearningDesign(); ArrayList activities = processor.getLastReadOnlyActivity(); - // open and release waiting list on system gate - GateActivity gate = null; + GateActivity gate = null; /* open and release waiting list on system gate */ if(activities != null) if(!activities.isEmpty() && activities.get(0).isGateActivity()) gate = (GateActivity) activities.get(0); - if(gate != null) { - // remove inputted system gate - design = removeTempSystemGate(gate, design); - - } + if(gate != null) + design = removeTempSystemGate(gate, design); /* remove inputted system gate */ - // the lesson may now have additional activities on the end, so clear any completed flags - lessonService.performMarkLessonUncompleted(lesson.getLessonId()); + lessonService.performMarkLessonUncompleted(lesson.getLessonId()); /* the lesson may now have additional activities on the end, so clear any completed flags */ learningDesignDAO.insertOrUpdate(design); @@ -419,18 +417,19 @@ } /** - * Remove a temporary system gate. Requires removing the gate from any learner progress entries - should only + * 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. * * This will leave a "hole" in the learner progress, but the progress engine can take care of that. + * @param gate + * @param design + * @return Learning Design with removed System Gate */ public LearningDesign removeTempSystemGate(GateActivity gate, LearningDesign design) { - // get transitions - Transition toTransition = gate.getTransitionTo(); + Transition toTransition = gate.getTransitionTo(); /* get transitions */ Transition fromTransition = gate.getTransitionFrom(); - // rearrange to-transition and/or delete redundant transition - if(toTransition != null && fromTransition != null) { + if(toTransition != null && fromTransition != null) { /* rearrange to-transition and/or delete redundant transition */ toTransition.setToActivity(fromTransition.getToActivity()); toTransition.setToUIID(toTransition.getToActivity().getActivityUIID()); @@ -444,67 +443,61 @@ design.getTransitions().remove(fromTransition); } - // remove temp system gate - design.getActivities().remove(gate); + design.getActivities().remove(gate); /* remove temp system gate */ - // increment design version field - design.setDesignVersion(design.getDesignVersion() + 1); + design.setDesignVersion(design.getDesignVersion() + 1); /* increment design version field */ - // need to remove it from any learner progress entries - lessonService.removeProgressReferencesToActivity(gate); + lessonService.removeProgressReferencesToActivity(gate); /* need to remove it from any learner progress entries */ return design; } + /** + * Add a temp. System Gate. to the design. + * + * @param activities + * @param design + */ public void addSystemGateAfterActivity(ArrayList activities, LearningDesign design) { GateActivity gate = null; - Integer syncType = null; - SystemTool systemTool = null; - Integer activityType = null; - String title = null; - Activity activity = (activities.isEmpty()) ? null : (Activity) activities.get(0); - + Integer syncType = new Integer(Activity.SYSTEM_GATE_ACTIVITY_TYPE); + Integer activityType = new Integer(Activity.SYSTEM_GATE_ACTIVITY_TYPE); Integer maxId = design.getMaxID(); + String title = "System Gate"; /* messageService.getMessage(MSG_KEY_SYNC_GATE); */ + + SystemTool systemTool = systemToolDAO.getSystemToolByID(SystemTool.SYSTEM_GATE); + Activity activity = (activities.isEmpty()) ? null : (Activity) activities.get(0); - syncType = new Integer(Activity.SYSTEM_GATE_ACTIVITY_TYPE); - activityType = new Integer(Activity.SYSTEM_GATE_ACTIVITY_TYPE); - systemTool = systemToolDAO.getSystemToolByID(SystemTool.SYSTEM_GATE); - title = "System Gate"; // messageService.getMessage(MSG_KEY_SYNC_GATE); - try { - // create new System Gate Activity - if ( syncType != null ) { - 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.setDefineLater(Boolean.FALSE); - gate.setCreateDateTime(new Date()); - gate.setRunOffline(Boolean.FALSE); - gate.setReadOnly(Boolean.TRUE); - gate.setLearningDesign(design); + 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.setDefineLater(Boolean.FALSE); + gate.setCreateDateTime(new Date()); + gate.setRunOffline(Boolean.FALSE); + 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; if(activity != null) { + fromTransition = activity.getTransitionFrom(); /* update transitions */ - // update transitions - fromTransition = activity.getTransitionFrom(); - if(fromTransition != null) { toActivity = fromTransition.getToActivity(); @@ -522,8 +515,7 @@ toActivity.setTransitionTo(newTransition); - // set x/y position for Gate - Integer x1 = (activity.getXcoord() != null) ? activity.getXcoord() : 0; + Integer x1 = (activity.getXcoord() != null) ? activity.getXcoord() : 0; /* set x/y position for Gate */ Integer x2 = (toActivity.getXcoord() != null) ? toActivity.getXcoord() : 0; gate.setXcoord(new Integer(((x1.intValue() + 123 + x2.intValue()) / 2) - 13)); @@ -546,8 +538,7 @@ activity.setTransitionFrom(fromTransition); gate.setTransitionTo(fromTransition); - // set x/y position for Gate - Integer x1 = (activity.getTransitionTo() != null) ? activity.getTransitionTo().getFromActivity().getXcoord() : null; + Integer x1 = (activity.getTransitionTo() != null) ? activity.getTransitionTo().getFromActivity().getXcoord() : null; /* set x/y position for Gate */ Integer x2 = (activity.getXcoord() != null) ? activity.getXcoord() : 0; if(x2 != null) gate.setXcoord(x2>=x1 ? new Integer(x2.intValue()+123+13+20) : new Integer(x2.intValue()-13-20)); @@ -557,8 +548,7 @@ } } else { - // no read-only activities insert gate at start of sequence - fromTransition = newTransition; + fromTransition = newTransition; /* no read-only activities insert gate at start of sequence */ toActivity = design.getFirstActivity(); newTransition.setTransitionUIID(++maxId); @@ -571,14 +561,11 @@ gate.setTransitionFrom(fromTransition); toActivity.setTransitionTo(fromTransition); - // keep gate door closed to stop learner's from going past this point - gate.setGateOpen(false); + gate.setGateOpen(false); /* keep gate door closed to stop learner's from going past this point */ - // set gate as first activity in sequence - design.setFirstActivity(gate); + design.setFirstActivity(gate); /* set gate as first activity in sequence */ - // set x/y position for Gate - Integer x1 = (toActivity.getXcoord() != null) ? toActivity.getXcoord() : 0; + Integer x1 = (toActivity.getXcoord() != null) ? toActivity.getXcoord() : 0; /* set x/y position for Gate */ Integer x2 = (toActivity.getTransitionFrom() != null) ? toActivity.getTransitionFrom().getToActivity().getXcoord() : null; if(x2 != null) gate.setXcoord(x2>=x1 ? new Integer(x1.intValue()-13-20) : new Integer(x1.intValue()+123+13+20)); @@ -590,8 +577,7 @@ design.getTransitions().add(newTransition); design.setMaxID(maxId); - // increment design version field - design.setDesignVersion(design.getDesignVersion() + 1); + design.setDesignVersion(design.getDesignVersion() + 1); /* increment design version field */ if(gate != null) activityDAO.update(gate); if(activity != null) activityDAO.update(activity); Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java,v diff -u -r1.19.6.6 -r1.19.6.7 --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java 19 Mar 2007 06:11:59 -0000 1.19.6.6 +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java 5 Apr 2007 03:01:12 -0000 1.19.6.7 @@ -247,12 +247,14 @@ * Prepares a LearningDesign to be ready for Edit-On-The-Fly (Editing). * Return a string representing the updated learning design in WDDX format. * - * @param learningDesignID The learning_design_id of the design whose WDDX packet is requested + * @param design The learning design whose WDDX packet is requested * @param userID user_id of the User who will be editing the design. * @throws UserException + * @throws LearningDesignException * @throws IOException */ - public String setupEditOnFly(Long learningDesignID, Integer userID) throws UserException, LearningDesignException, IOException; + public String setupEditOnFlyGate(Long learningDesignID, Integer userID) throws UserException, LearningDesignException, IOException; + public boolean setupEditOnFlyLock(Long learningDesignID, Integer userID) throws LearningDesignException, UserException, IOException; /** * @@ -284,8 +286,9 @@ * @param userID * @return * @throws LearningDesignException + * @throws IOException */ - public boolean isLearningDesignAvailable(LearningDesign design, Integer userID) throws LearningDesignException; + public boolean isLearningDesignAvailable(LearningDesign design, Integer userID) throws LearningDesignException, IOException; /** * Returns the generic help url from configuration Index: lams_central/src/java/org/lamsfoundation/lams/authoring/web/EditOnFlyServlet.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/authoring/web/EditOnFlyServlet.java,v diff -u -r1.1.2.2 -r1.1.2.3 --- lams_central/src/java/org/lamsfoundation/lams/authoring/web/EditOnFlyServlet.java 22 Feb 2007 04:15:24 -0000 1.1.2.2 +++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/EditOnFlyServlet.java 5 Apr 2007 03:01:12 -0000 1.1.2.3 @@ -103,11 +103,16 @@ private String doSetup(HttpServletRequest request, HttpServletResponse response) throws ServletException, UserException, IOException { String packet = null; + IAuthoringService service = getAuthoringService(); - LearningDesign design = service.getLearningDesign(learningDesignID); - if(service.isLearningDesignAvailable(design, userID)) - packet = service.setupEditOnFly(learningDesignID, userID); + try { + if(service.setupEditOnFlyLock(learningDesignID, userID)) + packet = service.setupEditOnFlyGate(learningDesignID, userID); + + } catch(Exception e) { + packet = FlashMessage.getExceptionOccured("doSetup", e.getMessage()).serializeMessage(); + } return packet; }