Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java =================================================================== diff -u -r81e8b06bd5291466798d9bf17ac25a7d4184af72 -rb5137f7e9fdfffbaec18f55e1c6e94bda6a201a1 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision 81e8b06bd5291466798d9bf17ac25a7d4184af72) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision b5137f7e9fdfffbaec18f55e1c6e94bda6a201a1) @@ -141,8 +141,19 @@ * @param lessonId the specified the lesson id. */ public void archiveLesson(long lessonId); + /** + * A lesson can only be suspended if it is started. The purpose of suspending is + * to hide the lesson from learners temporarily. If the teacher tries to suspend a lesson that + * is not in the STARTED_STATE, then an error should be returned. + * @param lessonId the lesson ID which will be suspended. + */ + public void suspendLesson(long lessonId); + /** + * Unsuspend a lesson, which state must be Lesson.SUSPEND_STATE. Otherwise an exception will be thrown. + * @param lessonId + */ + public void unsuspendLesson(long lessonId); - /** *
* Teachers sometimes find that there are just too many "old" designs and @@ -372,6 +383,7 @@ /* TODO Dummy methods - to be removed */ public List getOrganisationsUsers(Integer userId); public List getLearningDesigns(Long userId); + } Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -r81e8b06bd5291466798d9bf17ac25a7d4184af72 -rb5137f7e9fdfffbaec18f55e1c6e94bda6a201a1 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 81e8b06bd5291466798d9bf17ac25a7d4184af72) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision b5137f7e9fdfffbaec18f55e1c6e94bda6a201a1) @@ -416,7 +416,7 @@ //start the scheduling job try { - setLessonStatus(lessonId,Lesson.NOT_STARTED_STATE); + setLessonState(lessonId,Lesson.NOT_STARTED_STATE); scheduler.scheduleJob(startLessonJob, startLessonTrigger); } catch (SchedulerException e) @@ -503,25 +503,58 @@ * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#finishLesson(long) */ public void finishLesson(long lessonId) { - setLessonStatus(lessonId,Lesson.FINISHED_STATE); + setLessonState(lessonId,Lesson.FINISHED_STATE); } /** * Archive the specified the lesson. When archived, the data is retained * but the learners cannot access the details. * @param lessonId the specified the lesson id. */ public void archiveLesson(long lessonId) { - setLessonStatus(lessonId,Lesson.ARCHIVED_STATE); + setLessonState(lessonId,Lesson.ARCHIVED_STATE); } /** + * + * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#suspendLesson(long) + */ + public void suspendLesson(long lessonId) { + Lesson lesson = lessonDAO.getLesson(new Long(lessonId)); + Integer state = lesson.getLessonStateId(); + //only suspend started lesson + if(!Lesson.STARTED_STATE.equals(state)){ + throw new MonitoringServiceException("Lesson does not started yet. It can not be suspended."); + } + if ( lesson == null ) { + throw new MonitoringServiceException("Lesson for id="+lessonId+" is missing. Unable to suspend lesson."); + } + setLessonState(lesson,Lesson.SUSPENDED_STATE); + } + /** + * + * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#unsuspendLesson(long) + */ + public void unsuspendLesson(long lessonId) { + Lesson lesson = lessonDAO.getLesson(new Long(lessonId)); + Integer state = lesson.getLessonStateId(); + //only suspend started lesson + if(!Lesson.SUSPENDED_STATE.equals(state)){ + throw new MonitoringServiceException("Lesson is not suspended lesson. It can not be unsuspended."); + } + if ( lesson == null ) { + throw new MonitoringServiceException("Lesson for id="+lessonId+" is missing. Unable to suspend lesson."); + } + setLessonState(lesson,Lesson.STARTED_STATE); + } + + /** * Set lesson status to given status value. The stauts value will be one value of class level in * org.lamsfoundation.lams.lesson.Lesson. * * @param lessonId * @param status */ - private void setLessonStatus(long lessonId,Integer status) { + private void setLessonState(long lessonId,Integer status) { Lesson requestedLesson = lessonDAO.getLesson(new Long(lessonId)); if( status == null ){ @@ -531,6 +564,16 @@ throw new MonitoringServiceException("Lesson for id="+lessonId+" is missing. Unable to set lesson status to "+ status.intValue()); } + setLessonState(requestedLesson,status); + + } + /** + * @see setLessonState(long,Integer) + * @param requestedLesson + * @param status + */ + private void setLessonState(Lesson requestedLesson,Integer status) { + requestedLesson.setLessonStateId(status); lessonDAO.updateLesson(requestedLesson); Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java =================================================================== diff -u -ra28e6fbe16b6a29a83038a73012f7e7b9b5669e5 -rb5137f7e9fdfffbaec18f55e1c6e94bda6a201a1 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java (.../MonitoringAction.java) (revision a28e6fbe16b6a29a83038a73012f7e7b9b5669e5) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java (.../MonitoringAction.java) (revision b5137f7e9fdfffbaec18f55e1c6e94bda6a201a1) @@ -359,6 +359,79 @@ return outputPacket(mapping,request,response,message,"details"); } /** + * The purpose of suspending is to hide the lesson from learners temporarily. + * It doesn't make any sense to suspend a created or a not started (ie scheduled) + * lesson as they will not be shown on the learner interface anyway! If the teacher + * tries to suspend a lesson that is not in the STARTED_STATE, then an error should + * be returned to Flash. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws IOException + * @throws ServletException + */ + public ActionForward suspendLesson(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) throws IOException, + ServletException + { + FlashMessage flashMessage = null; + this.monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); + long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID); + + try { + monitoringService.suspendLesson(lessonId); + flashMessage = new FlashMessage("suspendLesson",Boolean.TRUE); + } catch (Exception e) { + flashMessage = new FlashMessage("suspendLesson", + "Error occurs :" + e.getMessage(), + FlashMessage.ERROR); + } + + String message = flashMessage.serializeMessage(); + + return outputPacket(mapping,request,response,message,"details"); + } + /** + * Unsuspend a lesson which state must be Lesson.SUPSENDED_STATE. Otherwise a error message will return to + * flash client. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws IOException + * @throws ServletException + */ + public ActionForward unsuspendLesson(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) throws IOException, + ServletException + { + FlashMessage flashMessage = null; + this.monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); + long lessonId = WebUtil.readLongParam(request,AttributeNames.PARAM_LESSON_ID); + + try { + monitoringService.unsuspendLesson(lessonId); + flashMessage = new FlashMessage("unsuspendLesson",Boolean.TRUE); + } catch (Exception e) { + flashMessage = new FlashMessage("unsuspendLesson", + "Error occurs :" + e.getMessage(), + FlashMessage.ERROR); + } + + String message = flashMessage.serializeMessage(); + + return outputPacket(mapping,request,response,message,"details"); + } + /** *
* The STRUTS action will send back a WDDX message after marking the lesson by the given lesson ID
* as Lesson.DISABLED_STATE
status.