From scribe at crosswire.org  Thu Sep 22 13:58:22 2016
From: scribe at crosswire.org (scribe at crosswire.org)
Date: Thu, 22 Sep 2016 13:58:22 -0700
Subject: [Ils-source] r1488 - trunk/src/com/resolutions/ils/data
Message-ID: <E1bnB4Y-0006lv-9c@crosswire.org>

Author: scribe
Date: 2016-09-22 13:58:22 -0700 (Thu, 22 Sep 2016)
New Revision: 1488

Modified:
   trunk/src/com/resolutions/ils/data/CourseAttempt.java
Log:
added check for active student before sending expired emails


Modified: trunk/src/com/resolutions/ils/data/CourseAttempt.java
===================================================================
--- trunk/src/com/resolutions/ils/data/CourseAttempt.java	2016-07-29 23:52:48 UTC (rev 1487)
+++ trunk/src/com/resolutions/ils/data/CourseAttempt.java	2016-09-22 20:58:22 UTC (rev 1488)
@@ -77,7 +77,7 @@
 	static String LOOKUP = "SELECT * FROM COURSEATTEMPT WHERE COMPANYID={COMPANYID}";
 	static String DELETE = "DELETE FROM COURSEATTEMPT WHERE COURSATTID={COURSATTID} AND COMPANYID={COMPANYID}";
 
-	static String LOOKUPCOURSECOMPLETE = "SELECT CA.COMPANYID, CA.COURSATTID, UP.USERPRID, UP.USERPRNUM, UP.USERPREMAIL, CC.COURSNAME, CC.COURSISCURRICULUM FROM COURSEATTEMPT CA" +
+	static String LOOKUPCOURSECOMPLETE = "SELECT CA.COMPANYID, CA.COURSATTID, UP.USERPRID, UP.USERPRNUM, UP.USERPREMAIL, UP.USERPRSTATUSID, CC.COURSNAME, CC.COURSISCURRICULUM FROM COURSEATTEMPT CA" +
 				" join USERPROFILE UP on UP.USERPRID = CA.USERPRID" +
 				" join COURSE CC on CC.COURSID=CA.COURSID";
 
@@ -198,20 +198,22 @@
 			String from            = sysConfig.getProperty("SendMailFrom");
 			for (Object o: results) {
 				CourseAttempt ca = (CourseAttempt)o;
-				try {
-					String to = ca.getStringValue("USERPREMAIL");
-System.out.println("**** revokeAllExpired: sending email to: " + to);
-					HashMap<String, Object> params = new HashMap<String, Object>();
-					params.put("SITEURL", sysConfig.getProperty("SiteURL", "your training site"));
-					params.putAll(ca.getData());
-					String subject = Utils.replaceParams(subjectTemplate, params);
-					String body    = Utils.replaceParams(bodyTemplate, params);
-					body += sysConfig.getProperty("SendMailSig", "");
-					SMTPMail.sendEmail(sysConfig, from, to, subject, body, true);
+				if (ca.getIntValue("USERPRSTATUSID")==1) {
+					try {
+						String to = ca.getStringValue("USERPREMAIL");
+	System.out.println("**** revokeAllExpired: sending email to: " + to);
+						HashMap<String, Object> params = new HashMap<String, Object>();
+						params.put("SITEURL", sysConfig.getProperty("SiteURL", "your training site"));
+						params.putAll(ca.getData());
+						String subject = Utils.replaceParams(subjectTemplate, params);
+						String body    = Utils.replaceParams(bodyTemplate, params);
+						body += sysConfig.getProperty("SendMailSig", "");
+						SMTPMail.sendEmail(sysConfig, from, to, subject, body, true);
+					}
+					catch (Exception e) {
+						e.printStackTrace();
+					}
 				}
-				catch (Exception e) {
-					e.printStackTrace();
-				}
 			}
 			SMTPMail.closeMailConnection();
 		}
@@ -260,13 +262,13 @@
 
 		if (courseID > 0) {
 			query.setCourseAttemptCourseID(courseID);
-			results = query.getDataSet(LOOKUPCOURSECOMPLETEPENDINGEXPCOURSE + "AND CAWARNEDON"+warningNumber+" IS NULL AND CC.COURSISACTIVE='T'");
-			String WARNEXPCOURSE = WARN + " WHERE COURSATTID IN (" + LOOKUPPENDINGEXPCOURSE + " AND CC.COURSISACTIVE='T')" + " AND CAWARNEDON"+warningNumber+" IS NULL";
+			results = query.getDataSet(LOOKUPCOURSECOMPLETEPENDINGEXPCOURSE + "AND CAWARNEDON"+warningNumber+" IS NULL AND CC.COURSISACTIVE='T' AND UP.USERPRSTATUSID=1");
+			String WARNEXPCOURSE = WARN + " WHERE COURSATTID IN (" + LOOKUPPENDINGEXPCOURSE + " AND CC.COURSISACTIVE='T' AND EXISTS(SELECT 1 FROM USERPROFILE XX WHERE XX.USERPRID=CA2.USERPRID AND XX.USERPRSTATUSID=1))" + " AND CAWARNEDON"+warningNumber+" IS NULL";
 			count = query.executeSQL(WARNEXPCOURSE);
 		}
 		else {
-			results = query.getDataSet(LOOKUPCOURSECOMPLETEPENDINGEXP + " AND CC.COURSISACTIVE='T' AND CAWARNEDON"+warningNumber+" IS NULL");
-			String WARNEXP = WARN + " WHERE COURSATTID IN (" + LOOKUPPENDINGEXP + " AND CC.COURSISACTIVE='T')" + " AND CAWARNEDON"+warningNumber+" IS NULL";
+			results = query.getDataSet(LOOKUPCOURSECOMPLETEPENDINGEXP + " AND CC.COURSISACTIVE='T' AND UP.USERPRSTATUSID=1 AND CAWARNEDON"+warningNumber+" IS NULL");
+			String WARNEXP = WARN + " WHERE COURSATTID IN (" + LOOKUPPENDINGEXP + " AND CC.COURSISACTIVE='T' AND EXISTS(SELECT 1 FROM USERPROFILE XX WHERE XX.USERPRID=CA2.USERPRID AND XX.USERPRSTATUSID=1))" + " AND CAWARNEDON"+warningNumber+" IS NULL";
 			count = query.executeSQL(WARNEXP);
 		}
 
@@ -1025,7 +1027,7 @@
 		if (httpSession != null) {
 			Properties sysConfig = Utils.getSysConfig(httpSession.getServletContext(), getCompanyID());
 			boolean emailNotice = "on".equals(sysConfig.getProperty("EmailEnableAssignedRetakes", "off"));
-			if (emailNotice) {
+			if (emailNotice && this.getIntValue("USERPRSTATUSID")==1) {
 				try {
 					Company company = Company.getCompany(getCompanyID());
 					UserProfile up = UserProfile.getUserProfile(getCompanyID(), ca.getCourseAttemptUserProfileID());



From scribe at crosswire.org  Thu Sep 22 14:16:34 2016
From: scribe at crosswire.org (scribe at crosswire.org)
Date: Thu, 22 Sep 2016 14:16:34 -0700
Subject: [Ils-source] r1489 - in trunk/src/com/resolutions: ils/data jobs
Message-ID: <E1bnBMA-0006un-Pu@crosswire.org>

Author: scribe
Date: 2016-09-22 14:16:34 -0700 (Thu, 22 Sep 2016)
New Revision: 1489

Modified:
   trunk/src/com/resolutions/ils/data/CourseAttempt.java
   trunk/src/com/resolutions/ils/data/UserProfile.java
   trunk/src/com/resolutions/jobs/WarnCourseExpEMails.java
Log:
fix for expired email
fix for reoccurent training for curriculum


Modified: trunk/src/com/resolutions/ils/data/CourseAttempt.java
===================================================================
--- trunk/src/com/resolutions/ils/data/CourseAttempt.java	2016-09-22 20:58:22 UTC (rev 1488)
+++ trunk/src/com/resolutions/ils/data/CourseAttempt.java	2016-09-22 21:16:34 UTC (rev 1489)
@@ -77,7 +77,7 @@
 	static String LOOKUP = "SELECT * FROM COURSEATTEMPT WHERE COMPANYID={COMPANYID}";
 	static String DELETE = "DELETE FROM COURSEATTEMPT WHERE COURSATTID={COURSATTID} AND COMPANYID={COMPANYID}";
 
-	static String LOOKUPCOURSECOMPLETE = "SELECT CA.COMPANYID, CA.COURSATTID, UP.USERPRID, UP.USERPRNUM, UP.USERPREMAIL, UP.USERPRSTATUSID, CC.COURSNAME, CC.COURSISCURRICULUM FROM COURSEATTEMPT CA" +
+	static String LOOKUPCOURSECOMPLETE = "SELECT CA.COMPANYID, CA.COURSATTID, CA.COURSID, UP.USERPRID, UP.USERPRNUM, UP.USERPREMAIL, UP.USERPRSTATUSID, CC.COURSNAME, CC.COURSISCURRICULUM FROM COURSEATTEMPT CA" +
 				" join USERPROFILE UP on UP.USERPRID = CA.USERPRID" +
 				" join COURSE CC on CC.COURSID=CA.COURSID";
 
@@ -148,13 +148,13 @@
 	* @return
 	*/
 	static public int revokeAllExpired(int companyID, ServletContext context, boolean sendEmail) {
-		return revokeAllExpired(companyID, 0, context, sendEmail);
+		return revokeAllExpired(companyID, -1, context, sendEmail);
 	}
 
 	/*******************
 	* 
-	* @param session
-	* @param courseID
+	* @param companyID
+	* @param courseID which course to expire; -1 for all
 	* @param email, pass the HTTP session if you wish to send email, otherwise pass null
 	* @return
 	*/

Modified: trunk/src/com/resolutions/ils/data/UserProfile.java
===================================================================
--- trunk/src/com/resolutions/ils/data/UserProfile.java	2016-09-22 20:58:22 UTC (rev 1488)
+++ trunk/src/com/resolutions/ils/data/UserProfile.java	2016-09-22 21:16:34 UTC (rev 1489)
@@ -62,7 +62,7 @@
     	" WHERE MG.COMPANYID={COMPANYID} AND UG.COMPANYID={COMPANYID}" +
     	" AND MG.ILSGROUPID=UG.ILSGROUPID AND UG.USERPRID={USERPRID}";
     
-    static String LOOKUPBYEMAIL = "SELECT COMPANYID, USERPRNUM, USERPRPASSWD FROM USERPROFILE WHERE COMPANYID={COMPANYID} AND USERPREMAIL={USERPREMAIL}";
+    static String LOOKUPBYEMAIL = "SELECT COMPANYID, USERPRNUM, USERPRPASSWD, USERPRSTATUSID FROM USERPROFILE WHERE COMPANYID={COMPANYID} AND USERPREMAIL={USERPREMAIL}";
     static String DELETE[] = {
     	"DELETE FROM USERGROUP     WHERE USERPRID={USERPRID} AND COMPANYID={COMPANYID}",
     	"DELETE FROM COURSEATTEMPT WHERE USERPRID={USERPRID} AND COMPANYID={COMPANYID}",
@@ -945,6 +945,7 @@
         Vector<UserProfile> results = filter.getDataSet(LOOKUPBYEMAIL);
         for (Object o: results) {
         	UserProfile p = (UserProfile)o;
+		if (p.getUserProfileStatusID() == STATUS_ACTIVE) {
 			String subject = Utils.getSysConfig(httpSession).getProperty("EmailTemplate0Subject");
 			String body    = Utils.getSysConfig(httpSession).getProperty("EmailTemplate0Body");
 			HashMap<String, Object> params = new HashMap<String, Object>();
@@ -952,12 +953,13 @@
 			params.putAll(p.getData());
 			subject = Utils.replaceParams(subject, params);
 			body    = Utils.replaceParams(body, params);
-	        body += Utils.getSysConfig(httpSession).getProperty("SendMailSig", "");
-            try {
-    			Utils.sendEmail(httpSession, Utils.getSysConfig(httpSession).getProperty("SendMailFrom"), email, subject, body, true);
+			body   += Utils.getSysConfig(httpSession).getProperty("SendMailSig", "");
+			try {
+				Utils.sendEmail(httpSession, Utils.getSysConfig(httpSession).getProperty("SendMailFrom"), email, subject, body, true);
 			} catch (Exception e) {
 				e.printStackTrace();
 			}
+		}
         }
         Utils.closeMailConnection();
         return results.size();

Modified: trunk/src/com/resolutions/jobs/WarnCourseExpEMails.java
===================================================================
--- trunk/src/com/resolutions/jobs/WarnCourseExpEMails.java	2016-09-22 20:58:22 UTC (rev 1488)
+++ trunk/src/com/resolutions/jobs/WarnCourseExpEMails.java	2016-09-22 21:16:34 UTC (rev 1489)
@@ -16,7 +16,7 @@
 
 public class WarnCourseExpEMails implements Job {
 
-    static Logger logger = Logger.getLogger(WarnCourseExpEMails.class);
+	static Logger logger = Logger.getLogger(WarnCourseExpEMails.class);
 
 	public void execute (JobExecutionContext context) throws JobExecutionException {
 		logger.info("Running Batch EMail Submission");
@@ -28,8 +28,8 @@
 			boolean enablePastDue = "on".equals(sysConfig.getProperty("EmailEnablePastDue", ""));
 			for (int i = 0; i < 4; ++i) {
 				if ((i < 2 && enableBeforeDue) || (i > 1 && enablePastDue)) {
-				    CourseAttempt.warnAllPendingExpired(c.getCompanyID(), servletContext, i+1);
-			    }
+					CourseAttempt.warnAllPendingExpired(c.getCompanyID(), servletContext, i+1);
+				}
 			}
 		}
 		logger.info("Finished Batch EMail Submission");
@@ -39,13 +39,11 @@
 			Company c = (Company)o;
 			Properties sysConfig = Utils.getSysConfig(servletContext, c.getCompanyID());
 			boolean autoAssignRetakes = "on".equals(sysConfig.getProperty("AutoAssignRetakes", ""));
-		logger.info("Auto-Assign Retakes ("+autoAssignRetakes+") for Company: " + c.getCompanyID());
+			logger.info("Auto-Assign Retakes ("+autoAssignRetakes+") for Company: " + c.getCompanyID());
 			if (autoAssignRetakes) {
-			    boolean emailNotice = "on".equals(sysConfig.getProperty("EmailEnableAssignedRetakes", "off"));
-		    	int count = CourseAttempt.revokeAllExpired(c.getCompanyID(), servletContext, emailNotice);
-		        logger.info(
-		        		"Assigned " + Integer.toString(count) + " Recurrent Courses " +
-		        		"for Company: " + c.getCompanyName() + " (" + c.getCompanyID() + ")");
+				boolean emailNotice = "on".equals(sysConfig.getProperty("EmailEnableAssignedRetakes", "off"));
+				int count = CourseAttempt.revokeAllExpired(c.getCompanyID(), servletContext, emailNotice);
+				logger.info("Assigned " + Integer.toString(count) + " Recurrent Courses " + "for Company: " + c.getCompanyName() + " (" + c.getCompanyID() + ")");
 			}
 		}
 		logger.info("Finished Batch Assign Retakes");



