[Ils-source] r1479 - in trunk: src/com/resolutions/ils/data webapp/api/courseattempt/get
scribe at crosswire.org
scribe at crosswire.org
Thu Jun 30 10:08:28 MST 2016
Author: scribe
Date: 2016-06-30 10:08:27 -0700 (Thu, 30 Jun 2016)
New Revision: 1479
Modified:
trunk/src/com/resolutions/ils/data/CourseAttempt.java
trunk/webapp/api/courseattempt/get/index.jsp
Log:
applied Adams patch (with small mods) to increase facets to CourseAttempt search
Modified: trunk/src/com/resolutions/ils/data/CourseAttempt.java
===================================================================
--- trunk/src/com/resolutions/ils/data/CourseAttempt.java 2016-06-28 22:18:12 UTC (rev 1478)
+++ trunk/src/com/resolutions/ils/data/CourseAttempt.java 2016-06-30 17:08:27 UTC (rev 1479)
@@ -825,7 +825,7 @@
}
- static public Vector getCourseAttempts(ILSSession session, Date sDate, Date eDate) {
+ static public Vector getCourseAttempts(ILSSession session, Date sDate, Date eDate, int userProfileID, int courseID) {
String sql = "SELECT * FROM COURSEATTEMPT CA, USERPROFILE UP, COURSE CR WHERE CA.USERPRID=UP.USERPRID AND CA.COURSID=CR.COURSID AND UP.COMPANYID={COMPANYID}";
CourseAttempt retVal = new CourseAttempt();
if (sDate != null) {
@@ -837,6 +837,14 @@
// retVal.setTSValue("CAENDDATE", makeEndOfDay(eDate)); // TODO: should probably use makeEndOfDay and change above to <=, but don't want to change any other logic right now. Hunt down callers
retVal.setTSValue("CAENDDATE", eDate);
}
+ if (userProfileID > 0) {
+ sql += " AND CA.USERPRID={USERPRID}";
+ retVal.setIntValue("USERPRID", userProfileID);
+ }
+ if (courseID > 0) {
+ sql += " AND CA.COURSID={COURSID}";
+ retVal.setCourseAttemptCourseID(courseID);
+ }
sql += " ORDER BY CA.CASTARTDATE";
@@ -845,7 +853,11 @@
return retVal.getDataSet(sql);
}
+ static public Vector getCourseAttempts(ILSSession session, Date sDate, Date eDate) {
+ return getCourseAttempts(session, sDate, eDate, -1, -1);
+ }
+
public String toXML() {
return toXML(DETAIL_COMPLETE);
}
Modified: trunk/webapp/api/courseattempt/get/index.jsp
===================================================================
--- trunk/webapp/api/courseattempt/get/index.jsp 2016-06-28 22:18:12 UTC (rev 1478)
+++ trunk/webapp/api/courseattempt/get/index.jsp 2016-06-30 17:08:27 UTC (rev 1479)
@@ -3,63 +3,83 @@
contentType="text/html;charset=utf-8"
%>
<%@ page trimDirectiveWhitespaces="true" %>
-<%@ page import="org.crosswire.utils.HTTPUtils" %>
<%@ page import="com.resolutions.ils.Utils" %>
<%@ page import="com.resolutions.ils.ILSSession" %>
-<%@ page import="com.resolutions.ils.data.UserProfile" %>
<%@ page import="com.resolutions.ils.data.Company" %>
<%@ page import="com.resolutions.ils.data.CourseAttempt" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.TimeZone" %>
-<%@ page import="java.io.File" %>
-<%@ page import="java.net.URL" %>
-<%@ page import="java.util.Properties" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="org.apache.log4j.Logger" %>
<%
// standard service header ---------------------------------------
+ String serviceName = "courseattempt/get";
+
+ Logger logger = Logger.getLogger(this.getClass());
+ Logger eventsLogger = Logger.getLogger("EVENTS");
+
response.setContentType("text/xml");
+
+ String errMsg = "";
int errCode = 0;
Company company = Company.getCompany(request);
boolean apiEnabled = "on".equals(Utils.getSysConfig(session.getServletContext(), company.getCompanyID()).getProperty("APIEnable", "off"));
++errCode;
if (!apiEnabled) {
- out.print("<error code=\""+errCode+"\" message=\"API not enabled in system management settings.\"/>");
+ errMsg = "API not enabled in system management settings.";
+ out.print("<error code=\""+errCode+"\" message=\""+errMsg+"\"/>");
+ eventsLogger.error(serviceName +": " + errMsg);
return;
}
String userID = request.getParameter("ILSUSER");
- String userPw = request.getParameter("ILSPASSWD");
- ILSSession ilsSession = (userID != null && userPw != null)
- ? ILSSession.login(company.getCompanyName(), userID, userPw)
+ String userPW = request.getParameter("ILSPASSWD");
+ ILSSession ilsSession = (userID != null && userPW != null)
+ ? ILSSession.login(company.getCompanyName(), userID, userPW)
: (ILSSession)session.getAttribute("ilsSession");
++errCode;
if (ilsSession == null) {
- out.print("<error code=\""+errCode+"\" message=\"Your iLS sign in information is not valid.\"/>");
+ errMsg = "iLS sign in information is not valid.";
+ out.print("<error code=\""+errCode+"\" message=\""+errMsg+"\"/>");
+ eventsLogger.error(serviceName +": " + errMsg);
return;
}
+
String detail = request.getParameter("detail");
int detailLevel = org.crosswire.data.DataObject.DETAIL_COMPLETE;
if ("headeronly".equals(detail)) detailLevel = org.crosswire.data.DataObject.DETAIL_HEADERONLY;
else if ("brief".equals(detail)) detailLevel = org.crosswire.data.DataObject.DETAIL_BRIEF;
// end standard service header -----------------------------------
-
- Logger logger = Logger.getLogger(this.getClass());
- Logger eventsLogger = Logger.getLogger("EVENTS");
+
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmm");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
SimpleDateFormat df_out = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
df_out.setTimeZone(TimeZone.getTimeZone("GMT"));
int courseAttemptID = -1; try { courseAttemptID = Integer.parseInt( request.getParameter("courseAttemptID") ); } catch(Exception e) {}
+ int userProfileID = -1; try { userProfileID = Integer.parseInt(request.getParameter("userProfileID")); } catch(Exception e) {};
+ int courseID = -1; try { courseID = Integer.parseInt(request.getParameter("courseID")); } catch(Exception e) {};
+ ++errCode;
String val = request.getParameter("startDateTime");
- Date startDateTime = null; try { startDateTime = df.parse(val); } catch (Exception e) {}
+ Date startDateTime = null;
+ try { if (val != null) startDateTime = df.parse(val); } catch (Exception e) {
+ out.print("<error code=\""+errCode+"\" message=\"startDateTime must be formatted as yyyyMMddhhmm\"/>");
+ return;
+ }
+ ++errCode;
+ val = request.getParameter("endDateTime");
+ Date endDateTime = null;
+ try { if (val != null) endDateTime = df.parse(val); } catch (Exception e) {
+ out.print("<error code=\""+errCode+"\" message=\"endDateTime must be formatted as yyyyMMddhhmm\"/>");
+ return;
+ }
+
Vector<CourseAttempt> cas = null;
++errCode;
@@ -68,24 +88,22 @@
CourseAttempt ca = CourseAttempt.getCourseAttempt(ilsSession, courseAttemptID);
if (ca == null) {
- out.print("<error code=\""+errCode+"\" message=\"Course Attempt ID not found.\"/>");
+ out.print("<error code=\""+errCode+"\" message=\"Course Attempt ID: "+courseAttemptID+" not found.\"/>");
return;
}
cas.add(ca);
}
- if (startDateTime != null) {
- val = request.getParameter("endDateTime");
- Date endDateTime = null;
- try { if (val != null) endDateTime = df.parse(val); } catch (Exception e) {
- out.print("<error message=\"startDateTime must be passed and formatted as yyyyMMddhhmm\"/>");
- return;
- }
-
- cas = CourseAttempt.getCourseAttempts(ilsSession, startDateTime, endDateTime);
+ else if (startDateTime != null || endDateTime != null || courseID > -1 || userProfileID > -1) {
+ cas = CourseAttempt.getCourseAttempts(ilsSession, startDateTime, endDateTime, userProfileID, courseID);
}
if (cas != null) {
- out.print("<courseAttempts count=\""+cas.size()+"\""+(startDateTime != null ? (" startDateTime=\""+df_out.format(startDateTime)+"\""):"")+">\n");
+ out.print("<courseAttempts count=\""+cas.size()+"\""
+ + (startDateTime != null ? (" startDateTime=\""+df_out.format(startDateTime)+"\""):"")
+ + (endDateTime != null ? (" endDateTime=\""+df_out.format(endDateTime)+"\""):"")
+ + (courseID > -1 ? (" courseID=\""+courseID+"\""):"")
+ + (userProfileID > -1 ? (" userProfileID=\""+userProfileID+"\""):"")
+ +">\n");
for (Object o : cas) {
out.print(((CourseAttempt)o).toXML(detailLevel));
}
@@ -103,9 +121,10 @@
<table border="1">
<tbody>
<tr><th>courseAttemptID</th><td>retrieve a specific course attempt by ID</td></tr>
-<tr><th>startDateTime</th><td>retrieve a set of course attempts by filters, the start of the date and time range for which to retrieve Course Attempt records, inclusive (yyyyMMddhhmm), e.g., 201201240000</td></tr>
-<tr><th>endDateTime</th><td>(optional) the end of the date and time range for which to retrieve Course Attempt records, exclusive (yyyyMMddhhmm), e.g., 201201250000</td></tr>
-<tr><th>profileID</th><td>(optional) restrict results to a single user</td></tr>
+<tr><th>startDateTime</th><td>retrieve a set of course attempts by filters, the start of the date and time range for which to retrieve Course Attempt records by completion date, inclusive (yyyyMMddhhmm), e.g., 201201240000</td></tr>
+<tr><th>endDateTime</th><td>the end of the date and time range for which to retrieve Course Attempt records by completion date, exclusive (yyyyMMddhhmm), e.g., 201201250000</td></tr>
+<tr><td><b>userProfileID</b></td><td>restrict results to a single user</td></tr>
+<tr><td><b>courseID</b></td><td>restrict results to a single course</td></tr>
<tr><th>detail</th><td>(complete), brief, headeronly</td></tr>
<tr><th>ILSUSER</th><td>ILS Login Credentials. Used to validate this API request.</td></tr>
<tr><th>ILSPASSWD</th><td>ILS Login Credentials. Used to validate this API request.</td></tr>
More information about the Ils-source
mailing list