Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/CloseScheduleGateJob.java =================================================================== RCS file: /usr/local/cvsroot/lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/Attic/CloseScheduleGateJob.java,v diff -u -r1.1 -r1.2 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/CloseScheduleGateJob.java 12 Apr 2005 08:09:48 -0000 1.1 +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/CloseScheduleGateJob.java 15 Apr 2005 04:30:00 -0000 1.2 @@ -70,12 +70,12 @@ Map properties = context.getJobDetail().getJobDataMap(); Long gateId = (Long)properties.get("gateId"); - if(log.isDebugEnabled()) - log.debug("Closing gate......["+gateId.longValue()+"]"); + //if(log.isDebugEnabled()) + log.info("Closing gate......["+gateId.longValue()+"]"); monitoringService.closeGate(gateId); - if(log.isDebugEnabled()) - log.debug("Gate......["+gateId.longValue()+"] Closed"); + //if(log.isDebugEnabled()) + log.info("Gate......["+gateId.longValue()+"] Closed"); } } Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java =================================================================== RCS file: /usr/local/cvsroot/lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java,v diff -u -r1.11 -r1.12 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java 14 Apr 2005 06:19:36 -0000 1.11 +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java 15 Apr 2005 04:30:00 -0000 1.12 @@ -48,7 +48,7 @@ * @param user user the user who want to create this lesson. * @return the lesson initialized. */ - public Lesson initializeLesson(String lessonName, String lessonDescription,long learningDesignId,User user);; + public Lesson initializeLesson(String lessonName, String lessonDescription,long learningDesignId,User user); /** @@ -71,7 +71,7 @@ * lams and tool interaction to start a * lesson. */ - public void startlesson(long lessonId)throws LamsToolServiceException; + public void startlesson(long lessonId); /** * Force the learner to complete all the activities for current lesson. Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== RCS file: /usr/local/cvsroot/lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java,v diff -u -r1.14 -r1.15 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java 14 Apr 2005 07:56:57 -0000 1.14 +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java 15 Apr 2005 04:30:00 -0000 1.15 @@ -265,8 +265,10 @@ /** * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#startlesson(long) */ - public void startlesson(long lessonId) throws LamsToolServiceException + public void startlesson(long lessonId) { + //if(log.isDebugEnabled()) + log.info("=============Starting Lesson "+lessonId+"=============="); //we get the lesson just created Lesson requestedLesson = lessonDAO.getLesson(new Long(lessonId)); //initialize tool sessions if necessary @@ -289,6 +291,9 @@ requestedLesson.setLessonStateId(Lesson.STARTED_STATE); lessonDAO.updateLesson(requestedLesson); + + //if(log.isDebugEnabled()) + log.info("=============Lesson "+lessonId+" started==============="); } /** @@ -304,6 +309,8 @@ */ private void runGateScheduler(ScheduleGateActivity scheduleGate) { + //if(log.isDebugEnabled()) + log.info("Running scheduler for gate "+scheduleGate.getActivityId()+"..."); JobDetail openScheduleGateJob = getOpenScheduleGateJob(); JobDetail closeScheduleGateJob = getCloseScheduleGateJob(); //setup the message for scheduling job @@ -329,6 +336,8 @@ throw new MonitoringServiceException("Error occurred at " + "[runGateScheduler]- fail to start scheduling",e); } + //if(log.isDebugEnabled()) + log.info("Scheduler for Gate "+scheduleGate.getActivityId()+" started..."); } /** @@ -450,19 +459,30 @@ * @param lesson the target lesson that these tool sessions belongs to. * @throws LamsToolServiceException the exception when lams is talking to tool. */ - private void initToolSessionFor(ToolActivity activity, Set learners,Lesson lesson) throws LamsToolServiceException + private void initToolSessionFor(ToolActivity activity, Set learners,Lesson lesson) { activity.setToolSessions(new HashSet()); - for (Iterator i = learners.iterator(); i.hasNext();) + try { - User learner = (User) i.next(); + for (Iterator i = learners.iterator(); i.hasNext();) + { + User learner = (User) i.next(); - ToolSession toolSession = lamsCoreToolService.createToolSession(learner,activity,lesson); - //ask tool to create their own tool sessions using the given id. - lamsCoreToolService.notifyToolsToCreateSession(toolSession.getToolSessionId(), activity); - //update the hibernate persistent object - activity.getToolSessions().add(toolSession); + ToolSession toolSession; + + toolSession = lamsCoreToolService.createToolSession(learner,activity,lesson); + + //ask tool to create their own tool sessions using the given id. + lamsCoreToolService.notifyToolsToCreateSession(toolSession.getToolSessionId(), activity); + //update the hibernate persistent object + activity.getToolSessions().add(toolSession); + } } + catch (LamsToolServiceException e) + { + throw new MonitoringServiceException("Error occurred at " + + "[initToolSessionFor]- Fail to call tool services",e); + } } /** Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringServiceProxy.java =================================================================== RCS file: /usr/local/cvsroot/lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringServiceProxy.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringServiceProxy.java 15 Apr 2005 04:30:00 -0000 1.1 @@ -0,0 +1,69 @@ +/*************************************************************************** + * 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 javax.servlet.ServletContext; + +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + + +/** + *

This class act as the proxy between web layer and service layer. It is + * designed to decouple the presentation logic and business logic completely. + * In this way, the presentation tier will no longer be aware of the changes in + * service layer. Therefore we can feel free to switch the business logic + * implementation.

+ * + * @author Jacky Fang + * @since 2005-4-15 + * @version 1.1 + * + */ +public class MonitoringServiceProxy +{ + + /** + * Return the learner domain service object. It will delegate to the Spring + * helper method to retrieve the proper bean from Spring bean factory. + * @param servletContext the servletContext for current application + * @return learner service object. + */ + public static final IMonitoringService getMonitoringService(ServletContext servletContext) + { + return (IMonitoringService)getDomainService(servletContext,"monitoringService"); + } + + + /** + * Retrieve the proper Spring bean from bean factory. + * @param servletContext the servletContext for current application + * @return the Spring service bean. + */ + private static Object getDomainService(ServletContext servletContext,String serviceName) + { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); + return wac.getBean(serviceName); + } + +} Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/OpenScheduleGateJob.java =================================================================== RCS file: /usr/local/cvsroot/lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/Attic/OpenScheduleGateJob.java,v diff -u -r1.1 -r1.2 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/OpenScheduleGateJob.java 12 Apr 2005 08:09:48 -0000 1.1 +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/OpenScheduleGateJob.java 15 Apr 2005 04:30:00 -0000 1.2 @@ -69,13 +69,13 @@ Map properties = context.getJobDetail().getJobDataMap(); Long gateId = (Long)properties.get("gateId"); - if(log.isDebugEnabled()) - log.debug("Openning gate......["+gateId.longValue()+"]"); + //if(log.isDebugEnabled()) + log.info("Openning gate......["+gateId.longValue()+"]"); monitoringService.openGate(gateId); - if(log.isDebugEnabled()) - log.debug("Gate......["+gateId.longValue()+"] opened"); + //if(log.isDebugEnabled()) + log.info("Gate......["+gateId.longValue()+"] opened"); } Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java 15 Apr 2005 04:30:00 -0000 1.1 @@ -0,0 +1,120 @@ +/*************************************************************************** + * 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.web; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; + +import org.lamsfoundation.lams.monitoring.service.IMonitoringService; +import org.lamsfoundation.lams.monitoring.service.MonitoringServiceProxy; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.action.LamsDispatchAction; + + +/** + * + *

The action servlet that provide all the monitoring functionalities. It + * interact with the teacher via flash and JSP monitoring interface.

+ * + * @author Jacky Fang + * @since 2005-4-15 + * @version 1.1 + * + * ----------------XDoclet Tags-------------------- + * + * @struts:action path="/monitoring" + * parameter="method" + * validate="false" + * @struts.action-exception key="error.system.monitor" scope="request" + * type="org.lamsfoundation.lams.monitoring.service.MonitoringServiceException" + * path=".systemError" + * handler="org.lamsfoundation.lams.util.CustomStrutsExceptionHandler" + * @struts:action-forward name="scheduler" path="/TestScheduler.jsp" + * + * ----------------XDoclet Tags-------------------- + */ +public class MonitoringAction extends LamsDispatchAction +{ + //--------------------------------------------------------------------- + // Instance variables + //--------------------------------------------------------------------- + private static Logger log = Logger.getLogger(MonitoringAction.class); + + private IMonitoringService monitoringService; + //--------------------------------------------------------------------- + // Class level constants - Struts forward + //--------------------------------------------------------------------- + private static final String SCHEDULER = "scheduler"; + + //--------------------------------------------------------------------- + // Class level constants - session attributes + //--------------------------------------------------------------------- + private static final String PARAM_LESSON_ID = "lessonId"; + + //--------------------------------------------------------------------- + // Struts Dispatch Method + //--------------------------------------------------------------------- + /** + * The Struts dispatch method that starts a lesson that has been created + * beforehand. Most likely, the request to start lesson should be triggered + * by the flash component. This method will delegate to the Spring service + * bean to complete all the steps for starting a lesson. Finally, a wddx + * acknowledgement message will be serialized and sent back to the flash + * component. + * + * @param mapping An ActionMapping class that will be used by the Action class to tell + * the ActionServlet where to send the end-user. + * + * @param form The ActionForm class that will contain any data submitted + * by the end-user via a form. + * @param request A standard Servlet HttpServletRequest class. + * @param response A standard Servlet HttpServletResponse class. + * @return An ActionForward class that will be returned to the ActionServlet indicating where + * the user is to go next. + * @throws IOException + * @throws ServletException + */ + public ActionForward startLesson(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) throws IOException, + ServletException + { + this.monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet().getServletContext()); + + long lessonId = WebUtil.readLongParam(request,PARAM_LESSON_ID); + + monitoringService.startlesson(lessonId); + + return mapping.findForward(SCHEDULER); + } + +} Index: lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/service/TestMonitoringService.java =================================================================== RCS file: /usr/local/cvsroot/lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/service/Attic/TestMonitoringService.java,v diff -u -r1.13 -r1.14 --- lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/service/TestMonitoringService.java 14 Apr 2005 07:56:20 -0000 1.13 +++ lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/service/TestMonitoringService.java 15 Apr 2005 04:30:10 -0000 1.14 @@ -164,7 +164,7 @@ } - +/** public void testStartlesson() throws LamsToolServiceException { monitoringService.startlesson(TEST_LESSON_ID.longValue()); @@ -195,19 +195,7 @@ public void testForceCompleteLessonByUser() { } - - /** - * Initialize all instance variables for testing - */ - private void initializeTestingData() - { - testUser = usermanageService.getUserById(TEST_USER_ID); - testStaff = usermanageService.getUserById(TEST_STAFF_ID); - testLearner = usermanageService.getUserById(TEST_LEARNER_ID); - testOrganisation = usermanageService.getOrganisationById(TEST_ORGANIZATION_ID); - } - public void testGetAllLessons()throws IOException{ String packet = monitoringService.getAllLessons(); System.out.print(packet); @@ -244,6 +232,17 @@ String packet = monitoringService.renameLesson(new Long(1),"New name after renaming",new Integer(1)); System.out.println(packet); } + */ - + /** + * Initialize all instance variables for testing + */ + private void initializeTestingData() + { + testUser = usermanageService.getUserById(TEST_USER_ID); + testStaff = usermanageService.getUserById(TEST_STAFF_ID); + testLearner = usermanageService.getUserById(TEST_LEARNER_ID); + testOrganisation = usermanageService.getOrganisationById(TEST_ORGANIZATION_ID); + } + }