Index: lams_central/src/java/org/lamsfoundation/lams/util/CentralConstants.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/util/CentralConstants.java,v diff -u -r1.3 -r1.3.2.1 --- lams_central/src/java/org/lamsfoundation/lams/util/CentralConstants.java 27 Apr 2007 05:19:56 -0000 1.3 +++ lams_central/src/java/org/lamsfoundation/lams/util/CentralConstants.java 12 Dec 2007 04:27:20 -0000 1.3.2.1 @@ -56,26 +56,56 @@ public static final String PARAM_METHOD = "method"; public static final String METHOD_START = "start"; + + public static final String METHOD_PREVIEW = "preview"; + public static final String METHOD_IMPORT = "import"; + public static final String METHOD_SCHEDULE = "schedule"; - public static final String METHOD_DELETE = "delete"; + public static final String METHOD_DELETE = "delete"; + public static final String METHOD_STUDENT_PROGRESS = "studentProgress"; + public static final String PARAM_MODE = "mode"; + public static final String PARAM_FILEPATH = "filePath"; + public static final String ATTR_COURSE_ID = "courseId"; + + public static final String ELEM_LEARNINGDESIGN = "Lesson"; + public static final String ELEM_LESSON = "Lesson"; + public static final String ELEM_LESSON_PROGRESS ="LessonProgress"; + public static final String ATTR_LESSON_ID = "lessonId"; public static final String ATTR_DELETED = "deleted"; + public static final String ATTR_STUDENT_ID = "studentId"; + public static final String ATTR_LESSON_COMPLETE = "lessonComplete"; + + public static final String ATTR_ACTIVITY_COUNT = "activityCount"; + + public static final String ATTR_ACTIVITIES_COMPLETED = "activitiesCompleted"; + + public static final String ATTR_ACTIVITIES_ATTEMPTED = "attemptedActivities"; + + public static final String ATTR_CURRENT_ACTIVITY = "currentActivity"; + + public static final String ELEM_LEARNER_PROGRESS = "LearnerProgress"; + public static final String ELEM_FOLDER = "Folder"; public static final String ELEM_LEARNING_DESIGN = "LearningDesign"; public static final String ATTR_NAME = "name"; + public static final String ATTR_USERNAME = "username"; + public static final String ATTR_RESOURCE_ID = "resourceId"; + + public static final String EXPORT_TOOLCONTENT_SERVICE_BEAN_NAME = "exportToolContentService"; } Index: lams_central/src/java/org/lamsfoundation/lams/web/LoginRequestServlet.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/LoginRequestServlet.java,v diff -u -r1.5 -r1.5.2.1 --- lams_central/src/java/org/lamsfoundation/lams/web/LoginRequestServlet.java 21 Feb 2007 04:53:25 -0000 1.5 +++ lams_central/src/java/org/lamsfoundation/lams/web/LoginRequestServlet.java 12 Dec 2007 04:27:44 -0000 1.5.2.1 @@ -109,6 +109,15 @@ String countryIsoCode = request.getParameter(LoginRequestDispatcher.PARAM_COUNTRY); String langIsoCode = request.getParameter(LoginRequestDispatcher.PARAM_LANGUAGE); + + + + String firstName = request.getParameter(LoginRequestDispatcher.PARAM_FIRST_NAME); + String lastName = request.getParameter(LoginRequestDispatcher.PARAM_LAST_NAME); + String email = request.getParameter(LoginRequestDispatcher.PARAM_EMAIL); + + + if (extUsername == null || method == null || serverId == null || timestamp == null || hash == null || extCourseId == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, @@ -118,7 +127,18 @@ ExtServerOrgMap serverMap = getService().getExtServerOrgMap(serverId); try { - ExtUserUseridMap userMap = getService().getExtUserUseridMap(serverMap, extUsername); + ExtUserUseridMap userMap = null; + + if (firstName==null && lastName==null) + { + userMap = getService().getExtUserUseridMap(serverMap, extUsername); + } + else + { + userMap = getService().getImplicitExtUserUseridMap(serverMap, extUsername, firstName, lastName, langIsoCode, countryIsoCode, email); + } + + Authenticator.authenticate(serverMap, timestamp, extUsername, method, hash); ExtCourseClassMap orgMap = getService().getExtCourseClassMap(serverMap, userMap, extCourseId, countryIsoCode, langIsoCode); User user = userMap.getUser(); @@ -165,17 +185,22 @@ hses.setAttribute(AttributeNames.USER, user.getUserDTO()); response.sendRedirect("j_security_check?j_username=" + login + "&j_password=" + pass); } catch (AuthenticationException e) { + log.error("Authentication error: ", e); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Login Failed - authentication error"); } catch (UserInfoFetchException e) { + log.error("User fetch info error: ", e); response.sendError(HttpServletResponse.SC_BAD_GATEWAY, "Login Failed - failed to fetch user info from the third party server"); } catch (FailedLoginException e) { + log.error("Login error: ", e); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Login Failed - user was not found"); } catch (NamingException e) { + log.error("Naming error: ", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } catch (SQLException e) { + log.error("Database error: ", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } } Index: lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LearningDesignRepositoryServlet.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LearningDesignRepositoryServlet.java,v diff -u -r1.1 -r1.1.4.1 --- lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LearningDesignRepositoryServlet.java 27 Apr 2007 05:19:55 -0000 1.1 +++ lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LearningDesignRepositoryServlet.java 12 Dec 2007 04:27:44 -0000 1.1.4.1 @@ -27,6 +27,7 @@ import org.lamsfoundation.lams.integration.security.AuthenticationException; import org.lamsfoundation.lams.integration.security.Authenticator; import org.lamsfoundation.lams.integration.service.IntegrationService; +import org.lamsfoundation.lams.integration.util.LoginRequestDispatcher; import org.lamsfoundation.lams.usermanagement.WorkspaceFolder; import org.lamsfoundation.lams.usermanagement.exception.UserAccessDeniedException; import org.lamsfoundation.lams.util.CentralConstants; @@ -281,6 +282,11 @@ String lang = request.getParameter(CentralConstants.PARAM_LANG); String modeStr = request.getParameter(CentralConstants.PARAM_MODE); + + String firstName = request.getParameter(LoginRequestDispatcher.PARAM_FIRST_NAME); + String lastName = request.getParameter(LoginRequestDispatcher.PARAM_LAST_NAME); + String email = request.getParameter(LoginRequestDispatcher.PARAM_EMAIL); + if (serverId == null || datetime == null || hashValue == null || username == null || courseId == null || country == null || lang == null || modeStr == null) { @@ -300,19 +306,25 @@ Authenticator .authenticate(serverMap, datetime, username, hashValue); - // get user map and course class map + // get user map, user is created if this is their first use + + ExtUserUseridMap userMap = null; + if (firstName==null && lastName==null) + { + userMap = integrationService.getExtUserUseridMap(serverMap, username); + } + else + { + userMap = integrationService.getImplicitExtUserUseridMap(serverMap, username, firstName, lastName, lang, country, email); + } + + + // create group for external course if necessary + + integrationService.getExtCourseClassMap(serverMap, userMap, + courseId, + country, lang); - ExtUserUseridMap userMap; - - userMap = integrationService.getExtUserUseridMap(serverMap, - username); - // integrationService.getExtCourseClassMap(serverMap, userMap, - // courseId, - // country, lang); - // TODO, do we need this ?? does not assign return values to a - // variable, - // copied from original WS - String contentTree = buildContentTree( userMap.getUser().getUserId(), mode).toString(); @@ -324,17 +336,25 @@ out.print(contentTree); } catch (NumberFormatException nfe) { - log.error("mode is not an integer"); + log.error("mode is not an integer", nfe); response.sendError(response.SC_BAD_REQUEST, "mode is not an integer"); } catch (AuthenticationException e) { + log.error("can not authenticate", e); response.sendError(response.SC_BAD_REQUEST, "can not authenticate"); } catch (UserInfoFetchException e) { + log.error("can not retreive user information", e); response.sendError(response.SC_BAD_REQUEST, "can not retreive user information"); } catch (UserAccessDeniedException e) { + log.error("user access denied", e); response.sendError(response.SC_BAD_REQUEST, "user access denied"); } catch (RepositoryCheckedException e) { + log.error("repository checked", e); response.sendError(response.SC_BAD_REQUEST, "repository checked"); + } catch (Exception e){ + log.error("Problem with LearningDesignRepositoryServlet request", e); + response.sendError(response.SC_BAD_REQUEST, "Problem with LearningDesignRepositoryServlet request"); } + } /** Index: lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java,v diff -u -r1.2 -r1.2.4.1 --- lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java 10 May 2007 01:13:45 -0000 1.2 +++ lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java 12 Dec 2007 04:27:44 -0000 1.2.4.1 @@ -1,17 +1,25 @@ package org.lamsfoundation.lams.webservice.xml; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.io.File; import java.rmi.RemoteException; import java.util.Date; import java.util.LinkedList; import java.util.List; +import java.util.Set; +import java.util.Iterator; +import java.util.ArrayList; import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -26,18 +34,30 @@ import org.lamsfoundation.lams.integration.ExtCourseClassMap; import org.lamsfoundation.lams.integration.ExtServerOrgMap; import org.lamsfoundation.lams.integration.ExtUserUseridMap; +import org.lamsfoundation.lams.integration.UserInfoFetchException; import org.lamsfoundation.lams.integration.security.Authenticator; import org.lamsfoundation.lams.integration.service.IntegrationService; import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.learningdesign.service.IExportToolContentService; +import org.lamsfoundation.lams.learningdesign.service.ImportToolContentException; import org.lamsfoundation.lams.monitoring.service.IMonitoringService; +import org.lamsfoundation.lams.lesson.service.ILessonService; +import org.lamsfoundation.lams.lesson.service.LessonService; +import org.lamsfoundation.lams.lesson.dto.LearnerProgressDTO; import org.lamsfoundation.lams.usermanagement.Organisation; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.util.CentralConstants; import org.lamsfoundation.lams.util.DateUtil; +import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.lesson.LearnerProgress; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; import org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService; +import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.Node; public class LessonManagerServlet extends HttpServlet { @@ -49,6 +69,10 @@ private static IMonitoringService monitoringService = null; + private static ILessonService lessonService = null; + + private static IExportToolContentService exportService = null; + /** * Constructor of the object. */ @@ -98,6 +122,7 @@ String startDate = request.getParameter(CentralConstants.PARAM_STARTDATE); String lang = request.getParameter(CentralConstants.PARAM_LANG); String method = request.getParameter(CentralConstants.PARAM_METHOD); + String filePath = request.getParameter(CentralConstants.PARAM_FILEPATH); Long ldId = null; Long lsId = null; @@ -120,6 +145,14 @@ element = document.createElement(CentralConstants.ELEM_LESSON); element.setAttribute(CentralConstants.ATTR_LESSON_ID, lessonId.toString()); + } else if (method.equals(CentralConstants.METHOD_PREVIEW)) { + ldId = new Long(ldIdStr); + Long lessonId = startPreview(serverId, datetime, hashValue, + username, ldId, courseId, title, desc, country, lang); + + element = document.createElement(CentralConstants.ELEM_LESSON); + element.setAttribute(CentralConstants.ATTR_LESSON_ID, lessonId.toString()); + } else if (method.equals(CentralConstants.METHOD_SCHEDULE)) { ldId = new Long(ldIdStr); Long lessonId = scheduleLesson(serverId, datetime, hashValue, @@ -130,14 +163,18 @@ element.setAttribute(CentralConstants.ATTR_LESSON_ID, lessonId.toString()); } else if (method.equals(CentralConstants.METHOD_DELETE)) { - lsId = new Long(lsIdStr); Boolean deleted = deleteLesson(serverId, datetime, hashValue, username, lsId); element = document.createElement(CentralConstants.ELEM_LESSON); element.setAttribute(CentralConstants.ATTR_LESSON_ID, lsId.toString()); element.setAttribute(CentralConstants.ATTR_DELETED, deleted.toString()); + } else if (method.equals(CentralConstants.METHOD_STUDENT_PROGRESS)) { + lsId = new Long(lsIdStr); + element = getAllStudentProgress(document, serverId, datetime, hashValue, + username, lsId, courseId); + } else { String msg = "Method :" + method + " is not recognised"; log.error(msg); @@ -157,18 +194,19 @@ out.write(writer.toString()); } catch (NumberFormatException nfe) { - log.error("lsId or ldId is not an integer" + lsIdStr + ldIdStr); + log.error("lsId or ldId is not an integer" + lsIdStr + ldIdStr, nfe); response.sendError(response.SC_BAD_REQUEST, "lsId or ldId is not an integer"); } catch (TransformerConfigurationException e) { - log.error("Can not convert XML document to string"); + log.error("Can not convert XML document to string", e); response.sendError(response.SC_INTERNAL_SERVER_ERROR); } catch (TransformerException e) { - log.error("Can not convert XML document to string"); - response.sendError(response.SC_INTERNAL_SERVER_ERROR); + log.error("Can not convert XML document to string", e); + response.sendError(response.SC_INTERNAL_SERVER_ERROR ); } catch (ParserConfigurationException e) { - log.error("Can not build XML document"); + log.error("Can not build XML document", e); response.sendError(response.SC_INTERNAL_SERVER_ERROR); } catch (Exception e) { + log.error("Problem loading learning manager servlet request", e); response.sendError(response.SC_INTERNAL_SERVER_ERROR); } @@ -200,6 +238,8 @@ out.flush(); out.close(); } + + public Long startLesson(String serverId, String datetime, String hashValue, String username, long ldId, String courseId, String title, @@ -263,6 +303,87 @@ } } + public Element getAllStudentProgress(Document document, String serverId, String datetime, + String hashValue, String username, long lsId, String courseID) + throws RemoteException + { + try { + ExtServerOrgMap serverMap = integrationService + .getExtServerOrgMap(serverId); + Authenticator + .authenticate(serverMap, datetime, username, hashValue); + ExtUserUseridMap userMap = integrationService.getExtUserUseridMap( + serverMap, username); + Lesson lesson = lessonService.getLesson(lsId); + + Element element = document.createElement(CentralConstants.ELEM_LESSON_PROGRESS); + element.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); + + String prefix = serverMap.getPrefix(); + if(lesson!=null){ + + int activitiesTotal = lesson.getLearningDesign().getActivities().size(); + Iterator iterator = lesson.getLearnerProgresses().iterator(); + while(iterator.hasNext()){ + LearnerProgress learnProg = (LearnerProgress)iterator.next(); + LearnerProgressDTO learnerProgress = learnProg.getLearnerProgressData(); + + //Iterator activities = learnProg.getLesson().getLearningDesign().getActivities().iterator(); + + //String currActivity = ""; + //while (activities.hasNext()) + //{ + // Activity act = (Activity)iterator.next(); + // + // if (learnerProgress.getCurrentActivityId() == ((Activity)iterator.next()).getActivityId()) + // { + // currActivity = act.getTitle(); + // break; + // } + //} + + + + // get the username with the integration prefix removed + String userNoPrefixName = learnerProgress.getUserName(). + substring(prefix.length()+1); + ExtUserUseridMap learnerMap = integrationService.getExtUserUseridMap( + serverMap, userNoPrefixName); + + Element learnerProgElem = document.createElement(CentralConstants.ELEM_LEARNER_PROGRESS); + + int completedActivities = learnerProgress.getCompletedActivities().length; + int attemptedActivities = learnerProgress.getAttemptedActivities().length; + + if(learnerProgElem.getNodeType()== Node.ELEMENT_NODE) + { + learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_COMPLETE , "" + learnerProgress.getLessonComplete()); + learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITY_COUNT , "" + activitiesTotal); + learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_COMPLETED , "" + completedActivities); + learnerProgElem.setAttribute(CentralConstants.ATTR_ACTIVITIES_ATTEMPTED , "" + attemptedActivities); + //learnerProgElem.setAttribute(CentralConstants.ATTR_CURRENT_ACTIVITY , currActivity); + learnerProgElem.setAttribute(CentralConstants.ATTR_STUDENT_ID, "" + learnerMap.getSid()); + learnerProgElem.setAttribute(CentralConstants.ATTR_COURSE_ID, courseID); + learnerProgElem.setAttribute(CentralConstants.ATTR_USERNAME, userNoPrefixName); + learnerProgElem.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lsId); + } + + element.appendChild(learnerProgElem); + } + } + else{ + throw new Exception("Lesson with lessonID: " + lsId + " could not be found for learner progresses"); + } + + return element; + + } catch (Exception e) { + throw new RemoteException(e.getMessage(), e); + } + + } + + public boolean deleteLesson(String serverId, String datetime, String hashValue, String username, long lsId) throws RemoteException { @@ -279,7 +400,39 @@ throw new RemoteException(e.getMessage(), e); } } + + public Long startPreview(String serverId, String datetime, String hashValue, + String username, Long ldId, String courseId, String title, + String desc, String countryIsoCode, String langIsoCode) + throws RemoteException { + try { + ExtServerOrgMap serverMap = integrationService + .getExtServerOrgMap(serverId); + Authenticator + .authenticate(serverMap, datetime, username, hashValue); + ExtUserUseridMap userMap = integrationService.getExtUserUseridMap( + serverMap, username); + ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap( + serverMap, userMap, courseId, countryIsoCode, langIsoCode); + // 1. init lesson + Lesson lesson = monitoringService + .initializeLessonForPreview(title, desc, ldId, userMap.getUser().getUserId()); + // 2. create lessonClass for lesson + monitoringService.createPreviewClassForLesson(userMap.getUser().getUserId(), lesson.getLessonId()); + + // 3. start lesson + monitoringService.startLesson(lesson.getLessonId(), userMap.getUser().getUserId()); + + return lesson.getLessonId(); + } catch (Exception e) { + throw new RemoteException(e.getMessage(), e); + } + + + + } + private void createLessonClass(Lesson lesson, Organisation organisation, User creator) { List staffList = new LinkedList(); @@ -291,7 +444,7 @@ .getUserId()); } - + // private IMonitoringService getMonitoringService() { // if (monitoringService == null) { // monitoringService = (IMonitoringService) WebApplicationContextUtils @@ -344,5 +497,16 @@ monitoringService = (IMonitoringService) WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()).getBean( "monitoringService"); + + lessonService = (ILessonService) WebApplicationContextUtils + .getRequiredWebApplicationContext(getServletContext()).getBean( + "lessonService"); + + exportService = (IExportToolContentService) WebApplicationContextUtils + .getRequiredWebApplicationContext(getServletContext()).getBean( + "exportToolContentService"); + } + + } Index: lams_central/web/author.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/author.jsp,v diff -u -r1.38 -r1.38.2.1 --- lams_central/web/author.jsp 17 May 2007 06:44:07 -0000 1.38 +++ lams_central/web/author.jsp 12 Dec 2007 04:27:44 -0000 1.38.2.1 @@ -24,6 +24,7 @@ String actColour = Configuration.get(ConfigurationKeys.AUTHORING_ACTS_COLOUR); String version = Configuration.get(ConfigurationKeys.VERSION); %> +