diff --git a/WebContent/adminLogin.jsp b/WebContent/adminLogin.jsp
index 95e1db4..e33796f 100644
--- a/WebContent/adminLogin.jsp
+++ b/WebContent/adminLogin.jsp
@@ -31,10 +31,27 @@ String database = "jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2f
String user = "b372dfe7409692";
String password = "74f6e317";
Class.forName("com.mysql.jdbc.Driver");
-Connection connection = DriverManager.getConnection(database, user, password);
-Statement stmt = connection.createStatement();
-ResultSet result;
-result = stmt.executeQuery("select admin.*,employee.Name FROM admin INNER JOIN employee ON admin.Admin_ID = employee.Employee_ID WHERE Admin_ID='" + ssoNum + "' AND Password='" + generatedPass + "'");
+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 = stmt.executeQuery("select admin.*,employee.Name FROM admin INNER JOIN employee ON admin.Admin_ID = employee.Employee_ID WHERE Admin_ID='" + ssoNum + "' AND Password='" + generatedPass + "'");
if (result.next()){
request.getSession();
diff --git a/WebContent/html/webpages/administration/admin.jsp b/WebContent/html/webpages/administration/admin.jsp
index 0e6ea28..d74b3fc 100644
--- a/WebContent/html/webpages/administration/admin.jsp
+++ b/WebContent/html/webpages/administration/admin.jsp
@@ -7,7 +7,7 @@
-
Synchrony Financial
+Innovation Hub
diff --git a/WebContent/html/webpages/administration/adminApprove.jsp b/WebContent/html/webpages/administration/adminApprove.jsp
index 737541d..e144f39 100644
--- a/WebContent/html/webpages/administration/adminApprove.jsp
+++ b/WebContent/html/webpages/administration/adminApprove.jsp
@@ -11,7 +11,7 @@
- Synchrony Financial
+ Innovation Hub
diff --git a/WebContent/html/webpages/administration/adminDeviceSettings.jsp b/WebContent/html/webpages/administration/adminDeviceSettings.jsp
index 28ae345..c2a24c8 100644
--- a/WebContent/html/webpages/administration/adminDeviceSettings.jsp
+++ b/WebContent/html/webpages/administration/adminDeviceSettings.jsp
@@ -11,10 +11,16 @@ pageEncoding="ISO-8859-1"%>
- Synchrony Financial
+ Innovation Hub
+
+
+
+
+
+
@@ -68,7 +78,7 @@ pageEncoding="ISO-8859-1"%>
diff --git a/WebContent/html/webpages/somethingwrong.jsp b/WebContent/html/webpages/somethingwrong.jsp
index bfee42c..cfa5191 100644
--- a/WebContent/html/webpages/somethingwrong.jsp
+++ b/WebContent/html/webpages/somethingwrong.jsp
@@ -8,7 +8,7 @@
- Synchrony Financial
+ Innovation Hub
diff --git a/WebContent/html/webpages/statisticsPage.jsp b/WebContent/html/webpages/statisticsPage.jsp
index dfb2309..bae860d 100644
--- a/WebContent/html/webpages/statisticsPage.jsp
+++ b/WebContent/html/webpages/statisticsPage.jsp
@@ -7,7 +7,7 @@
- Synchrony Financial
+ Innovation Hub
diff --git a/WebContent/html/webpages/userLogin.jsp b/WebContent/html/webpages/userLogin.jsp
index f3f35ff..000f5cb 100644
--- a/WebContent/html/webpages/userLogin.jsp
+++ b/WebContent/html/webpages/userLogin.jsp
@@ -11,7 +11,7 @@
- Synchrony Financial
+ Innovation Hub
@@ -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/WebContent/index.jsp b/WebContent/index.jsp
index 7c4f219..a7e27bd 100644
--- a/WebContent/index.jsp
+++ b/WebContent/index.jsp
@@ -12,7 +12,7 @@
- Synchrony Financial
+ Innovation Hub
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 14a1b3a..43a98b8 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(
@@ -96,12 +190,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 08f0f2a..0f28d9e 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,137 +59,232 @@ 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();
- 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);
- 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);
+ }
+ }
+ 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);
+ 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, 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 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 changed to 'status' since 'millieconds' and associated with 'employee'
+ public static Ticket[] getRecentlyChangedTickets(int userID, String status, 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 = '"+status+"' 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++;
}
- // Returns all tickets changed to 'status' since 'millieconds' and associated with 'employee'
- public static Ticket[] getRecentlyChangedTickets(int userID, String status, 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 = '"+status+"' 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;
+ stmt.close();
+ connect.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);
+ }
}
- 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;
+ 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