Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/CloseScheduleGateJob.java =================================================================== diff -u --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/CloseScheduleGateJob.java (revision 0) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/CloseScheduleGateJob.java (revision 955340c23e43ecd35929add1f6074d8c2504397a) @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * ***********************************************************************/ + +package org.lamsfoundation.lams.monitoring.service; + +import java.util.Map; + +import org.apache.log4j.Logger; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.springframework.scheduling.quartz.QuartzJobBean; + + +/** + * The Quartz sheduling job that closes the gate. It is configured as a Spring + * bean and will be triggered by the scheduler to perform its work. + * + * @author Jacky Fang + * @since 2005-4-12 + * @version 1.1 + */ +public class CloseScheduleGateJob extends QuartzJobBean +{ + + //--------------------------------------------------------------------- + // Instance variables + //--------------------------------------------------------------------- + private static Logger log = Logger.getLogger(OpenScheduleGateJob.class); + private IMonitoringService monitoringService; + + //--------------------------------------------------------------------- + // Inverse of control - method injection + //--------------------------------------------------------------------- + /** + * @param monitoringService The monitoringService to set. + */ + public void setMonitoringService(IMonitoringService monitoringService) + { + this.monitoringService = monitoringService; + } + + //--------------------------------------------------------------------- + // Overridden method + //--------------------------------------------------------------------- + /** + * @see org.springframework.scheduling.quartz.QuartzJobBean#executeInternal(org.quartz.JobExecutionContext) + */ + protected void executeInternal(JobExecutionContext context) throws JobExecutionException + { + //getting gate id set from scheduler + Map properties = context.getJobDetail().getJobDataMap(); + Long gateId = (Long)properties.get("gateId"); + + if(log.isDebugEnabled()) + log.debug("Closing gate......["+gateId.longValue()+"]"); + + monitoringService.closeGate(gateId); + + if(log.isDebugEnabled()) + log.debug("Gate......["+gateId.longValue()+"] Closed"); + } +} Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java =================================================================== diff -u -rb763be8a2bbb86f0b8589ae2a51f64f69e9208c1 -r955340c23e43ecd35929add1f6074d8c2504397a --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision b763be8a2bbb86f0b8589ae2a51f64f69e9208c1) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision 955340c23e43ecd35929add1f6074d8c2504397a) @@ -22,7 +22,6 @@ import java.util.List; -import org.lamsfoundation.lams.learningdesign.GateActivity; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.tool.service.LamsToolServiceException; import org.lamsfoundation.lams.usermanagement.Organisation; @@ -82,13 +81,13 @@ /** * Set the gate to open to let all the learners through. This learning service * is triggerred by the system scheduler. - * @param gate the gate that we need to open. + * @param gate the id of the gate we need to open. */ - public void openGate(GateActivity gate); + public void openGate(Long gateId); /** * Set the gate to closed. - * @param gate the gate that we need to close. + * @param gate the id of the gate we need to close. */ - public void closeGate(GateActivity gate); + public void closeGate(Long gateId); } Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -rb763be8a2bbb86f0b8589ae2a51f64f69e9208c1 -r955340c23e43ecd35929add1f6074d8c2504397a --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision b763be8a2bbb86f0b8589ae2a51f64f69e9208c1) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 955340c23e43ecd35929add1f6074d8c2504397a) @@ -30,6 +30,7 @@ import org.lamsfoundation.lams.learningdesign.GateActivity; import org.lamsfoundation.lams.learningdesign.Group; import org.lamsfoundation.lams.learningdesign.LearningDesign; +import org.lamsfoundation.lams.learningdesign.ScheduleGateActivity; import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.learningdesign.dao.IActivityDAO; import org.lamsfoundation.lams.lesson.Lesson; @@ -41,6 +42,8 @@ import org.lamsfoundation.lams.tool.service.LamsToolServiceException; import org.lamsfoundation.lams.usermanagement.Organisation; import org.lamsfoundation.lams.usermanagement.User; +import org.quartz.JobDetail; +import org.quartz.Scheduler; /** *

This is the major service facade for all monitoring functionalities. It is @@ -63,7 +66,9 @@ private ILamsCoreToolService lamsCoreToolService; private IAuthoringService authoringService; private IActivityDAO activityDAO; - + private JobDetail openScheduleGateJob; + private JobDetail closeScheduleGateJob; + private Scheduler scheduler; //--------------------------------------------------------------------- // Inversion of Control Methods - Method injection //--------------------------------------------------------------------- @@ -106,6 +111,29 @@ { this.activityDAO = activityDAO; } + + /** + * @param openScheduleGateJob The openScheduleGateJob to set. + */ + public void setOpenScheduleGateJob(JobDetail openScheduleGateJob) + { + this.openScheduleGateJob = openScheduleGateJob; + } + + /** + * @param closeScheduleGateJob The closeScheduleGateJob to set. + */ + public void setCloseScheduleGateJob(JobDetail closeScheduleGateJob) + { + this.closeScheduleGateJob = closeScheduleGateJob; + } + /** + * @param scheduler The scheduler to set. + */ + public void setScheduler(Scheduler scheduler) + { + this.scheduler = scheduler; + } //--------------------------------------------------------------------- // Service Methods //--------------------------------------------------------------------- @@ -190,11 +218,12 @@ //TODO this is for testing purpose as survey is the only tool available //so far. if (shouldInitToolSessionFor(activity)&&this.isSurvey((ToolActivity)activity)) - { initToolSessionFor((ToolActivity) activity, requestedLesson.getAllLearners(), requestedLesson); - } + //if it is schedule gate, we need to initialize sheduler for it. + if(activity.getActivityTypeId().intValue()==Activity.SCHEDULE_GATE_ACTIVITY_TYPE) + initGateScheduler((ScheduleGateActivity)activity); } //update lesson status requestedLesson.setLessonStateId(Lesson.STARTED_STATE); @@ -203,19 +232,29 @@ } /** + * @param activity + */ + private void initGateScheduler(ScheduleGateActivity scheduleGate) + { + + } + + /** * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#openGate(org.lamsfoundation.lams.learningdesign.GateActivity) */ - public void openGate(GateActivity gate) + public void openGate(Long gateId) { + GateActivity gate = (GateActivity)activityDAO.getActivityByActivityId(gateId); gate.setGateOpen(new Boolean(true)); activityDAO.update(gate); } /** * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#closeGate(org.lamsfoundation.lams.learningdesign.GateActivity) */ - public void closeGate(GateActivity gate) + public void closeGate(Long gateId) { + GateActivity gate = (GateActivity)activityDAO.getActivityByActivityId(gateId); gate.setGateOpen(new Boolean(false)); activityDAO.update(gate); } Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/OpenScheduleGateJob.java =================================================================== diff -u --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/OpenScheduleGateJob.java (revision 0) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/OpenScheduleGateJob.java (revision 955340c23e43ecd35929add1f6074d8c2504397a) @@ -0,0 +1,82 @@ +/*************************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * ***********************************************************************/ + +package org.lamsfoundation.lams.monitoring.service; + +import java.util.Map; + +import org.apache.log4j.Logger; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.springframework.scheduling.quartz.QuartzJobBean; + + +/** + * The Quartz sheduling job that opens the gate. It is configured as a Spring + * bean and will be triggered by the scheduler to perform its work. + * @author Jacky Fang + * @since 2005-4-12 + * @version 1.1 + * + */ +public class OpenScheduleGateJob extends QuartzJobBean +{ + //--------------------------------------------------------------------- + // Instance variables + //--------------------------------------------------------------------- + private static Logger log = Logger.getLogger(OpenScheduleGateJob.class); + private IMonitoringService monitoringService; + + //--------------------------------------------------------------------- + // Inverse of control - method injection + //--------------------------------------------------------------------- + /** + * @param monitoringService The monitoringService to set. + */ + public void setMonitoringService(IMonitoringService monitoringService) + { + this.monitoringService = monitoringService; + } + + //--------------------------------------------------------------------- + // Overridden method + //--------------------------------------------------------------------- + /** + * @see org.springframework.scheduling.quartz.QuartzJobBean#executeInternal(org.quartz.JobExecutionContext) + */ + protected void executeInternal(JobExecutionContext context) throws JobExecutionException + { + //getting gate id set from scheduler + Map properties = context.getJobDetail().getJobDataMap(); + Long gateId = (Long)properties.get("gateId"); + + if(log.isDebugEnabled()) + log.debug("Openning gate......["+gateId.longValue()+"]"); + + monitoringService.openGate(gateId); + + if(log.isDebugEnabled()) + log.debug("Gate......["+gateId.longValue()+"] opened"); + } + + +} Index: lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/monitoringApplicationContext.xml =================================================================== diff -u -r05c83089b5b441f4752e33bea2aca4167eaf9b54 -r955340c23e43ecd35929add1f6074d8c2504397a --- lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/monitoringApplicationContext.xml (.../monitoringApplicationContext.xml) (revision 05c83089b5b441f4752e33bea2aca4167eaf9b54) +++ lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/monitoringApplicationContext.xml (.../monitoringApplicationContext.xml) (revision 955340c23e43ecd35929add1f6074d8c2504397a) @@ -44,7 +44,8 @@ - + + @@ -55,8 +56,38 @@ PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED + PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED + PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED + + + org.lamsfoundation.lams.monitoring.service.OpenScheduleGateJob + + + + + + + + + + + + + org.lamsfoundation.lams.monitoring.service.CloseScheduleGateJob + + + + + + + + + + + +