From b33a42726fd85a18a1aecc7adff5d3b49faac5a8 Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Mon, 17 Apr 2017 16:55:03 -0400 Subject: [PATCH 01/43] Device Hub now supports some extra fields --- .../html/webpages/administration/admin.jsp | 3 +- .../administration/adminDeviceSettings.jsp | 43 ++++++++++++++++--- .../html/webpages/components/adminsidebar.jsp | 6 +-- .../html/webpages/redirect/deviceRedirect.jsp | 7 ++- src/database/DeviceQueries.java | 4 +- src/entities/Device.java | 15 +++++++ 6 files changed, 63 insertions(+), 15 deletions(-) diff --git a/WebContent/html/webpages/administration/admin.jsp b/WebContent/html/webpages/administration/admin.jsp index 6719058..c36986e 100644 --- a/WebContent/html/webpages/administration/admin.jsp +++ b/WebContent/html/webpages/administration/admin.jsp @@ -74,7 +74,8 @@ div.approveConfirm { <%@ include file="../components/adminsidebar.jsp" %>
-

Welcome to the admin page

+

Welcome to The Admin Hub!

+

Select from any option in the sidebar to exert your administrative power!

diff --git a/WebContent/html/webpages/administration/adminDeviceSettings.jsp b/WebContent/html/webpages/administration/adminDeviceSettings.jsp index f19c36f..28ae345 100644 --- a/WebContent/html/webpages/administration/adminDeviceSettings.jsp +++ b/WebContent/html/webpages/administration/adminDeviceSettings.jsp @@ -88,19 +88,23 @@ pageEncoding="ISO-8859-1"%> +
+ + +
+
+ + +
-
- - -
+
+ + +
+
+ + +
@@ -143,10 +155,18 @@ pageEncoding="ISO-8859-1"%>
+
+ + +
+
+ + +
+
+ + +
@@ -187,8 +211,7 @@ pageEncoding="ISO-8859-1"%>
-

Device Listing

- +

Device Hub

@@ -199,11 +222,14 @@ pageEncoding="ISO-8859-1"%> Name + Locker Position Description + Admin Comments Availability MAC Address Manufacturer Hardware Type + Operating System Model Name Serial Number NFC ID @@ -278,7 +304,7 @@ document.getElementById('modifyAvailability').innerHTML = availabilityHTML; function populateDevices(deviceArray){ var html = ""; for(var i = 0; i < deviceArray.length; i++){ - html += "" + deviceArray[i].name + "" + deviceArray[i].description + "" + deviceArray[i].status + "" + deviceArray[i].mac + "" + deviceArray[i].manufacturer + "" + deviceArray[i].hardware + "" + deviceArray[i].model + "" + deviceArray[i].serial + "" + deviceArray[i].nfc + ""; + html += "" + deviceArray[i].name + "" + deviceArray[i].locker + "" + deviceArray[i].description + "" + deviceArray[i].admincomment + "" + deviceArray[i].status + "" + deviceArray[i].mac + "" + deviceArray[i].manufacturer + "" + deviceArray[i].hardware + "" + deviceArray[i].os + "" + deviceArray[i].model + "" + deviceArray[i].serial + "" + deviceArray[i].nfc + ""; if(findInArray(deviceArray[i].manufacturer,manufacturers) == false){ manufacturers.push(deviceArray[i].manufacturer); } @@ -431,6 +457,9 @@ function modifyModal(){ $("#modifyModel").val(devices[i].model.replace(/"/g,"\"")); $("#modifySerial").val(devices[i].serial); $("#modifyNFC").val(devices[i].nfc); + $("#modifyOS").val(devices[i].os); + $("#modifycomment").val(devices[i].admincomment); + $("#modifyPos").val(devices[i].locker); $("#modifyID").val(devices[i].id); $("#modifyModal").show(); } diff --git a/WebContent/html/webpages/components/adminsidebar.jsp b/WebContent/html/webpages/components/adminsidebar.jsp index 10b20d6..0caa9bc 100644 --- a/WebContent/html/webpages/components/adminsidebar.jsp +++ b/WebContent/html/webpages/components/adminsidebar.jsp @@ -2,9 +2,9 @@
\ No newline at end of file diff --git a/WebContent/html/webpages/redirect/deviceRedirect.jsp b/WebContent/html/webpages/redirect/deviceRedirect.jsp index 1c2273b..cc1f993 100644 --- a/WebContent/html/webpages/redirect/deviceRedirect.jsp +++ b/WebContent/html/webpages/redirect/deviceRedirect.jsp @@ -36,9 +36,12 @@ String hardware = request.getParameter("hardware").replace("\"","\\\""); String model = request.getParameter("model").replace("\"","\\\""); String serial = request.getParameter("serial"); String nfc = request.getParameter("NFC"); +String os = request.getParameter("OS"); +String locker = request.getParameter("locker"); +String comment = request.getParameter("admincomments"); //add form was submitted if(request.getParameter("add") != null){ - Device device = new Device(name,1,description,hardware,model,manufacturer,status,mac,serial,nfc); + Device device = new Device(name,1,description,hardware,model,manufacturer,status,mac,serial,nfc,locker,os,comment); DeviceQueries.addDevice(device); } @@ -48,7 +51,7 @@ if(request.getParameter("modify") != null){ String strID = request.getParameter("id"); //turn to int for constructor int id = Integer.parseInt(strID); - Device device = new Device(name,id,description,hardware,model,manufacturer,status,mac,serial,nfc); + Device device = new Device(name,id,description,hardware,model,manufacturer,status,mac,serial,nfc,locker,os,comment); DeviceQueries.modifyDevice(device); } diff --git a/src/database/DeviceQueries.java b/src/database/DeviceQueries.java index f6ca830..3e779c5 100644 --- a/src/database/DeviceQueries.java +++ b/src/database/DeviceQueries.java @@ -126,7 +126,7 @@ public static void addDevice(Device device) throws SQLException, ClassNotFoundEx id = results.getInt("Device_ID"); id++; //tries this statement, otherwise tries again with a new id - String command = "INSERT INTO devices (Device_ID,Device_Name,Device_Description,MAC_Address,Manufacturer,Hardware,Model,Serial_Num,Status,Added_By,NFC_ID) " + "VALUES (" + id +",\"" + device.getName() + "\",\"" + device.getDesc()+ "\",\"" + device.getMAC() + "\",\"" + device.getManufacturer() + "\",\""+device.getHardware()+ "\",\"" + device.getModel() + "\",\"" + device.getSerial() + "\",\"" + device.getStatus() + "\",30,\"" + device.getNFC() + "\");"; + String command = "INSERT INTO devices (Device_ID,Device_Name,Device_Description,MAC_Address,Manufacturer,Hardware,Model,Serial_Num,Status,NFC_ID,Locker_Position,Operating_System,Admin_Comments) " + "VALUES (" + id +",\"" + device.getName() + "\",\"" + device.getDesc()+ "\",\"" + device.getMAC() + "\",\"" + device.getManufacturer() + "\",\""+device.getHardware()+ "\",\"" + device.getModel() + "\",\"" + device.getSerial() + "\",\"" + device.getStatus() + "\",\"" + device.getNFC() + "\",\"" + device.getPos() + "\",\"" + device.getOS() + "\",\"" + device.getComment() +"\");"; System.out.println(command); i = stmt.executeUpdate(command); } @@ -139,7 +139,7 @@ public static void modifyDevice(Device device) throws ClassNotFoundException, SQ Class.forName("com.mysql.jdbc.Driver"); Connection connection = DriverManager.getConnection(database, user, password); Statement stmt = connection.createStatement(); - stmt.executeUpdate("UPDATE devices SET Device_Name = \"" + device.getName() + "\", Device_Description = \"" + device.getDesc() + "\", MAC_Address = \"" + device.getMAC() + "\", Manufacturer = \"" + device.getManufacturer() + "\", Hardware = \"" + device.getHardware() + "\", Model = \"" + device.getModel() + "\", Serial_Num = \"" + device.getSerial() + "\", Status = \"" + device.getStatus() + "\", NFC_ID = \"" + device.getNFC() + "\" WHERE Device_ID = " + device.getID()); + stmt.executeUpdate("UPDATE devices SET Device_Name = \"" + device.getName() + "\", Device_Description = \"" + device.getDesc() + "\", MAC_Address = \"" + device.getMAC() + "\", Manufacturer = \"" + device.getManufacturer() + "\", Hardware = \"" + device.getHardware() + "\", Model = \"" + device.getModel() + "\", Serial_Num = \"" + device.getSerial() + "\", Status = \"" + device.getStatus() + "\", NFC_ID = \"" + device.getNFC() + "\", Admin_Comments = \"" + device.getComment() + "\", Operating_System = \"" + device.getOS() + "\", Locker_Position = \"" + device.getPos() + "\" WHERE Device_ID = " + device.getID()); stmt.close(); connection.close(); } diff --git a/src/entities/Device.java b/src/entities/Device.java index 593fead..ad0eb56 100644 --- a/src/entities/Device.java +++ b/src/entities/Device.java @@ -42,13 +42,16 @@ public String toString(){ StringBuilder sb = new StringBuilder(); String comma = ", "; sb.append("{\"name\": \"").append(Device_Name).append("\"").append(comma); + sb.append("\"locker\": \"").append(locker_position).append("\"").append(comma); sb.append("\"id\": \"").append(Device_ID).append("\"").append(comma); sb.append("\"description\": \"").append(Device_Description).append("\"").append(comma); + sb.append("\"admincomment\": \"").append(Admin_Comments).append("\"").append(comma); sb.append("\"hardware\": \"").append(Hardware).append("\"").append(comma); sb.append("\"status\": \"").append(Status).append("\"").append(comma); sb.append("\"model\": \"").append(Model).append("\"").append(comma); sb.append("\"manufacturer\": \"").append(Manu).append("\"").append(comma); sb.append("\"mac\": \"").append(MAC).append("\"").append(comma); + sb.append("\"os\": \"").append(OS).append("\"").append(comma); sb.append("\"serial\": \"").append(Serial).append("\"").append(comma); sb.append("\"nfc\": \"").append(NFC).append("\""); sb.append("}"); @@ -112,4 +115,16 @@ public String getNFC() { public String getStatus(){ return Status; } + + public String getPos(){ + return locker_position; + } + + public String getOS(){ + return OS; + } + + public String getComment(){ + return Admin_Comments; + } } From 734d223e15ce8b8321ee12611d4cf38ebfa2058f Mon Sep 17 00:00:00 2001 From: Adam R Claxton Date: Tue, 18 Apr 2017 00:20:56 -0400 Subject: [PATCH 02/43] Replaced my personal email with a dummy email so everyone can get emails now --- src/utilities/Mail.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utilities/Mail.java b/src/utilities/Mail.java index 008d0d0..10ee409 100644 --- a/src/utilities/Mail.java +++ b/src/utilities/Mail.java @@ -16,8 +16,8 @@ public class Mail { - private String sender = "arclaxton@gmail.com"; - private String password = ""; + private String sender = "Senior.design.synchrony.test@gmail.com"; + private String password = "synchrony123"; private User client; public Mail(User client){ this.client=client; @@ -50,7 +50,7 @@ public void sendTicketConfirmation(int[] ticketIDs) throws IOException, Interrup } msg=msg.replace("{TICKETS GO HERE}",tickethtml); Properties properties = System.getProperties(); - properties = setProp(sender, client.getEmail()); + // properties = setProp(sender, client.getEmail()); Session session = Session.getInstance(properties, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication(){ return new PasswordAuthentication(sender, password); From a8b1ed8f989ba3225fa7137819e33fe61fe47af2 Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Tue, 18 Apr 2017 09:50:23 -0400 Subject: [PATCH 03/43] Latitude and Longitude Support --- .../webpages/administration/adminLocation.jsp | 51 +++++++++++++-- .../webpages/redirect/locationRedirect.jsp | 6 +- .../webpages/redirect/orderFormHandler.jsp | 11 ++-- src/database/LocationQueries.java | 40 ++++++++---- src/entities/Location.java | 65 ++++++++----------- 5 files changed, 113 insertions(+), 60 deletions(-) diff --git a/WebContent/html/webpages/administration/adminLocation.jsp b/WebContent/html/webpages/administration/adminLocation.jsp index 76d6d88..a4bc324 100644 --- a/WebContent/html/webpages/administration/adminLocation.jsp +++ b/WebContent/html/webpages/administration/adminLocation.jsp @@ -15,6 +15,9 @@ + + + + + + + + + <% Cookie userCookie,newCookie; @@ -29,11 +88,21 @@ if (result.next()){ response.addCookie(newCookie); stmt.close(); connection.close(); - response.sendRedirect("html/webpages/index.jsp"); -} else { - stmt.close(); - connection.close(); - response.sendRedirect("html/webpages/index.jsp"); + response.sendRedirect("index.jsp"); } +connection.close(); +stmt.close(); +String locations = Location.arrayToString(LocationQueries.getLocations(ssoNum)); +%> -%> \ No newline at end of file + \ No newline at end of file diff --git a/WebContent/index.jsp b/WebContent/index.jsp index a5d580e..7c4f219 100644 --- a/WebContent/index.jsp +++ b/WebContent/index.jsp @@ -94,7 +94,7 @@
diff --git a/WebContent/html/webpages/userLogin.jsp b/WebContent/html/webpages/userLogin.jsp index 3d78a28..000f5cb 100644 --- a/WebContent/html/webpages/userLogin.jsp +++ b/WebContent/html/webpages/userLogin.jsp @@ -70,24 +70,42 @@ Class.forName("com.mysql.jdbc.Driver"); String database = "jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317"; String user = "b372dfe7409692"; String password = "74f6e317"; -Connection connection = DriverManager.getConnection(database, user, password); -Statement stmt = connection.createStatement(); +Connection connection; +Statement stmt; +for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } +} +for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } +} ResultSet result; result = stmt.executeQuery("select * FROM employee where Employee_ID='" + ssoNum + "'"); if (result.next()){ request.getSession(); session.setAttribute("ssoNum", ssoNum); - userCookie = new Cookie("ssoNum", Integer.toString(ssoNum)); - userCookie.setMaxAge(30*60); - userCookie.setPath("/"); - response.addCookie(userCookie); newCookie = new Cookie("name",result.getString("Name")); + stmt.close(); + connection.close(); newCookie.setMaxAge(30*60); newCookie.setPath("/"); response.addCookie(newCookie); - stmt.close(); - connection.close(); + userCookie = new Cookie("ssoNum", Integer.toString(ssoNum)); + userCookie.setMaxAge(30*60); + userCookie.setPath("/"); + response.addCookie(userCookie); response.sendRedirect("index.jsp"); } connection.close(); diff --git a/src/database/AdminQueries.java b/src/database/AdminQueries.java index 4a7f3a3..5a3a364 100644 --- a/src/database/AdminQueries.java +++ b/src/database/AdminQueries.java @@ -8,11 +8,29 @@ public class AdminQueries { private static String user = "b372dfe7409692"; private static String password = "74f6e317"; - public static boolean isAdmin(int id) throws ClassNotFoundException, SQLException{ + public static boolean isAdmin(int id) throws ClassNotFoundException, SQLException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } ResultSet results = stmt.executeQuery("SELECT * from admin WHERE Admin_ID = " + id); results.next(); return true; diff --git a/src/database/DeviceQueries.java b/src/database/DeviceQueries.java index 1254712..6281521 100644 --- a/src/database/DeviceQueries.java +++ b/src/database/DeviceQueries.java @@ -10,11 +10,30 @@ public class DeviceQueries { private static String user = "b372dfe7409692"; private static String password = "74f6e317"; - public static Device[] getUserDevices(String userID) throws SQLException, ClassNotFoundException{ + public static Device[] getUserDevices(String userID) throws SQLException, ClassNotFoundException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + ResultSet resultSet = stmt.executeQuery("SELECT * FROM devices WHERE Renter = " + userID + " AND Status <> \"Available\" AND Status <> \"Returning \""); int counter = 0; @@ -50,22 +69,41 @@ public static Device[] getUserDevices(String userID) throws SQLException, ClassN return devices; } - public static Device[] getAllDevices() throws SQLException, ClassNotFoundException{ + public static Device[] getAllDevices() throws SQLException, ClassNotFoundException, InterruptedException{ //database connect System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + ResultSet resultSet = stmt.executeQuery("SELECT * FROM devices"); int counter = 0; resultSet.last(); int rows = resultSet.getRow(); resultSet.beforeFirst(); - + //Covers amount of rows, and 6 attributes (indices 0-5) Device[] devices = new Device[rows]; - + //iterate result set while(resultSet.next()){ devices[counter] = new Device( @@ -91,12 +129,31 @@ public static Device[] getAllDevices() throws SQLException, ClassNotFoundExcepti return devices; } - public static Device[] getAvailableDevices() throws SQLException, ClassNotFoundException{ + public static Device[] getAvailableDevices() throws SQLException, ClassNotFoundException, InterruptedException{ //database connect System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + ResultSet resultSet = stmt.executeQuery("SELECT * FROM devices WHERE Status = \"Available\""); int counter = 0; @@ -139,13 +196,32 @@ public static Device[] getAvailableDevices() throws SQLException, ClassNotFoundE * @param devices * @throws ClassNotFoundException * @throws SQLException + * @throws InterruptedException */ - public static void returnDevices(String devices) throws ClassNotFoundException, SQLException{ + public static void returnDevices(String devices) throws ClassNotFoundException, SQLException, InterruptedException{ //connect to DB System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } //make into string array; queries need to have numbers as strings! String[] deviceArray = devices.replaceAll("\\[","").replaceAll("\\]","").replaceAll("\\s","").split(","); for(int i = 0; i < deviceArray.length; i++){ @@ -156,11 +232,29 @@ public static void returnDevices(String devices) throws ClassNotFoundException, connection.close(); } - public static void addDevice(Device device) throws SQLException, ClassNotFoundException{ + public static void addDevice(Device device) throws SQLException, ClassNotFoundException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } int i = -1; int id=0; @@ -179,21 +273,57 @@ public static void addDevice(Device device) throws SQLException, ClassNotFoundEx connection.close(); } - public static void modifyDevice(Device device) throws ClassNotFoundException, SQLException{ + public static void modifyDevice(Device device) throws ClassNotFoundException, SQLException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } stmt.executeUpdate("UPDATE devices SET Device_Name = \"" + device.getName() + "\", Device_Description = \"" + device.getDesc() + "\", MAC_Address = \"" + device.getMAC() + "\", Manufacturer = \"" + device.getManufacturer() + "\", Hardware = \"" + device.getHardware() + "\", Model = \"" + device.getModel() + "\", Serial_Num = \"" + device.getSerial() + "\", Status = \"" + device.getStatus() + "\", NFC_ID = \"" + device.getNFC() + "\", Admin_Comments = \"" + device.getComment() + "\", Operating_System = \"" + device.getOS() + "\", Locker_Position = \"" + device.getPos() + "\" WHERE Device_ID = " + device.getID()); stmt.close(); connection.close(); } - public static void deleteDevice(int id) throws ClassNotFoundException, SQLException{ + public static void deleteDevice(int id) throws ClassNotFoundException, SQLException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } stmt.executeUpdate("DELETE from devices WHERE Device_ID = " + id); stmt.close(); connection.close(); diff --git a/src/database/EmployeeQueries.java b/src/database/EmployeeQueries.java index 3ddb5e0..53cbd25 100644 --- a/src/database/EmployeeQueries.java +++ b/src/database/EmployeeQueries.java @@ -10,34 +10,91 @@ public class EmployeeQueries { private static String user = "b372dfe7409692"; private static String password = "74f6e317"; - public static void initializeEmployee(int id) throws ClassNotFoundException, SQLException + public static void initializeEmployee(int id) + throws ClassNotFoundException, SQLException, InterruptedException { System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } stmt.executeUpdate("INSERT INTO employee (Employee_ID) VALUES ("+id+");"); stmt.close(); connection.close(); } - public static void addEmployee(String sso, String loc, String name, String ph, String email) throws SQLException, ClassNotFoundException{ + public static void addEmployee(String sso, String loc, String name, String ph, String email) + throws SQLException, ClassNotFoundException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } stmt.executeUpdate("INSERT INTO employee (Employee_ID,Location_ID,Name,Phone_Number,Email) VALUES ("+Integer.parseInt(sso)+", " + Integer.parseInt(loc) + ", \"" + name + "\", \"" + ph + "\", \"" + email + "\");"); stmt.close(); connection.close(); } - public static void updateEmployee(int id, String name, String phone, int location, String email) throws ClassNotFoundException, SQLException + public static void updateEmployee(int id, String name, String phone, int location, String email) + throws ClassNotFoundException, SQLException, InterruptedException { System.out.println("Updating employee "+id+": "+name+".\nPhone: "+phone+", location: "+location); System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } String query = ""; query+="UPDATE employee SET "; query+="Name='"+name; @@ -51,12 +108,31 @@ public static void updateEmployee(int id, String name, String phone, int locatio connection.close(); } - public static void updateEmployee(int id, String name, int icon, String phone, String email) throws ClassNotFoundException, SQLException + public static void updateEmployee(int id, String name, int icon, String phone, String email) + throws ClassNotFoundException, SQLException, InterruptedException { System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } System.out.println("Updating employee "+id+": "+name+".\nPhone: "+phone+", icon: "+icon+", email: "+email); String query = ""; query+="UPDATE employee SET "; @@ -71,12 +147,30 @@ public static void updateEmployee(int id, String name, int icon, String phone, S connection.close(); } - public static User getEmployeeByID(int id) throws ClassNotFoundException, SQLException + public static User getEmployeeByID(int id) throws ClassNotFoundException, SQLException, InterruptedException { System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } ResultSet resultSet = stmt.executeQuery("Select * FROM employee WHERE Employee_ID = "+id); resultSet.next(); User employee = new User( @@ -95,12 +189,30 @@ public static User getEmployeeByID(int id) throws ClassNotFoundException, SQLExc return employee; } - public static User[] getAllUsers() throws SQLException, ClassNotFoundException{ + public static User[] getAllUsers() throws SQLException, ClassNotFoundException, InterruptedException{ //database connect System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } ResultSet resultSet = stmt.executeQuery("SELECT * FROM employee"); int counter = 0; diff --git a/src/database/LocationQueries.java b/src/database/LocationQueries.java index 3370ba3..db96484 100644 --- a/src/database/LocationQueries.java +++ b/src/database/LocationQueries.java @@ -10,12 +10,30 @@ public class LocationQueries { private static String user = "b372dfe7409692"; private static String password = "74f6e317"; - public static int locationStringToInt(String locString) throws SQLException, ClassNotFoundException + public static int locationStringToInt(String locString) throws SQLException, ClassNotFoundException, InterruptedException { System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } ResultSet resultSet = stmt.executeQuery("SELECT Location_ID FROM location WHERE Address = '"+locString+"'"); resultSet.next(); int returnResult = resultSet.getInt("Location_ID"); @@ -24,12 +42,30 @@ public static int locationStringToInt(String locString) throws SQLException, Cla return returnResult; } - public static String locationIntToString(int locInt) throws ClassNotFoundException, SQLException + public static String locationIntToString(int locInt) throws ClassNotFoundException, SQLException, InterruptedException { System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } ResultSet resultSet = stmt.executeQuery("SELECT Address FROM location WHERE Location_ID = "+locInt); resultSet.next(); String returnResult = resultSet.getString("Address"); @@ -39,12 +75,30 @@ public static String locationIntToString(int locInt) throws ClassNotFoundExcepti } // returns ID of new location - public static int addLocation(Location location) throws SQLException, ClassNotFoundException + public static int addLocation(Location location) throws SQLException, ClassNotFoundException, InterruptedException { System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } int i = -1; int id=0; while(i <= 0){ @@ -61,13 +115,31 @@ public static int addLocation(Location location) throws SQLException, ClassNotFo return id; } - public static Location[] getAdminLocations() throws ClassNotFoundException, SQLException{ + public static Location[] getAdminLocations() throws ClassNotFoundException, SQLException, InterruptedException{ //database connect System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); - ResultSet resultSet = stmt.executeQuery("SELECT * FROM location WHERE Employee_Flag = 0"); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + ResultSet resultSet = stmt.executeQuery("SELECT * FROM location WHERE Employee_Flag = 0 ORDER BY Location_ID"); int counter = 0; resultSet.last(); @@ -88,26 +160,74 @@ public static Location[] getAdminLocations() throws ClassNotFoundException, SQLE resultSet.getString("Zip_Code"), resultSet.getInt("Employee_Flag"), resultSet.getString("Latitude"), - resultSet.getString("Longitude") + resultSet.getString("Longitude"), + 0,0 ); counter++; } + resultSet = stmt.executeQuery("SELECT location.location_id, count(*) AS 'count' FROM location JOIN devices ON devices.location = location.location_id WHERE employee_flag = 0 group by location.Location_ID ORDER BY location.Location_ID"); + resultSet.last(); + rows = resultSet.getRow(); + resultSet.beforeFirst(); + resultSet.next(); + int i = 0; + int j = 0; + while(i < rows){ + if(resultSet.getInt("location_id") == locations[j].getID()){ + locations[i].setNumDevices(resultSet.getInt("count")); + resultSet.next(); + i++; + } + j++; + } + resultSet = stmt.executeQuery("SELECT location.location_id, count(*) AS 'count' FROM location JOIN employee ON employee.location_id = location.location_id WHERE employee_flag = 0 group by location.Location_ID ORDER BY location.Location_ID"); + resultSet.last(); + rows = resultSet.getRow(); + resultSet.beforeFirst(); + resultSet.next(); + i = 0;j = 0; + while(i < rows){ + if(resultSet.getInt("location_id") == locations[j].getID()){ + locations[i].setNumEmployees(resultSet.getInt("count")); + resultSet.next(); + i++; + } + j++; + } stmt.close(); connection.close(); return locations; } - public static Location[] getLocations() throws ClassNotFoundException, SQLException{ + public static Location[] getLocations() throws ClassNotFoundException, SQLException, InterruptedException{ return getLocations(0); } - public static Location[] getLocations(int userID) throws SQLException, ClassNotFoundException + public static Location[] getLocations(int userID) throws SQLException, ClassNotFoundException, InterruptedException { String query = "SELECT * FROM location WHERE Employee_Flag = 0 OR Employee_Flag = "+userID+" ORDER BY Name ASC"; System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } ResultSet rs = stmt.executeQuery("SELECT COUNT(Location_ID) FROM location WHERE Employee_Flag = 0 OR Employee_Flag = "+userID); rs.next(); Location[] locations = new Location[rs.getInt("COUNT(Location_ID)")]; @@ -124,7 +244,8 @@ public static Location[] getLocations(int userID) throws SQLException, ClassNotF rs.getString("Zip_Code"), rs.getInt("Employee_Flag"), rs.getString("Latitude"), - rs.getString("Longitude") + rs.getString("Longitude"), + 0,0 ); i++; } @@ -138,15 +259,34 @@ public static Location[] getLocations(int userID) throws SQLException, ClassNotF * @param location * @throws ClassNotFoundException * @throws SQLException + * @throws InterruptedException */ - public static void modifyLocation(Location location) throws ClassNotFoundException, SQLException{ + public static void modifyLocation(Location location) throws ClassNotFoundException, SQLException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317"); - Statement stmt = connect.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } stmt.executeUpdate("UPDATE location SET Name = \"" + location.getName() + "\", Address = \"" + location.getAddress() + "\", Town = \"" + location.getTown() + "\", State = \"" + location.getState() + "\", Zip_Code = \"" + location.getZip() + "\", Latitude = \"" + location.getLat() + "\", Longitude = \"" + location.getLng() + "\" WHERE Location_ID = " + location.getID()); stmt.close(); - connect.close(); + connection.close(); } /** @@ -154,30 +294,67 @@ public static void modifyLocation(Location location) throws ClassNotFoundExcepti * @param id * @throws ClassNotFoundException * @throws SQLException + * @throws InterruptedException */ - public static int deleteLocation(int id) throws ClassNotFoundException, SQLException{ + public static int deleteLocation(int id) throws ClassNotFoundException, SQLException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317"); - Statement stmt = connect.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } try { stmt.executeUpdate("DELETE from location WHERE Location_ID = " + id); } catch (SQLException e) { stmt.close(); - connect.close(); + connection.close(); return -1; } stmt.close(); - connect.close(); + connection.close(); return 0; } - public static Location[] getAllLocations() throws SQLException, ClassNotFoundException{ + public static Location[] getAllLocations() throws SQLException, ClassNotFoundException, InterruptedException{ //database connect System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } ResultSet resultSet = stmt.executeQuery("SELECT * FROM location"); int counter = 0; @@ -199,7 +376,8 @@ public static Location[] getAllLocations() throws SQLException, ClassNotFoundExc resultSet.getString("Zip_Code"), resultSet.getInt("Employee_Flag"), resultSet.getString("Latitude"), - resultSet.getString("Longitude") + resultSet.getString("Longitude"), + 0,0 ); counter++; } @@ -208,36 +386,4 @@ public static Location[] getAllLocations() throws SQLException, ClassNotFoundExc connection.close(); return locations; } - - /** - * This method returns the number of devices at a given location - * @return - * @throws ClassNotFoundException - * @throws SQLException - */ - public static int numberDevices(int id) throws ClassNotFoundException, SQLException{ - System.getenv("VCAP_SERVICES"); - Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); - ResultSet resultSet = stmt.executeQuery("SELECT COUNT(*) FROM devices WHERE Location = " + id ); - resultSet.next(); - int num = resultSet.getInt(1); - stmt.close(); - connection.close(); - return num; - } - - public static int numberEmployees(int id) throws ClassNotFoundException, SQLException{ - System.getenv("VCAP_SERVICES"); - Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); - ResultSet resultSet = stmt.executeQuery("SELECT COUNT(*) FROM employee WHERE Location_ID = " + id ); - resultSet.next(); - int num = resultSet.getInt(1); - stmt.close(); - connection.close(); - return num; - } } \ No newline at end of file diff --git a/src/database/StatisticsQueries.java b/src/database/StatisticsQueries.java index 289252d..b373d58 100644 --- a/src/database/StatisticsQueries.java +++ b/src/database/StatisticsQueries.java @@ -8,12 +8,31 @@ public class StatisticsQueries { private static String user = "b372dfe7409692"; private static String password = "74f6e317"; - public static Statistics[] getStatistics() throws ClassNotFoundException, SQLException { + public static Statistics[] getStatistics() + throws ClassNotFoundException, SQLException, InterruptedException { //database connect System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } ResultSet resultSet = stmt.executeQuery("SELECT Status, count(*) FROM devices GROUP BY Status"); int counter = 0; diff --git a/src/database/TicketQueries.java b/src/database/TicketQueries.java index ddbf298..29e8cca 100644 --- a/src/database/TicketQueries.java +++ b/src/database/TicketQueries.java @@ -11,17 +11,36 @@ public class TicketQueries { private static String user = "b372dfe7409692"; private static String password = "74f6e317"; - public static int generateTicket(int requester, int location, int device, String returnDate) throws ClassNotFoundException, SQLException + public static int generateTicket(int requester, int location, int device, String returnDate, int perm) + throws ClassNotFoundException, SQLException, InterruptedException { long time = new Date().getTime(); //Using milliseconds because sql is annoying with dates. int ticketID = (int)((time+requester+device+location)%10000); String stat = "Requested"; System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } String query = ""; - query+="INSERT INTO ticket (Ticket_ID, Requestor, Request_Date, Location, Device_ID, Status, Status_Date_Fields, Return_Date) "; + query+="INSERT INTO ticket (Ticket_ID, Requestor, Request_Date, Location, Device_ID, Status, Status_Date_Fields, Return_Date, Permanent_Order) "; query+="VALUES ("; query+= ticketID +", "; query+= requester +", "; @@ -29,8 +48,9 @@ public static int generateTicket(int requester, int location, int device, String query+= location +", "; query+= device +", "; query+= "'"+stat+"'" +", "; - query+= "'"+time+"'" +","; - query+= "'"+returnDate+"'" +");"; + query+= "'"+time+"'" +", "; + query+= "'"+returnDate+"'" + ", "; + query+= perm + ");"; System.out.println(query); stmt.executeUpdate(query); stmt.close(); @@ -39,134 +59,246 @@ public static int generateTicket(int requester, int location, int device, String } //get all tickets - public static Ticket[] getTickets() throws SQLException, ClassNotFoundException{ - int i = 0; - System.getenv("VCAP_SERVICES"); - Class.forName("com.mysql.jdbc.Driver"); - Connection connection = DriverManager.getConnection(database, user, password); - Statement stmt = connection.createStatement(); - ResultSet resultSet = stmt.executeQuery("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 = 'Requested'"); - - resultSet.last(); - int rows = resultSet.getRow(); - resultSet.beforeFirst(); - Ticket[] tickets = new Ticket[rows]; + public static Ticket[] getTickets() + throws SQLException, ClassNotFoundException, InterruptedException{ + int i = 0; + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + ResultSet resultSet = stmt.executeQuery("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 = 'Requested'"); + resultSet.last(); + int rows = resultSet.getRow(); + resultSet.beforeFirst(); + Ticket[] tickets = new Ticket[rows]; - while(resultSet.next()){ - tickets[i] = new Ticket( - resultSet.getInt("Ticket_ID"), - resultSet.getInt("Requestor"), - resultSet.getLong("Request_Date"), - resultSet.getInt("Location"), - resultSet.getInt("Device_ID"), - "Requested", - resultSet.getLong("Status_Date_Fields"), - resultSet.getString("Return_Date"), - resultSet.getString("username"), - resultSet.getString("Device_Name"), - resultSet.getString("locationname") - ); - i++; - } - stmt.close(); - connection.close(); - return tickets; + while(resultSet.next()){ + tickets[i] = new Ticket( + resultSet.getInt("Ticket_ID"), + resultSet.getInt("Requestor"), + resultSet.getLong("Request_Date"), + resultSet.getInt("Location"), + resultSet.getInt("Device_ID"), + "Requested", + resultSet.getLong("Status_Date_Fields"), + resultSet.getString("Return_Date"), + resultSet.getString("username"), + resultSet.getString("Device_Name"), + resultSet.getString("locationname") + ); + i++; } + stmt.close(); + connection.close(); + return tickets; + } - public static void acceptTicket(int ticketid, int deviceid, int locationid, int sso) throws SQLException, ClassNotFoundException{ - System.getenv("VCAP_SERVICES"); - Class.forName("com.mysql.jdbc.Driver"); - Connection connect = DriverManager.getConnection(database, user, password); - Statement stmt = connect.createStatement(); - long milliseconds = new java.util.Date().getTime(); - 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); - - stmt.close(); - connect.close(); + public static void acceptTicket(int ticketid, int deviceid, int locationid, int sso) + throws SQLException, ClassNotFoundException, InterruptedException{ + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + long milliseconds = new java.util.Date().getTime(); + String query = "UPDATE ticket, devices SET ticket.Status = \"Approved\"" + +", ticket.Status_Date_Fields = " + milliseconds + +", devices.Ticket_ID = " + ticketid + +", devices.Status = \"Ready to Ship\", 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); + + stmt.close(); + connection.close(); + } - public static void rejectTicket(int id) throws SQLException, ClassNotFoundException{ - System.getenv("VCAP_SERVICES"); - Class.forName("com.mysql.jdbc.Driver"); - Connection connect = DriverManager.getConnection(database, user, password); - Statement stmt = connect.createStatement(); - stmt.executeUpdate("UPDATE ticket SET Status = \"Rejected\" WHERE Ticket_ID = " + id); - stmt.close(); - connect.close(); + public static void rejectTicket(int id) + throws SQLException, ClassNotFoundException, InterruptedException{ + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + stmt.executeUpdate("UPDATE ticket SET Status = \"Rejected\" WHERE Ticket_ID = " + id); + stmt.close(); + connection.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(); - stmt.close(); - connect.close(); - return results.getLong("MAX(Status_Date_Fields)"); - } - // Returns all tickets approved since 'millieconds' and associated with 'employee' - 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; - System.out.println("Executing query '"+query+"'"); - ResultSet results = stmt.executeQuery(query); - results.last(); - int rows = results.getRow(); - results.beforeFirst(); - Ticket[] tickets = new Ticket[rows]; - int i=0; - while(results.next()) - { - tickets[i]=new Ticket( results.getInt("Ticket_ID"), - results.getInt("Requestor"), - results.getLong("Request_Date"), - results.getInt("Location"), - results.getInt("Device_ID"), - results.getString("Status"), - results.getLong("Status_Date_Fields"), - results.getString("Return_Date"), - results.getString("username"), - results.getString("locationname"), - results.getString("Device_Name") - ); - i++; - } - stmt.close(); - connect.close(); - return tickets; - } - public static int getUserID(int ticketID) throws ClassNotFoundException, SQLException{ - System.getenv("VCAP_SERVICES"); - Class.forName("com.mysql.jdbc.Driver"); - Connection connect = DriverManager.getConnection(database, user, password); - Statement stmt = connect.createStatement(); - String query = "SELECT Requestor FROM ticket WHERE Ticket_ID = "+ticketID+";"; - ResultSet results = stmt.executeQuery(query); - results.next(); - int answer = results.getInt("Requestor"); - stmt.close(); - connect.close(); - return answer; + // 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, InterruptedException{ + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + 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(); + stmt.close(); + connection.close(); + return results.getLong("MAX(Status_Date_Fields)"); + } + // Returns all tickets approved since 'millieconds' and associated with 'employee' + public static Ticket[] getRecentApprovedTickets(int userID, long milliseconds) + throws SQLException, ClassNotFoundException, InterruptedException { + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + 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(); + results.beforeFirst(); + Ticket[] tickets = new Ticket[rows]; + int i=0; + while(results.next()) + { + tickets[i]=new Ticket( results.getInt("Ticket_ID"), + results.getInt("Requestor"), + results.getLong("Request_Date"), + results.getInt("Location"), + results.getInt("Device_ID"), + results.getString("Status"), + results.getLong("Status_Date_Fields"), + results.getString("Return_Date"), + results.getString("username"), + results.getString("locationname"), + results.getString("Device_Name") + ); + i++; + } + stmt.close(); + connection.close(); + return tickets; + } + public static int getUserID(int ticketID) throws ClassNotFoundException, SQLException, InterruptedException{ + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + String query = "SELECT Requestor FROM ticket WHERE Ticket_ID = "+ticketID+";"; + ResultSet results = stmt.executeQuery(query); + results.next(); + int answer = results.getInt("Requestor"); + stmt.close(); + connection.close(); + return answer; + } } diff --git a/src/entities/ListedDevice.java b/src/entities/ListedDevice.java deleted file mode 100644 index 8352c29..0000000 --- a/src/entities/ListedDevice.java +++ /dev/null @@ -1,59 +0,0 @@ -package entities; -/** - * Simple Modification of the RentedDevice class for use in the listed devices page. - * @author John Costa III - * - */ -public class ListedDevice { - private String Device_Name; - private String Device_ID; - private String Device_Description; - private String Hardware; - private String Model; - private String Manu; - private String Status; - public ListedDevice(String name, String id, String desc, String hardware, String model, String manufacturer, String available) { - Device_ID = id; - Device_Name = name; - Device_Description = desc; - Hardware = hardware; - Model = model; - Manu = manufacturer; - Status = available; - } - /** - * Formatting the device to fit a JSON object. - * @author - Connor - */ - public String toString(){ - StringBuilder sb = new StringBuilder(); - String comma = ", "; - sb.append("{\"name\": \"").append(Device_Name).append("\"").append(comma); - sb.append("\"id\": \"").append(Device_ID).append("\"").append(comma); - sb.append("\"description\": \"").append(Device_Description).append("\"").append(comma); - sb.append("\"hardware\": \"").append(Hardware).append("\"").append(comma); - sb.append("\"status\": \"").append(Status).append("\"").append(comma); - sb.append("\"model\": \"").append(Model).append("\"").append(comma); - sb.append("\"manufacturer\": \"").append(Manu).append("\""); - sb.append("}"); - return sb.toString(); - } - /** - * This is a static function which will turn a Listed Device array into its proper string. (modification) - * @author - Connor - * @param array - * @return - */ - public static String arrayToString(ListedDevice[] array){ - StringBuilder sb = new StringBuilder(); - sb.append("["); - for(int i = 0; i < array.length; i++){ - sb.append(array[i].toString()); - if(i+1 != array.length){ - sb.append(","); - } - } - sb.append("]"); - return sb.toString(); - } -} diff --git a/src/entities/Location.java b/src/entities/Location.java index dbd0960..f117838 100644 --- a/src/entities/Location.java +++ b/src/entities/Location.java @@ -2,8 +2,6 @@ import java.sql.SQLException; -import database.LocationQueries; - /** * Representation of locations from database. * @author conno @@ -26,6 +24,7 @@ public class Location { * Constructor for location bean. * @throws SQLException * @throws ClassNotFoundException + * @throws InterruptedException */ public Location( int id, @@ -36,16 +35,18 @@ public Location( String zip, int flag, String lat, - String lng - ) throws ClassNotFoundException, SQLException{ + String lng, + int numDevice, + int numEmployee + ){ this.id = id; this.name = name; this.address = address; this.town = town; this.state = state; this.zip = zip; - this.numDevices = LocationQueries.numberDevices(id); - this.numEmployees = LocationQueries.numberEmployees(id); + this.numDevices = numDevice; + this.numEmployees = numEmployee; this.employee_flag = flag; this.lat = lat; this.lng = lng; @@ -128,4 +129,12 @@ public String getLat(){ public String getLng(){ return lng; } + + public void setNumDevices(int num){ + this.numDevices = num; + } + + public void setNumEmployees(int num){ + this.numEmployees = num; + } } diff --git a/src/entities/RentedDevice.java b/src/entities/RentedDevice.java deleted file mode 100644 index 2382fd7..0000000 --- a/src/entities/RentedDevice.java +++ /dev/null @@ -1,86 +0,0 @@ -package entities; - -/** - * Will support querying devices a certain user has rented out. - * @author conno - * - */ -public class RentedDevice { - private String Device_ID; - private String Device_Name; - private String Device_Description; - private String Ticket_ID; - //Smartphone, tablet, etc. - private String Hardware; - //iPhone, Galaxy S5, etc. - private String Model; - private String Borrow_Date; - - public RentedDevice(String id, String name, String desc, String ticketid, String hardware, String model, String date){ - Device_ID = id; - Device_Name = name; - Device_Description = desc; - Ticket_ID = ticketid; - Hardware = hardware; - Model = model; - Borrow_Date = date; - } -/** - * Formatting the device to fit a JSON object. - */ - public String toString(){ - StringBuilder sb = new StringBuilder(); - String comma = ", "; - sb.append("{\"id\": ").append(Device_ID).append(comma); - sb.append("\"name\": \"").append(Device_Name).append("\"").append(comma); - sb.append("\"description\": \"").append(Device_Description).append("\"").append(comma); - sb.append("\"ticket\": \"").append(Ticket_ID).append("\"").append(comma); - sb.append("\"hardware\": \"").append(Hardware).append("\"").append(comma); - sb.append("\"model\": \"").append(Model).append("\"").append(comma); - sb.append("\"checkout\": \"").append(Borrow_Date).append("\""); - sb.append("}"); - return sb.toString(); - } - - /** - * This is a static function which will turn a Rented Device array into its proper string. - * @param array - * @return - */ - public static String arrayToString(RentedDevice[] array){ - StringBuilder sb = new StringBuilder(); - sb.append("["); - for(int i = 0; i < array.length; i++){ - sb.append(array[i].toString()); - if(i+1 != array.length){ - sb.append(","); - } - } - sb.append("]"); - return sb.toString(); - } - - public String getID(){ - return Device_ID; - } - - public String getName(){ - return Device_Name; - } - - public String getDesc(){ - return Device_Description; - } - - public String getTicketID(){ - return Ticket_ID; - } - - public String getModel(){ - return Model; - } - - public String getHardware(){ - return Hardware; - } -} \ No newline at end of file From 7e61ec86140bfd941181d6d0c637c4c9a0d9a6be Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Thu, 20 Apr 2017 21:23:24 -0400 Subject: [PATCH 18/43] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8ee797b..bf30d82 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ -# [Synchrony Financial Mobile Device Tracking System](https://seniordesign.cfapps.io/html/webpages/) +# [Innovation Hub](https://seniordesign.cfapps.io/html/webpages/) In the Innovation Station at Synchrony Financial, applications are used by over 60 million cardholders across the US, and those customers use a huge variety of devices to access them. To make sure applications work on all devices they house hundreds of smart phones, tablets, and other connected devices to test with. The devices are lent to employees across the country for their individual testing needs. The goal of this project is to build and design an application that allows employees to view a list of available devices, allow employees to request one of those devices, and for it to be shipped for their testing needs. The current goal of this project is to design this as a Java web application that will work proficiently on phones and desktops. Team member on this project include: -* Brianna Boyce +* Connor Jackson * Adam Claxton +* Brianna Boyce * John Costa * Maegan Dyakiw -* Connor Jackson + From 49c6fbf127dfae8074d42078a227b2f0fc87e169 Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Thu, 20 Apr 2017 21:35:20 -0400 Subject: [PATCH 19/43] Obliterating Rented Device --- WebContent/html/webpages/redirect/orderFormHandler.jsp | 3 +-- WebContent/html/webpages/returnComplete.jsp | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/WebContent/html/webpages/redirect/orderFormHandler.jsp b/WebContent/html/webpages/redirect/orderFormHandler.jsp index 08ac232..b2c680a 100644 --- a/WebContent/html/webpages/redirect/orderFormHandler.jsp +++ b/WebContent/html/webpages/redirect/orderFormHandler.jsp @@ -32,8 +32,7 @@ if(Integer.parseInt(request.getParameter("location_dropdown"))==0) request.getParameter("state"), request.getParameter("zip"), Integer.parseInt(navsso), - "", - "") + "","",0,0) ); } diff --git a/WebContent/html/webpages/returnComplete.jsp b/WebContent/html/webpages/returnComplete.jsp index 5d42fb0..6133e6c 100644 --- a/WebContent/html/webpages/returnComplete.jsp +++ b/WebContent/html/webpages/returnComplete.jsp @@ -1,4 +1,4 @@ -<%@ page import = "database.*,entities.RentedDevice" %> +<%@ page import = "database.*" %> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> @@ -37,8 +37,8 @@
<% //get string from request form -//String devices = request.getParameter("devicesToReturn"); -//DeviceQueries.returnDevices(devices); +String devices = request.getParameter("devicesToReturn"); +DeviceQueries.returnDevices(devices); %> \ No newline at end of file From 684f0040ae0602b299732f25bea851cd33165add Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Fri, 21 Apr 2017 00:24:46 -0400 Subject: [PATCH 20/43] I have learned to hate JSON. Goodnight. --- .../webpages/administration/adminApprove.jsp | 8 ++- .../webpages/administration/ticketApprove.jsp | 66 +++++++++++++++++++ .../webpages/redirect/locationRedirect.jsp | 4 +- .../webpages/redirect/orderFormHandler.jsp | 12 ++-- .../webpages/redirect/ticketAdminRedirect.jsp | 19 +++--- src/database/LocationQueries.java | 40 +++++++++++ src/database/TicketQueries.java | 9 ++- src/entities/Ticket.java | 8 ++- src/utilities/NotificationQueue.java | 2 +- 9 files changed, 146 insertions(+), 22 deletions(-) create mode 100644 WebContent/html/webpages/administration/ticketApprove.jsp diff --git a/WebContent/html/webpages/administration/adminApprove.jsp b/WebContent/html/webpages/administration/adminApprove.jsp index e144f39..1820d59 100644 --- a/WebContent/html/webpages/administration/adminApprove.jsp +++ b/WebContent/html/webpages/administration/adminApprove.jsp @@ -107,6 +107,7 @@ Location Name Device Name Status + Permanent? Return Date @@ -118,6 +119,7 @@ +
@@ -133,6 +135,7 @@ Location Name Device Name Status + Permanent? Return Date @@ -167,18 +170,19 @@ var html = ""; for(var i = 0; i < tickets.length; i++){ //NEED TO ADD IN RETURN DATE AT END BUT THAT WOULD BREAK THINGS AT THE MOMENT - html += "" + tickets[i].id + "" + tickets[i].username + "" + tickets[i].locationname + "" + tickets[i].devicename + "" + tickets[i].status + "" + tickets[i].return + ""; + html += "" + tickets[i].id + "" + tickets[i].username + "" + tickets[i].locationname + "" + tickets[i].devicename + "" + tickets[i].status + "" + tickets[i].permanent + "" + tickets[i].return + ""; } document.getElementById("tablebodymain").innerHTML = html; } function ticketAction(){ var id = this.id; - var html = "" + tickets[id].id + "" + tickets[id].username + "" + tickets[id].locationname + "" + tickets[id].devicename + "" + tickets[id].status + "" + tickets[id].return + ""; + var html = "" + tickets[id].id + "" + tickets[id].username + "" + tickets[id].locationname + "" + tickets[id].devicename + "" + tickets[id].status + "" + tickets[id].permanent + "" + tickets[id].return + ""; document.getElementById("tablemodal").innerHTML = html; $("#ticketIDfield").val(tickets[id].id); $("#deviceIDfield").val(tickets[id].deviceID); $("#locationIDfield").val(tickets[id].location); + $("#permField").val(tickets[id].permanent); $("#Modal").show(); } diff --git a/WebContent/html/webpages/administration/ticketApprove.jsp b/WebContent/html/webpages/administration/ticketApprove.jsp new file mode 100644 index 0000000..7b35f4c --- /dev/null +++ b/WebContent/html/webpages/administration/ticketApprove.jsp @@ -0,0 +1,66 @@ +<%@ page import = "database.*,entities.Location" %> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + + + + + + + + Innovation Hub + + + + + + + + + + + +
+

Approving Tickets

+

Thanks for approving a ticket!

+

You can ship the devices to the following address:

+
+ Synchrony Financial

+
+
+ +
+
+ +<% +int locationid = -1; +for(Cookie c : usercookies){ + if(c.getName().equals("location")){ + locationid = Integer.parseInt(c.getValue()); + c.setMaxAge(0); + c.setPath("/"); + response.addCookie(c); + } +} +Location location = LocationQueries.getLocationByID(locationid); +String address = location.getAddress(); +String town = location.getTown(); +String state = location.getState(); +String zip = location.getZip(); +%> + + \ No newline at end of file diff --git a/WebContent/html/webpages/redirect/locationRedirect.jsp b/WebContent/html/webpages/redirect/locationRedirect.jsp index 8700f23..9c80f3d 100644 --- a/WebContent/html/webpages/redirect/locationRedirect.jsp +++ b/WebContent/html/webpages/redirect/locationRedirect.jsp @@ -37,7 +37,7 @@ String lng = request.getParameter("lng"); int er = 0; //add form was submitted if(request.getParameter("add") != null){ - Location location = new Location(0,name,address,town,state,zip,0,lat,lng); + Location location = new Location(0,name,address,town,state,zip,0,lat,lng,0,0); LocationQueries.addLocation(location); } //modify form was submitted @@ -46,7 +46,7 @@ if(request.getParameter("modify") != null){ String strID = request.getParameter("id"); //turn to int for constructor int id = Integer.parseInt(strID); - Location location = new Location(id,name,address,town,state,zip,0,lat,lng); + Location location = new Location(id,name,address,town,state,zip,0,lat,lng,0,0); LocationQueries.modifyLocation(location); } //delete form was submitted diff --git a/WebContent/html/webpages/redirect/orderFormHandler.jsp b/WebContent/html/webpages/redirect/orderFormHandler.jsp index b2c680a..aff74f9 100644 --- a/WebContent/html/webpages/redirect/orderFormHandler.jsp +++ b/WebContent/html/webpages/redirect/orderFormHandler.jsp @@ -43,11 +43,13 @@ String email = request.getParameter("email"); String[] options = request.getParameterValues("checkboxes"); int perm = 0; int urgent = 0; -for(int j = 0; j < options.length; j++){ - if(options[j].equals("perm")) - perm = 1; - if(options[j].equals("urgent")) - urgent = 1; +if(options != null){ + for(int j = 0; j < options.length; j++){ + if(options[j].equals("perm")) + perm = 1; + if(options[j].equals("urgent")) + urgent = 1; + } } // read location ID, but only if we haven't already generated it when adding new location to db if(location==-1){ location = Integer.parseInt(request.getParameter("location_dropdown"));} diff --git a/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp b/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp index e85a30f..2ab57a0 100644 --- a/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp +++ b/WebContent/html/webpages/redirect/ticketAdminRedirect.jsp @@ -23,27 +23,32 @@ -

Redirect Page

-

You shouldn't be seeing this page :)

- <% //make instance String ticketidstr = request.getParameter("ticketid"); String deviceidstr = request.getParameter("deviceid"); String locationidstr = request.getParameter("locationid"); +String permanent = request.getParameter("permField"); int ticketid = Integer.parseInt(ticketidstr); int deviceid = Integer.parseInt(deviceidstr); int locationid = Integer.parseInt(locationidstr); +int perm = permanent.equals("Yes") ? 1 : 0; //approve form was submitted if(request.getParameter("approve") != null){ - TicketQueries.acceptTicket(ticketid,deviceid,locationid,Integer.parseInt(navsso)); + Cookie location = new Cookie("location",Integer.toString(locationid)); + location.setMaxAge(30*60); + location.setPath("/"); + response.addCookie(location); + TicketQueries.acceptTicket(ticketid,deviceid,locationid,Integer.parseInt(navsso),perm); User client = EmployeeQueries.getEmployeeByID(TicketQueries.getUserID(ticketid)); boolean notificationPreferences = (Math.floor(client.getNotificationPreferences()/2)%2==1); //The second least significant bit of notificationPreferences - the 2's place - is used for ticket approval notifications. if(notificationPreferences){ NotificationQueue q = new NotificationQueue(client,"ticketConfirmations"); q.start(); + response.sendRedirect("../administration/ticketApprove.jsp"); + return; } } //reject form was submitted @@ -55,12 +60,10 @@ if(request.getParameter("reject") != null){ if(notificationPreferences){ NotificationQueue q = new NotificationQueue(client, "ticketRejections"); q.start(); + response.sendRedirect("../administration/adminApprove.jsp"); + return; } } %> - - \ No newline at end of file diff --git a/src/database/LocationQueries.java b/src/database/LocationQueries.java index db96484..d3e5222 100644 --- a/src/database/LocationQueries.java +++ b/src/database/LocationQueries.java @@ -386,4 +386,44 @@ public static Location[] getAllLocations() throws SQLException, ClassNotFoundExc connection.close(); return locations; } + + public static Location getLocationByID(int id) throws InterruptedException, ClassNotFoundException, SQLException{ + //database connect + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + ResultSet resultSet = stmt.executeQuery("SELECT * FROM location WHERE Location_ID = " + id); + resultSet.next(); + return new Location( + resultSet.getInt("Location_ID"), + resultSet.getString("Name"), + resultSet.getString("Address"), + resultSet.getString("Town"), + resultSet.getString("State"), + resultSet.getString("Zip_Code"), + resultSet.getInt("Employee_Flag"), + resultSet.getString("Latitude"), + resultSet.getString("Longitude"), + 0,0 + ); + } } \ No newline at end of file diff --git a/src/database/TicketQueries.java b/src/database/TicketQueries.java index 0f28d9e..65d29d7 100644 --- a/src/database/TicketQueries.java +++ b/src/database/TicketQueries.java @@ -102,7 +102,8 @@ public static Ticket[] getTickets() resultSet.getString("Return_Date"), resultSet.getString("username"), resultSet.getString("Device_Name"), - resultSet.getString("locationname") + resultSet.getString("locationname"), + resultSet.getInt("Permanent_Order") ); i++; } @@ -111,7 +112,7 @@ public static Ticket[] getTickets() return tickets; } - public static void acceptTicket(int ticketid, int deviceid, int locationid, int sso) + public static void acceptTicket(int ticketid, int deviceid, int locationid, int sso, int perm) throws SQLException, ClassNotFoundException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); @@ -141,6 +142,7 @@ public static void acceptTicket(int ticketid, int deviceid, int locationid, int +", devices.Ticket_ID = " + ticketid +", devices.Status = \"Ready to Ship\", devices.Renter = " + sso +", devices.Location = " + locationid + +", devices.Permanent = " + perm +" WHERE ticket.Ticket_ID = " + ticketid + " AND devices.Device_ID = " + deviceid; System.out.println("Executing query: "+query); stmt.executeUpdate(query); @@ -246,7 +248,8 @@ public static Ticket[] getRecentlyChangedTickets(int userID, String status, long results.getString("Return_Date"), results.getString("username"), results.getString("locationname"), - results.getString("Device_Name") + results.getString("Device_Name"), + results.getInt("Permanent_Order") ); i++; } diff --git a/src/entities/Ticket.java b/src/entities/Ticket.java index f66ec62..e6b1bea 100644 --- a/src/entities/Ticket.java +++ b/src/entities/Ticket.java @@ -15,8 +15,9 @@ public class Ticket { private String username; private String locationname; private String devicename; + private String permanent; - public Ticket(int id, int requestor, long requestDate, int location, int deviceId, String status, long statusDateFields, String returnDate, String username, String locationname, String devicename){ + public Ticket(int id, int requestor, long requestDate, int location, int deviceId, String status, long statusDateFields, String returnDate, String username, String locationname, String devicename, int permanent){ this._id = id; this._requestor = requestor; this._requestDate = requestDate; @@ -28,6 +29,10 @@ public Ticket(int id, int requestor, long requestDate, int location, int deviceI this.username = username; this.locationname = locationname; this.devicename = devicename; + if(permanent == 0) + this.permanent = "No"; + else + this.permanent = "Yes"; } public String toString(){ @@ -41,6 +46,7 @@ public String toString(){ sb.append("\"username\": \"").append(username).append("\"").append(comma); sb.append("\"locationname\": \"").append(locationname).append("\"").append(comma); sb.append("\"devicename\": \"").append(devicename).append("\"").append(comma); + sb.append("\"permanent\": \"").append(permanent).append("\"").append(comma); sb.append("\"return\": \"").append(_returnDate).append("\""); sb.append("}"); return sb.toString(); diff --git a/src/utilities/NotificationQueue.java b/src/utilities/NotificationQueue.java index 06bf161..62e39e0 100644 --- a/src/utilities/NotificationQueue.java +++ b/src/utilities/NotificationQueue.java @@ -99,7 +99,7 @@ private void startTicketApproveQueue(User employee) throws InterruptedException, long milliseconds = new Date().getTime()-5000; Thread.sleep(threadWaitTime); System.out.println("NotificationQueue: sending summary approval email from thread "+Thread.currentThread().getName()); - Ticket[] tickets = TicketQueries.getRecentlyChangedTickets(employee.getID(), "Shipped", milliseconds); + Ticket[] tickets = TicketQueries.getRecentlyChangedTickets(employee.getID(), "Approved", milliseconds); Mail mail = new Mail(employee); mail.sendTicketApproval(tickets); } From b9d4c8565865107ea9d7198b559b0ef0c90d7aab Mon Sep 17 00:00:00 2001 From: Adam R Claxton Date: Fri, 21 Apr 2017 01:20:36 -0400 Subject: [PATCH 21/43] Ticket page search bar --- WebContent/html/webpages/administration/adminApprove.jsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebContent/html/webpages/administration/adminApprove.jsp b/WebContent/html/webpages/administration/adminApprove.jsp index 3afa299..f6d7f79 100644 --- a/WebContent/html/webpages/administration/adminApprove.jsp +++ b/WebContent/html/webpages/administration/adminApprove.jsp @@ -167,7 +167,7 @@ String ticketStr = Ticket.arrayToString(tickets); var searchbar = document.getElementsByName('searchBar'); searchbar[0].onkeyup = refresh; function refresh() { - populateTickets(fuzzyFilter(ticks)); + populateTickets(fuzzyFilter(JSON.parse(window.json))); //adds event listeners to all table records $("tr.entry").click(ticketAction); } From c1fe6d40999e083f55e91d3a784099161ea7c8a0 Mon Sep 17 00:00:00 2001 From: Adam R Claxton Date: Fri, 21 Apr 2017 01:26:36 -0400 Subject: [PATCH 22/43] Made device search rainbow --- .../html/webpages/administration/adminDeviceSettings.jsp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WebContent/html/webpages/administration/adminDeviceSettings.jsp b/WebContent/html/webpages/administration/adminDeviceSettings.jsp index c2a24c8..b6a908f 100644 --- a/WebContent/html/webpages/administration/adminDeviceSettings.jsp +++ b/WebContent/html/webpages/administration/adminDeviceSettings.jsp @@ -359,7 +359,7 @@ function fuzzyFilter(deviceArray) ////// First pass: filter by device name var options = { - pre: "", + pre: "", post: '', extract: function(arg) {return arg.name;} } @@ -370,6 +370,7 @@ function fuzzyFilter(deviceArray) } ////// Second pass: filter by MAC address options.extract = function(arg) {return arg.mac;}; + options.pre = "span style='color: orange; font-size: 115%'>" var macFilterResults = fuzzy.filter(searchText, deviceArray, options); // replace releveant field with bolded string for (var i = macFilterResults.length - 1; i >= 0; i--) { @@ -377,6 +378,7 @@ function fuzzyFilter(deviceArray) } ////// Third pass: filter by Manufacture options.extract = function(arg) {return arg.manufacturer;}; + options.pre = "span style='color: gold; font-size: 115%'>" var manufacturerFilterResults = fuzzy.filter(searchText, deviceArray, options); // replace releveant field with bolded string for (var i = manufacturerFilterResults.length - 1; i >= 0; i--) { @@ -384,6 +386,7 @@ function fuzzyFilter(deviceArray) } ////// Fourth pass: filter by Hardware options.extract = function(arg) {return arg.hardware;}; + options.pre = "span style='color: green; font-size: 115%'>" var hardwareFilterResults = fuzzy.filter(searchText, deviceArray, options); // replace releveant field with bolded string for (var i = hardwareFilterResults.length - 1; i >= 0; i--) { @@ -391,6 +394,7 @@ function fuzzyFilter(deviceArray) } ////// Fifth pass: filter by Model options.extract = function(arg) {return arg.model;}; + options.pre = "span style='color: blue; font-size: 115%'>" var modelFilterResults = fuzzy.filter(searchText, deviceArray, options); // replace releveant field with bolded string for (var i = modelFilterResults.length - 1; i >= 0; i--) { @@ -398,6 +402,7 @@ function fuzzyFilter(deviceArray) } ////// Sixth pass: filter by Serial options.extract = function(arg) {return arg.serial;}; + options.pre = "span style='color: violet; font-size: 115%'>" var serialFilterResults = fuzzy.filter(searchText, deviceArray, options); // replace releveant field with bolded string for (var i = serialFilterResults.length - 1; i >= 0; i--) { From fc200b494e1efbc687dc8058b89b935bf3df7aa3 Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Fri, 21 Apr 2017 13:32:11 -0400 Subject: [PATCH 23/43] Password Reset Functionality --- WebContent/adminLogin.jsp | 277 ++++++--- .../administration/adminpasswordsetting.jsp | 62 ++ .../adminpasswordsettingtryagain.jsp | 63 ++ .../webpages/administration/ticketApprove.jsp | 6 +- .../html/webpages/components/adminnavbar.jsp | 3 +- .../html/webpages/components/adminsidebar.jsp | 1 + .../html/webpages/components/navbar.jsp | 3 +- WebContent/html/webpages/error.jsp | 2 +- WebContent/html/webpages/index.jsp | 2 +- WebContent/html/webpages/listingPage.jsp | 14 +- WebContent/html/webpages/profileSettings.jsp | 33 +- .../webpages/redirect/adminpasswordchange.jsp | 22 +- .../webpages/redirect/adminpasswordupdate.jsp | 205 +++++++ WebContent/html/webpages/requestPage.jsp | 12 +- WebContent/html/webpages/returnComplete.jsp | 32 +- WebContent/html/webpages/returnPage.jsp | 92 +-- WebContent/html/webpages/shoppingCart.jsp | 576 +++++++++--------- WebContent/html/webpages/somethingwrong.jsp | 2 +- WebContent/html/webpages/statisticsPage.jsp | 104 ++-- WebContent/html/webpages/userLogin.jsp | 76 +-- WebContent/index.jsp | 73 +-- 21 files changed, 1077 insertions(+), 583 deletions(-) create mode 100644 WebContent/html/webpages/administration/adminpasswordsetting.jsp create mode 100644 WebContent/html/webpages/administration/adminpasswordsettingtryagain.jsp create mode 100644 WebContent/html/webpages/redirect/adminpasswordupdate.jsp diff --git a/WebContent/adminLogin.jsp b/WebContent/adminLogin.jsp index e33796f..df36b10 100644 --- a/WebContent/adminLogin.jsp +++ b/WebContent/adminLogin.jsp @@ -1,88 +1,221 @@ <%@ page import = "database.*" %> -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import = "java.sql.*" %> <%@ page import = "java.security.MessageDigest" %> <%@ page import = "java.security.NoSuchAlgorithmException" %> -<% -int ssoNum; -String pass; -Cookie adminCookie; +<%@ page import = "java.util.Random" %> + + + + + + + + + -ssoNum = Integer.parseInt(request.getParameter("username")); -pass = request.getParameter("pass"); -String generatedPass = null; + Innovation Hub -try { - MessageDigest md = MessageDigest.getInstance("MD5"); - md.update(pass.getBytes()); - byte[] bytes = md.digest(); - StringBuilder sb = new StringBuilder(); - for(int i = 0; i + + + + + + + + + +<% +/* + If admin chose to login, we work on this form. +*/ +if(request.getParameter("login") != null){ + /* + Get form information from last page. + */ + int ssoNum = Integer.parseInt(request.getParameter("username")); + String pass = request.getParameter("pass"); + Cookie adminCookie; + String generatedPass = null; -} - -String database = "jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317"; -String user = "b372dfe7409692"; -String password = "74f6e317"; -Class.forName("com.mysql.jdbc.Driver"); -Connection connection; -Statement stmt; -for(;;){ - try{ - connection = DriverManager.getConnection(database, user, password); - break; + /* + Hash what the user put in, so we can see if the passwords match up. + */ + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(pass.getBytes()); + byte[] bytes = md.digest(); + StringBuilder sb = new StringBuilder(); + for(int i = 0; i \ No newline at end of file +/* + Goes back to the previous page. +*/ +function goBack(){ + window.history.back(); +} + + \ No newline at end of file diff --git a/WebContent/html/webpages/administration/adminpasswordsetting.jsp b/WebContent/html/webpages/administration/adminpasswordsetting.jsp new file mode 100644 index 0000000..0359bc0 --- /dev/null +++ b/WebContent/html/webpages/administration/adminpasswordsetting.jsp @@ -0,0 +1,62 @@ + + + + + + + + + + Innovation Hub + + + + + + + + + + + + + + + +
+ +
+

Change Your Password

+
+ + +
+
+ + +
+
+ + +
+ +
+
+

Change Pincode

+
+ + +
+ +
+
+ + \ No newline at end of file diff --git a/WebContent/html/webpages/administration/adminpasswordsettingtryagain.jsp b/WebContent/html/webpages/administration/adminpasswordsettingtryagain.jsp new file mode 100644 index 0000000..f006479 --- /dev/null +++ b/WebContent/html/webpages/administration/adminpasswordsettingtryagain.jsp @@ -0,0 +1,63 @@ + + + + + + + + + + Innovation Hub + + + + + + + + + + + + + + + +
+ +
+

Something went wrong. Try again!

+

Change Your Password

+
+ + +
+
+ + +
+
+ + +
+ +
+
+

Change Pincode

+
+ + +
+ +
+
+ + \ No newline at end of file diff --git a/WebContent/html/webpages/administration/ticketApprove.jsp b/WebContent/html/webpages/administration/ticketApprove.jsp index 7b35f4c..7116095 100644 --- a/WebContent/html/webpages/administration/ticketApprove.jsp +++ b/WebContent/html/webpages/administration/ticketApprove.jsp @@ -29,6 +29,10 @@ + +

Approving Tickets

Thanks for approving a ticket!

@@ -36,7 +40,7 @@
Synchrony Financial

-
+
diff --git a/WebContent/html/webpages/components/adminnavbar.jsp b/WebContent/html/webpages/components/adminnavbar.jsp index 160a20a..e3cde2c 100644 --- a/WebContent/html/webpages/components/adminnavbar.jsp +++ b/WebContent/html/webpages/components/adminnavbar.jsp @@ -24,6 +24,7 @@
  • Device Hub
  • Location Hub
  • +
  • Update Password/Pincode
  • \ No newline at end of file diff --git a/WebContent/html/webpages/components/navbar.jsp b/WebContent/html/webpages/components/navbar.jsp index 0f32c01..ac1ec25 100644 --- a/WebContent/html/webpages/components/navbar.jsp +++ b/WebContent/html/webpages/components/navbar.jsp @@ -24,6 +24,7 @@ diff --git a/WebContent/html/webpages/components/navbar.jsp b/WebContent/html/webpages/components/navbar.jsp index 99c35ac..cd353f8 100644 --- a/WebContent/html/webpages/components/navbar.jsp +++ b/WebContent/html/webpages/components/navbar.jsp @@ -32,6 +32,7 @@ diff --git a/WebContent/html/webpages/mytickets.jsp b/WebContent/html/webpages/mytickets.jsp new file mode 100644 index 0000000..ee3e086 --- /dev/null +++ b/WebContent/html/webpages/mytickets.jsp @@ -0,0 +1,250 @@ +<%@ page import = "database.*,entities.*" %> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" +pageEncoding="ISO-8859-1"%> + + + + + + + + + + + Innovation Hub + + + + + + + + + + + + + + + + + + + +
    +

    My Tickets

    + +
    + +
    + + + + + + + + + + + + + + +
    Ticket IDRequestor NameLocation NameDevice NameStatusPermanent?Return Date
    +
    + +<% +/* + Get all tickets in users name. +*/ +Ticket[] tickets = TicketQueries.getAllTickets(Integer.parseInt(navsso)); +String ticketStr = Ticket.arrayToString(tickets); +%> + + + + + \ No newline at end of file diff --git a/WebContent/html/webpages/shoppingCart.jsp b/WebContent/html/webpages/shoppingCart.jsp index 35a396d..2e2a398 100644 --- a/WebContent/html/webpages/shoppingCart.jsp +++ b/WebContent/html/webpages/shoppingCart.jsp @@ -17,9 +17,9 @@ pageEncoding="ISO-8859-1"%> Innovation Hub + - @@ -85,7 +74,7 @@ pageEncoding="ISO-8859-1"%>

    - +

    @@ -171,7 +160,7 @@ pageEncoding="ISO-8859-1"%>
    - +
    diff --git a/src/database/AdminQueries.java b/src/database/AdminQueries.java index ad0bddc..5a1d541 100644 --- a/src/database/AdminQueries.java +++ b/src/database/AdminQueries.java @@ -6,7 +6,6 @@ * This class is responsible for performing most queries corresponding * to admin (object) actions. * @author Connor Jackson - * */ public class AdminQueries { diff --git a/src/database/DeviceQueries.java b/src/database/DeviceQueries.java index 6281521..5bbf7a8 100644 --- a/src/database/DeviceQueries.java +++ b/src/database/DeviceQueries.java @@ -4,12 +4,22 @@ import entities.Device; +/** + * This class is responsible for performing most queries corresponding + * to device actions. + * @author Connor Jackson + */ public class DeviceQueries { private static String database = "jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317"; private static String user = "b372dfe7409692"; private static String password = "74f6e317"; + /** + * This function retrieves all devices checked out by a certain user. + * This is in support of the "My Devices" webpage. + * @author Connor Jackson + */ public static Device[] getUserDevices(String userID) throws SQLException, ClassNotFoundException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); @@ -69,6 +79,11 @@ public static Device[] getUserDevices(String userID) throws SQLException, ClassN return devices; } + /** + * This function retrieves all devices currently in inventory. + * This is in support of the Device Library webpage, and Device Admin Settings. + * @author Connor Jackson + */ public static Device[] getAllDevices() throws SQLException, ClassNotFoundException, InterruptedException{ //database connect System.getenv("VCAP_SERVICES"); @@ -129,6 +144,11 @@ public static Device[] getAllDevices() throws SQLException, ClassNotFoundExcepti return devices; } + /** + * This function retrieves all devices that are currently available. + * This is to support the Request Hub, we only want users to see devices they can actually order. + * @author Connor Jackson + */ public static Device[] getAvailableDevices() throws SQLException, ClassNotFoundException, InterruptedException{ //database connect System.getenv("VCAP_SERVICES"); @@ -190,13 +210,9 @@ public static Device[] getAvailableDevices() throws SQLException, ClassNotFoundE } /** - * This function will take devices as input and return them. - * More specifically, the input will be a string that looks like an array. - * The values in this array correspond to device ID's. - * @param devices - * @throws ClassNotFoundException - * @throws SQLException - * @throws InterruptedException + * This function will change the device's status to "Returning", indicating that it's on its way + * home. + * @param devices A Stringified Array on Device ID's */ public static void returnDevices(String devices) throws ClassNotFoundException, SQLException, InterruptedException{ //connect to DB @@ -232,6 +248,11 @@ public static void returnDevices(String devices) throws ClassNotFoundException, connection.close(); } + /** + * This function will create a new device in the database. + * This is in support of the Device Hub webpage for admins. + * @author Connor Jackson + */ public static void addDevice(Device device) throws SQLException, ClassNotFoundException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); @@ -273,6 +294,11 @@ public static void addDevice(Device device) throws SQLException, ClassNotFoundEx connection.close(); } + /** + * This function will update information about a device in the database. + * This supports the Device Hub for admins. + * @author Connor Jackson + */ public static void modifyDevice(Device device) throws ClassNotFoundException, SQLException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); @@ -301,6 +327,11 @@ public static void modifyDevice(Device device) throws ClassNotFoundException, SQ connection.close(); } + /** + * This function will delete a device from the database. + * This is to support the Device Hub for admins. + * @author Connor Jackson + */ public static void deleteDevice(int id) throws ClassNotFoundException, SQLException, InterruptedException{ System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); diff --git a/src/database/TicketQueries.java b/src/database/TicketQueries.java index 85a2701..18ecc4a 100644 --- a/src/database/TicketQueries.java +++ b/src/database/TicketQueries.java @@ -8,7 +8,6 @@ * This class is responsible for performing most queries corresponding * to ticket actions. * @author Brianna Boyce, Connor Jackson, Adam Claxton - * */ public class TicketQueries { @@ -181,6 +180,63 @@ public static Ticket[] getAllTickets() return tickets; } + /** + * This function retrieves all tickets based on user id.. + * @author Connor Jackson + */ + public static Ticket[] getAllTickets(int sso) + throws SQLException, ClassNotFoundException, InterruptedException{ + int i = 0; + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection; + Statement stmt; + for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } + } + ResultSet resultSet = stmt.executeQuery("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 Requestor = " + sso); + resultSet.last(); + int rows = resultSet.getRow(); + resultSet.beforeFirst(); + Ticket[] tickets = new Ticket[rows]; + + while(resultSet.next()){ + tickets[i] = new Ticket( + resultSet.getInt("Ticket_ID"), + resultSet.getInt("Requestor"), + resultSet.getLong("Request_Date"), + resultSet.getInt("Location"), + resultSet.getInt("Device_ID"), + resultSet.getString("Status"), + resultSet.getLong("Status_Date_Fields"), + resultSet.getString("Return_Date"), + resultSet.getString("username"), + resultSet.getString("Device_Name"), + resultSet.getString("locationname"), + resultSet.getInt("Permanent_Order") + ); + i++; + } + stmt.close(); + connection.close(); + return tickets; + } + /** * This function accepts a ticket, and assigns that ticket & device to its * corresponding renter and location. diff --git a/src/entities/Ticket.java b/src/entities/Ticket.java index e6b1bea..edcdadc 100644 --- a/src/entities/Ticket.java +++ b/src/entities/Ticket.java @@ -17,7 +17,7 @@ public class Ticket { private String devicename; private String permanent; - public Ticket(int id, int requestor, long requestDate, int location, int deviceId, String status, long statusDateFields, String returnDate, String username, String locationname, String devicename, int permanent){ + public Ticket(int id, int requestor, long requestDate, int location, int deviceId, String status, long statusDateFields, String returnDate, String username, String devicename, String locationname, int permanent){ this._id = id; this._requestor = requestor; this._requestDate = requestDate; From c5bd266d380de09acdd1e79c716d5cbc61ec1cef Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Sun, 23 Apr 2017 18:25:34 -0400 Subject: [PATCH 39/43] Adding logs --- WebContent/html/javascript/request.jsp | 1 + .../webpages/redirect/adminpasswordchange.jsp | 4 +- .../webpages/redirect/adminpasswordupdate.jsp | 5 +- src/database/DeviceQueries.java | 31 +++++++--- src/database/LocationQueries.java | 60 ++++++++++++------- src/database/TicketQueries.java | 24 +++++--- 6 files changed, 84 insertions(+), 41 deletions(-) diff --git a/WebContent/html/javascript/request.jsp b/WebContent/html/javascript/request.jsp index 78a1ce9..640eb5e 100644 --- a/WebContent/html/javascript/request.jsp +++ b/WebContent/html/javascript/request.jsp @@ -11,6 +11,7 @@ Device[] mydevices = DeviceQueries.getAvailableDevices(); //string representation of array. String deviceString = Device.arrayToString(mydevices); +deviceString = deviceString.replace("'","\\'"); //out.println(description); //out.println(hardware); %> diff --git a/WebContent/html/webpages/redirect/adminpasswordchange.jsp b/WebContent/html/webpages/redirect/adminpasswordchange.jsp index b0181bb..5d226df 100644 --- a/WebContent/html/webpages/redirect/adminpasswordchange.jsp +++ b/WebContent/html/webpages/redirect/adminpasswordchange.jsp @@ -76,7 +76,9 @@ if(request.getParameter("submit") != null){ } } ResultSet result; - result = stmt.executeQuery("select * FROM admin where Admin_ID='" + navsso + "' AND Password='" + generatedOldPass + "'"); + String query = "select * FROM admin where Admin_ID='" + navsso + "' AND Password='" + generatedOldPass + "'"; + result = stmt.executeQuery(query); + System.out.println("Executing query: "+query); if(result.next()){//if old password is accurate if (!old.equals(newpass) && newpass.equals(confirm) && pincode.length() == 4 && AdminQueries.pincodeInt(pincode)){//if the password is new AND both news ones are equal AND pincode is 4 digits AND pincode is a number try { diff --git a/WebContent/html/webpages/redirect/adminpasswordupdate.jsp b/WebContent/html/webpages/redirect/adminpasswordupdate.jsp index 5dc7241..b8b9363 100644 --- a/WebContent/html/webpages/redirect/adminpasswordupdate.jsp +++ b/WebContent/html/webpages/redirect/adminpasswordupdate.jsp @@ -87,8 +87,9 @@ if(request.getParameter("password") != null){ } } ResultSet result; - result = stmt.executeQuery("select * FROM admin where Admin_ID='" + navsso + "' AND Password='" + generatedOldPass + "'"); - + String query = "select * FROM admin where Admin_ID='" + navsso + "' AND Password='" + generatedOldPass + "'"; + result = stmt.executeQuery(query); + System.out.println("Executing query: "+query); /* If the old password is correct, then we can continue to change the password. */ diff --git a/src/database/DeviceQueries.java b/src/database/DeviceQueries.java index 5bbf7a8..d19e753 100644 --- a/src/database/DeviceQueries.java +++ b/src/database/DeviceQueries.java @@ -43,8 +43,9 @@ public static Device[] getUserDevices(String userID) throws SQLException, ClassN Thread.sleep(1); } } - - ResultSet resultSet = stmt.executeQuery("SELECT * FROM devices WHERE Renter = " + userID + " AND Status <> \"Available\" AND Status <> \"Returning \""); + String query = "SELECT * FROM devices WHERE Renter = " + userID + " AND Status <> \"Available\" AND Status <> \"Returning \""; + ResultSet resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); int counter = 0; resultSet.last(); @@ -109,7 +110,9 @@ public static Device[] getAllDevices() throws SQLException, ClassNotFoundExcepti } } - ResultSet resultSet = stmt.executeQuery("SELECT * FROM devices"); + String query = "SELECT * FROM devices"; + ResultSet resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); int counter = 0; resultSet.last(); @@ -174,7 +177,9 @@ public static Device[] getAvailableDevices() throws SQLException, ClassNotFoundE } } - ResultSet resultSet = stmt.executeQuery("SELECT * FROM devices WHERE Status = \"Available\""); + String query = "SELECT * FROM devices WHERE Status = \"Available\""; + ResultSet resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); int counter = 0; resultSet.last(); @@ -242,7 +247,9 @@ public static void returnDevices(String devices) throws ClassNotFoundException, String[] deviceArray = devices.replaceAll("\\[","").replaceAll("\\]","").replaceAll("\\s","").split(","); for(int i = 0; i < deviceArray.length; i++){ //update statement - stmt.executeUpdate("UPDATE devices SET Status = \"Returning\" WHERE Device_ID = " + deviceArray[i]); + String query = "UPDATE devices SET Status = \"Returning\" WHERE Device_ID = " + deviceArray[i]; + stmt.executeUpdate(query); + System.out.println("Executing query: "+query); } stmt.close(); connection.close(); @@ -280,15 +287,17 @@ public static void addDevice(Device device) throws SQLException, ClassNotFoundEx int i = -1; int id=0; while(i <= 0){ - ResultSet results = stmt.executeQuery("SELECT * from devices ORDER BY Device_ID"); + String query = "SELECT * from devices ORDER BY Device_ID"; + ResultSet results = stmt.executeQuery(query); + System.out.println("Executing query: "+query); results.last(); //gets largest ID id = results.getInt("Device_ID"); id++; //tries this statement, otherwise tries again with a new id String command = "INSERT INTO devices (Device_ID,Device_Name,Device_Description,MAC_Address,Manufacturer,Hardware,Model,Serial_Num,Status,NFC_ID,Locker_Position,Operating_System,Admin_Comments) " + "VALUES (" + id +",\"" + device.getName() + "\",\"" + device.getDesc()+ "\",\"" + device.getMAC() + "\",\"" + device.getManufacturer() + "\",\""+device.getHardware()+ "\",\"" + device.getModel() + "\",\"" + device.getSerial() + "\",\"" + device.getStatus() + "\",\"" + device.getNFC() + "\",\"" + device.getPos() + "\",\"" + device.getOS() + "\",\"" + device.getComment() +"\");"; - System.out.println(command); i = stmt.executeUpdate(command); + System.out.println("Executing query: "+command); } stmt.close(); connection.close(); @@ -322,7 +331,9 @@ public static void modifyDevice(Device device) throws ClassNotFoundException, SQ Thread.sleep(1); } } - stmt.executeUpdate("UPDATE devices SET Device_Name = \"" + device.getName() + "\", Device_Description = \"" + device.getDesc() + "\", MAC_Address = \"" + device.getMAC() + "\", Manufacturer = \"" + device.getManufacturer() + "\", Hardware = \"" + device.getHardware() + "\", Model = \"" + device.getModel() + "\", Serial_Num = \"" + device.getSerial() + "\", Status = \"" + device.getStatus() + "\", NFC_ID = \"" + device.getNFC() + "\", Admin_Comments = \"" + device.getComment() + "\", Operating_System = \"" + device.getOS() + "\", Locker_Position = \"" + device.getPos() + "\" WHERE Device_ID = " + device.getID()); + String query = "UPDATE devices SET Device_Name = \"" + device.getName() + "\", Device_Description = \"" + device.getDesc() + "\", MAC_Address = \"" + device.getMAC() + "\", Manufacturer = \"" + device.getManufacturer() + "\", Hardware = \"" + device.getHardware() + "\", Model = \"" + device.getModel() + "\", Serial_Num = \"" + device.getSerial() + "\", Status = \"" + device.getStatus() + "\", NFC_ID = \"" + device.getNFC() + "\", Admin_Comments = \"" + device.getComment() + "\", Operating_System = \"" + device.getOS() + "\", Locker_Position = \"" + device.getPos() + "\" WHERE Device_ID = " + device.getID(); + stmt.executeUpdate(query); + System.out.println("Executing query: "+query); stmt.close(); connection.close(); } @@ -355,7 +366,9 @@ public static void deleteDevice(int id) throws ClassNotFoundException, SQLExcept Thread.sleep(1); } } - stmt.executeUpdate("DELETE from devices WHERE Device_ID = " + id); + String query = "DELETE from devices WHERE Device_ID = " + id; + stmt.executeUpdate(query); + System.out.println("Executing query: "+query); stmt.close(); connection.close(); } diff --git a/src/database/LocationQueries.java b/src/database/LocationQueries.java index d3e5222..8bf5313 100644 --- a/src/database/LocationQueries.java +++ b/src/database/LocationQueries.java @@ -34,7 +34,9 @@ public static int locationStringToInt(String locString) throws SQLException, Cla Thread.sleep(1); } } - ResultSet resultSet = stmt.executeQuery("SELECT Location_ID FROM location WHERE Address = '"+locString+"'"); + String query = "SELECT Location_ID FROM location WHERE Address = '"+locString+"'"; + ResultSet resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); resultSet.next(); int returnResult = resultSet.getInt("Location_ID"); stmt.close(); @@ -66,7 +68,9 @@ public static String locationIntToString(int locInt) throws ClassNotFoundExcepti Thread.sleep(1); } } - ResultSet resultSet = stmt.executeQuery("SELECT Address FROM location WHERE Location_ID = "+locInt); + String query = "SELECT Address FROM location WHERE Location_ID = "+locInt; + ResultSet resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); resultSet.next(); String returnResult = resultSet.getString("Address"); stmt.close(); @@ -101,14 +105,19 @@ public static int addLocation(Location location) throws SQLException, ClassNotFo } int i = -1; int id=0; + String query = "SELECT * from location ORDER BY Location_ID"; while(i <= 0){ - ResultSet results = stmt.executeQuery("SELECT * from location ORDER BY Location_ID"); + ResultSet results = stmt.executeQuery(query); + System.out.println("Executing query: "+query); results.last(); //gets largest ID id = results.getInt("Location_ID"); id++; //tries this statement, otherwise tries again with a new id - i = stmt.executeUpdate("INSERT INTO location (Location_ID,Name,Address,Town,State,Zip_Code,Employee_Flag,Latitude,Longitude) VALUES (" + id +",\"" + location.getName() + "\",\"" + location.getAddress()+ "\",\"" + location.getTown() + "\",\"" + location.getState() + "\",\"" + location.getZip() + "\"," + location.getEmployeeFlag() + ",\"" + location.getLat() + "\",\"" + location.getLng() + "\")"); + query = "INSERT INTO location (Location_ID,Name,Address,Town,State,Zip_Code,Employee_Flag,Latitude,Longitude) VALUES (" + id +",\"" + location.getName() + "\",\"" + location.getAddress()+ "\",\"" + location.getTown() + "\",\"" + location.getState() + "\",\"" + location.getZip() + "\"," + location.getEmployeeFlag() + ",\"" + location.getLat() + "\",\"" + location.getLng() + "\")"; + i = stmt.executeUpdate(query); + System.out.println("Executing query: "+query); + query = "SELECT * from location ORDER BY Location_ID"; } stmt.close(); connection.close(); @@ -139,7 +148,9 @@ public static Location[] getAdminLocations() throws ClassNotFoundException, SQLE Thread.sleep(1); } } - ResultSet resultSet = stmt.executeQuery("SELECT * FROM location WHERE Employee_Flag = 0 ORDER BY Location_ID"); + String query = "SELECT * FROM location WHERE Employee_Flag = 0 ORDER BY Location_ID"; + ResultSet resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); int counter = 0; resultSet.last(); @@ -165,7 +176,9 @@ public static Location[] getAdminLocations() throws ClassNotFoundException, SQLE ); counter++; } - resultSet = stmt.executeQuery("SELECT location.location_id, count(*) AS 'count' FROM location JOIN devices ON devices.location = location.location_id WHERE employee_flag = 0 group by location.Location_ID ORDER BY location.Location_ID"); + query = "SELECT location.location_id, count(*) AS 'count' FROM location JOIN devices ON devices.location = location.location_id WHERE employee_flag = 0 group by location.Location_ID ORDER BY location.Location_ID"; + resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); resultSet.last(); rows = resultSet.getRow(); resultSet.beforeFirst(); @@ -180,7 +193,9 @@ public static Location[] getAdminLocations() throws ClassNotFoundException, SQLE } j++; } - resultSet = stmt.executeQuery("SELECT location.location_id, count(*) AS 'count' FROM location JOIN employee ON employee.location_id = location.location_id WHERE employee_flag = 0 group by location.Location_ID ORDER BY location.Location_ID"); + query = "SELECT location.location_id, count(*) AS 'count' FROM location JOIN employee ON employee.location_id = location.location_id WHERE employee_flag = 0 group by location.Location_ID ORDER BY location.Location_ID"; + resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); resultSet.last(); rows = resultSet.getRow(); resultSet.beforeFirst(); @@ -228,10 +243,13 @@ public static Location[] getLocations(int userID) throws SQLException, ClassNotF Thread.sleep(1); } } - ResultSet rs = stmt.executeQuery("SELECT COUNT(Location_ID) FROM location WHERE Employee_Flag = 0 OR Employee_Flag = "+userID); + String resultlength = "SELECT COUNT(Location_ID) FROM location WHERE Employee_Flag = 0 OR Employee_Flag = "+userID; + ResultSet rs = stmt.executeQuery(resultlength); + System.out.println("Executing query: "+query); rs.next(); Location[] locations = new Location[rs.getInt("COUNT(Location_ID)")]; rs = stmt.executeQuery(query); + System.out.println("Executing query: "+query); int i=0; while(rs.next()) { @@ -256,10 +274,7 @@ public static Location[] getLocations(int userID) throws SQLException, ClassNotF /** * Updates a location, assuming that all input fields have been changed. - * @param location - * @throws ClassNotFoundException - * @throws SQLException - * @throws InterruptedException + * @author Connor Jackson */ public static void modifyLocation(Location location) throws ClassNotFoundException, SQLException, InterruptedException{ System.getenv("VCAP_SERVICES"); @@ -284,17 +299,16 @@ public static void modifyLocation(Location location) throws ClassNotFoundExcepti Thread.sleep(1); } } - stmt.executeUpdate("UPDATE location SET Name = \"" + location.getName() + "\", Address = \"" + location.getAddress() + "\", Town = \"" + location.getTown() + "\", State = \"" + location.getState() + "\", Zip_Code = \"" + location.getZip() + "\", Latitude = \"" + location.getLat() + "\", Longitude = \"" + location.getLng() + "\" WHERE Location_ID = " + location.getID()); + String query = "UPDATE location SET Name = \"" + location.getName() + "\", Address = \"" + location.getAddress() + "\", Town = \"" + location.getTown() + "\", State = \"" + location.getState() + "\", Zip_Code = \"" + location.getZip() + "\", Latitude = \"" + location.getLat() + "\", Longitude = \"" + location.getLng() + "\" WHERE Location_ID = " + location.getID(); + stmt.executeUpdate(query); + System.out.println("Executing query: "+query); stmt.close(); connection.close(); } /** * Deletes a location based on input id. - * @param id - * @throws ClassNotFoundException - * @throws SQLException - * @throws InterruptedException + * @author Connor Jackson */ public static int deleteLocation(int id) throws ClassNotFoundException, SQLException, InterruptedException{ System.getenv("VCAP_SERVICES"); @@ -319,8 +333,10 @@ public static int deleteLocation(int id) throws ClassNotFoundException, SQLExcep Thread.sleep(1); } } + String query = "DELETE from location WHERE Location_ID = " + id; try { - stmt.executeUpdate("DELETE from location WHERE Location_ID = " + id); + stmt.executeUpdate(query); + System.out.println("Executing query: "+query); } catch (SQLException e) { stmt.close(); connection.close(); @@ -355,7 +371,9 @@ public static Location[] getAllLocations() throws SQLException, ClassNotFoundExc Thread.sleep(1); } } - ResultSet resultSet = stmt.executeQuery("SELECT * FROM location"); + String query = "SELECT * FROM location"; + ResultSet resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); int counter = 0; resultSet.last(); @@ -411,7 +429,9 @@ public static Location getLocationByID(int id) throws InterruptedException, Clas Thread.sleep(1); } } - ResultSet resultSet = stmt.executeQuery("SELECT * FROM location WHERE Location_ID = " + id); + String query = "SELECT * FROM location WHERE Location_ID = " + id; + ResultSet resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); resultSet.next(); return new Location( resultSet.getInt("Location_ID"), diff --git a/src/database/TicketQueries.java b/src/database/TicketQueries.java index 18ecc4a..b93f5be 100644 --- a/src/database/TicketQueries.java +++ b/src/database/TicketQueries.java @@ -59,8 +59,8 @@ public static int generateTicket(int requester, int location, int device, String query+= "'"+time+"'" +", "; query+= "'"+returnDate+"'" + ", "; query+= perm + ");"; - System.out.println(query); stmt.executeUpdate(query); + System.out.println("Executing query: "+query); stmt.close(); connection.close(); return ticketID; @@ -95,7 +95,9 @@ public static Ticket[] getRequestedTickets() Thread.sleep(1); } } - ResultSet resultSet = stmt.executeQuery("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 = 'Requested'"); + 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 = 'Requested'"; + ResultSet resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); resultSet.last(); int rows = resultSet.getRow(); resultSet.beforeFirst(); @@ -152,7 +154,9 @@ public static Ticket[] getAllTickets() Thread.sleep(1); } } - ResultSet resultSet = stmt.executeQuery("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"); + 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"; + ResultSet resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); resultSet.last(); int rows = resultSet.getRow(); resultSet.beforeFirst(); @@ -209,7 +213,9 @@ public static Ticket[] getAllTickets(int sso) Thread.sleep(1); } } - ResultSet resultSet = stmt.executeQuery("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 Requestor = " + sso); + 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 Requestor = " + sso; + ResultSet resultSet = stmt.executeQuery(query); + System.out.println("Executing query: "+query); resultSet.last(); int rows = resultSet.getRow(); resultSet.beforeFirst(); @@ -273,10 +279,9 @@ public static void acceptTicket(int ticketid, int deviceid, int locationid, int +", devices.Status = \"Ready to Ship\", devices.Renter = " + sso +", devices.Location = " + locationid +", devices.Permanent = " + perm - +" WHERE ticket.Ticket_ID = " + ticketid + " AND devices.Device_ID = " + deviceid; - System.out.println("Executing query: "+query); + +" WHERE ticket.Ticket_ID = " + ticketid + " AND devices.Device_ID = " + deviceid; stmt.executeUpdate(query); - + System.out.println("Executing query: "+query); stmt.close(); connection.close(); } @@ -311,8 +316,8 @@ public static void rejectTicket(int id) } long milliseconds = new Date().getTime(); String query="UPDATE ticket SET Status = \"Rejected\", Status_Date_Fields = "+milliseconds+" WHERE Ticket_ID = " + id; - System.out.println("Executing query "+query); stmt.executeUpdate(query); + System.out.println("Executing query: "+query); stmt.close(); connection.close(); } @@ -332,8 +337,8 @@ public static Ticket[] getRecentlyChangedTickets(int userID, String status, long +"INNER JOIN location ON ticket.Location = location.Location_ID " +"WHERE ticket.Status = '"+status+"' AND Requestor = " + userID +" AND Status_Date_Fields >= " + milliseconds; - System.out.println("Executing query '"+query+"'"); ResultSet results = stmt.executeQuery(query); + System.out.println("Executing query: "+query); results.last(); int rows = results.getRow(); results.beforeFirst(); @@ -391,6 +396,7 @@ public static int getUserID(int ticketID) throws ClassNotFoundException, SQLExce } String query = "SELECT Requestor FROM ticket WHERE Ticket_ID = "+ticketID+";"; ResultSet results = stmt.executeQuery(query); + System.out.println("Executing query: "+query); results.next(); int answer = results.getInt("Requestor"); stmt.close(); From 4fe48e21ad4a00b2390a2903280cc03d265ffaf9 Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Sun, 23 Apr 2017 20:11:09 -0400 Subject: [PATCH 40/43] Bootstrap Tables. Boostrap Tables Everywhere. --- .../webpages/administration/adminApprove.jsp | 56 +++++++++---- .../webpages/administration/adminLocation.jsp | 80 +++++++++++++++---- .../webpages/administration/allTickets.jsp | 14 ++-- WebContent/html/webpages/mytickets.jsp | 7 +- 4 files changed, 117 insertions(+), 40 deletions(-) diff --git a/WebContent/html/webpages/administration/adminApprove.jsp b/WebContent/html/webpages/administration/adminApprove.jsp index af64ee3..4eafaf7 100644 --- a/WebContent/html/webpages/administration/adminApprove.jsp +++ b/WebContent/html/webpages/administration/adminApprove.jsp @@ -11,13 +11,18 @@ pageEncoding="ISO-8859-1"%> - Innovation Hub - - - - - - + Innovation Hub + + + + + + + + + + + @@ -93,16 +107,16 @@ pageEncoding="ISO-8859-1"%>
    - +
    - - - - - - - + + + + + + + @@ -147,6 +161,18 @@ String ticketStr = Ticket.arrayToString(tickets); var searchbar = document.getElementsByName('searchBar'); searchbar[0].onkeyup = refresh; + // Set up table record event listeners + $('#tabledisplay').bootstrapTable({onClickRow: function(row,$element){ + var id = $element[0].getAttribute('id'); + var html = ""; + document.getElementById("tablemodal").innerHTML = html; + $("#ticketIDfield").val(ticks[id].id); + $("#deviceIDfield").val(ticks[id].deviceID); + $("#locationIDfield").val(ticks[id].location); + $("#permField").val(ticks[id].permanent); + $("#Modal").show(); + }}); + /* Params: tickets - array of objects, formatted as tickets. This function will display tickets in a table on the webpage. diff --git a/WebContent/html/webpages/administration/adminLocation.jsp b/WebContent/html/webpages/administration/adminLocation.jsp index 4868e39..9bb08d9 100644 --- a/WebContent/html/webpages/administration/adminLocation.jsp +++ b/WebContent/html/webpages/administration/adminLocation.jsp @@ -15,11 +15,17 @@ + + + + + + + + - -
    Ticket IDRequestor NameLocation NameDevice NameStatusPermanent?Return DateTicket IDRequestor NameLocation NameDevice NameStatusPermanent?Return Date
    " + ticks[id].id + "" + ticks[id].username + "" + ticks[id].locationname + "" + ticks[id].devicename + "" + ticks[id].status + "" + ticks[id].permanent + "" + ticks[id].return + "
    - - - - - - - - - - - - +
    NameAddressTownStateZip Code
    + + + + + + + + + + + +
    NameAddressTownStateZip Code
    @@ -297,6 +312,41 @@ window.onkeydown = function(e){if (e.keyCode == 27){closeAddModal();closeModifyM //Event listener exits modal when click outside modal. window.onclick = function(e){var add = document.getElementById('addModal'); var modify = document.getElementById('modifyModal'); if(e.target == add || e.target == modify) {closeAddModal();closeModifyModal();}} +// Event listener for table records. +$('#tabledisplay').bootstrapTable({onClickRow: function(row,$element){ + var id = $element[0].getAttribute('id'); + for(var i = 0; i < locations.length; i++){ + if(id == locations[i].id) + break; + } + //autofill all information from what you clicked on into modal + $("#modifyName").val(locations[i].name.replace(/"/g,"\"")); + $("#modifyAddress").val(locations[i].address.replace(/"/g,"\"")); + $("#modifyTown").val(locations[i].town.replace(/"/g,"\"")); + $("#modifyState").val(locations[i].state); + $("#modifyZip").val(locations[i].zip); + $("#modifyID").val(locations[i].id); + + var geocoder = new google.maps.Geocoder(); + //this function assumes that you are using a proper zip code... + geocoder.geocode({'address':locations[i].zip}, function(results,status) + {if (status == google.maps.GeocoderStatus.OK) + {$("#modifylat").val(results[0].geometry.location.lat()); + $("#modifylng").val(results[0].geometry.location.lng());} + }); + + //if the location has a foreign key constraint, then the delete button should be restricted + if(locations[i].numDevices > 0 || locations[i].numEmployees > 0){ + $('#thedeletebutton').attr('disabled',true); + $('#thedeletebutton').attr('title','Cannot delete because devices and/or employees are at this location!'); + } + else{ + $('#thedeletebutton').attr('disabled',false); + $('#thedeletebutton').removeAttr('title'); + } + $("#modifyModal").show(); +}}); + //Places all locations from query into page function populateLocations(){ var html = ""; diff --git a/WebContent/html/webpages/administration/allTickets.jsp b/WebContent/html/webpages/administration/allTickets.jsp index a512dc0..0ea097a 100644 --- a/WebContent/html/webpages/administration/allTickets.jsp +++ b/WebContent/html/webpages/administration/allTickets.jsp @@ -29,10 +29,6 @@ pageEncoding="ISO-8859-1"%> text-align: center; } - tr.entry{ - cursor: pointer; - } - .table{ width: auto; background-color: #E9EAEB; @@ -45,6 +41,12 @@ pageEncoding="ISO-8859-1"%> body{ overflow: visible; } + + div.displayDevice{ + padding-right: 30px; + padding-bottom: 30px; + } + @@ -65,7 +67,8 @@ pageEncoding="ISO-8859-1"%>
    -
    + +
    @@ -81,6 +84,7 @@ pageEncoding="ISO-8859-1"%>
    +
    <% diff --git a/WebContent/html/webpages/mytickets.jsp b/WebContent/html/webpages/mytickets.jsp index ee3e086..47047c1 100644 --- a/WebContent/html/webpages/mytickets.jsp +++ b/WebContent/html/webpages/mytickets.jsp @@ -30,10 +30,6 @@ pageEncoding="ISO-8859-1"%> width: 50%; } - tr.entry{ - cursor: pointer; - } - .table{ background-color: #E9EAEB; } @@ -43,10 +39,11 @@ pageEncoding="ISO-8859-1"%> } div.displayDevice{ - overflow: visible; padding-right: 30px; margin-bottom: 30px; + overflow: hidden; height: auto; + width: auto; } From 8c76ed6c208d3025de3f5b8c773b564877431695 Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Sun, 23 Apr 2017 20:27:35 -0400 Subject: [PATCH 41/43] Loading GIF added into a form. Experimental! Gonna see how I feel about this. --- WebContent/html/imgs/loader.gif | Bin 0 -> 1849 bytes WebContent/html/webpages/shoppingCart.jsp | 4 +++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 WebContent/html/imgs/loader.gif diff --git a/WebContent/html/imgs/loader.gif b/WebContent/html/imgs/loader.gif new file mode 100644 index 0000000000000000000000000000000000000000..9bfca92b9ae82a3b7c31ac9a259cc1e34ea0db06 GIT binary patch literal 1849 zcma*odr(tX9tZI2z31lM+(&YVk%mZ}5P~KlG2s=WSbGzm0!x7^P##Mnh7t-jP!X0Q zk_SQ}Po-L1tlDK;6l?(>v)e5ZBQx4|Y-Q?nr@Px3?9h(3ZWr3^tj=`ZP57gKr87N$ zp2wWee1GRRCwo_xahnw)5cxNPJbCg2L6DV|6`#+yw6v6!mDS$f9-JvFD^n;GQ&UrZ zzh5jCkByB101O60U0q#p_1BM>|Ir1RyPr=t6=o)G)nn^|Cu5#S)0=J91Gas#R{McE znYG^9*0A5YZ>#;~+Wkn(W5B0^yELIYLP!K}mB~<)AM@1&nqekynuaEGqPrzoH|KodRXJy)%+w_fu3nE5>@Bd_b zqC$EQ;{c`T&?EsNO|igL9gC7Ygxv?aQUEXMq?~>wg{EyW;VcJ37CUF#HjrT=KQO_* zS>M9yydXk18D(+QDJ1>r);Lav_uYKp$T?4vr{Q$lTo&pKv^?(>L-)G2*lwH!Ah7k? z7oH<8h-(KTKt5V6$8gF)C7Io&P5=SjTh)=zV=E2EUhQZP##L8S{d%UK>>+y82>+FV+#^BzW7u3F)Bb>=lYQ%%j`F>ASe zo*cw@V#u6T`A2He;70mR(V&iV&-7{qP~=SRf&jm9-T{*ZeZ}$rd0#6c&fLG^xJcf5 z+p<`wJYgW+_s*V{uI$nMB;%8`S_3>PfGOj3Rq}@Cx^+j?rk92fANSFDBYnOqQ>Vdj z)(|$AhP4t&Lb=Gvo2#3Gl%9<=Gv`Mz?Po@P4iLF!x}GUWJICDlFk-hS^Whyh7x~VH z@0vD1>HYD4&e+~yzS*-sFR{9`{QEEZO1zg7>R&7cHts-6j!xHVdA8eI+ZlVzd%`es zJT@$#GX(gvCJ1oJN%yLBK}{V=V;seo;!w|Yte!W1%5qLNFWqvZW>h&IiH+oPT=b@E zPhGzv5=(Un*X>v`>%8h_nj^NdYcE6NHS_ifkCV$*D)Tqrbu`s;<=t<4 zAHNqNV?6(g<1PY-w@#I-WYFViz?9TrkMr)u0g`O`u|>T;k|2sV*YF^punvT;$SuTy{j3Gv)yqD!R_CF>yR)MzmmYS5v+~R zXAdD%ng9?df;wd8GxR#%3O+gz};Vo;)sK%Bj-q>Oq%R7JU-KD?vYu>#2UjaDo z&8$>5xW~?KPD_#XFToU1hIb*VOMidUr6iYiO0N|i-7s`T8!cFT`rN!^1Pt78J93i6 z5HI1wIM$94m{3SLDvISDe6$ZG1;eq_D9RTaaC>=cO{@Bs>$IlPCPJJ$h$)-3vzNUQ6OsN#_zWxey!_9%hxwH2_dEJi=yY|1c7nDm2_Lm!Cof8-R_+9UkS zcBE(o47yE)oMR(Q=dp1a2wTX5KvvGyLqlWTa7V&!A*|w|)ax~1_~aJ0=_Lilg*0iQk7#ZD EAE}xSi~s-t literal 0 HcmV?d00001 diff --git a/WebContent/html/webpages/shoppingCart.jsp b/WebContent/html/webpages/shoppingCart.jsp index bc0d203..1c3e84a 100644 --- a/WebContent/html/webpages/shoppingCart.jsp +++ b/WebContent/html/webpages/shoppingCart.jsp @@ -174,7 +174,7 @@ pageEncoding="ISO-8859-1"%> - + @@ -453,6 +453,8 @@ function forceUpdateLocationMetadata() { // This is called just before order form is submitted. In order for any database activity to occur, // we must first append the employees ID as well as the ids of whatever devices are selected. + document.getElementById("load").style.visibility = 'visible'; + // First, employee id userID=getUserID(); document.orderForm.userID.value=userID; From bad76543f34cbea8c558b59932d98a612d2379ec Mon Sep 17 00:00:00 2001 From: Adam R Claxton Date: Sun, 23 Apr 2017 23:03:16 -0400 Subject: [PATCH 42/43] Admin add/removal update from meagan --- .../webpages/administration/adminThings.jsp | 75 ++++++ .../webpages/administration/approveAdmin.jsp | 240 ++++++++++++++++++ src/database/AdminQuery.java | 152 +++++++++++ 3 files changed, 467 insertions(+) create mode 100644 WebContent/html/webpages/administration/adminThings.jsp create mode 100644 WebContent/html/webpages/administration/approveAdmin.jsp create mode 100644 src/database/AdminQuery.java diff --git a/WebContent/html/webpages/administration/adminThings.jsp b/WebContent/html/webpages/administration/adminThings.jsp new file mode 100644 index 0000000..587e09a --- /dev/null +++ b/WebContent/html/webpages/administration/adminThings.jsp @@ -0,0 +1,75 @@ + + +<%@ page import = "database.*,entities.*" %> +<%@ page import = "java.util.Random" %> +<%@ page import = "database.*" %> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> +<%@ page import = "java.sql.*" %> +<%@ page import = "java.security.MessageDigest" %> +<%@ page import = "java.security.NoSuchAlgorithmException" %> + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WebContent/html/webpages/administration/approveAdmin.jsp b/WebContent/html/webpages/administration/approveAdmin.jsp new file mode 100644 index 0000000..8c67fd7 --- /dev/null +++ b/WebContent/html/webpages/administration/approveAdmin.jsp @@ -0,0 +1,240 @@ +<%@ page import="database.*,entities.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + + + + + + + + +Synchrony Financial + + + + + + + + + + + + + + +
    + + + + + + + + +
    NameSSOFinger Print
    + + +
    + + + +