diff --git a/res/userdb.db b/res/userdb.db deleted file mode 100644 index 5d9b977..0000000 Binary files a/res/userdb.db and /dev/null differ diff --git a/src/main/java/seng202/group9/Controller/AirlineParser.java b/src/main/java/seng202/group9/Controller/AirlineParser.java index 9f2b8a0..4a354b9 100644 --- a/src/main/java/seng202/group9/Controller/AirlineParser.java +++ b/src/main/java/seng202/group9/Controller/AirlineParser.java @@ -1,5 +1,7 @@ package seng202.group9.Controller; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import seng202.group9.Core.Airline; import java.io.*; diff --git a/src/main/java/seng202/group9/Controller/AirportParser.java b/src/main/java/seng202/group9/Controller/AirportParser.java index 3598adf..04c1b15 100644 --- a/src/main/java/seng202/group9/Controller/AirportParser.java +++ b/src/main/java/seng202/group9/Controller/AirportParser.java @@ -1,10 +1,14 @@ package seng202.group9.Controller; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import seng202.group9.Core.Airport; import seng202.group9.Core.City; import seng202.group9.Core.Country; +import javax.jws.Oneway; import java.io.*; +import java.lang.reflect.Array; import java.util.ArrayList; public class AirportParser extends Parser { diff --git a/src/main/java/seng202/group9/Controller/App.java b/src/main/java/seng202/group9/Controller/App.java index fd6bfbb..da3dbde 100644 --- a/src/main/java/seng202/group9/Controller/App.java +++ b/src/main/java/seng202/group9/Controller/App.java @@ -54,13 +54,36 @@ public class App extends Application e.printStackTrace(); } primaryStage.show(); - /* + //testing out dataset try { currentDataset = new Dataset("test's", Dataset.getExisting); }catch (DataException e){ e.printStackTrace(); + + } + /* + //testout single route adding + try { + currentDataset.addRoute("D2", "MAC", "WIN", "Y", "0", "NOW"); + }catch (DataException e){ + e.printStackTrace(); + } + //testout single airport adding + try { + currentDataset.addAirport("Windows 10", "PC", "Windows", "WIN", "WIND", "0.0", "0.0", "0.0", "0.0", "U", "PC/Windows"); + }catch (DataException e){ + e.printStackTrace(); + } + /* + //testout single airline adding + try { + currentDataset.addAirline("Dota2", "Valve", "D2", "DOT", "Defence of the Ancients", "Steam", "Y"); + }catch (DataException e){ + e.printStackTrace(); } + + //testing out airport parser try { System.out.println(currentDataset.importAirport("res/Samples/Airports.txt")); @@ -78,8 +101,15 @@ public class App extends Application System.out.println(currentDataset.importRoute("res/Samples/Routes.txt")); } catch (DataException e) { e.printStackTrace(); - } - */ + }*/ + + //testing out flight parser + try { + System.out.println(currentDataset.importFlight("res/Samples/NZCH-WSSS.csv")); + } catch (DataException e) { + e.printStackTrace(); + } + } /** diff --git a/src/main/java/seng202/group9/Controller/Dataset.java b/src/main/java/seng202/group9/Controller/Dataset.java index 19c4056..8ca4b3a 100644 --- a/src/main/java/seng202/group9/Controller/Dataset.java +++ b/src/main/java/seng202/group9/Controller/Dataset.java @@ -1,6 +1,8 @@ package seng202.group9.Controller; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import seng202.group9.Core.*; import java.sql.Connection; @@ -13,7 +15,7 @@ import java.util.LinkedHashMap; public class Dataset { String name; - static boolean getExisting = true;//constructor variables for action + public static boolean getExisting = true;//constructor variables for action static boolean createNew = false;//constructor variables for action ArrayList airlines; ArrayList airports; @@ -21,12 +23,12 @@ public class Dataset { ArrayList flightPaths; ArrayList countries; ArrayList cities; - LinkedHashMap airlineDictionary; - LinkedHashMap airportDictionary; - LinkedHashMap routeDictionary; - LinkedHashMap flightPathDictionary; - LinkedHashMap countryDictionary; - LinkedHashMap cityDictionary; + LinkedHashMap airlineDictionary; + LinkedHashMap airportDictionary; + LinkedHashMap routeDictionary; + LinkedHashMap flightPathDictionary; + LinkedHashMap countryDictionary; + LinkedHashMap cityDictionary; /** * @@ -42,11 +44,11 @@ public class Dataset { this.routes = new ArrayList(); this.cities = new ArrayList(); this.countries = new ArrayList(); - this.airlineDictionary = new LinkedHashMap(); - this.airportDictionary = new LinkedHashMap();; - this.routeDictionary = new LinkedHashMap();; - this.countryDictionary = new LinkedHashMap();; - this.cityDictionary = new LinkedHashMap();; + this.airlineDictionary = new LinkedHashMap(); + this.airportDictionary = new LinkedHashMap();; + this.routeDictionary = new LinkedHashMap();; + this.countryDictionary = new LinkedHashMap();; + this.cityDictionary = new LinkedHashMap();; if (action == getExisting){ updateDataset(); //after this make connections. ie filling in the country.cities airports.routes etc @@ -423,7 +425,7 @@ public class Dataset { return message; } /** - * Imports Airline files to the dataset + * Imports Airport files to the dataset * @param filePath * @return Success Message * @throws DataException @@ -557,7 +559,7 @@ public class Dataset { } /** - * Imports Airline files to dataset + * Imports Route files to dataset * @param filePath * @return Success Message * @throws DataException @@ -585,6 +587,7 @@ public class Dataset { nextID = Integer.parseInt(IDResult.getString("seq")) + 1;//for some reason sqlite3 stores incremental values as a string... } stmt.close(); + stmt = c.createStatement(); String insertRouteQuery = "INSERT INTO `" + this.name + "_Routes` (`Airline`, `Source_Airport`, `Destination_Airport`," + " `Codeshare`, `Stops`, `Equipment`) VALUES "; @@ -631,19 +634,17 @@ public class Dataset { } /** - * Imports Airline files to dataset + * Imports Flight files to dataset * @param filePath * @return Success Message * @throws DataException */ - - /* public String importFlight(String filePath) throws DataException { FlightPathParser parser = new FlightPathParser(filePath); //remember this still has to append the duplicate message to it. //routes are identified in the diction by routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip; String message = parser.parse(); - ArrayList flightsToImport = parser.getResult(); + ArrayList flightPointsToImport = parser.getResult(); //check for dup int numOfDuplicates = 0; int nextID = -1; @@ -654,49 +655,69 @@ public class Dataset { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); stmt = c.createStatement(); - String queryName = this.name.replace("'", "''").replace("\"", "\"\""); - String IDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = '"+queryName+"_Routes' LIMIT 1;"; + String queryName = this.name.replace("'", "''"); + String IDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = '"+queryName+"_Flight_Points' LIMIT 1;"; ResultSet IDResult = stmt.executeQuery(IDQuery); while(IDResult.next()){ nextID = Integer.parseInt(IDResult.getString("seq")) + 1;//for some reason sqlite3 stores incremental values as a string... } stmt.close(); stmt = c.createStatement(); - String insertFlightQuery = "INSERT INTO `" + this.name + "_Routes` (`Airline`, `Source_Airport`, `Destination_Airport`," + - " `Codeshare`, `Stops`, `Equipment`) VALUES "; - int numOfRoutes = 0; - for (int i = 0; i < flightsToImport.size(); i ++){ - String routeIdentifier = flightsToImport.get(i).getType() + flightsToImport.get(i).getID() + - flightsToImport.get(i).getAltitude() + flightsToImport.get(i).getLatitude() + - flightsToImport.get(i).getLongitude(); - //if (routeDictionary.containsKey(routeIdentifier)){ - // numOfDuplicates ++; - //}else{ - //route variables - String flightType = flightsToImport.get(i).getType().replace("\"", "\"\""); - String flightID = flightsToImport.get(i).getID().replace("\"", "\"\""); - double flightAltitude = flightsToImport.get(i).getAltitude(); - double flightLatitude = flightsToImport.get(i).getLatitude(); - double flightLongitude = flightsToImport.get(i).getLongitude(); + //ADDED + String firstPt = flightPointsToImport.get(0).getName(); + String lastPt = flightPointsToImport.get(flightPointsToImport.size() - 1).getName(); + FlightPath flightPathToAdd = new FlightPath(firstPt, lastPt); + + String insertFlightPathQuery = "INSERT INTO `" + this.name + "_Flight_Path` (`Source_Airport`, `Destination_Airport`)" + + "VALUES ( \"" + firstPt + "\",\"" + lastPt + "\") "; + stmt.execute(insertFlightPathQuery); + stmt.close(); + stmt = c.createStatement(); + int flightPathId = 0; + String getLastestIndex = "SELECT * FROM `sqlite_sequence` WHERE `name` = \"" + this.name.replace("\"", "\"\"") + + "_Flight_Path\" LIMIT 1;"; + ResultSet lastestIdResult = stmt.executeQuery(getLastestIndex); + while(lastestIdResult.next()){ + flightPathId = Integer.parseInt(lastestIdResult.getString("seq"));//for some reason sqlite3 stores incremental values as a string... + } + stmt.close(); + lastestIdResult.close(); + stmt = c.createStatement(); + flightPathToAdd.setID(flightPathId); + //ADDED + String insertFlightPointQuery = "INSERT INTO `" + this.name + "_Flight_Points` (`Index_ID`, `Name`, `Type`," + + " `Altitude`, `Longitude`, `Latitude`) VALUES "; + int numOfFlights = 0; + for (int i = 0; i < flightPointsToImport.size(); i ++){ + String flightPointIdentifier = flightPointsToImport.get(i).getType() + flightPointsToImport.get(i).getName() + + flightPointsToImport.get(i).getAltitude() + flightPointsToImport.get(i).getLatitude() + + flightPointsToImport.get(i).getLongitude(); + + String flightType = flightPointsToImport.get(i).getType().replace("\"", "\"\""); + String flightName = flightPointsToImport.get(i).getName().replace("\"", "\"\""); + double flightAltitude = flightPointsToImport.get(i).getAltitude(); + double flightLatitude = flightPointsToImport.get(i).getLatitude(); + double flightLongitude = flightPointsToImport.get(i).getLongitude(); //insert import into database - if (numOfRoutes > 0){ - insertFlightQuery += ","; + if (numOfFlights > 0){ + insertFlightPointQuery += ","; } - insertFlightQuery += "(\""+flightType+"\", \"" + flightID + "\", \"" + flightAltitude + "\", " + - "\"" + flightLatitude + "\", " + flightLongitude + "\")"; - flightsToImport.get(i).setID(nextID); + insertFlightPointQuery += "(" + flightPathId +", \""+ flightName +"\", \"" + flightType + "\", "+ flightAltitude + ", " + + "" + flightLatitude + ", " + flightLongitude + ")"; + flightPointsToImport.get(i).setID(nextID); //add data to dataset array. //this is placed after incase the database messes up - flights.add(flightsToImport.get(i)); - routeDictionary.put(routeIdentifier, flightsToImport.get(i)); + flightPathToAdd.addFlightPoint(flightPointsToImport.get(i)); + //routeDictionary.put(routeIdentifier, flightsToImport.get(i)); nextID++; - numOfRoutes++; + numOfFlights++; //} } - if (numOfRoutes > 0){ - stmt.execute(insertRouteQuery); + if (numOfFlights > 0){ + stmt.execute(insertFlightPointQuery); stmt.close(); } + flightPaths.add(flightPathToAdd); } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); System.exit(0); @@ -705,10 +726,10 @@ public class Dataset { createDataLinks(); return message; } - /* - */ + + /** * This function updates the connections between airports citys countries etc. */ @@ -717,6 +738,250 @@ public class Dataset { } + /** + * Addes Single Airline to Program and Database. + * @param name + * @param alias + * @param IATA + * @param ICAO + * @param callsign + * @param country + * @param active + * @throws DataException + */ + public void addAirline(String name, String alias, String IATA, String ICAO, String callsign, String country, String active) throws DataException{ + Airline airlineToAdd = new Airline(name, alias, IATA, ICAO, callsign, country, active); + addAirline(airlineToAdd); + } + + public void addAirline(Airline airlineToAdd) throws DataException{ + if (airlineToAdd.getIATA().length() != 0 && airlineToAdd.getIATA().length() != 2){ + throw new DataException("IATA is either empty or length of 2 Letters."); + } + if (airlineToAdd.getICAO().length() != 0 && airlineToAdd.getICAO().length() != 3){ + throw new DataException("ICAO is either empty or length of 3 Letters."); + } + if (airlineToAdd.getActive().length() != 1){ + throw new DataException ("Active must be Y or N."); + } + for (String key : airlineDictionary.keySet()){ + airlineDictionary.get(key).hasDuplicate(airlineToAdd); + } + //checking is done now we add it to the dictionary and the database + //query database. + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + //add the airline + stmt = c.createStatement(); + String insertAirlineQuery = "INSERT INTO `" + this.name + "_Airline` (`Name`, `Alias`, `IATA`, `ICAO`" + + ", `Callsign`, `Country`, `Active`) VALUES (\""+airlineToAdd.getName()+"\", \"" + airlineToAdd.getAlias() + "\", " + + "\"" + airlineToAdd.getIATA() + "\", \"" + airlineToAdd.getICAO() + "\", \"" + airlineToAdd.getCallSign() + "\", " + + "\"" + airlineToAdd.getCountry() + "\", \"" + airlineToAdd.getActive() + "\");"; + stmt.execute(insertAirlineQuery); + //get the airline id + stmt = c.createStatement(); + String airlineIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+this.name+"_Airline\" LIMIT 1;"; + ResultSet airlineIDRes= stmt.executeQuery(airlineIDQuery); + int airlineID = 0; + while (airlineIDRes.next()){ + airlineID = Integer.parseInt(airlineIDRes.getString("seq")); + } + airlineToAdd.setID(airlineID); + airlines.add(airlineToAdd); + airlineDictionary.put(airlineToAdd.getName(), airlineToAdd); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); + } + } + + public void addAirport(String name, String city, String country, String IATA_FFA, String ICAO, String latitude, String longitude, + String altitude, String timezone, String DST, String olsonTz) throws DataException{ + try{ + double latitudeVal = Double.parseDouble(latitude); + double longitudeVal = Double.parseDouble(longitude); + double altitudeVal = Double.parseDouble(altitude); + double timezoneVal = Double.parseDouble(timezone); + Airport airportToAdd = new Airport(name, city, country, IATA_FFA, ICAO, latitudeVal, longitudeVal, altitudeVal); + City cityToAdd = new City(city, country, timezoneVal, olsonTz); + Country countryToAdd = new Country(DST, country); + addAirport(airportToAdd); + addCity(cityToAdd); + addCountry(countryToAdd); + }catch (NumberFormatException e){ + throw new DataException("Latitude, Longitude, Altitude and Timezone must be numbers"); + } + } + + public void addAirport(Airport airportToAdd) throws DataException{ + if (airportToAdd.getIATA_FFA() != "" && airportToAdd.getIATA_FFA().length() != 3){ + throw new DataException("IATA/FFA either empty or 3 letters"); + } + if (airportToAdd.getICAO() != "" && airportToAdd.getICAO().length() != 4){ + throw new DataException("ICAO either empty or 4 letters"); + } + for (String key : airportDictionary.keySet()){ + airportDictionary.get(key).hasDuplicate(airportToAdd); + } + //checking is done now we add it to the dictionary and the database + //query database. + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + //add the airport + stmt = c.createStatement(); + String insertAirportQuery = "INSERT INTO `" + this.name + "_Airport` (`Name`, `City`, `Country`, `IATA/FFA`, " + + "`ICAO`, `Latitude`, `Longitude`, `Altitude`) VALUES (\""+airportToAdd.getName()+"\", \""+airportToAdd.getCity()+"\", " + + "\""+airportToAdd.getCountry()+"\", \""+airportToAdd.getIATA_FFA()+"\", \""+airportToAdd.getICAO()+"\", " + + ""+airportToAdd.getLatitude()+", "+airportToAdd.getLongitude()+", "+airportToAdd.getAltitude()+");"; + stmt.execute(insertAirportQuery); + //get the airport id + stmt = c.createStatement(); + String airportIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+this.name+"_Airport\" LIMIT 1;"; + ResultSet airportIDRes= stmt.executeQuery(airportIDQuery); + int airportID = 0; + while (airportIDRes.next()){ + airportID = Integer.parseInt(airportIDRes.getString("seq")); + } + airportToAdd.setID(airportID); + airports.add(airportToAdd); + airportDictionary.put(airportToAdd.getName(), airportToAdd); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); + } + } + + public void addCity(City city){ + if (!cityDictionary.containsKey(city.getName())){ + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + //add the city + stmt = c.createStatement(); + String cityName = city.getName().replace("\"", "\"\""); + String countryName = city.getCountry().replace("\"", "\"\""); + String olson = city.getTimeOlson().replace("\"", "\"\""); + String insertCityQuery = "INSERT INTO `" + this.name + "_City` (`City_Name`, `Country_Name`, `Timezone`, " + + "`Olson_Timezone`) VALUES (\""+cityName+"\", \""+countryName+"\", "+city.getTimezone() + ", \""+olson+"\");"; + stmt.execute(insertCityQuery); + stmt.close(); + cityDictionary.put(city.getName(), city); + cities.add(city); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); + } + } + } + + public void addCountry(Country country){ + if (!countryDictionary.containsKey(country.getName())){ + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + //add the city + stmt = c.createStatement(); + String countryName = country.getName().replace("\"", "\"\""); + String countryDST = country.getDST().replace("\"", "\"\""); + String insertCityQuery = "INSERT INTO `" + this.name + "_Country` (`Country_Name`, `DST`) VALUES" + + " (\""+countryName+"\", \""+countryDST+"\");"; + stmt.execute(insertCityQuery); + stmt.close(); + countryDictionary.put(country.getName(), country); + countries.add(country); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); + } + } + } + + /** + * Adds one single route to the program. + * @param airline + * @param sourceAirport + * @param destAirport + * @param codeshare + * @param stops + * @param equipment + * @throws DataException + */ + public void addRoute(String airline, String sourceAirport, String destAirport, String codeshare, String stops, String equipment) throws DataException{ + int stopsVal = 0; + try{ + stopsVal = Integer.parseInt(stops); + }catch (NumberFormatException e){ + throw new DataException("Stops must be a greater than or equal to 0."); + } + if (stopsVal < 0){ + throw new DataException("Stops must be a greater than or equal to 0."); + } + Route routeToAdd = new Route(airline, sourceAirport, destAirport, codeshare, stopsVal, equipment); + addRoute(routeToAdd); + } + + public void addRoute(Route routeToAdd) throws DataException{ + if (routeToAdd.getAirline().length() != 2 && routeToAdd.getAirline().length() != 3){ + throw new DataException("Airline ICAO code must be 2 or 3 letters."); + } + if (routeToAdd.departsFrom().length() != 3 && routeToAdd.departsFrom().length() != 4){ + throw new DataException("Airport Source Airport IATA must be 3 letters or 4 letters if ICAO."); + } + if (routeToAdd.arrivesAt().length() != 3 && routeToAdd.arrivesAt().length() != 4){ + throw new DataException("Airport Destination Airport IATA must be 3 letters or 4 letters if ICAO."); + } + if (routeToAdd.getCode().length() != 0 && routeToAdd.getCode().length() != 1){ + throw new DataException("Codeshare has to be empty or Y."); + } + for (String key : routeDictionary.keySet()){ + routeDictionary.get(key).hasDuplicate(routeToAdd); + } + //checking is done now we add it to the dictionary and the database + //query database. + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + //add the airline + stmt = c.createStatement(); + String airline = routeToAdd.getAirline().replace("\"", "\"\""); + String sourceAir = routeToAdd.departsFrom().replace("\"", "\"\""); + String destAir = routeToAdd.arrivesAt().replace("\"", "\"\""); + String equipment = routeToAdd.getEquipment().replace("\"", "\"\""); + String insertRouteQuery = "INSERT INTO `" + this.name + "_Routes` (`Airline`, `Source_Airport`, `Destination_Airport`," + + " `Codeshare`, `Stops`, `Equipment`) VALUES (\""+airline+"\", \""+sourceAir+"\", \""+destAir+"\", " + + "\""+routeToAdd.getCode()+"\", "+routeToAdd.getStops()+", \""+equipment+"\")"; + stmt.execute(insertRouteQuery); + //get the airline id + stmt = c.createStatement(); + String routeIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+this.name+"_Route\" LIMIT 1;"; + ResultSet routeIDRes= stmt.executeQuery(routeIDQuery); + int routeID = 0; + while (routeIDRes.next()){ + routeID = Integer.parseInt(routeIDRes.getString("seq")); + } + routeToAdd.setID(routeID); + routes.add(routeToAdd); + //routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip + String routeKey = routeToAdd.getAirline() + routeToAdd.departsFrom() + routeToAdd.arrivesAt() + routeToAdd.getCode() + routeToAdd.getStops() + routeToAdd.getEquipment(); + routeDictionary.put(routeKey, routeToAdd); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); + } + } + public ArrayList getAirlines() { return airlines; } diff --git a/src/main/java/seng202/group9/Core/Airline.java b/src/main/java/seng202/group9/Core/Airline.java index f98368b..54ebc8d 100644 --- a/src/main/java/seng202/group9/Core/Airline.java +++ b/src/main/java/seng202/group9/Core/Airline.java @@ -205,7 +205,7 @@ public class Airline { } /** * Function Overload of addRoutes this allow the adding of a list to route - * @param routes + * @param routesToAdd array list of routes to add routes */ public void addRoutes(ArrayList routesToAdd){ for (int i = 0; i < routesToAdd.size(); i ++){ @@ -228,6 +228,29 @@ public class Airline { public void delRoutes(int index){ routes.remove(index); } + + /** + * checks if the airline has a duplicate unique entry to another. Used for validating + * @param airline + * @return + */ + public void hasDuplicate(Airline airline) throws DataException{ + if (this.name.equals(airline.getName())){ + throw new DataException("This Airline Name already Exists, Please Choose Another."); + } + if (!this.IATA.equals("") && this.IATA.equals(airline.getIATA())){ + throw new DataException("This IATA Code already Exists, Please Choose Another."); + } + if (!this.ICAO.equals("") && this.ICAO.equals(airline.getICAO())){ + throw new DataException("This ICAO Code already Exists, Please Choose Another."); + } + if (!this.alias.equals("") && this.alias.equals(airline.getAlias())){ + throw new DataException("This Alias already Exists, Please Choose Another."); + } + if (!this.callSign.equals("") && this.callSign.equals(airline.getCallSign())){ + throw new DataException("This Callsign already Exists, Please Choose Another."); + } + } /** * returns the name of the airline when concatenated to a string. */ diff --git a/src/main/java/seng202/group9/Core/Airport.java b/src/main/java/seng202/group9/Core/Airport.java index 5de5e4d..64c5d31 100644 --- a/src/main/java/seng202/group9/Core/Airport.java +++ b/src/main/java/seng202/group9/Core/Airport.java @@ -195,9 +195,9 @@ public class Airport { * gets the IATA/FFA of the airport * @return IATA/FFA Code */ - public String IATA_FFA(){ - return IATA_FFA; - } +// public String IATA_FFA(){ +// return IATA_FFA; +// } /** * gets the altitude of the airport * @return Altitude of Airport @@ -304,9 +304,21 @@ public class Airport { distance = 6371 * c; return distance; } + public void hasDuplicate(Airport airport) throws DataException{ + if (!airport.getName().equals("") && airport.getName().equals(this.name)){ + throw new DataException("Airport Name already Exists, Please Choose Another."); + } + if (!airport.getIATA_FFA().equals("") && airport.getIATA_FFA().equals(this.name)){ + throw new DataException("Airport IATA/FFA already Exists, Please Choose Another."); + } + if (!airport.getICAO().equals("") && airport.getICAO().equals(this.name)){ + throw new DataException("Airport ICAO already Exists, Please Choose Another."); + } + } /** * Information of the airport returned in String format. */ + @Override public String toString(){ return this.city+" Airport has ICAO: "+this.ICAO+", IATA/FFA: "+this.IATA_FFA+" and is located at ("+this.latitude+", "+this.longitude diff --git a/src/main/java/seng202/group9/Core/FlightPath.java b/src/main/java/seng202/group9/Core/FlightPath.java index 5ab3894..e0df38a 100644 --- a/src/main/java/seng202/group9/Core/FlightPath.java +++ b/src/main/java/seng202/group9/Core/FlightPath.java @@ -20,6 +20,13 @@ public class FlightPath { this.arrivalAirport = arrivalAirport; this.flightPoints = new ArrayList(); } + + public FlightPath(String departureAirport, String arrivalAirport){ + this.ID = -1; + this.departureAirport = departureAirport; + this.arrivalAirport = arrivalAirport; + this.flightPoints = new ArrayList(); + } public ArrayList getFlightPoints() { return flightPoints; diff --git a/src/main/java/seng202/group9/Core/FlightPoint.java b/src/main/java/seng202/group9/Core/FlightPoint.java index 6115e93..34c043f 100644 --- a/src/main/java/seng202/group9/Core/FlightPoint.java +++ b/src/main/java/seng202/group9/Core/FlightPoint.java @@ -15,14 +15,14 @@ public class FlightPoint { private double latitude; private double longitude; - public FlightPoint(String type, String via, double altitude, double latitude, double longitude){ + public FlightPoint(String type, String name, double altitude, double latitude, double longitude){ //extra calculations will have to be used to find heading, legdistance and total distance. If necessary //Type 1 file the file the lecturers gave us - this.name = ""; + this.name = name; this.ID = -1; this.indexID = -1; this.type = type; - this.via = via; + this.via = ""; this.heading = 0; this.altitude = altitude; this.legDistance = 0.0; diff --git a/src/main/java/seng202/group9/Core/Route.java b/src/main/java/seng202/group9/Core/Route.java index 8a874ab..9a6a7c0 100644 --- a/src/main/java/seng202/group9/Core/Route.java +++ b/src/main/java/seng202/group9/Core/Route.java @@ -158,7 +158,18 @@ public class Route { public String arrivesAt(){ return arrivalAirport; } - + + /** + * Checks is passed route is a duplicate of the current one if so it throws an DataException + */ + public void hasDuplicate(Route route) throws DataException{ + //routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip + if (route.getAirline().equals(this.airline) && route.departsFrom().equals(this.departureAirport) + && route.arrivesAt().equals(this.arrivalAirport) && route.getCode().equals(this.codeShare) + && route.getStops() == this.stops && route.getEquipment().equals(this.equipment)){ + throw new DataException("This Route already exists."); + } + } @Override public String toString(){ diff --git a/src/main/java/seng202/group9/GUI/AirlineRDController.java b/src/main/java/seng202/group9/GUI/AirlineRDController.java new file mode 100644 index 0000000..854651b --- /dev/null +++ b/src/main/java/seng202/group9/GUI/AirlineRDController.java @@ -0,0 +1,104 @@ +package seng202.group9.GUI; + +import javafx.collections.FXCollections; +import javafx.fxml.FXML; +import javafx.scene.control.Alert; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.TextField; +import javafx.scene.control.cell.PropertyValueFactory; +import seng202.group9.Controller.App; +import seng202.group9.Controller.Dataset; +import seng202.group9.Core.Airline; + +/** + * Created by Sunguin on 2016/09/13. + */ +public class AirlineRDController extends MenuController { + + @FXML + private TableView tableView; + @FXML + private TableColumn airlIDcol; + @FXML + private TableColumn airlNamecol; + @FXML + private TableColumn airlAliascol; + @FXML + private TableColumn airlIATAcol; + @FXML + private TableColumn airlICAOcol; + @FXML + private TableColumn airlCallsigncol; + @FXML + private TableColumn airlCountrycol; + @FXML + private TableColumn airlActivecol; + @FXML + private TextField airlNameBox; + @FXML + private TextField airlAliasBox; + @FXML + private TextField airlIATABox; + @FXML + private TextField airlICAOBox; + @FXML + private TextField airlCallsignBox; + @FXML + private TextField airlCountryBox; + @FXML + private TextField airlActiveBox; + + + App parent; + + public void setApp(App parent){ + this.parent = parent; + } + + private Dataset theDataSet = null; + + public void loadTables() { + airlIDcol.setCellValueFactory(new PropertyValueFactory("ID")); + airlNamecol.setCellValueFactory(new PropertyValueFactory("Name")); + airlAliascol.setCellValueFactory(new PropertyValueFactory("Alias")); + //Need to check IATA and ICAO + airlIATAcol.setCellValueFactory(new PropertyValueFactory("ICAO")); + airlICAOcol.setCellValueFactory(new PropertyValueFactory("IATA")); + airlCallsigncol.setCellValueFactory(new PropertyValueFactory("CallSign")); + airlCountrycol.setCellValueFactory(new PropertyValueFactory("Country")); + airlActivecol.setCellValueFactory(new PropertyValueFactory("Active")); + + theDataSet = this.parent.getCurrentDataset(); + tableView.setItems(FXCollections.observableArrayList(theDataSet.getAirlines())); + } + + //Dummy function to test the add button. + //Will edit when ID is added automatically. + public void addAirlineSingle() { + try { + theDataSet.addAirline( + airlNameBox.getText(), + airlAliasBox.getText(), + airlIATABox.getText(), + airlICAOBox.getText(), + airlCallsignBox.getText(), + airlCountryBox.getText(), + airlActiveBox.getText()); + airlNameBox.clear(); + airlAliasBox.clear(); + airlIATABox.clear(); + airlICAOBox.clear(); + airlCallsignBox.clear(); + airlCountryBox.clear(); + airlActiveBox.clear(); + tableView.setItems(FXCollections.observableArrayList(theDataSet.getAirlines())); + } catch ( Exception e ) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Airline Data Error"); + alert.setHeaderText("Error adding a custom airline entry."); + alert.setContentText(e.getMessage()); + alert.showAndWait(); + } + } +} diff --git a/src/main/java/seng202/group9/GUI/AirportRDController.java b/src/main/java/seng202/group9/GUI/AirportRDController.java new file mode 100644 index 0000000..b551c95 --- /dev/null +++ b/src/main/java/seng202/group9/GUI/AirportRDController.java @@ -0,0 +1,151 @@ +package seng202.group9.GUI; + +import javafx.beans.InvalidationListener; +import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.util.Callback; +import seng202.group9.Controller.App; +import seng202.group9.Controller.Dataset; +import seng202.group9.Core.Airport; +import seng202.group9.Core.City; +import seng202.group9.Core.Country; + + +/** + * Created by Sunguin on 2016/09/13. + */ +public class AirportRDController extends MenuController{ + + @FXML + private TableView tableViewAirportRD; + @FXML + private TableColumn airpIDcol; + @FXML + private TableColumn airpNamecol; + @FXML + private TableColumn airpCitycol; + @FXML + private TableColumn airpCountrycol; + @FXML + private TableColumn airpIATAFFAcol; + @FXML + private TableColumn airpICAOcol; + @FXML + private TableColumn airpLatitudecol; + @FXML + private TableColumn airpLongitudecol; + @FXML + private TableColumn airpAltitudecol; + @FXML + private TableColumn airpTimezonecol; + @FXML + private TableColumn airpDSTcol; + @FXML + private TableColumn airpTzcol; + + @FXML + private TextField airpNameBox; + @FXML + private TextField airpCityBox; + @FXML + private TextField airpCountryBox; + @FXML + private TextField airpIATAFFABox; + @FXML + private TextField airpICAOBox; + @FXML + private TextField airpLatitudeBox; + @FXML + private TextField airpLongitudeBox; + @FXML + private TextField airpAltitudeBox; + @FXML + private TextField airpTimezoneBox; + @FXML + private TextField airpDSTBox; + @FXML + private TextField airpTzBox; + + + private Dataset theDataSet = null; + + App parent; + + public void setApp(App parent){ + this.parent = parent; + } + + public void loadTables() { + airpIDcol.setCellValueFactory(new PropertyValueFactory("ID")); + airpNamecol.setCellValueFactory(new PropertyValueFactory("Name")); + airpCitycol.setCellValueFactory(new PropertyValueFactory("City")); + airpCountrycol.setCellValueFactory(new PropertyValueFactory("Country")); + airpIATAFFAcol.setCellValueFactory(new PropertyValueFactory("IATA_FFA")); + airpICAOcol.setCellValueFactory(new PropertyValueFactory("ICAO")); + airpLatitudecol.setCellValueFactory(new PropertyValueFactory("Latitude")); + airpLongitudecol.setCellValueFactory(new PropertyValueFactory("Longitude")); + airpAltitudecol.setCellValueFactory(new PropertyValueFactory("Altitude")); + airpTimezonecol.setCellValueFactory(new PropertyValueFactory("Timezone")); + airpDSTcol.setCellValueFactory(new PropertyValueFactory("DST")); + airpTzcol.setCellValueFactory(new PropertyValueFactory("Tz")); + +// airpTimezonecol.setCellFactory(new Callback, TableCell>() { +// +// @Override +// public TableCell call(TableColumn param) { +// TableCell timeZoneCell = new TableCell() { +// @Override +// protected void updateItem(City timezone, boolean empty) { +// if (timezone != null) { +// Label timeZoneLabel = new Label(timezone.getTimeOlson()); +// setGraphic(timeZoneLabel); +// } +// } +// }; +// +// return timeZoneCell; +// } +// }); + theDataSet = this.parent.getCurrentDataset(); + tableViewAirportRD.setItems(FXCollections.observableArrayList(theDataSet.getAirports())); + } + + public void addAirportSingle() { + try { + theDataSet.addAirport( + airpNameBox.getText(), + airpCityBox.getText(), + airpCountryBox.getText(), + airpIATAFFABox.getText(), + airpICAOBox.getText(), + airpLatitudeBox.getText(), + airpLongitudeBox.getText(), + airpAltitudeBox.getText(), + airpTimezoneBox.getText(), + airpDSTBox.getText(), + airpTzBox.getText()); + airpCityBox.clear(); + airpCountryBox.clear(); + airpIATAFFABox.clear(); + airpICAOBox.clear(); + airpLatitudeBox.clear(); + airpLongitudeBox.clear(); + airpAltitudeBox.clear(); + airpTimezoneBox.clear(); + airpDSTBox.clear(); + airpTzBox.clear(); + tableViewAirportRD.setItems(FXCollections.observableArrayList(theDataSet.getAirports())); + } catch ( Exception e ) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Airline Data Error"); + alert.setHeaderText("Error adding a custom airport entry."); + alert.setContentText(e.getMessage()); + alert.showAndWait(); + } + } + +} diff --git a/src/main/java/seng202/group9/GUI/FlightRawDataController.java b/src/main/java/seng202/group9/GUI/FlightRawDataController.java index 4eb91e3..d69260c 100644 --- a/src/main/java/seng202/group9/GUI/FlightRawDataController.java +++ b/src/main/java/seng202/group9/GUI/FlightRawDataController.java @@ -1,22 +1,125 @@ package seng202.group9.GUI; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.EventHandler; +import javafx.fxml.FXML; import javafx.fxml.Initializable; +import javafx.scene.control.ListView; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.input.MouseEvent; import seng202.group9.Controller.App; +import seng202.group9.Controller.Dataset; +import seng202.group9.Core.FlightPath; +import seng202.group9.Core.FlightPoint; import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; import java.util.ResourceBundle; /** + * Controller for the Flights Raw Data Scene. * Created by Liam Beckett on 13/09/2016. */ public class FlightRawDataController implements Initializable { - App parent; + private Dataset theDataSet = null; + App parent; public void setApp(App parent){ this.parent = parent; } + @FXML + private TableView flightTableView; + @FXML + private TableColumn flightIdCol; + @FXML + private TableColumn flightNameCol; + @FXML + private TableColumn flightTypeCol; + @FXML + private TableColumn flightViaCol; + @FXML + private TableColumn flightAltitudeCol; + @FXML + private TableColumn flightLatCol; + @FXML + private TableColumn flightLongCol; + @FXML + private TableColumn flightHeadCol; + @FXML + private TableColumn flightLegDisCol; + @FXML + private TableColumn flightTotDisCol; + + @FXML + ListView flightPathListView; + final ObservableList flightList = FXCollections.observableArrayList(); + + + /** + * Loads the Flight paths into the List View and waits for a mouse clicked event for which it will update the table + * to display the selected Flight paths points. Called from the MenuController. + */ + public void flightPathListView() { + try { + ArrayList flightPaths = new ArrayList(); + flightPaths = theDataSet.getFlightPaths(); + for(int i = 0; i() { + public void handle(MouseEvent event) { + String flightPathDisplayNameClicked = flightPathListView.getSelectionModel().getSelectedItem(); + String[] segments = flightPathDisplayNameClicked.split("_"); + String pathIdClicked = segments[0]; + + ArrayList flightPaths; + flightPaths = theDataSet.getFlightPaths(); + ArrayList flightPoints = flightPaths.get(Integer.parseInt(pathIdClicked)-1).getFlight(); + flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); + + } + }); + + flightPathListView.setItems(flightList); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Function used to load the table for the Flight points initially from the MenuController + */ + public void loadTables() { + flightIdCol.setCellValueFactory(new PropertyValueFactory("ID")); + flightNameCol.setCellValueFactory(new PropertyValueFactory("Name")); + flightTypeCol.setCellValueFactory(new PropertyValueFactory("Type")); + flightViaCol.setCellValueFactory(new PropertyValueFactory("Via")); + flightAltitudeCol.setCellValueFactory(new PropertyValueFactory("Altitude")); + flightLatCol.setCellValueFactory(new PropertyValueFactory("Latitude")); + flightLongCol.setCellValueFactory(new PropertyValueFactory("Longitude")); + flightHeadCol.setCellValueFactory(new PropertyValueFactory("Heading")); + flightLegDisCol.setCellValueFactory(new PropertyValueFactory("Leg_Dist")); + flightTotDisCol.setCellValueFactory(new PropertyValueFactory("Tot_Dist")); + + theDataSet = this.parent.getCurrentDataset(); + + ArrayList flightPaths; + flightPaths = theDataSet.getFlightPaths(); + int firstID = flightPaths.get(0).getID(); + ArrayList flightPoints = flightPaths.get(0).getFlight(); + flightTableView.setItems(FXCollections.observableArrayList(flightPoints)); + } + public void initialize(URL arg0, ResourceBundle arg1) { // TODO Auto-generated method stub diff --git a/src/main/java/seng202/group9/GUI/FlightSummaryController.java b/src/main/java/seng202/group9/GUI/FlightSummaryController.java index 53d1dd7..5b8fba4 100644 --- a/src/main/java/seng202/group9/GUI/FlightSummaryController.java +++ b/src/main/java/seng202/group9/GUI/FlightSummaryController.java @@ -1,22 +1,57 @@ package seng202.group9.GUI; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; import javafx.fxml.Initializable; +import javafx.scene.control.ListView; import seng202.group9.Controller.App; +import seng202.group9.Controller.Dataset; +import seng202.group9.Core.FlightPath; import java.net.URL; +import java.util.ArrayList; import java.util.ResourceBundle; /** + * Controller for the Flights Summary Scene. * Created by Liam Beckett on 13/09/2016. */ public class FlightSummaryController implements Initializable { - App parent; + private Dataset theDataSet = null; + App parent; public void setApp(App parent){ this.parent = parent; } + @FXML + ListView flightPathListView; + final ObservableList flightList = FXCollections.observableArrayList(); + + /** + * Loads the Flight paths into the List View and is called from the MenuController. + */ + public void flightPathListView() { + try { + theDataSet = this.parent.getCurrentDataset(); + ArrayList flightPaths = new ArrayList(); + flightPaths = theDataSet.getFlightPaths(); + for(int i = 0; i - - - - - - + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - + - - -