From e8e507cf1aed99a3a4a9d3ac97671a45bc688daa Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Thu, 30 Mar 2017 11:12:55 -0400 Subject: [PATCH] Working off of One Device Class --- WebContent/html/javascript/listing.jsp | 6 +++--- src/database/MySQLAccess.java | 8 ++++---- src/entities/Device.java | 26 ++++++++++---------------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/WebContent/html/javascript/listing.jsp b/WebContent/html/javascript/listing.jsp index 64ca8fc..94fda82 100644 --- a/WebContent/html/javascript/listing.jsp +++ b/WebContent/html/javascript/listing.jsp @@ -1,4 +1,4 @@ -<%@ page import = "database.MySQLAccess,entities.ListedDevice" %> +<%@ page import = "database.MySQLAccess,entities.Device" %> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> @@ -9,10 +9,10 @@ <% MySQLAccess myaccess = new MySQLAccess(); -ListedDevice[] mydevices = myaccess.getAllDevices(); +Device[] mydevices = myaccess.getAllDevices(); //string representation of array. -String deviceString = ListedDevice.arrayToString(mydevices); +String deviceString = Device.arrayToString(mydevices); //out.println(description); //out.println(hardware); diff --git a/src/database/MySQLAccess.java b/src/database/MySQLAccess.java index c2e5fd0..dad52d9 100644 --- a/src/database/MySQLAccess.java +++ b/src/database/MySQLAccess.java @@ -3,7 +3,7 @@ import java.sql.*; import java.util.Date; -import entities.ListedDevice; +import entities.Device; import entities.Location; import entities.RentedDevice; import entities.User; @@ -240,7 +240,7 @@ public RentedDevice[] getUserDevices(String userID) throws SQLException, ClassNo return devices; } - public ListedDevice[] getAllDevices() throws SQLException, ClassNotFoundException{ + public Device[] getAllDevices() throws SQLException, ClassNotFoundException{ //database connect System.getenv("VCAP_SERVICES"); Class.forName("com.mysql.jdbc.Driver"); @@ -254,11 +254,11 @@ public ListedDevice[] getAllDevices() throws SQLException, ClassNotFoundExceptio resultSet.beforeFirst(); //Covers amount of rows, and 6 attributes (indices 0-5) - ListedDevice[] devices = new ListedDevice[rows]; + Device[] devices = new Device[rows]; //iterate result set while(resultSet.next()){ - devices[counter] = new ListedDevice(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.getString("Device_ID"),resultSet.getString("Device_Description"),resultSet.getString("Hardware"), resultSet.getString("Model"), resultSet.getString("Manufacturer"), resultSet.getString("Status")); counter++; } diff --git a/src/entities/Device.java b/src/entities/Device.java index 8ec6f6a..29a5975 100644 --- a/src/entities/Device.java +++ b/src/entities/Device.java @@ -6,24 +6,22 @@ * */ public class Device { - private String Device_ID; private String Device_Name; + private String Device_ID; 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; + private String Manu; + private String Status; - public Device(String id, String name, String desc, String ticketid, String hardware, String model, String date){ + public Device(String name, String id, String desc, String hardware, String model, String manufacturer, String available) { Device_ID = id; Device_Name = name; Device_Description = desc; - Ticket_ID = ticketid; Hardware = hardware; Model = model; - Borrow_Date = date; + Manu = manufacturer; + Status = available; } /** * Formatting the device to fit a JSON object. @@ -31,13 +29,13 @@ public Device(String id, String name, String desc, String ticketid, String hardw 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("{\"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("\"ticket\": \"").append(Ticket_ID).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("\"checkout\": \"").append(Borrow_Date).append("\""); + sb.append("\"manufacturer\": \"").append(Manu).append("\""); sb.append("}"); return sb.toString(); } @@ -72,10 +70,6 @@ public String getDesc(){ return Device_Description; } - public String getTicketID(){ - return Ticket_ID; - } - public String getModel(){ return Model; }