Index: lams_central/src/java/org/lamsfoundation/lams/authoring/authoringApplicationContext.xml =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/authoring/authoringApplicationContext.xml,v diff -u -r1.13.6.5 -r1.13.6.6 --- lams_central/src/java/org/lamsfoundation/lams/authoring/authoringApplicationContext.xml 20 Mar 2007 10:33:37 -0000 1.13.6.5 +++ lams_central/src/java/org/lamsfoundation/lams/authoring/authoringApplicationContext.xml 19 Apr 2007 01:06:26 -0000 1.13.6.6 @@ -51,6 +51,7 @@ + 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.17 -r1.41.2.18 --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java 18 Apr 2007 07:53:34 -0000 1.41.2.17 +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java 19 Apr 2007 01:06:26 -0000 1.41.2.18 @@ -51,6 +51,7 @@ import org.lamsfoundation.lams.learningdesign.GroupingActivity; import org.lamsfoundation.lams.learningdesign.LearningDesign; import org.lamsfoundation.lams.learningdesign.License; +import org.lamsfoundation.lams.learningdesign.ScheduleGateActivity; import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.learningdesign.Transition; import org.lamsfoundation.lams.learningdesign.dao.hibernate.ActivityDAO; @@ -68,6 +69,8 @@ import org.lamsfoundation.lams.learningdesign.service.ILearningDesignService; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.lesson.service.ILessonService; +import org.lamsfoundation.lams.monitoring.service.IMonitoringService; +import org.lamsfoundation.lams.monitoring.service.MonitoringServiceException; import org.lamsfoundation.lams.tool.SystemTool; import org.lamsfoundation.lams.tool.Tool; import org.lamsfoundation.lams.tool.ToolContentIDGenerator; @@ -111,6 +114,7 @@ protected ILearningDesignService learningDesignService; protected MessageService messageService; protected ILessonService lessonService; + protected IMonitoringService monitoringService; protected ToolContentIDGenerator contentIDGenerator; @@ -221,7 +225,11 @@ this.lessonService = lessonService; } + public void setMonitoringService(IMonitoringService monitoringService) { + this.monitoringService = monitoringService; + } + /** * @param contentIDGenerator The contentIDGenerator to set. */ @@ -405,7 +413,8 @@ design = removeTempSystemGate(gate, design); /* remove inputted system gate */ lessonService.performMarkLessonUncompleted(lesson.getLessonId()); /* the lesson may now have additional activities on the end, so clear any completed flags */ - + + initialiseToolActivityForRuntime(design, lesson); learningDesignDAO.insertOrUpdate(design); flashMessage = new FlashMessage("finishEditOnFly", lesson.getLessonId()); @@ -612,6 +621,45 @@ return activity; } + 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(); + + if ( activity.isInitialised() ) { + if ( ! activity.isActivityReadOnly() && activity.isToolActivity() ) { + // Activity is initialised so it was set up previously. So its tool content will be okay + // but the run offline flags and define later flags might have been changed, so they need to be updated + // Content ID shouldn't change, but we update it in case it does change while we update the status flags. + ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); + Long newContentId = lamsCoreToolService.notifyToolOfStatusFlags(toolActivity); + toolActivity.setToolContentId(newContentId); + } + + } else { + // this is a new activity - need to set up the content, do any scheduling, etc + // always have to copy the tool content, even though it may point to unique content - that way if the + // teacher has double clicked on the tool icon (and hence set up a tool content id) but not saved any content + // the code in copyToolContent will ensure that there is content for this activity. So we end up with a few + // unused records - we are trading database space for reliability. If we don't ensure that there is always + // a content record, then shortcomings in the createToolSession code may throw exceptions. + if ( activity.isToolActivity() ) { + ToolActivity toolActivity = (ToolActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); + Long newContentId = lamsCoreToolService.notifyToolToCopyContent(toolActivity, true); + toolActivity.setToolContentId(newContentId); + + } else if ( activity.isScheduleGate() ) { + //if it is schedule gate, we need to initialize the sheduler for it. + ScheduleGateActivity gateActivity = (ScheduleGateActivity) activityDAO.getActivityByActivityId(activity.getActivityId()); + monitoringService.runGateScheduler(gateActivity,now,lesson.getLessonName()); + } + activity.setInitialised(Boolean.TRUE); + activityDAO.update(activity); + } + } + } public LearningDesign copyLearningDesign(Long originalDesignID,Integer copyType, Integer userID, Integer workspaceFolderID, boolean setOriginalDesign)