[Ils-source] r1562 - in trunk: src/com/resolutions/ils/data webapp
scribe at crosswire.org
scribe at crosswire.org
Fri Jan 5 07:24:34 MST 2018
Author: scribe
Date: 2018-01-05 07:24:34 -0700 (Fri, 05 Jan 2018)
New Revision: 1562
Modified:
trunk/src/com/resolutions/ils/data/CourseAttempt.java
trunk/webapp/aicc.jsp
Log:
Added aicc_userdata to allow 3rd parties to set aicc data block variables when they launch a course. Mostly from patch from Adam.
Modified: trunk/src/com/resolutions/ils/data/CourseAttempt.java
===================================================================
--- trunk/src/com/resolutions/ils/data/CourseAttempt.java 2018-01-05 14:20:09 UTC (rev 1561)
+++ trunk/src/com/resolutions/ils/data/CourseAttempt.java 2018-01-05 14:24:34 UTC (rev 1562)
@@ -57,9 +57,15 @@
import java.io.ByteArrayInputStream;
import org.apache.batik.transcoder.TranscoderOutput;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+import java.util.List;
+import java.util.ArrayList;
+
+
public class CourseAttempt extends DataObject {
public static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); //"EEE MMM dd HH:mm:ss z yyyy");
@@ -1278,6 +1284,29 @@
return data;
}
+ public static List<String> getINIKeys(String iniBuffer) {
+ List<String> result = new ArrayList<String>();
+ int iniBufferLength = iniBuffer.split("=").length - 1;
+ if (iniBufferLength > 0) {
+ Pattern p = Pattern.compile("([^=|\\\n]*)=");
+ Matcher matcher = p.matcher(iniBuffer);
+ for (int m = 0; m < iniBufferLength; m++) {
+ matcher.find();
+ result.add(matcher.group(1));
+ }
+ }
+ return result;
+ }
+
+ public static String mergeINIValues(String iniBlock, String newData) {
+ List<String> dataKeys = getINIKeys(newData);
+ int dataKeysLength = dataKeys.size();
+ for (int k = 0; k < dataKeysLength; k++) {
+ iniBlock = setINIValue(iniBlock, dataKeys.get(k), getINIValue(newData, dataKeys.get(k)));
+ }
+ return iniBlock;
+ }
+
public static String join(String delimeter, Collection items) {
if (items == null || items.size() == 0) return "";
Modified: trunk/webapp/aicc.jsp
===================================================================
--- trunk/webapp/aicc.jsp 2018-01-05 14:20:09 UTC (rev 1561)
+++ trunk/webapp/aicc.jsp 2018-01-05 14:24:34 UTC (rev 1562)
@@ -6,9 +6,10 @@
<%@page import="java.util.Vector"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Date"%>
+<%@page import="java.util.List"%>
<%@page import="java.io.File"%>
<%@page import="java.io.FileWriter"%>
-<%@ page import="org.apache.log4j.Logger" %>
+<%@page import="org.apache.log4j.Logger" %>
<%!
void sendNotifications(HttpSession session, CourseAttempt ca, Course course, UserProfile user) {
@@ -44,6 +45,8 @@
}
}
}
+
+ public static final String AICC_INITIAL_DATA = "[core]\r\nlesson_status=i\r\nscore=0\r\nlesson_location=0\r\ntime=00:00:00\r\n";
%>
<%
Logger logger = Logger.getLogger("AICC");
@@ -60,6 +63,8 @@
String courseID = request.getParameter("courseid");
String asid = request.getParameter("session_id");
String aicc_data = request.getParameter("aicc_data");
+ String aicc_userdata = request.getParameter("aicc_userdata");
+ logger.info("aicc_userdata passed: [" + aicc_userdata + "]");
String preview = request.getParameter("preview");
CourseAttempt ca = null;
Course course = null;
@@ -74,6 +79,11 @@
// Launch a course
if (courseID != null) {
course = Course.getCourse(ilsSession, Integer.parseInt(courseID));
+ if (course == null) {
+ response.setContentType("text/xml");
+ out.print("<error message=\"course ID not found: " + courseID+"\" />");
+ return;
+ }
if (!"true".equals(preview) || ((user.getUserProfileAccessLevel() < UserProfile.ACCESS_ADMIN) && (!user.hasAccess(UserProfile.ACCESS_MODE_MENU_COURSE_MGMT)))) {
@@ -115,7 +125,16 @@
if ((course.getCourseURL() != null) && (!course.getCourseURL().endsWith("frameset.htm"))) {
// ca.setCourseAttemptStatusID(ca.STATUS_PASSED);
}
+
ca = ca.saveNew(ilsSession);
+
+ if (aicc_userdata != null) {
+ //If I saveNew with CASTAGE set I get an index out of bounds error
+ CourseAttempt orig = (CourseAttempt) ca.clone();
+ ca.setCourseAttemptStage(CourseAttempt.mergeINIValues(AICC_INITIAL_DATA, aicc_userdata));
+ ca.save(orig);
+ }
+
// what is this crap?!!! Why do we have the same check above separated only by saveNew.
// this is only for non-eXpress Course stuff anyway, so I'm not touching it.
if ((course.getCourseURL() != null) && (!course.getCourseURL().endsWith("frameset.htm"))) {
@@ -123,6 +142,7 @@
}
}
else {
+logger.info("******** relaunching course");
ca = (CourseAttempt) cas.get(0);
if (ca.getCourseAttemptStatusID() != ca.STATUS_IN_PROGRESS) {
CourseAttempt orig = (CourseAttempt) ca.clone();
@@ -140,13 +160,25 @@
//ca.setCourseAttemptStage("");
}
+
ca.save(orig);
}
else {
logger.info("Launching in progress course...");
}
+ // check for aicc_userdata
+ if (aicc_userdata != null) {
+ CourseAttempt orig = (CourseAttempt) ca.clone();
+ String caStage = ca.getCourseAttemptStage();
+logger.info("******** relaunching course: aicc_data existing: " + caStage);
+ ca.setCourseAttemptStage(CourseAttempt.mergeINIValues((caStage != null && caStage.length() >= 2) ? caStage : AICC_INITIAL_DATA, aicc_userdata));
+logger.info("******** relaunching course: aicc_data adjusted: " + ca.getCourseAttemptStage());
+ ca.save(orig);
+ }
}
}
+
+
String ilsURL = Utils.getSysConfig(session).getProperty("ILSURL");
String aiccURL = "AICC_URL=" + ((ilsURL == null || ilsURL.length() < 1) ? request.getRequestURL() : (ilsURL+(ilsURL.endsWith("/")?"":"/")+"aicc.jsp"));
String aiccSID = "AICC_SID=" + (!"true".equals(preview)?ca.getCourseAttemptID():-1);
@@ -158,6 +190,8 @@
// response.setHeader("Location", url);
// response.setHeader("Connection", "close");
// return;
+
+
}
else if (asid != null) {
ca = CourseAttempt.getCourseAttempt(ilsSession, Integer.parseInt(asid));
@@ -175,10 +209,6 @@
}
-
-
-
-
// ---------------------------------------------------------------------
// CLEARLOG
// ---------------------------------------------------------------------
@@ -277,11 +307,7 @@
// code to get [core] node by session_id form value.
aicc_data = ca.getCourseAttemptStage();
if ((aicc_data == null) || (aicc_data.length() < 2)) {
- aicc_data = "[core]\r\n";
- aicc_data += "lesson_status=i\r\n";
- aicc_data += "score=0\r\n";
- aicc_data += "lesson_location=0\r\n";
- aicc_data += "time=00:00:00\r\n";
+ aicc_data = AICC_INITIAL_DATA;
}
else {
if ("".equals(CourseAttempt.getINIValue(aicc_data, "lesson_location"))) {
More information about the Ils-source
mailing list