diff --git a/src/main/java/seng202/group9/Controller/App.java b/src/main/java/seng202/group9/Controller/App.java index 53f1e34..bb8c65a 100644 --- a/src/main/java/seng202/group9/Controller/App.java +++ b/src/main/java/seng202/group9/Controller/App.java @@ -23,7 +23,7 @@ import seng202.group9.GUI.MenuController; */ public class App extends Application { - private ArrayList Datasets = new ArrayList(); + private ArrayList datasets = new ArrayList(); private Dataset currentDataset = null; private Stage primaryStage = null; private VBox mainContainer; @@ -75,14 +75,12 @@ public class App extends Application }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")); @@ -136,4 +134,9 @@ public class App extends Application public Dataset getCurrentDataset(){ return currentDataset; } + + public void deleteDataset(Dataset dataset){ + dataset.deleteDataset(); + datasets.remove(dataset); + } } diff --git a/src/main/java/seng202/group9/Controller/Dataset.java b/src/main/java/seng202/group9/Controller/Dataset.java index 9009349..f22568e 100644 --- a/src/main/java/seng202/group9/Controller/Dataset.java +++ b/src/main/java/seng202/group9/Controller/Dataset.java @@ -1016,6 +1016,242 @@ public class Dataset { } } + /** + * This is called in conjunction to the App deleteDataset DO NOT CALL UNLESS THROUGH APP.DELETEDATASET + */ + public void deleteDataset(){ + //drop the tables + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + String[] tablesToDrop = {"_Airline", "_Airport", "_City", "_Country", "_Routes", "_Flight_Path", "_Flight_Points"}; + for (int i = 0; i < tablesToDrop.length; i++){ + stmt = c.createStatement(); + String dropTableStatment = "DROP TABLE `"+this.name+tablesToDrop[i]+"`"; + stmt.execute(dropTableStatment); + stmt.close(); + } + stmt = c.createStatement(); + String deleteDatasetEntry = "DELETE FROM `Datasets` WHERE `Dataset_Name` = \""+this.name+"\""; + stmt.execute(deleteDatasetEntry); + stmt.close(); + c.close(); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); + } + } + + /** + * deletes an airline from the dataset. + * @param airline + */ + public void deleteAirline(Airline airline){ + //drop the entries + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + String deleteQuery = "DELETE FROM `"+this.name+"_Airline` WHERE `Airline_ID` = " + airline.getID() + ";"; + stmt = c.createStatement(); + stmt.execute(deleteQuery); + stmt.close(); + stmt = c.createStatement(); + //check if number of countries that contain airlines > 0 else delete the country + String countCountry = "SELECT COUNT(*) FROM `"+this.name+"_Airline` JOIN `"+this.name+"_Country` ON" + + " `"+this.name+"_Country`.`Country_Name` = `"+this.name+"_Airline`.`Country`" + + " WHERE `"+this.name+"_Airline`.`Country` = \""+airline.getCountry().getName().replace("\"", "\"\"")+"\""; + ResultSet countCountryRes = stmt.executeQuery(countCountry); + int countryCount = 0; + while (countCountryRes.next()){ + countryCount += countCountryRes.getInt("COUNT(*)"); + } + countCountryRes.close(); + stmt.close(); + //check if number of counties that contain airports > 0 else delete the country + String countCountryA = "SELECT COUNT(*) FROM `"+this.name+"_Airport` JOIN `"+this.name+"_Country` ON" + + " `"+this.name+"_Country`.`Country_Name` = `"+this.name+"_Airport`.`Country`" + + " WHERE `"+this.name+"_Airport`.`Country` = \""+airline.getCountry().getName().replace("\"", "\"\"")+"\""; + countCountryRes = stmt.executeQuery(countCountryA); + while (countCountryRes.next()){ + countryCount += countCountryRes.getInt("COUNT(*)"); + } + countCountryRes.close(); + stmt.close(); + //delete country if there are no matches + if (countryCount == 0){ + stmt = c.createStatement(); + String deleteCountry = "DELETE FROM `"+this.name+"_Country` WHERE `Country_Name` = \""+airline.getCountry().getName()+"\""; + stmt.execute(deleteCountry); + stmt.close(); + } + c.close(); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); + } + airlines.remove(airline); + } + + public void deleteAirline(int index){ + deleteAirline(airlines.get(index)); + } + + /** + * deletes an airport from the dataset. + * @param airport + */ + public void deleteAirport(Airport airport){ + //drop the entries + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + String deleteQuery = "DELETE FROM `"+this.name+"_Airport` WHERE `Airport_ID` = " + airport.getID() + ";"; + stmt = c.createStatement(); + stmt.execute(deleteQuery); + stmt.close(); + //check if number of countries that contain airports and airlines > 0 else delete the country + String countCountry = "SELECT COUNT(*) FROM `"+this.name+"_Airport` JOIN `"+this.name+"_Country` ON" + + " `"+this.name+"_Country`.`Country_Name` = `"+this.name+"_Airport`.`Country`" + + " WHERE `"+this.name+"_Airport`.`Country` = \""+airport.getCountry().getName().replace("\"", "\"\"")+"\""; + ResultSet countCountryRes = stmt.executeQuery(countCountry); + int countryCount = 0; + while (countCountryRes.next()){ + countryCount = countCountryRes.getInt("COUNT(*)"); + } + countCountryRes.close(); + stmt.close(); + //check if number of countries that contain airlines > 0 else delete the country + String countCountryA = "SELECT COUNT(*) FROM `"+this.name+"_Airline` JOIN `"+this.name+"_Country` ON" + + " `"+this.name+"_Country`.`Country_Name` = `"+this.name+"_Airline`.`Country`" + + " WHERE `"+this.name+"_Airline`.`Country` = \""+airport.getCountry().getName().replace("\"", "\"\"")+"\""; + ResultSet countCountryResA = stmt.executeQuery(countCountry); + while (countCountryResA.next()){ + countryCount += countCountryResA.getInt("COUNT(*)"); + } + countCountryResA.close(); + stmt.close(); + //delete country if no matches + if (countryCount == 0){ + stmt = c.createStatement(); + String deleteCountry = "DELETE FROM `"+this.name+"_Country` WHERE `Country_Name` = \""+airport.getCountry().getName()+"\""; + stmt.execute(deleteCountry); + stmt.close(); + } + //cehck if number cities that contain airports > 0 else delete the city + String countCity = "SELECT COUNT(*) FROM `"+this.name+"_Airport` JOIN `"+this.name+"_City` ON" + + " `"+this.name+"_City`.`City_Name` = `"+this.name+"_Airport`.`City`" + + " WHERE `"+this.name+"_Airport`.`City` = \""+airport.getCityName().replace("\"", "\"\"")+"\""; + ResultSet countCityRes = stmt.executeQuery(countCity); + int cityCount = 0; + while (countCityRes.next()){ + cityCount = countCityRes.getInt("COUNT(*)"); + } + countCountryRes.close(); + stmt.close(); + //delete country if no matches + if (cityCount == 0){ + stmt = c.createStatement(); + String deleteCity = "DELETE FROM `"+this.name+"_City` WHERE `City_Name` = \""+airport.getCityName()+"\""; + stmt.execute(deleteCity); + stmt.close(); + } + c.close(); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); + } + airports.remove(airport); + } + + public void deleteAirport(int index){ + deleteAirport(airports.get(index)); + } + /** + * deletes an route from the dataset. + * @param route + */ + public void deleteRoute(Route route){ + //drop the entries + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + String deleteQuery = "DELETE FROM `"+this.name+"_Routes` WHERE `Route_ID` = " + route.getID() + ";"; + stmt = c.createStatement(); + stmt.execute(deleteQuery); + c.close(); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); + } + routes.remove(route); + } + + public void deleteRoute(int index){ + deleteRoute(routes.get(index)); + } + /** + * deletes an airline from the dataset. + * @param flightPath + */ + public void deleteFlightPath(FlightPath flightPath){ + //delete all flight points with the id + while(flightPath.getFlightPoints().size() > 0){ + deleteFlightPoint(flightPath.getFlightPoints().get(0), flightPath); + } + //drop the entries + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + String deleteQuery = "DELETE FROM `"+this.name+"_Flight_Path` WHERE `Path_ID` = " + flightPath.getID() + ";"; + stmt = c.createStatement(); + stmt.execute(deleteQuery); + c.close(); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); + } + flightPaths.remove(flightPath); + } + + public void deleteFlightPath(int index){ + deleteFlightPath(flightPaths.get(index)); + } + /** + * deletes an airline from the dataset. + * @param flightPoint + */ + public void deleteFlightPoint(FlightPoint flightPoint, FlightPath flightPath){ + //drop the tables + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + String deleteQuery = "DELETE FROM `"+this.name+"_Flight_Points` WHERE `Point_ID` = " + flightPoint.getID() + ";"; + stmt = c.createStatement(); + stmt.execute(deleteQuery); + c.close(); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + System.exit(0); + } + flightPath.getFlightPoints().remove(flightPoint); + } + + public void deleteFlightPoint(int pathIndex, int pointIndex){ + deleteFlightPoint(flightPaths.get(pathIndex).getFlightPoints().get(pointIndex), flightPaths.get(pathIndex)); + } + public ArrayList getAirlines() { return airlines; } diff --git a/src/main/java/seng202/group9/Core/FlightPoint.java b/src/main/java/seng202/group9/Core/FlightPoint.java index 34c043f..b059626 100644 --- a/src/main/java/seng202/group9/Core/FlightPoint.java +++ b/src/main/java/seng202/group9/Core/FlightPoint.java @@ -18,6 +18,8 @@ public class FlightPoint { 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 + //indexID = flight path ID + //ID = unique Auto Increment value this.name = name; this.ID = -1; this.indexID = -1; diff --git a/src/main/java/seng202/group9/GUI/AirlineSummaryController.java b/src/main/java/seng202/group9/GUI/AirlineSummaryController.java index fa5ba73..07be386 100644 --- a/src/main/java/seng202/group9/GUI/AirlineSummaryController.java +++ b/src/main/java/seng202/group9/GUI/AirlineSummaryController.java @@ -43,5 +43,48 @@ public class AirlineSummaryController extends MenuController{ currentData = this.parent.getCurrentDataset(); tableView.setItems(FXCollections.observableArrayList(currentData.getAirlines())); } - + public void airlineRawDataButton() { + try { + AirlineRDController rawDataController = (AirlineRDController) + parent.replaceSceneContent("airline_raw_data.fxml"); + rawDataController.setApp(parent); + rawDataController.loadTables(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public void flightSummaryButton() { + try { + FlightSummaryController summaryController = (FlightSummaryController) + parent.replaceSceneContent("flight_data_summary.fxml"); + summaryController.setApp(parent); + summaryController.flightPathListView(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public void airportSummaryButton() { + try { + AirportSummaryController summaryController = (AirportSummaryController) + parent.replaceSceneContent("airport_summary.fxml"); + summaryController.setApp(parent); + summaryController.loadTables(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public void routeSummaryButton() { + try { + RouteSummaryController summaryController = (RouteSummaryController) + parent.replaceSceneContent("routes_summary.fxml"); + summaryController.setApp(parent); + summaryController.loadTables(); + } + catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/src/main/java/seng202/group9/GUI/AirportSummaryController.java b/src/main/java/seng202/group9/GUI/AirportSummaryController.java index 467e331..03d3dad 100644 --- a/src/main/java/seng202/group9/GUI/AirportSummaryController.java +++ b/src/main/java/seng202/group9/GUI/AirportSummaryController.java @@ -44,5 +44,48 @@ public class AirportSummaryController extends MenuController{ currentData = this.parent.getCurrentDataset(); tableView.setItems(FXCollections.observableArrayList(currentData.getAirports())); } - + public void airportRawDataButton() { + try { + AirportRDController rawDataController = (AirportRDController) + parent.replaceSceneContent("airport_raw_data.fxml"); + rawDataController.setApp(parent); + rawDataController.loadTables(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public void flightSummaryButton() { + try { + FlightSummaryController summaryController = (FlightSummaryController) + parent.replaceSceneContent("flight_data_summary.fxml"); + summaryController.setApp(parent); + summaryController.flightPathListView(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public void routeSummaryButton() { + try { + RouteSummaryController summaryController = (RouteSummaryController) + parent.replaceSceneContent("routes_summary.fxml"); + summaryController.setApp(parent); + summaryController.loadTables(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public void airlineSummaryButton() { + try { + AirlineSummaryController summaryController = (AirlineSummaryController) + parent.replaceSceneContent("airline_summary.fxml"); + summaryController.setApp(parent); + summaryController.loadTables(); + } + catch (Exception e) { + e.printStackTrace(); + } + } } \ No newline at end of file diff --git a/src/main/java/seng202/group9/GUI/FlightSummaryController.java b/src/main/java/seng202/group9/GUI/FlightSummaryController.java index 0704d8d..a534407 100644 --- a/src/main/java/seng202/group9/GUI/FlightSummaryController.java +++ b/src/main/java/seng202/group9/GUI/FlightSummaryController.java @@ -76,6 +76,40 @@ public class FlightSummaryController implements Initializable { } } + public void airportSummaryButton() { + try { + AirportSummaryController summaryController = (AirportSummaryController) + parent.replaceSceneContent("airport_summary.fxml"); + summaryController.setApp(parent); + summaryController.loadTables(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public void routeSummaryButton() { + try { + RouteSummaryController summaryController = (RouteSummaryController) + parent.replaceSceneContent("routes_summary.fxml"); + summaryController.setApp(parent); + summaryController.loadTables(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public void airlineSummaryButton() { + try { + AirlineSummaryController summaryController = (AirlineSummaryController) + parent.replaceSceneContent("airline_summary.fxml"); + summaryController.setApp(parent); + summaryController.loadTables(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public void initialize(URL arg0, ResourceBundle arg1) { // TODO Auto-generated method stub diff --git a/src/main/java/seng202/group9/GUI/RouteSummaryController.java b/src/main/java/seng202/group9/GUI/RouteSummaryController.java index c4f6412..b5f023e 100644 --- a/src/main/java/seng202/group9/GUI/RouteSummaryController.java +++ b/src/main/java/seng202/group9/GUI/RouteSummaryController.java @@ -43,5 +43,49 @@ public class RouteSummaryController extends MenuController{ currentData = this.parent.getCurrentDataset(); tableView.setItems(FXCollections.observableArrayList(currentData.getRoutes())); } + public void routeRawDataButton() { + try { + RouteRDController rawDataController = (RouteRDController) + parent.replaceSceneContent("route_raw_data.fxml"); + rawDataController.setApp(parent); + rawDataController.loadTables(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public void flightSummaryButton() { + try { + FlightSummaryController summaryController = (FlightSummaryController) + parent.replaceSceneContent("flight_data_summary.fxml"); + summaryController.setApp(parent); + summaryController.flightPathListView(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public void airportSummaryButton() { + try { + AirportSummaryController summaryController = (AirportSummaryController) + parent.replaceSceneContent("airport_summary.fxml"); + summaryController.setApp(parent); + summaryController.loadTables(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public void airlineSummaryButton() { + try { + AirlineSummaryController summaryController = (AirlineSummaryController) + parent.replaceSceneContent("airline_summary.fxml"); + summaryController.setApp(parent); + summaryController.loadTables(); + } + catch (Exception e) { + e.printStackTrace(); + } + } } \ No newline at end of file diff --git a/src/main/resources/airline_summary.fxml b/src/main/resources/airline_summary.fxml index 7d7d55e..13a97f9 100644 --- a/src/main/resources/airline_summary.fxml +++ b/src/main/resources/airline_summary.fxml @@ -1,17 +1,17 @@ - - - - - - - - - - - - + + + + + + + + + + + + @@ -34,16 +34,18 @@ - - - - - - - - - - + + + + + + + + + + + + @@ -54,24 +56,24 @@ - - - - - + + + - - - - - - + + + - - -