Index: lams_webct_integration/.classpath
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/.classpath,v
diff -u -r1.1 -r1.2
--- lams_webct_integration/.classpath 13 Nov 2007 00:33:47 -0000 1.1
+++ lams_webct_integration/.classpath 19 Nov 2007 22:57:42 -0000 1.2
@@ -10,5 +10,7 @@
+
+
Index: lams_webct_integration/DeployableComponentConfig.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/DeployableComponentConfig.xml,v
diff -u -r1.1 -r1.2
--- lams_webct_integration/DeployableComponentConfig.xml 13 Nov 2007 00:33:47 -0000 1.1
+++ lams_webct_integration/DeployableComponentConfig.xml 19 Nov 2007 22:57:42 -0000 1.2
@@ -4,12 +4,12 @@
- 0.0.7
+ 0.0.12
1.0
lams.integration
sso
- org.lamsfoundation.integration.webct.AuthorModule
+ org.lamsfoundation.integration.webct.LamsModule
Luke Foxton
LAMS-WebCt integration module
@@ -108,32 +108,79 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ default-value="@lamsServerUrl@" />
-
+ default-value="@serverId@" />
-
+ default-value="@secretKey@" />
+ default-value="@reqSrc@" />
Index: lams_webct_integration/build.properties
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/build.properties,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_webct_integration/build.properties 19 Nov 2007 22:57:42 -0000 1.1
@@ -0,0 +1,35 @@
+# Build.properties for configuring the LAMS/WebCt integration module
+
+# DATABASE CONFIGURATION (cant be changed after installation)
+#############################
+
+# The host of the SQL Server
+dbHost=localhost
+
+# The port SQL Server is running through
+dbPort=1433
+
+# Database name user and password with permision to webct database
+dbName=webctdatabase
+dbUser=sa
+dbPass=hernamewaslola
+
+#############################
+
+
+# DEFAULT SERVER CONFIGURATION (configurable in webct admin)
+#############################
+
+# The URL that points to LAMS, make sure it finishes with a '/'
+lamsServerUrl=http://192.168.111.30:8080/lams/
+
+# Server id
+serverId=webctlams
+
+# Secret Key
+secretKey=webctlams
+
+# Resuest source name for your WebCt server
+reqSrc=WebCt
+
+#############################
\ No newline at end of file
Index: lams_webct_integration/build.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/build.xml,v
diff -u -r1.1 -r1.2
--- lams_webct_integration/build.xml 13 Nov 2007 00:33:47 -0000 1.1
+++ lams_webct_integration/build.xml 19 Nov 2007 22:57:42 -0000 1.2
@@ -1,5 +1,7 @@
+
+
@@ -11,6 +13,12 @@
+
+
+
+
+
+
@@ -58,18 +66,26 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
@@ -88,7 +104,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: lams_webct_integration/db/sql/createTable.sql
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/db/sql/Attic/createTable.sql,v
diff -u
Binary files differ
Index: lams_webct_integration/db/sql/deleteTable.sql
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/db/sql/Attic/deleteTable.sql,v
diff -u
Binary files differ
Index: lams_webct_integration/lib/sqljdbc.jar
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/lib/sqljdbc.jar,v
diff -u
Binary files differ
Index: lams_webct_integration/src/org/lamsfoundation/integration/dao/LamsLessonDaoJDBC.java
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/src/org/lamsfoundation/integration/dao/LamsLessonDaoJDBC.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_webct_integration/src/org/lamsfoundation/integration/dao/LamsLessonDaoJDBC.java 19 Nov 2007 22:57:42 -0000 1.1
@@ -0,0 +1,315 @@
+package org.lamsfoundation.integration.dao;
+
+import java.util.Date;
+import java.util.Map;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.PreparedStatement;
+import java.sql.Statement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+
+import org.apache.log4j.Logger;
+import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
+
+import org.lamsfoundation.integration.util.Constants;
+import org.lamsfoundation.integration.webct.LamsModule;
+import org.lamsfoundation.integration.webct.LamsLesson;
+
+
+
+/**
+ * Database connector for webct/lams integration
+ * @author luke foxton
+ *
+ */
+public class LamsLessonDaoJDBC {
+
+ private Map settings;
+
+ private String dbUrl;
+ private String dbHost;
+ private String dbPort;
+ private String dbName;
+ private String dbUser;
+ private String dbPass;
+
+ private static final Logger log = Logger.getLogger(LamsLessonDaoJDBC.class);
+
+
+ /**
+ * Empty constructor
+ */
+ public LamsLessonDaoJDBC() {
+ }
+
+ /**
+ * Constructor using the lamswebct Powerlink settings hashmap
+ * @param settings lamswebct Powerlink settings hashmap
+ */
+ public LamsLessonDaoJDBC(Map settings) {
+ this.settings = settings;
+
+ dbHost = (String)settings.get(Constants.SETTING_DB_HOST);
+ dbPort = (String)settings.get(Constants.SETTING_DB_PORT);
+ dbName = (String)settings.get(Constants.SETTING_DB_NAME);
+ dbUser = (String)settings.get(Constants.SETTING_DB_USER);
+ dbPass = (String)settings.get(Constants.SETTING_DB_PASS);
+
+ this.dbUrl = "jdbc:microsoft:sqlserver://" +dbHost+
+ ":" +dbPort+ "/" +dbName+ "/";
+ }
+
+ /**
+ * Full constructor
+ */
+ public LamsLessonDaoJDBC(String dbHost, String dbPort,
+ String dbName, String dbUser, String dbPass) {
+ this.dbHost = dbHost;
+ this.dbPort = dbPort;
+ this.dbName = dbName;
+ this.dbUser = dbUser;
+ this.dbPass = dbPass;
+
+ this.dbUrl = "jdbc:microsoft:sqlserver://" +dbHost+
+ ":" +dbPort+ "/" +dbName+ "/";
+ }
+
+ public Connection getConnection() throws SQLException
+ {
+
+ //DriverManager.registerDriver(new SQLServerDriver());
+ //DriverManager.registerDriver(new Driver());
+ //Connection connection = DriverManager.getConnection(dbUrl, dbUser, dbPass);
+ //return connection;
+
+ SQLServerDataSource ds = new SQLServerDataSource();
+ ds.setServerName(dbHost);
+ ds.setUser(dbUser);
+ ds.setPassword(dbPass);
+ ds.setPortNumber(Integer.parseInt(dbPort));
+ ds.setDatabaseName(dbName);
+ return ds.getConnection();
+
+
+ }
+
+ public ArrayList getDBLessons(long learningContextId, long ptId) throws Exception
+ {
+ ArrayList lessons = new ArrayList();
+
+ Connection connection;
+ try
+ {
+ connection = getConnection();
+ Statement stmt = connection.createStatement();
+
+ String query = "SELECT [lesson_id]," +
+ "[learning_context_id]," +
+ "[sequence_id]," +
+ "[owner_id]," +
+ "[owner_first_name]," +
+ "[owner_last_name]," +
+ "[title]," +
+ "[description]," +
+ "[hidden]," +
+ "[schedule]," +
+ "[start_date_time]," +
+ "[end_date_time] " +
+ "FROM [webctdatabase].[dbo].[LAMS_LESSON] " +
+ "WHERE (learning_context_id=" +learningContextId+ ")" +
+ "AND (pt_id=" +ptId+ ")";
+
+ System.out.println("SQL INSERT: " +query);
+
+ ResultSet rs = stmt.executeQuery(query);
+
+ while (rs.next())
+ {
+ LamsLesson lesson = new LamsLesson();
+ lesson.setLessonId(rs.getLong("lesson_id"));
+ lesson.setLearningContextId(rs.getLong("learning_context_id"));
+ lesson.setSequenceId(rs.getLong("sequence_id"));
+ lesson.setTitle(rs.getString("title"));
+ lesson.setDescription(rs.getString("description"));
+ lesson.setOwnerId(rs.getString("owner_id"));
+ lesson.setOwnerFirstName(rs.getString("owner_first_name"));
+ lesson.setOwnerLastName(rs.getString("owner_last_name"));
+ lesson.setHidden(rs.getBoolean("hidden"));
+ lesson.setSchedule(rs.getBoolean("schedule"));
+ lesson.setStartDate(rs.getDate("start_date_time"));
+ lesson.setEndDate(rs.getDate("end_date_time"));
+
+ lessons.add(lesson);
+ }
+
+ stmt.close();
+ connection.close();
+ }
+ catch (SQLException e)
+ {
+ log.error("Failed to get a list of LAMS lessons.", e);
+ throw new Exception ("Failed to get a list of LAMS lessons.");
+ }
+ return lessons;
+ }
+
+ public boolean createDbLesson(LamsLesson lesson) throws Exception
+ {
+ Connection connection;
+
+ System.out.println(lesson.toString());
+
+ int hidden=0;
+ int schedule=0;
+
+ if (lesson.getHidden()) {hidden=1;}
+ if (lesson.getSchedule()) {schedule=1;}
+
+ try
+ {
+ connection = getConnection();
+ Statement stmt = connection.createStatement();
+
+
+ String insert = "INSERT INTO [webctdatabase].[dbo].[LAMS_LESSON]" +
+ "([lesson_id]," +
+ "[pt_id]," +
+ "[learning_context_id]," +
+ "[sequence_id]," +
+ "[owner_id]," +
+ "[owner_first_name]," +
+ "[owner_last_name]," +
+ "[title]," +
+ "[description]," +
+ "[hidden]," +
+ "[schedule]," +
+ "[start_date_time]," +
+ "[end_date_time])" +
+ "VALUES" +
+ "(" +lesson.getLessonId()+ "," +
+ "" +lesson.getPtId()+ "," +
+ "" +lesson.getLearningContextId()+ "," +
+ "" +lesson.getSequenceId()+ "," +
+ "\'" +lesson.getOwnerId()+ "\'," +
+ "\'" +lesson.getOwnerFirstName()+ "\'," +
+ "\'" +lesson.getOwnerLastName()+ "\'," +
+ "\'" +lesson.getTitle()+ "\'," +
+ "\'" +lesson.getDescription()+ "\'," +
+ "" +hidden+ ","+
+ "" +schedule+ "," +
+ "\'" +lesson.getStartDate()+ "\'," +
+ "\'" +lesson.getEndDate()+ "\')";
+
+ System.out.println("SQL INSERT: " +insert);
+
+ int rows = stmt.executeUpdate(insert);
+ connection.commit();
+ stmt.close();
+ connection.close();
+
+ return rows>0;
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ log.error("Error inserting LAMS lesson into database.", e);
+ throw new Exception ("Error inserting LAMS lesson into database. " + e);
+ }
+
+ }
+
+
+ public boolean deleteDbLesson(long lsId)
+ {
+ Connection connection;
+ int rows = 0;
+ try
+ {
+ connection = getConnection();
+ Statement stmt = connection.createStatement();
+
+ String delete="DELETE FROM [webctdatabase].[dbo].[LAMS_LESSON] WHERE lesson_id=" +lsId;
+ System.out.println("DELETE: " + delete);
+
+ rows = stmt.executeUpdate(delete);
+ stmt.close();
+
+ connection.commit();
+ connection.close();
+
+
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ log.error("Error deleting LAMS lesson from database.", e);
+ }
+
+ return rows>0;
+
+ }
+
+
+ public String getDbUrl() {
+ return dbUrl;
+ }
+
+ public void setDbUrl(String dbUrl) {
+ this.dbUrl = dbUrl;
+ }
+
+ public String getDbHost() {
+ return dbHost;
+ }
+
+ public void setDbHost(String dbHost) {
+ this.dbHost = dbHost;
+ }
+
+ public String getDbPort() {
+ return dbPort;
+ }
+
+ public void setDbPort(String dbPort) {
+ this.dbPort = dbPort;
+ }
+
+ public String getDbName() {
+ return dbName;
+ }
+
+ public void setDbName(String dbName) {
+ this.dbName = dbName;
+ }
+
+ public String getDbUser() {
+ return dbUser;
+ }
+
+ public void setDbUser(String dbUser) {
+ this.dbUser = dbUser;
+ }
+
+ public String getDbPass() {
+ return dbPass;
+ }
+
+ public void setDbPass(String dbPass) {
+ this.dbPass = dbPass;
+ }
+
+
+ public Map getSettings() {
+ return settings;
+ }
+
+
+ public void setSettings(Map settings) {
+ this.settings = settings;
+ }
+
+
+
+}
Index: lams_webct_integration/src/org/lamsfoundation/integration/util/Constants.java
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/src/org/lamsfoundation/integration/util/Constants.java,v
diff -u -r1.1 -r1.2
--- lams_webct_integration/src/org/lamsfoundation/integration/util/Constants.java 13 Nov 2007 00:33:47 -0000 1.1
+++ lams_webct_integration/src/org/lamsfoundation/integration/util/Constants.java 19 Nov 2007 22:57:42 -0000 1.2
@@ -54,5 +54,15 @@
public static final String ELEM_LEARNING_DESIGN = "LearningDesign";
public static final String ATTR_NAME = "name";
public static final String ATTR_RESOURCE_ID = "resourceId";
+
+ public static final String SETTING_LAMS_SERVER_URL = "lamsServerUrl";
+ public static final String SETTING_SERVER_ID = "serverId";
+ public static final String SETTING_SECRET_KEY = "secretKey";
+ public static final String SETTING_REQUEST_SRC = "webctRequestSource";
+ public static final String SETTING_DB_NAME = "dbName";
+ public static final String SETTING_DB_HOST = "dbHost";
+ public static final String SETTING_DB_PORT = "dbPort";
+ public static final String SETTING_DB_USER = "dbUser";
+ public static final String SETTING_DB_PASS = "dbPass";
}
Fisheye: Tag 1.2 refers to a dead (removed) revision in file `lams_webct_integration/src/org/lamsfoundation/integration/webct/AuthorModule.java'.
Fisheye: No comparison available. Pass `N' to diff?
Index: lams_webct_integration/src/org/lamsfoundation/integration/webct/LamsLesson.java
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/src/org/lamsfoundation/integration/webct/LamsLesson.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_webct_integration/src/org/lamsfoundation/integration/webct/LamsLesson.java 19 Nov 2007 22:57:42 -0000 1.1
@@ -0,0 +1,205 @@
+package org.lamsfoundation.integration.webct;
+
+
+import java.sql.Date;
+
+
+/**
+ * Class for mapping LAMS lessons to the database
+ * @author luke foxton
+ *
+ */
+public class LamsLesson {
+
+ private long id;
+ private long ptId; // powerlink instance id
+ private long lessonId;
+ private long learningContextId; // webct learning context id
+ private long sequenceId;
+ private String title;
+ private String description;
+ private String ownerId; // webct userId
+ private String ownerFirstName; // webct user first name
+ private String ownerLastName; // webct user second name
+ private boolean hidden; // only visible to owner if true
+ private boolean schedule;
+ private Date startDate;
+ private Date endDate;
+
+
+
+ /**
+ * Default constructor
+ */
+ public LamsLesson() {}
+
+ /**
+ * Minimal constructor
+ */
+ public LamsLesson(long lessonId, long learningContextId, String title) {
+ this.lessonId = lessonId;
+ this.learningContextId = learningContextId;
+ this.title = title;
+ }
+
+ /**
+ * Full constructor
+ */
+ public LamsLesson(
+ long lessonId,
+ long ptId,
+ long learningContextId,
+ long sequenceId,
+ String title,
+ String description,
+ String ownerId,
+ String ownerFirstName,
+ String ownerLastName,
+ boolean hidden,
+ boolean schedule,
+ Date startDate,
+ Date endDate)
+ {
+ this.lessonId = lessonId;
+ this.ptId = ptId;
+ this.learningContextId = learningContextId;
+ this.sequenceId = sequenceId;
+ this.title = title;
+ this.description = description;
+ this.ownerId = ownerId;
+ this.ownerFirstName = ownerFirstName;
+ this.ownerLastName = ownerLastName;
+ this.hidden = hidden;
+ this.schedule = schedule;
+ this.startDate = startDate;
+ this.endDate = endDate;
+ }
+
+
+
+ public long getLessonId() {
+ return lessonId;
+ }
+ public void setLessonId(long lessonId) {
+ this.lessonId = lessonId;
+ }
+ public long getSequenceId() {
+ return sequenceId;
+ }
+ public void setSequenceId(long sequenceId) {
+ this.sequenceId = sequenceId;
+ }
+ public String getTitle() {
+ return title;
+ }
+ public void setTitle(String title) {
+ this.title = title;
+ }
+ public String getOwnerId() {
+ return ownerId;
+ }
+ public void setOwnerId(String ownerId) {
+ this.ownerId = ownerId;
+ }
+ public String getOwnerFirstName() {
+ return ownerFirstName;
+ }
+ public void setOwnerFirstName(String ownerFirstName) {
+ this.ownerFirstName = ownerFirstName;
+ }
+ public String getOwnerLastName() {
+ return ownerLastName;
+ }
+ public void setOwnerLastName(String ownerLastName) {
+ this.ownerLastName = ownerLastName;
+ }
+ public boolean getHidden() {
+ return hidden;
+ }
+ public void setHidden(boolean hidden) {
+ this.hidden = hidden;
+ }
+ public boolean getSchedule() {
+ return schedule;
+ }
+ public void setSchedule(boolean schedule) {
+ this.schedule = schedule;
+ }
+ public Date getStartDate() {
+ return startDate;
+ }
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate;
+ }
+ public Date getEndDate() {
+ return endDate;
+ }
+ public void setEndDate(Date endDate) {
+ this.endDate = endDate;
+ }
+
+ public long getLearningContextId() {
+ return learningContextId;
+ }
+
+ public void setLearningContextId(long learningContextId) {
+ this.learningContextId = learningContextId;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Constructs a String
with all attributes
+ * in name = value format.
+ *
+ * @return a String
representation
+ * of this object.
+ */
+ public String toString()
+ {
+ final String TAB = " ";
+
+ String retValue = "";
+
+ retValue = "LamsLesson ( "
+ + "lessonId = " + this.lessonId + TAB
+ + "ptId = " + this.ptId + TAB
+ + "learningContextId = " + this.learningContextId + TAB
+ + "sequenceId = " + this.sequenceId + TAB
+ + "title = " + this.title + TAB
+ + "description = " + this.description + TAB
+ + "ownerId = " + this.ownerId + TAB
+ + "ownerFirstName = " + this.ownerFirstName + TAB
+ + "ownerLastName = " + this.ownerLastName + TAB
+ + "hidden = " + this.hidden + TAB
+ + "schedule = " + this.schedule + TAB
+ + "startDate = " + this.startDate + TAB
+ + "endDate = " + this.endDate + TAB
+ + " )";
+
+ return retValue;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public long getPtId() {
+ return ptId;
+ }
+
+ public void setPtId(long ptId) {
+ this.ptId = ptId;
+ }
+
+}
Index: lams_webct_integration/src/org/lamsfoundation/integration/webct/LamsModule.java
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/src/org/lamsfoundation/integration/webct/LamsModule.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_webct_integration/src/org/lamsfoundation/integration/webct/LamsModule.java 19 Nov 2007 22:57:42 -0000 1.1
@@ -0,0 +1,499 @@
+package org.lamsfoundation.integration.webct;
+
+import java.io.StringWriter;
+import java.net.URLEncoder;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Properties;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+
+import javax.security.auth.login.LoginException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.webct.platform.sdk.context.gen.*;
+import com.webct.platform.sdk.context.client.*;
+import com.webct.platform.sdk.security.authentication.module.AuthenticationModule;
+import com.webct.platform.sdk.proxytool.common.ProcessCallback;
+import com.webct.platform.sdk.security.authentication.module.WebCTSSOContext;
+import com.webct.platform.sdk.context.client.ContextSDK;
+import com.webct.platform.sdk.context.gen.SessionVO;
+import com.webct.platform.sdk.context.gen.LearningCtxtVO;
+import com.webct.platform.sdkext.authmoduledata.*;
+import com.webct.platform.sdk.context.gen.SessionVO;
+
+//-------- Velocity imports --------------
+import java.io.StringWriter;
+import java.rmi.RemoteException;
+import java.sql.Date;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.Template;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.exception.*;
+//import org.apache.axis.AxisFault;
+
+import java.net.URL;
+import org.apache.log4j.Logger;
+
+import org.lamsfoundation.integration.webct.LamsSecurityUtil;
+import org.lamsfoundation.integration.dao.LamsLessonDaoJDBC;
+import org.lamsfoundation.integration.util.Constants;
+
+
+/**
+ * @author Luke Foxton
+ *
+ */
+public class LamsModule extends AuthenticationModule
+{
+
+ public static final String VERSION = "1.0.0";
+ public static final String JARSTR = "lams2-webct-integration-" + VERSION + ".jar";
+ private HttpServletRequest request = null;
+ private Map settings = null;
+ private String lamsServerUrl;
+ private String lamsServerId;
+ private String lamsServerSecretKey;
+ private String webctRequestSource;
+
+
+
+
+ private static final Logger log = Logger.getLogger(LamsModule.class);
+
+
+
+ private static final String GUTENBERG_QUERY_URL = "http://www.gutenberg.org/catalog/world/results";
+
+
+ public LamsModule()
+ {
+ super();
+ }
+
+ public LamsModule(Hashtable hashtable)
+ {
+ super(hashtable);
+ }
+
+ public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options)
+ {
+ super.initialize(subject, callbackHandler, sharedState, options);
+ }
+
+ public boolean validate()
+ {
+ return true;
+ }
+
+ public boolean login() throws LoginException
+ {
+ return true;
+ }
+
+ public boolean abort() throws LoginException
+ {
+ return super.abort();
+ }
+
+ public boolean commit() throws LoginException
+ {
+ if(!super.getCurrentMode().equals(super.OUTGOING_MODE))
+ {
+ // shouldn't be here
+ return false;
+ }
+
+
+
+ Map settings = super.getSettings();
+ //user = super.getUserId();
+ lamsServerUrl = (String)settings.get(Constants.SETTING_LAMS_SERVER_URL);
+ lamsServerId = (String)settings.get(Constants.SETTING_SERVER_ID);
+ lamsServerSecretKey = (String)settings.get(Constants.SETTING_SECRET_KEY);
+ webctRequestSource = (String)settings.get(Constants.SETTING_REQUEST_SRC);
+
+
+ UserVO user = null;
+ List roles;
+ Long lcID = super.getCurrentLearningContextId();
+
+ request = super.getRequest();
+ Map params = new HashMap();
+ String html=null;
+ String authorUrl = null;
+ String learningDesigns = null;
+ String learnerUrl = "";
+ String monitorUrl = "";
+
+ String ptid = request.getParameter("id");
+ if(ptid==null)
+ {
+ // the id param was null, so PT was probably called from My WebCT
+ ptid = request.getParameter("tid");
+
+ params.put("id_param_name", "tid");
+ }
+ else
+ {
+ params.put("id_param_name", "id");
+ }
+ params.put("pt_id", ptid);
+ params.put("page_id", request.getParameter("page_id"));
+
+
+ boolean isTeacher = false;
+ boolean isStudent = false;
+ try {
+ user = UserService.getInstance().getUser(super.getUserId(), lcID);
+ roles = user.getUserRoles();
+ Iterator it = roles.iterator();
+ while (it.hasNext())
+ {
+ String role = it.next().toString().trim();
+
+ System.out.println("ROLE: " + role);
+ if (role.equals(UserRole.COURSE_INSTRUCTOR_ROLE.toString()) || role.equals(UserRole.SECTION_INSTRUCTOR_ROLE.toString()) )
+ {
+ isTeacher=true;
+ }
+ else if (role.equals(UserRole.STUDENT_ROLE.toString()))
+ {
+ isStudent=true;
+ }
+ }
+ if (!isStudent && !isTeacher)
+ {
+ throw new LoginException("User's role does not have access to these pages.");
+ }
+ }
+ catch (VistaDataException e)
+ {
+ log.error("Problem getting user info:", e);
+ e.printStackTrace();
+ return false;
+ }
+
+
+
+ String action = request.getParameter("form_action");
+
+ if(action==null || action.trim().length()==0 ||action.equals("preview"))
+ {
+
+ try{
+ learnerUrl = generateRequestURL(user, lcID, "learner");
+ }
+ catch (Exception e)
+ {
+ throw new LoginException("Bad learner request: " + e.getMessage());
+ }
+
+ if (isTeacher)
+ {
+ // generate teacher page
+ // ie list of running lessons, and a create new lesson button
+ try{
+ LamsLessonDaoJDBC lessonDao = new LamsLessonDaoJDBC(settings);
+ List lessons = lessonDao.getDBLessons(lcID.longValue(), Long.parseLong(ptid));
+
+ monitorUrl = generateRequestURL(user, lcID, "monitor");
+
+ params.put("lessons", lessons);
+ params.put("learnerUrl", learnerUrl);
+ params.put("monitorUrl", monitorUrl);
+ params.put("liveEditUrl", authorUrl);
+
+ html = this.generatePage("web/teach.vm", params);
+ }
+ catch (Exception e)
+ {
+ log.error("Error creating LAMS teach page", e);
+ throw new LoginException("Error creating LAMS teach page");
+ }
+ }
+ else
+ {
+ // generate student page
+ // ie list of running lessons
+ try{
+ LamsLessonDaoJDBC lessonDao = new LamsLessonDaoJDBC(settings);
+
+ // test
+ //List lessons = lessonDao.getDBLessons(1);
+
+ List lessons = lessonDao.getDBLessons(lcID.longValue(), Long.parseLong(ptid));
+
+ params.put("lessons", lessons);
+
+ params.put("learnerUrl", learnerUrl);
+
+ html = this.generatePage("web/learner.vm", params);
+ }
+ catch (Exception e)
+ {
+ throw new LoginException("Error creating LAMS learner page");
+ }
+ }
+ }
+ else if (action.equalsIgnoreCase("create_lesson"))
+ {
+ // goto create lesson form
+ try {
+ // get the authorUrl for the author link
+ authorUrl = generateRequestURL(user, lcID, "author");
+ params.put("authorUrl", authorUrl);
+
+
+
+ String previewUrl = LamsSecurityUtil.generatePreviewUrl(
+ lamsServerUrl,
+ lamsServerId,
+ lamsServerSecretKey,
+ webctRequestSource,
+ user.getUserId(),
+ "" +lcID,
+ "en",
+ "US",
+ user.getFirstname(),
+ user.getLastname(),
+ user.getEmail());
+ params.put("previewUrl", previewUrl);
+
+
+ // get the learning designs to display the workspace tree
+ learningDesigns = getLearningDesigns(user, lcID);
+ params.put("learningDesigns", learningDesigns);
+
+ html = this.generatePage("web/create.vm", params);
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ log.error("Error creating LAMS create lesson page: ", e);
+ throw new LoginException("Error creating LAMS create lesson page: " + e.getMessage());
+ }
+ }
+ else if (action.equals("delete_lesson"))
+ {
+ String successMessage="LAMS lesson deleted.";
+
+ String lsID = request.getParameter("lsID");
+ LamsLessonDaoJDBC lessonDao = new LamsLessonDaoJDBC(settings);
+
+ boolean success = lessonDao.deleteDbLesson(Long.parseLong(lsID));
+
+ if (!success)
+ {
+ successMessage="Failed to delete LAMS lesson.";
+ }
+
+
+ params.put("successMessage", successMessage);
+
+ try{
+ html = this.generatePage("web/lessonCreated.vm", params);
+
+ }
+ catch (Exception e)
+ {
+ throw new LoginException("Error creating LAMSpage: " + e.getMessage());
+ }
+
+ }
+ else if (action.equalsIgnoreCase("start_lesson"))
+ {
+ String seqID = request.getParameter("sequence_id");
+ String title = request.getParameter("title");
+ String description = request.getParameter("description");
+ String successMessage="";
+
+ long lsID = LamsSecurityUtil.startLesson(
+ lamsServerUrl,
+ lamsServerId,
+ lamsServerSecretKey,
+ webctRequestSource,
+ user.getUserId(),
+ "" + seqID,
+ "en",
+ "US",
+ user.getFirstname(),
+ user.getLastname(),
+ user.getEmail(),
+ seqID,
+ title,
+ description);
+
+
+ if (lsID==-1)
+ {
+ successMessage="Failed to create LAMS lesson.";
+ }
+ else
+ {
+ LamsLessonDaoJDBC lessonDao = new LamsLessonDaoJDBC(settings);
+ LamsLesson lesson = new LamsLesson(
+ lsID,
+ Long.parseLong(ptid),
+ lcID.longValue(),
+ Long.parseLong(seqID),
+ title,
+ description,
+ user.getUserId(),
+ user.getFirstname(),
+ user.getLastname(),
+ false,
+ false,
+ new Date(0),
+ new Date(0)
+ );
+
+ try{
+ // create the lesson
+ lessonDao.createDbLesson(lesson);
+ }
+ catch (Exception e)
+ {
+ log.error("Could not create LAMS lesson", e);
+ throw new LoginException("Could not create LAMS lesson");
+ }
+
+ successMessage="LAMS lesson started.";
+ }
+
+ params.put("successMessage", successMessage);
+
+ try{
+ html = this.generatePage("web/lessonCreated.vm", params);
+
+
+ }
+ catch (Exception e)
+ {
+ log.error("Error creating LAMS lesson created page: ", e);
+ throw new LoginException("Error creating LAMS lesson created page: " + e.getMessage());
+ }
+ }
+
+
+ super.setResponseContent(html);
+
+ return true;
+
+ }
+
+
+ private String generatePage(String htmlTemplate, Map contextObjects) throws Exception
+ {
+ String jar_base = "./deployablecomponents/lams2/";
+
+ VelocityEngine ve = new VelocityEngine();
+
+ Properties props = new Properties();
+ props.setProperty("resource.loader", "file, jar");
+ props.setProperty("file.resource.loader.path", jar_base);
+ props.setProperty("jar.resource.loader.class", "org.apache.velocity.runtime.resource.loader.JarResourceLoader");
+ props.setProperty("jar.resource.loader.path", "jar:file:" + jar_base + JARSTR);
+ ve.init(props);
+
+ VelocityContext context = new VelocityContext();
+
+ for(Iterator it = contextObjects.keySet().iterator(); it.hasNext();)
+ {
+ String key = (String)it.next();
+ context.put(key, contextObjects.get(key));
+ }
+
+ context.put("request", request);
+ context.put("settings", settings);
+ context.put("authmod", this);
+
+ Template template = null;
+ template = ve.getTemplate(htmlTemplate);
+ StringWriter html = new StringWriter();
+ template.merge(context, html);
+ return html.toString();
+ }
+
+ public String generateRequestURL(UserVO user, Long lcID, String method) throws LoginException
+ {
+ String authorUrl="";
+
+ try
+ {
+ authorUrl = LamsSecurityUtil.generateRequestURL(
+ lamsServerUrl,
+ lamsServerId,
+ lamsServerSecretKey,
+ webctRequestSource,
+ user.getUserId(),
+ "" + lcID,
+ "en",
+ "AU",
+ user.getFirstname(),
+ user.getLastname(),
+ user.getEmail(),
+ method);
+
+
+ log.info("LAMS AUTHOR REQUEST: " + authorUrl);
+ System.out.println("LAMS AUTHOR REQUEST: " + authorUrl);
+ return authorUrl;
+ }
+ catch (Exception e)
+ {
+ log.error("Problem generating request url:", e);
+ System.out.println("Problem generating request url: " + e.getMessage() );
+ e.printStackTrace();
+ throw new LoginException("Problem getting author url:" + e.getMessage());
+ }
+ }
+
+ public String getLearningDesigns(UserVO user, Long lcID) throws LoginException
+ {
+ String learningDesigns = "";
+ try
+ {
+ learningDesigns = LamsSecurityUtil.getLearningDesigns(
+ lamsServerUrl,
+ lamsServerId,
+ lamsServerSecretKey,
+ user.getUserId(),
+ "" + lcID,
+ "en",
+ "AU",
+ user.getFirstname(),
+ user.getLastname(),
+ user.getEmail(),
+ "1");
+
+ log.info("LAMS LEARNING DESIGNS: " + learningDesigns);
+ System.out.println("LAMS LEARNING DESIGN: " + learningDesigns);
+ return learningDesigns;
+
+ }
+ catch (Exception e)
+ {
+ log.error("Problem getting learning desings:", e);
+ System.out.println("Problem getting learning desings: " + e.getMessage() );
+ e.printStackTrace();
+ throw new LoginException("Problem getting learning desings: " + e.getMessage());
+ }
+ }
+
+
+ public boolean logout() throws LoginException
+ {
+ return super.logout();
+ }
+}
+
+
\ No newline at end of file
Index: lams_webct_integration/src/org/lamsfoundation/integration/webct/LamsSecurityUtil.java
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/src/org/lamsfoundation/integration/webct/LamsSecurityUtil.java,v
diff -u -r1.1 -r1.2
--- lams_webct_integration/src/org/lamsfoundation/integration/webct/LamsSecurityUtil.java 13 Nov 2007 00:33:47 -0000 1.1
+++ lams_webct_integration/src/org/lamsfoundation/integration/webct/LamsSecurityUtil.java 19 Nov 2007 22:57:42 -0000 1.2
@@ -37,7 +37,7 @@
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.lang.StringBuffer;
-
+import java.sql.Date;
import org.apache.commons.codec.binary.Hex;
import org.lamsfoundation.integration.util.Constants;
import org.w3c.dom.Document;
@@ -245,7 +245,7 @@
String firstName,
String lastName,
String email,
- long ldId,
+ String ldId,
String title,
String desc)
{
@@ -268,7 +268,7 @@
+ "&username=" + URLEncoder.encode(username, "utf8")
+ "&hashValue=" + hash
+ "&courseId=" + URLEncoder.encode(courseId, "utf8")
- + "&ldId=" + new Long(ldId).toString()
+ + "&ldId=" + ldId
+ "&country=" + country
+ "&lang=" + lang
+ "&method=" + "start"
@@ -339,6 +339,56 @@
}
+ public static String generatePreviewUrl(
+ String serverAddr,
+ String serverId,
+ String secretKey,
+ String reqSrc,
+ String username,
+ String courseId,
+ String lang,
+ String country,
+ String firstName,
+ String lastName,
+ String email
+ ) throws Exception
+ {
+ String url="";
+
+
+ // If lams.properties could not be read, throw exception
+ if(serverAddr == null || serverId == null || reqSrc==null){
+ throw new Exception("Configuration Exception " + serverAddr + ", " + serverId);
+ }
+
+ String timestamp = new Long(System.currentTimeMillis()).toString();
+ String hash = generateAuthenticationHash(timestamp, username, serverId, secretKey);
+
+ try {
+ url = serverAddr + "/services/xml/LessonManager?"
+ + "&uid=" + URLEncoder.encode(username, "UTF8")
+ + "&ts=" + timestamp
+ + "&sid=" + serverId
+ + "&hash=" + hash
+ + "&courseid=" + URLEncoder.encode(courseId, "UTF8")
+ + "&country=" + country
+ + "&lang=" + lang
+ + "&requestSrc=" + URLEncoder.encode(reqSrc, "UTF8")
+ + "&firstName=" + firstName
+ + "&lastName=" + lastName
+ + "&email=" + email
+ + "&method=preview";
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException();
+ }
+
+ logger.info("LAMS Req: " + url);
+ System.out.println("PREVIEW: " + url);
+
+ return url;
+ }
+
+
/**
*
* @param node the node from which to do the recursive conversion
Index: lams_webct_integration/test/Test.java
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/test/Test.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_webct_integration/test/Test.java 19 Nov 2007 22:57:42 -0000 1.1
@@ -0,0 +1,47 @@
+package org.lamsfoundation.integration.webct;
+
+import java.sql.*;
+
+import com.microsoft.sqlserver.jdbc.*;
+
+/**
+ * Microsoft SQL Server JDBC test program
+ */
+public class Test {
+ public Test() throws Exception {
+ // Get connection
+
+ SQLServerDataSource ds = new SQLServerDataSource();
+ ds.setServerName("localhost");
+ ds.setUser("sa");
+ ds.setPassword("hernamewaslola");
+ ds.setPortNumber(1433);
+ ds.setDatabaseName("webctdatabase");
+ Connection connection = ds.getConnection();
+
+//DriverManager.registerDriver(new Driver());
+ //Connection connection = DriverManager.getConnection(
+ //"jdbc:microsoft:sqlserver://localhost:1433","sa","hernamewaslola");
+ if (connection != null) {
+ System.out.println();
+ System.out.println("Successfully connected");
+ System.out.println();
+ // Meta data
+ DatabaseMetaData meta = connection.getMetaData();
+ System.out.println("\nDriver Information");
+ System.out.println("Driver Name: "
+ + meta.getDriverName());
+ System.out.println("Driver Version: "
+ + meta.getDriverVersion());
+ System.out.println("\nDatabase Information ");
+ System.out.println("Database Name: "
+ + meta.getDatabaseProductName());
+ System.out.println("Database Version: "+
+ meta.getDatabaseProductVersion());
+ }
+} // Test
+public static void main (String args[]) throws Exception {
+ Test test = new Test();
+ while(true){}
+}
+}
\ No newline at end of file
Index: lams_webct_integration/web/create.vm
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/web/create.vm,v
diff -u -r1.1 -r1.2
Binary files differ
Index: lams_webct_integration/web/include.vm
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/web/Attic/include.vm,v
diff -u
Binary files differ
Index: lams_webct_integration/web/learner.vm
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/web/learner.vm,v
diff -u
Binary files differ
Index: lams_webct_integration/web/lessonCreated.vm
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/web/Attic/lessonCreated.vm,v
diff -u
Binary files differ
Index: lams_webct_integration/web/teach.vm
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/web/teach.vm,v
diff -u -r1.1 -r1.2
Binary files differ
Index: lams_webct_integration/web/lib/tigra/tree_tpl.js
===================================================================
RCS file: /usr/local/cvsroot/lams_webct_integration/web/lib/tigra/tree_tpl.js,v
diff -u -r1.1 -r1.2
--- lams_webct_integration/web/lib/tigra/tree_tpl.js 13 Nov 2007 00:33:47 -0000 1.1
+++ lams_webct_integration/web/lib/tigra/tree_tpl.js 19 Nov 2007 22:57:42 -0000 1.2
@@ -31,6 +31,6 @@
'icon_18' : '/webct/images/tigra_plusbottom.gif', // junction for closed node
'icon_19' : '/webct/images/tigra_plus.gif', // junction for last closed node
'icon_26' : '/webct/images/tigra_minusbottom.gif',// junction for opened node
- 'icon_27' : '/webct/images/tigra_icons/minus.gif' // junction for last opened node
+ 'icon_27' : '/webct/images/tigra_minus.gif' // junction for last opened node
};