Skip to content

Commit

Permalink
Working off of One Device Class
Browse files Browse the repository at this point in the history
  • Loading branch information
clj13001 committed Mar 30, 2017
1 parent f256d44 commit e8e507c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
6 changes: 3 additions & 3 deletions WebContent/html/javascript/listing.jsp
Original file line number Diff line number Diff line change
@@ -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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
Expand All @@ -9,10 +9,10 @@
<body>
<%
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);
Expand Down
8 changes: 4 additions & 4 deletions src/database/MySQLAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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++;
}

Expand Down
26 changes: 10 additions & 16 deletions src/entities/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,36 @@
*
*/
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.
*/
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();
}
Expand Down Expand Up @@ -72,10 +70,6 @@ public String getDesc(){
return Device_Description;
}

public String getTicketID(){
return Ticket_ID;
}

public String getModel(){
return Model;
}
Expand Down

0 comments on commit e8e507c

Please sign in to comment.