Index: lams_central/.classpath =================================================================== RCS file: /usr/local/cvsroot/lams_central/.classpath,v diff -u -r1.14 -r1.15 --- lams_central/.classpath 1 Jul 2009 02:39:12 -0000 1.14 +++ lams_central/.classpath 9 Feb 2012 11:50:52 -0000 1.15 @@ -17,5 +17,6 @@ + Index: lams_central/conf/language/lams/ApplicationResources.properties =================================================================== RCS file: /usr/local/cvsroot/lams_central/conf/language/lams/ApplicationResources.properties,v diff -u -r1.94 -r1.95 --- lams_central/conf/language/lams/ApplicationResources.properties 2 Feb 2012 08:13:47 -0000 1.94 +++ lams_central/conf/language/lams/ApplicationResources.properties 9 Feb 2012 11:50:52 -0000 1.95 @@ -280,11 +280,18 @@ index.emailnotifications =Notifications index.emailnotifications.tooltip =Email notifications index.conditions =Conditions -index.conditions.tooltip =Conditions of participation in lesson +index.conditions.tooltip =Conditions of participation in the lesson +index.conditions.flag.tooltip =Participation in the lesson depends on completion of other lessons label.conditions.box.title =Lesson "{0}" will only be available after these lesson(s) are completed: label.conditions.box.no.dependency =There are no dependencies for this lesson. label.conditions.box.add.dependency =Select lesson that will need to be completed first: label.conditions.box.remove.dependency =Remove lesson dependency +label.conditions.box.finish.date =Lesson finishes after {0} days from its start {1} +label.conditions.box.no.finish.date =Lesson does not have a fixed number days to finish +label.days =days +label.set =Set +error.conditions.box.finish.date.number =Finish date must be a positive number +error.conditions.box.finish.date =Error while setting lesson finish date: {0} label.portrait.please.wait =Please wait label.portrait.take.snapshot.from.webcamera =Take portrait using Webcam label.portrait.configure =Configure Index: lams_central/src/java/org/lamsfoundation/lams/web/LessonConditionsAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/LessonConditionsAction.java,v diff -u -r1.3 -r1.4 --- lams_central/src/java/org/lamsfoundation/lams/web/LessonConditionsAction.java 6 Feb 2012 12:29:11 -0000 1.3 +++ lams_central/src/java/org/lamsfoundation/lams/web/LessonConditionsAction.java 9 Feb 2012 11:50:52 -0000 1.4 @@ -24,6 +24,7 @@ package org.lamsfoundation.lams.web; import java.util.ArrayList; +import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -36,11 +37,16 @@ import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.ActionMessage; +import org.apache.struts.action.ActionMessages; import org.apache.struts.actions.DispatchAction; -import org.lamsfoundation.lams.contentrepository.InvalidParameterException; +import org.joda.time.Interval; +import org.joda.time.Period; +import org.joda.time.PeriodType; import org.lamsfoundation.lams.index.IndexLessonBean; import org.lamsfoundation.lams.lesson.Lesson; -import org.lamsfoundation.lams.lesson.service.LessonService; +import org.lamsfoundation.lams.lesson.service.ILessonService; +import org.lamsfoundation.lams.monitoring.service.IMonitoringService; import org.lamsfoundation.lams.tool.exception.DataMissingException; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.CentralConstants; @@ -66,8 +72,11 @@ private static final String PARAM_PRECEDING_LESSONS = "precedingLessons"; private static final String PARAM_PRECEDING_LESSON_ID = "precedingLessonId"; private static final String PARAM_AVAILABLE_LESSONS = "availableLessons"; + private static final String PARAM_LESSON_START_DATE = "lessonStartDate"; + private static final String PARAM_LESSON_DAYS_TO_FINISH = "lessonDaysToFinish"; - private static LessonService lessonService; + private static ILessonService lessonService; + private static IMonitoringService monitoringService; /** * Prepares data for thickbox displayed on Index page. @@ -76,12 +85,12 @@ */ @SuppressWarnings("unchecked") public ActionForward getIndexLessonConditions(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws InvalidParameterException { + HttpServletResponse response) { Long lessonId = WebUtil.readLongParam(request, CentralConstants.PARAM_LESSON_ID, false); Lesson lesson = getLessonService().getLesson(lessonId); if (lesson == null) { - throw new InvalidParameterException("Lesson with ID: " + lessonId + " does not exist."); + throw new IllegalArgumentException("Lesson with ID: " + lessonId + " does not exist."); } List precedingLessons = new ArrayList(lesson.getPrecedingLessons().size()); @@ -106,6 +115,17 @@ } request.setAttribute(LessonConditionsAction.PARAM_AVAILABLE_LESSONS, availableLessons); + Date endDate = lesson.getScheduleEndDate(); + if (endDate != null) { + Date startDate = (lesson.getStartDateTime() == null) ? lesson.getScheduleStartDate() : lesson + .getStartDateTime(); + Interval interval = new Interval(startDate.getTime(), endDate.getTime()); + Period daysToLessonFinish = interval.toPeriod(PeriodType.days()); + + request.setAttribute(LessonConditionsAction.PARAM_LESSON_START_DATE, startDate); + request.setAttribute(LessonConditionsAction.PARAM_LESSON_DAYS_TO_FINISH, daysToLessonFinish.getDays()); + } + request.setAttribute(CentralConstants.PARAM_EDIT, canEdit(request, lesson)); return mapping.findForward(LessonConditionsAction.FORWARD_INDEX_LESSON_CONDITION); @@ -117,19 +137,12 @@ * @throws InvalidParameterException */ public ActionForward removeLessonDependency(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws InvalidParameterException { + HttpServletResponse response) { Long lessonId = WebUtil.readLongParam(request, CentralConstants.PARAM_LESSON_ID, false); Long removedPrecedingLessonId = WebUtil.readLongParam(request, LessonConditionsAction.PARAM_PRECEDING_LESSON_ID, false); - Lesson lesson = getLessonService().getLesson(lessonId); - if (lesson == null) { - throw new InvalidParameterException("Lesson with ID: " + lessonId + " does not exist."); - } - if (!canEdit(request, lesson)) { - throw new SecurityException("Current user can not edit lesson conditions"); - } - + Lesson lesson = getLessonAndCheckPermissions(request, lessonId); Iterator precedingLessonIter = lesson.getPrecedingLessons().iterator(); while (precedingLessonIter.hasNext()) { if (precedingLessonIter.next().getLessonId().equals(removedPrecedingLessonId)) { @@ -148,21 +161,15 @@ * @throws InvalidParameterException */ public ActionForward addLessonDependency(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws InvalidParameterException { + HttpServletResponse response) { Long lessonId = WebUtil.readLongParam(request, CentralConstants.PARAM_LESSON_ID, false); Long addedPrecedingLessonId = WebUtil.readLongParam(request, LessonConditionsAction.PARAM_PRECEDING_LESSON_ID, false); - Lesson lesson = getLessonService().getLesson(lessonId); - if (lesson == null) { - throw new InvalidParameterException("Lesson with ID: " + lessonId + " does not exist."); - } - if (!canEdit(request, lesson)) { - throw new SecurityException("Current user can not edit lesson conditions"); - } + Lesson lesson = getLessonAndCheckPermissions(request, lessonId); Lesson addedPrecedingLesson = getLessonService().getLesson(addedPrecedingLessonId); if (addedPrecedingLesson == null) { - throw new InvalidParameterException("Preceding lesson with ID: " + lessonId + " does not exist."); + throw new IllegalArgumentException("Preceding lesson with ID: " + lessonId + " does not exist."); } lesson.getPrecedingLessons().add(addedPrecedingLesson); @@ -172,6 +179,58 @@ } /** + * Sets a new lesson scheduled finish date, based on give number of days. + */ + public ActionForward setDaysToLessonFinish(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + Long lessonId = WebUtil.readLongParam(request, CentralConstants.PARAM_LESSON_ID, false); + Integer daysToLessonFinish = null; + ActionMessages errors = new ActionMessages(); + try { + daysToLessonFinish = WebUtil.readIntParam(request, LessonConditionsAction.PARAM_LESSON_DAYS_TO_FINISH, + false); + if (daysToLessonFinish <= 0) { + throw new IllegalArgumentException("Number of days to lesson finish is a nonpositive number"); + } + } catch (IllegalArgumentException e) { + LessonConditionsAction.logger.error(e); + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.conditions.box.finish.date.number")); + } + + if (daysToLessonFinish != null) { + Lesson lesson = getLessonAndCheckPermissions(request, lessonId); + HttpSession session = SessionManager.getSession(); + UserDTO currentUser = (UserDTO) session.getAttribute(AttributeNames.USER); + try { + // reschedule the lesson + getMonitoringService().finishLessonOnSchedule(lessonId, daysToLessonFinish, currentUser.getUserID()); + } catch (IllegalArgumentException e) { + LessonConditionsAction.logger.error(e); + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.conditions.box.finish.date", + new Object[] { e.getMessage() })); + } + } + + if (!errors.isEmpty()) { + saveErrors(request, errors); + } + + // after operation, display contents again + return getIndexLessonConditions(mapping, form, request, response); + } + + private Lesson getLessonAndCheckPermissions(HttpServletRequest request, Long lessonId) { + Lesson lesson = getLessonService().getLesson(lessonId); + if (lesson == null) { + throw new IllegalArgumentException("Lesson with ID: " + lessonId + " does not exist."); + } + if (!canEdit(request, lesson)) { + throw new SecurityException("Current user can not edit lesson conditions"); + } + return lesson; + } + + /** * Checks if user is allowed to edit lesson conditions. */ private boolean canEdit(HttpServletRequest request, Lesson lesson) { @@ -183,12 +242,21 @@ return currentUser.getUserID().equals(lesson.getUser().getUserId()); } - private LessonService getLessonService() { + private ILessonService getLessonService() { if (LessonConditionsAction.lessonService == null) { WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() .getServletContext()); - LessonConditionsAction.lessonService = (LessonService) ctx.getBean("lessonService"); + LessonConditionsAction.lessonService = (ILessonService) ctx.getBean("lessonService"); } return LessonConditionsAction.lessonService; } + + private IMonitoringService getMonitoringService() { + if (LessonConditionsAction.monitoringService == null) { + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + LessonConditionsAction.monitoringService = (IMonitoringService) ctx.getBean("monitoringService"); + } + return LessonConditionsAction.monitoringService; + } } Index: lams_central/web/groupContents.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/groupContents.jsp,v diff -u -r1.11 -r1.12 --- lams_central/web/groupContents.jsp 5 Dec 2011 16:04:12 -0000 1.11 +++ lams_central/web/groupContents.jsp 9 Feb 2012 11:50:52 -0000 1.12 @@ -28,6 +28,7 @@ " >  " >  " >  + " >  Index: lams_central/web/indexLessonConditions.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/indexLessonConditions.jsp,v diff -u -r1.3 -r1.4 --- lams_central/web/indexLessonConditions.jsp 6 Feb 2012 12:29:11 -0000 1.3 +++ lams_central/web/indexLessonConditions.jsp 9 Feb 2012 11:50:52 -0000 1.4 @@ -2,6 +2,8 @@ <%@ taglib uri="tags-fmt" prefix="fmt"%> <%@ taglib uri="tags-core" prefix="c"%> <%@ taglib uri="tags-lams" prefix="lams"%> +<%@ taglib uri="tags-logic" prefix="logic" %> +<%@ taglib uri="tags-html" prefix="html" %> @@ -10,6 +12,10 @@ + + + +