From 84490751214b665500ce427193719b266b0e33a2 Mon Sep 17 00:00:00 2001 From: Brianna Date: Thu, 6 Apr 2017 00:56:28 -0400 Subject: [PATCH 1/2] Accept Tickets -- tickets still need to be viewable --- WebContent/html/webpages/admin.jsp | 2 +- WebContent/html/webpages/adminApprove.jsp | 35 +++++++---- WebContent/html/webpages/approve.jsp | 17 ++++++ WebContent/html/webpages/navbar.html | 2 +- src/database/TicketQueries.java | 30 +++++++++- src/entities/Ticket.java | 73 +++++++++++++++++++++++ 6 files changed, 144 insertions(+), 15 deletions(-) create mode 100644 WebContent/html/webpages/approve.jsp create mode 100644 src/entities/Ticket.java diff --git a/WebContent/html/webpages/admin.jsp b/WebContent/html/webpages/admin.jsp index d3992f8..afdf899 100644 --- a/WebContent/html/webpages/admin.jsp +++ b/WebContent/html/webpages/admin.jsp @@ -73,7 +73,7 @@ div.approveConfirm { + +

Admin View Approvals

-
- +
- - - - + + + + - - <%TicketQueries tickets = new TicketQueries(); - tickets.getTickets(); %> - - - + + +
IdRequestorLocationDevice IDTicket IDRequestor NameLocation NameDevice Name Status Return Date
- - + <%TicketQueries query = new TicketQueries(); + Ticket[] tickets = query.getTickets(); + User[] users = EmployeeQueries.getAllUsers(); + Location[] locations = LocationQueries.getAllLocations(); + ListedDevice[] devices = DeviceQueries.getAllDevices(); + String ticketStr = Ticket.arrayToString(tickets); + String userStr = User.arrayToString(users); + String locationStr = Location.arrayToString(locations).replace("'","\\'"); + String deviceStr = ListedDevice.arrayToString(devices); + %> + + \ No newline at end of file diff --git a/WebContent/html/webpages/approve.jsp b/WebContent/html/webpages/approve.jsp deleted file mode 100644 index cbdc670..0000000 --- a/WebContent/html/webpages/approve.jsp +++ /dev/null @@ -1,17 +0,0 @@ -<%@ page import = "database.*" %> -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> -<%@ page import = "java.sql.*" %> -<% -MySQLAccess myaccess = new MySQLAccess(); -Statement statement = myaccess.getStatement(); -ResultSet result = statement.executeQuery("select * FROM ticket where Status='Requested'"); -if (result.next()){ - statement.executeQuery("UPDATE ticket SET Status='Approved'"); //is this the right status we wanted?? - myaccess.closeConnection(); - response.sendRedirect("html/webpages/adminApprove.jsp"); -} else { - myaccess.closeConnection(); - response.sendRedirect("adminApprove.jsp"); -} -%> \ No newline at end of file diff --git a/WebContent/html/webpages/navbar.html b/WebContent/html/webpages/navbar.html index 5b76006..578a279 100644 --- a/WebContent/html/webpages/navbar.html +++ b/WebContent/html/webpages/navbar.html @@ -6,7 +6,7 @@ - + diff --git a/WebContent/html/webpages/ticketAdminRedirect.jsp b/WebContent/html/webpages/ticketAdminRedirect.jsp new file mode 100644 index 0000000..6e61fbe --- /dev/null +++ b/WebContent/html/webpages/ticketAdminRedirect.jsp @@ -0,0 +1,53 @@ +<%@ page import = "database.*" %> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + + + + + + + + Synchrony Financial + + + + + + + + + + +

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"); +int ticketid = Integer.parseInt(ticketidstr); +int deviceid = Integer.parseInt(deviceidstr); +int locationid = Integer.parseInt(locationidstr); + +//add form was submitted +if(request.getParameter("approve") != null){ + TicketQueries.acceptTicket(ticketid,deviceid,locationid); +} +//modify form was submitted +if(request.getParameter("reject") != null){ + TicketQueries.rejectTicket(ticketid); +} +%> + + + + \ No newline at end of file diff --git a/src/database/EmployeeQueries.java b/src/database/EmployeeQueries.java index 981329b..b10daf9 100644 --- a/src/database/EmployeeQueries.java +++ b/src/database/EmployeeQueries.java @@ -48,4 +48,29 @@ public static User getEmployeeByID(int id) throws ClassNotFoundException, SQLExc access.closeConnection(); return employee; } + + public static User[] getAllUsers() throws SQLException, ClassNotFoundException{ + //database connect + System.getenv("VCAP_SERVICES"); + MySQLAccess access = new MySQLAccess(); + Statement stmt = access.getStatement(); + ResultSet resultSet = stmt.executeQuery("SELECT * FROM employee"); + int counter = 0; + + resultSet.last(); + int rows = resultSet.getRow(); + resultSet.beforeFirst(); + + //Covers amount of rows, and 6 attributes (indices 0-5) + User[] users = new User[rows]; + + //iterate result set + while(resultSet.next()){ + users[counter] = new User(resultSet.getInt("Employee_ID"),resultSet.getInt("Location_ID"),resultSet.getString("Name"),resultSet.getString("Phone_Number")); + counter++; + } + + access.closeConnection(); + return users; + } } \ No newline at end of file diff --git a/src/database/LocationQueries.java b/src/database/LocationQueries.java index cbac6d5..7dc01a1 100644 --- a/src/database/LocationQueries.java +++ b/src/database/LocationQueries.java @@ -139,4 +139,29 @@ public static void deleteLocation(int id) throws ClassNotFoundException, SQLExce stmt.close(); connect.close(); } + + public static Location[] getAllLocations() throws SQLException, ClassNotFoundException{ + //database connect + System.getenv("VCAP_SERVICES"); + MySQLAccess access = new MySQLAccess(); + Statement stmt = access.getStatement(); + ResultSet resultSet = stmt.executeQuery("SELECT * FROM location"); + int counter = 0; + + resultSet.last(); + int rows = resultSet.getRow(); + resultSet.beforeFirst(); + + //Covers amount of rows, and 6 attributes (indices 0-5) + Location[] locations = new Location[rows]; + + //iterate result set + while(resultSet.next()){ + locations[counter] = new Location(resultSet.getInt("Location_ID"),resultSet.getString("Name"),resultSet.getString("Address"),resultSet.getString("Town"),resultSet.getString("State"),resultSet.getString("Zip_Code")); + counter++; + } + + access.closeConnection(); + return locations; + } } \ No newline at end of file diff --git a/src/database/TicketQueries.java b/src/database/TicketQueries.java index 92f148c..ce71bbf 100644 --- a/src/database/TicketQueries.java +++ b/src/database/TicketQueries.java @@ -54,5 +54,26 @@ public Ticket[] getTickets() throws SQLException, ClassNotFoundException{ myaccess.closeConnection(); return tickets; } + + public static void acceptTicket(int ticketid, int deviceid, int locationid) throws SQLException, ClassNotFoundException{ + 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(); + stmt.executeUpdate("UPDATE ticket SET Status = \"Approved\" WHERE Ticket_ID = " + ticketid); + stmt.executeUpdate("UPDATE devices SET Ticket_ID = " + ticketid + ", Status = \"Shipped\", Renter = 10, Location = " + locationid + " WHERE Device_ID = " + deviceid); + stmt.close(); + connect.close(); + } + + public static void rejectTicket(int id) throws SQLException, ClassNotFoundException{ + 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(); + stmt.executeUpdate("UPDATE ticket SET Status = \"Rejected\" WHERE Ticket_ID = " + id); + stmt.close(); + connect.close(); + } } diff --git a/src/entities/Ticket.java b/src/entities/Ticket.java index a25450c..2ab6cc9 100644 --- a/src/entities/Ticket.java +++ b/src/entities/Ticket.java @@ -22,6 +22,32 @@ public Ticket(int id, int requestor, int location, int deviceId, String status, this._returnDate = returnDate; } + public String toString(){ + StringBuilder sb = new StringBuilder(); + String comma = ", "; + sb.append("{\"requestor\": ").append(_requestor).append(comma); + sb.append("\"id\": ").append(_id).append(comma); + sb.append("\"location\": ").append(_location).append(comma); + sb.append("\"deviceID\": ").append(_deviceId).append(comma); + sb.append("\"status\": \"").append(_status).append("\"").append(comma); + sb.append("\"return\": \"").append(_returnDate).append("\""); + sb.append("}"); + return sb.toString(); + } + + public static String arrayToString(Ticket[] 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 int getId(){ return _id; } diff --git a/src/entities/User.java b/src/entities/User.java index 5545d91..da619e3 100644 --- a/src/entities/User.java +++ b/src/entities/User.java @@ -13,6 +13,31 @@ public User(int id, int location, String name, String phone){ this.name = name; //later will do table lookup to determine by id this.phone = phone; } + + public String toString(){ + StringBuilder sb = new StringBuilder(); + String comma = ", "; + sb.append("{\"id\": ").append(id).append(comma); + sb.append("\"location\": ").append(location).append(comma); + sb.append("\"name\": \"").append(name).append("\"").append(comma); + sb.append("\"phone\": \"").append(phone).append("\""); + sb.append("}"); + return sb.toString(); + } + + public static String arrayToString(User[] 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 int getID() { return id;