From c474ccc51a9229ad73f4a9ba894d9e3b3bdf55b1 Mon Sep 17 00:00:00 2001 From: Adam R Claxton Date: Wed, 19 Apr 2017 00:57:37 -0400 Subject: [PATCH] max_user_questions. Guess I'm done for tonight. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The concept behing my notification queue works, now it just needs to get information needed to compose a summary email. That's where the database is giving me trouble. I reduced the number of queries it needs to run, but haven't been able to test yet. We'll see if it works later. ¯\_(ツ)_/¯ --- .../webpages/redirect/ticketAdminRedirect.jsp | 2 +- src/database/TicketQueries.java | 30 +++++++++++++---- src/utilities/Mail.java | 3 ++ src/utilities/NotificationQueue.java | 32 +++++++++++++++---- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp b/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp index 6142f85..d37f5f3 100644 --- a/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp +++ b/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp @@ -43,7 +43,7 @@ if(request.getParameter("approve") != null){ boolean notificationPreferences = true; //TODO get real preference if(notificationPreferences){ NotificationQueue q = new NotificationQueue(client,"ticketConfirmations"); - q.run(); + q.start(); } } //reject form was submitted diff --git a/src/database/TicketQueries.java b/src/database/TicketQueries.java index 582742e..adaa0f8 100644 --- a/src/database/TicketQueries.java +++ b/src/database/TicketQueries.java @@ -3,6 +3,7 @@ import java.sql.*; import java.util.Date; import entities.Ticket; +import entities.User; public class TicketQueries { @@ -78,11 +79,15 @@ public static void acceptTicket(int ticketid, int deviceid, int locationid, int Connection connect = DriverManager.getConnection(database, user, password); Statement stmt = connect.createStatement(); long milliseconds = new java.util.Date().getTime(); - stmt.executeUpdate("UPDATE ticket, devices SET ticket.Status = \"Approved\", devices.Ticket_ID = " + ticketid + ", devices.Status = \"Shipped\", devices.Renter = " + sso + ", devices.Location = " + locationid + " WHERE ticket.Ticket_ID = " + ticketid + " AND devices.Device_ID = " + deviceid); + String query = "UPDATE ticket, devices SET ticket.Status = \"Approved\"" + +", ticket.Status_Date_Fields = " + milliseconds + +", devices.Ticket_ID = " + ticketid + +", devices.Status = \"Shipped\", devices.Renter = " + sso + +", devices.Location = " + locationid + +" WHERE ticket.Ticket_ID = " + ticketid + " AND devices.Device_ID = " + deviceid; + System.out.println("Executing query: "+query); + stmt.executeUpdate(query); - // We also need to update ticket's STD field (the one with the date of its last modification) -+ String query = "UPDATE ticket SET Status_Date_Fields = "+milliseconds+" WHERE Ticket_ID = "+ticketid+";"; -+ stmt.executeQuery(query); stmt.close(); connect.close(); } @@ -97,13 +102,26 @@ public static void rejectTicket(int id) throws SQLException, ClassNotFoundExcept connect.close(); } + // Returns millisecond value of the most recently modified ticket assigned to 'employee' with status 'status' + public static long getLatestTicketActivity(User employee, String status) throws SQLException, ClassNotFoundException{ + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connect = DriverManager.getConnection(database, user, password); + Statement stmt = connect.createStatement(); + String query = "SELECT MAX(Status_Date_Fields) FROM ticket WHERE Requestor = "+employee.getID()+" AND Status = '"+status+"';"; + System.out.println("Executing query '"+query+"'"); + ResultSet results = stmt.executeQuery(query); + results.next(); + return results.getLong("MAX(Status_Date_Fields)"); + } // Returns all tickets approved since 'millieconds' and associated with 'employee' - public static Ticket[] getApprovedTickets(int userID, long milliseconds) throws SQLException, ClassNotFoundException { + public static Ticket[] getRecentApprovedTickets(int userID, long milliseconds) throws SQLException, ClassNotFoundException { System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); Connection connect = DriverManager.getConnection(database, user, password); Statement stmt = connect.createStatement(); - String query= "SELECT ticket.*, employee.Name AS 'username', devices.Device_Name, location.Name AS 'locationname' FROM ticket INNER JOIN employee ON ticket.Requestor = employee.Employee_ID INNER JOIN devices ON ticket.Device_ID = devices.Device_ID INNER JOIN location ON ticket.Location = location.Location_ID WHERE ticket.Status = 'Approved' AND Requestor = " + userID + " AND Status_Date_Fields > " + milliseconds; + String query= "SELECT ticket.*, employee.Name AS 'username', devices.Device_Name, location.Name AS 'locationname' FROM ticket INNER JOIN employee ON ticket.Requestor = employee.Employee_ID INNER JOIN devices ON ticket.Device_ID = devices.Device_ID INNER JOIN location ON ticket.Location = location.Location_ID WHERE ticket.Status = 'Approved' AND Requestor = " + userID + " AND Status_Date_Fields >= " + milliseconds; + System.out.println("Executing query '"+query+"'"); ResultSet results = stmt.executeQuery(query); results.last(); int rows = results.getRow(); diff --git a/src/utilities/Mail.java b/src/utilities/Mail.java index 61cbc6e..8cb97ac 100644 --- a/src/utilities/Mail.java +++ b/src/utilities/Mail.java @@ -74,6 +74,9 @@ protected PasswordAuthentication getPasswordAuthentication(){ } + public void sendTicketApproval(int[] ticketIDs) throws IOException, InterruptedException { + + } private Properties setProp(String email, String targetEmail) { Properties props = null; try { diff --git a/src/utilities/NotificationQueue.java b/src/utilities/NotificationQueue.java index ea5c00a..8bd8744 100644 --- a/src/utilities/NotificationQueue.java +++ b/src/utilities/NotificationQueue.java @@ -1,6 +1,9 @@ package utilities; +import java.sql.SQLException; import java.util.Set; +import database.TicketQueries; +import entities.Ticket; import entities.User; @@ -28,11 +31,15 @@ public void run(){ Set threadSet = Thread.getAllStackTraces().keySet(); Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]); boolean match = false; + System.out.println("NotificationQueue: Checking active threads for match with "+threadName+"..."); for (int i=0; i