[Ils-source] r1472 - in trunk/webapp/api/courseattempt: . put
scribe at crosswire.org
scribe at crosswire.org
Mon Jun 27 16:25:43 MST 2016
Author: scribe
Date: 2016-06-27 16:25:42 -0700 (Mon, 27 Jun 2016)
New Revision: 1472
Added:
trunk/webapp/api/courseattempt/put/
trunk/webapp/api/courseattempt/put/index.jsp
Log:
applied patch from Adam adding courseattempt/put API call
Added: trunk/webapp/api/courseattempt/put/index.jsp
===================================================================
--- trunk/webapp/api/courseattempt/put/index.jsp (rev 0)
+++ trunk/webapp/api/courseattempt/put/index.jsp 2016-06-27 23:25:42 UTC (rev 1472)
@@ -0,0 +1,214 @@
+<%@ page language="java" contentType="text/xml;charset=utf-8" %>
+<%@ page trimDirectiveWhitespaces="true" %>
+<%@ 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.Date" %>
+<%@ page import="java.text.SimpleDateFormat" %>
+<%@ page import="org.apache.log4j.Logger" %>
+
+<%
+ // standard service header ---------------------------------------
+
+ String serviceName = "courseattempt/put";
+
+ 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) {
+ 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)
+ : (ILSSession)session.getAttribute("ilsSession");
+ ++errCode;
+ if (ilsSession == null) {
+ errMsg = "iLS sign in information is not valid.";
+ out.print("<error code=\""+errCode+"\" message=\""+errMsg+"\"/>");
+ eventsLogger.error(serviceName +": " + errMsg);
+ return;
+ }
+ // end standard service header -----------------------------------
+
+
+ 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) {}
+
+
+// one of these must be supplied; otherwise, show usage info
+if ( courseAttemptID != -1 || (courseID != -1 && userProfileID != -1) ) {
+
+ UserProfile adminUser = ilsSession.getCurrentUserProfile();
+
+ SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmm");
+ CourseAttempt current = new CourseAttempt();
+ current.defaultAll();
+ boolean createMode = "create".equals(request.getParameter("action"));
+
+ ++errCode;
+ if ((adminUser.getUserProfileAccessLevel() > UserProfile.ACCESS_MANAGER) || (adminUser.hasAccess(UserProfile.ACCESS_MODE_USERPR_SEARCH_VIEW))) {
+ if (!createMode) {
+ CourseAttempt lookup = null;
+ if (courseAttemptID != -1) {
+ lookup = CourseAttempt.getCourseAttempt(ilsSession, courseAttemptID);
+ if (lookup == null) {
+ out.print("<error code=\""+errCode+"\" message=\"Permission denied.\"/>");
+ return;
+ }
+ }
+
+ if (lookup != null) {
+ current = lookup;
+ }
+ else {
+ if (!"update".equals(request.getParameter("action"))) createMode = true;
+ else current = null;
+ }
+ }
+ }
+ else {
+ ++errCode;
+ out.print("<error code=\""+errCode+"\" message=\"Permission denied.\"/>");
+ return;
+ }
+
+ ++errCode;
+ if (current == null) {
+ out.print("<error code=\""+errCode+"\" message=\"Course attempt not found.\"/>");
+ return;
+ }
+ ++errCode;
+ if (createMode && current.getCourseAttemptID() > 0) {
+ out.print("<error code=\""+errCode+"\" message=\"Course attempt exists.\"/>");
+ return;
+ }
+ ++errCode;
+ if (current.getCourseAttemptID() > 0 && adminUser.getUserProfileAccessLevel() <= UserProfile.ACCESS_MANAGER && !adminUser.hasAccess(UserProfile.ACCESS_MODE_MENU_STUDENT_RECORDS)) {
+ out.print("<error code=\""+errCode+"\" message=\"Permission denied to edit course attempt.\"/>");
+ return;
+ }
+
+ CourseAttempt orig = (CourseAttempt)current.clone();
+
+
+ if (courseID != -1) current.setCourseAttemptCourseID(courseID);
+ if (userProfileID != - 1) current.setCourseAttemptUserProfileID(userProfileID);
+
+ String val = request.getParameter("score");
+ if (val != null && val.trim().length() > 0) current.setCourseAttemptScore(Integer.parseInt(val));
+ val = request.getParameter("statusID");
+ if (val != null && val.trim().length() > 0) current.setCourseAttemptStatusID(Integer.parseInt(val));
+ val = request.getParameter("stage");
+ if (val != null && val.trim().length() > 0) current.setCourseAttemptStage(val);
+ val = request.getParameter("managerApproved");
+ if (val != null && val.trim().length() > 0) current.setCourseAttemptManagerApproved(Boolean.valueOf(val));
+ val = request.getParameter("expire");
+ if (val != null && val.trim().length() > 0) current.setCourseAttemptExpired(val);
+ val = request.getParameter("callbackStatus");
+ if (val != null && val.trim().length() > 0) current.setCourseAttemptCallbackStatus(val);
+
+ if (current.getCourseAttemptID() > 0 && adminUser.getUserProfileAccessLevel() <= UserProfile.ACCESS_MANAGER && !adminUser.hasAccess(UserProfile.ACCESS_MODE_STUDENTREC_PASS_OVERRIDE)) {
+ out.print("<error code=\""+errCode+"\" message=\"Permission denied to force pass course attempt.\"/>");
+ return;
+ } else {
+ val = request.getParameter("forcePass");
+ if (val != null && val.trim().length() > 0) current.setCourseAttemptForcePass(val);
+ }
+
+
+ ++errCode;
+ val = request.getParameter("startDate");
+ if (val != null) {
+ Date startDate = null;
+ try {
+ startDate = df.parse(val);
+ current.setCourseAttemptStartDate(startDate);
+ } catch (Exception e) {
+ out.print("<error code=\""+errCode+"\" message=\"startDate must be passed and formatted as yyyyMMddhhmm\"/>");
+ return;
+ }
+ }
+
+ ++errCode;
+ val = request.getParameter("completeDate");
+ if (val != null) {
+ Date completeDate = null;
+ try {
+ completeDate = df.parse(val);
+ current.setCourseAttemptCompleteDate(completeDate);
+ } catch (Exception e) {
+ out.print("<error code=\""+errCode+"\" message=\"completeDate must be passed and formatted as yyyyMMddhhmm\"/>");
+ return;
+ }
+ }
+
+ ++errCode;
+ if (current.getCourseAttemptCourseID() <= 0) {
+ out.print("<error code=\""+errCode+"\" message=\"You must supply a courseID\"/>");
+ return;
+ }
+ ++errCode;
+ if (current.getCourseAttemptUserProfileID() <= 0) {
+ out.print("<error code=\""+errCode+"\" message=\"You must supply a userProfileID\"/>");
+ return;
+ }
+
+ if (orig.getCourseAttemptID() > 0) {
+ current.save(orig);
+ }
+ else {
+ current = current.saveNew(ilsSession);
+ }
+%>
+<success courseAttemptID="<%=current.getCourseAttemptID()%>"/>
+<%
+ return;
+
+}
+response.setContentType("text/html");
+%>
+<html>
+<style>th { text-align:left; }</style>
+<body>
+<h1>courseattempt/put</h1>
+<p>Create or modify a course attempt record</p>
+<h3>Parameters</h3>
+<table border="1">
+<tbody>
+<tr><th>courseAttemptID</th><td>The record to modify.</td></tr>
+<tr><th>action</th><td>(optional) [update|create] If not supplied, action is determined by: <ul><li>if courseAttemptID is supplied, action is update.</li><li>otherwise, action is create.</li></ul></td></tr>
+<tr><th>courseID</th><td>Course ID (required if action is create)</td></tr>
+<tr><th>userProfileID</th><td>User Profile ID (required if action is create</td></tr>
+<tr><th>score</th><td>score</td></tr>
+<tr><th>statusID</th><td>Attempt status</td></tr>
+<tr><th>stage</th><td>Attempt stage</td></tr>
+<tr><th>startDate</th><td>Start date (yyyyMMddhhmm), e.g., 201201240000</td></tr>
+<tr><th>completeDate</th><td>Completion date (yyyyMMddhhmm), e.g., 201201250000</td></tr>
+<tr><th>managerApproved</th><td>Manager approved (boolean) e.g., true</td></tr>
+<tr><th>expire</th>The reason the attempt is expired, the expriation date will be the current system time<td></td></tr>
+<tr><th>forcePass</th><td>The reason the attempt is passed, the force pass date will be the current system time</td></tr>
+<tr><th>callbackStatus</th><td>Callback status</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>
+</tbody>
+</table>
+</body>
+</html>
+
More information about the Ils-source
mailing list