diff --git a/WebContent/html/webpages/deviceRedirect.jsp b/WebContent/html/webpages/deviceRedirect.jsp
new file mode 100644
index 0000000..7ba8b98
--- /dev/null
+++ b/WebContent/html/webpages/deviceRedirect.jsp
@@ -0,0 +1,70 @@
+<%@ page import = "database.MySQLAccess,entities.Device" %>
+<%@ 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
+MySQLAccess myaccess = new MySQLAccess();
+String name = request.getParameter("name").replace("\"","\\\"");
+String description = request.getParameter("description").replace("\"","\\\"");
+String mac = request.getParameter("MAC");
+String manufacturer = request.getParameter("manu").replace("\"","\\\"");
+String hardware = request.getParameter("hardware").replace("\"","\\\"");
+String model = request.getParameter("model").replace("\"","\\\"");
+String serial = request.getParameter("serial");
+String nfc = request.getParameter("NFC");
+//add form was submitted
+if(request.getParameter("add") != null){
+ Device device = new Device(name,description,mac,manufacturer,hardware,model,serial,nfc);
+ myaccess.addDevice(device);
+}
+/*
+//modify form was submitted
+if(request.getParameter("modify") != null){
+ //getParameter() always returns string
+ 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);
+ myaccess.modifyLocation(location);
+}
+
+//delete form was submitted
+if(request.getParameter("delete") != null){
+ String strID = request.getParameter("id");
+ int id = Integer.parseInt(strID);
+ myaccess.deleteLocation(id);
+}
+*/
+%>
+
+
+
+
+
\ No newline at end of file
diff --git a/src/database/MySQLAccess.java b/src/database/MySQLAccess.java
index dad52d9..cd28de6 100644
--- a/src/database/MySQLAccess.java
+++ b/src/database/MySQLAccess.java
@@ -122,7 +122,6 @@ public int addLocation(Location location) throws SQLException, ClassNotFoundExce
id = results.getInt("Location_ID");
id++;
//tries this statement, otherwise tries again with a new id
- System.out.println("INSERT INTO location (Location_ID,Name,Address,Town,State,Zip_Code,Employee_Flag) VALUES (" + id +",\"" + location.getName() + "\",\"" + location.getAddress()+ "\",\"" + location.getTown() + "\",\"" + location.getState() + "\",\"" + location.getZip()+"\","+location.getEmployeeFlag() + ")");
i = stmt.executeUpdate("INSERT INTO location (Location_ID,Name,Address,Town,State,Zip_Code,Employee_Flag) VALUES (" + id +",\"" + location.getName() + "\",\"" + location.getAddress()+ "\",\"" + location.getTown() + "\",\"" + location.getState() + "\",\"" + location.getZip()+"\","+location.getEmployeeFlag() + ")");
}
stmt.close();
@@ -258,7 +257,7 @@ public Device[] getAllDevices() throws SQLException, ClassNotFoundException{
//iterate result set
while(resultSet.next()){
- devices[counter] = new Device(resultSet.getString("Device_Name"),resultSet.getString("Device_ID"),resultSet.getString("Device_Description"),resultSet.getString("Hardware"), resultSet.getString("Model"), resultSet.getString("Manufacturer"), resultSet.getString("Status"));
+ devices[counter] = new Device(resultSet.getString("Device_Name"),resultSet.getInt("Device_ID"),resultSet.getString("Device_Description"),resultSet.getString("Hardware"),resultSet.getString("Model"),resultSet.getString("Manufacturer"),resultSet.getString("Status"),resultSet.getString("MAC_Address"),resultSet.getString("Serial_Num"),resultSet.getInt("NFC_ID"));
counter++;
}
@@ -322,4 +321,26 @@ public void deleteLocation(int id) throws ClassNotFoundException, SQLException{
stmt.close();
connect.close();
}
+
+ public void addDevice(Device device) 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();
+ int i = -1;
+ int id=0;
+ while(i <= 0){
+ ResultSet results = stmt.executeQuery("SELECT * from devices ORDER BY Device_ID");
+ 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,Added_By,NFC_ID) " + "VALUES (" + id +",\"" + device.getName() + "\",\"" + device.getDesc()+ "\",\"" + device.getMAC() + "\",\"" + device.getManufacturer() + "\",\""+device.getHardware()+ "\",\"" + device.getModel() + "\",\"" + device.getSerial() + "\",30," + device.getNFC() + ");"; //TODO update the Added_By to include cookies
+ System.out.println(command);
+ i = stmt.executeUpdate(command);
+ }
+ stmt.close();
+ connect.close();
+ }
}
diff --git a/src/entities/Device.java b/src/entities/Device.java
index 29a5975..5b339e5 100644
--- a/src/entities/Device.java
+++ b/src/entities/Device.java
@@ -7,14 +7,17 @@
*/
public class Device {
private String Device_Name;
- private String Device_ID;
+ private int Device_ID;
private String Device_Description;
private String Hardware;
private String Model;
private String Manu;
private String Status;
+ private String MAC;
+ private String Serial;
+ private int NFC;
- public Device(String name, String id, String desc, String hardware, String model, String manufacturer, String available) {
+ public Device(String name, int id, String desc, String hardware, String model, String manufacturer, String available, String mac, String serial, int nfc) {
Device_ID = id;
Device_Name = name;
Device_Description = desc;
@@ -22,6 +25,31 @@ public Device(String name, String id, String desc, String hardware, String model
Model = model;
Manu = manufacturer;
Status = available;
+ MAC = mac;
+ Serial = serial;
+ NFC = nfc;
+ }
+
+ /**
+ * Constructor for newly created devices (so we omit the ID)
+ * @param name
+ * @param description
+ * @param mac
+ * @param manufacturer
+ * @param hardware
+ * @param model
+ * @param serial
+ * @param nfc
+ */
+ public Device(String name, String description, String mac, String manufacturer, String hardware, String model, String serial, String nfc){
+ Device_Name = name;
+ Device_Description = description;
+ MAC = mac;
+ Manu = manufacturer;
+ Hardware = hardware;
+ Model = model;
+ Serial = serial;
+ NFC = Integer.parseInt(nfc);
}
/**
* Formatting the device to fit a JSON object.
@@ -35,7 +63,10 @@ public String toString(){
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("\"manufacturer\": \"").append(Manu).append("\"").append(comma);
+ sb.append("\"mac\": \"").append(MAC).append("\"").append(comma);
+ sb.append("\"serial\": \"").append(Serial).append("\"").append(comma);
+ sb.append("\"nfc\": ").append(NFC);
sb.append("}");
return sb.toString();
}
@@ -58,7 +89,7 @@ public static String arrayToString(Device[] array){
return sb.toString();
}
- public String getID(){
+ public int getID(){
return Device_ID;
}
@@ -77,4 +108,20 @@ public String getModel(){
public String getHardware(){
return Hardware;
}
+
+ public String getMAC(){
+ return MAC;
+ }
+
+ public String getManufacturer(){
+ return Manu;
+ }
+
+ public String getSerial(){
+ return Serial;
+ }
+
+ public int getNFC() {
+ return NFC;
+ }
}