Refactoring bugs fixed again
This commit is contained in:
Binary file not shown.
@@ -1,6 +1,7 @@
|
||||
package seng202.group9.Controller;
|
||||
|
||||
|
||||
import javafx.scene.chart.PieChart;
|
||||
import seng202.group9.Core.*;
|
||||
|
||||
import java.sql.Connection;
|
||||
@@ -786,6 +787,15 @@ public class Dataset {
|
||||
*/
|
||||
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);
|
||||
if (name.equals("")) {
|
||||
throw new DataException("You cannot have a blank airline name.");
|
||||
}
|
||||
if (alias.length() <= 0) {
|
||||
throw new DataException("Please insert '\\N' if the airline has no alias.");
|
||||
}
|
||||
if (country.equals("")) {
|
||||
throw new DataException("You cannot have a blank country of origin field.");
|
||||
}
|
||||
addAirline(airlineToAdd);
|
||||
}
|
||||
|
||||
@@ -827,6 +837,8 @@ public class Dataset {
|
||||
airlineToAdd.setID(airlineID);
|
||||
airlines.add(airlineToAdd);
|
||||
airlineDictionary.put(airlineToAdd.getName(), airlineToAdd);
|
||||
stmt.close();
|
||||
c.close();
|
||||
} catch ( Exception e ) {
|
||||
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||
System.exit(0);
|
||||
@@ -837,28 +849,39 @@ public class Dataset {
|
||||
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{
|
||||
//System.out.print(name + city + country + IATA_FFA + ICAO + latitude + longitude + altitude + timezone + DST + olsonTz);
|
||||
double latitudeVal = Double.parseDouble(latitude);
|
||||
double longitudeVal = Double.parseDouble(longitude);
|
||||
double altitudeVal = Double.parseDouble(altitude);
|
||||
double timezoneVal = Double.parseDouble(timezone);
|
||||
if (city.equals("")) {
|
||||
throw new DataException("You cannot have a blank city name.");
|
||||
}
|
||||
if (country.equals("")) {
|
||||
throw new DataException("You cannot have a blank country name.");
|
||||
}
|
||||
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);
|
||||
createDataLinks();
|
||||
}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){
|
||||
if (airportToAdd.getIATA_FFA().length() != 0 && airportToAdd.getIATA_FFA().length() != 3){
|
||||
throw new DataException("IATA/FFA either empty or 3 letters");
|
||||
}
|
||||
if (airportToAdd.getICAO() != "" && airportToAdd.getICAO().length() != 4){
|
||||
if (airportToAdd.getICAO().length() != 0 && airportToAdd.getICAO().length() != 4){
|
||||
throw new DataException("ICAO either empty or 4 letters");
|
||||
}
|
||||
if (airportToAdd.getName().equals("")) {
|
||||
throw new DataException("You cannot have an airport without a name.");
|
||||
}
|
||||
for (String key : airportDictionary.keySet()){
|
||||
airportDictionary.get(key).hasDuplicate(airportToAdd);
|
||||
}
|
||||
@@ -876,6 +899,7 @@ public class Dataset {
|
||||
"\""+airportToAdd.getCountryName()+"\", \""+airportToAdd.getIATA_FFA()+"\", \""+airportToAdd.getICAO()+"\", " +
|
||||
""+airportToAdd.getLatitude()+", "+airportToAdd.getLongitude()+", "+airportToAdd.getAltitude()+");";
|
||||
stmt.execute(insertAirportQuery);
|
||||
stmt.close();
|
||||
//get the airport id
|
||||
stmt = c.createStatement();
|
||||
String airportIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+this.name+"_Airport\" LIMIT 1;";
|
||||
@@ -887,11 +911,13 @@ public class Dataset {
|
||||
airportToAdd.setID(airportID);
|
||||
airports.add(airportToAdd);
|
||||
airportDictionary.put(airportToAdd.getName(), airportToAdd);
|
||||
stmt.close();
|
||||
airportIDRes.close();
|
||||
c.close();
|
||||
} catch ( Exception e ) {
|
||||
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||
System.exit(0);
|
||||
}
|
||||
createDataLinks();
|
||||
}
|
||||
|
||||
public void addCity(City city){
|
||||
@@ -912,6 +938,7 @@ public class Dataset {
|
||||
stmt.close();
|
||||
cityDictionary.put(city.getName(), city);
|
||||
cities.add(city);
|
||||
c.close();
|
||||
} catch ( Exception e ) {
|
||||
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||
System.exit(0);
|
||||
@@ -936,6 +963,7 @@ public class Dataset {
|
||||
stmt.close();
|
||||
countryDictionary.put(country.getName(), country);
|
||||
countries.add(country);
|
||||
c.close();
|
||||
} catch ( Exception e ) {
|
||||
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||
System.exit(0);
|
||||
@@ -1013,6 +1041,8 @@ public class Dataset {
|
||||
//routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip
|
||||
String routeKey = routeToAdd.getAirline() + routeToAdd.getDepartureAirport() + routeToAdd.getArrivalAirport() + routeToAdd.getCode() + routeToAdd.getStops() + routeToAdd.getEquipment();
|
||||
routeDictionary.put(routeKey, routeToAdd);
|
||||
stmt.close();
|
||||
c.close();
|
||||
} catch ( Exception e ) {
|
||||
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||
System.exit(0);
|
||||
@@ -1195,19 +1225,19 @@ public class Dataset {
|
||||
//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("\"", "\"\"")+"\"";
|
||||
" WHERE `"+this.name+"_Airline`.`Country` = \""+airline.getCountryName().replace("\"", "\"\"")+"\"";
|
||||
ResultSet countCountryRes = stmt.executeQuery(countCountry);
|
||||
int countryCount = 0;
|
||||
while (countCountryRes.next()){
|
||||
while (countCountryRes.next()) {
|
||||
countryCount += countCountryRes.getInt("COUNT(*)");
|
||||
}
|
||||
countCountryRes.close();
|
||||
stmt.close();
|
||||
|
||||
stmt = c.createStatement();
|
||||
//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("\"", "\"\"")+"\"";
|
||||
" WHERE `"+this.name+"_Airport`.`Country` = \""+airline.getCountryName().replace("\"", "\"\"")+"\"";
|
||||
countCountryRes = stmt.executeQuery(countCountryA);
|
||||
while (countCountryRes.next()){
|
||||
countryCount += countCountryRes.getInt("COUNT(*)");
|
||||
@@ -1217,12 +1247,13 @@ public class Dataset {
|
||||
//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()+"\"";
|
||||
String deleteCountry = "DELETE FROM `"+this.name+"_Country` WHERE `Country_Name` = \""+airline.getCountryName()+"\"";
|
||||
stmt.execute(deleteCountry);
|
||||
stmt.close();
|
||||
}
|
||||
c.close();
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||
//System.exit(0);
|
||||
}
|
||||
|
||||
@@ -365,7 +365,8 @@ public class Airport {
|
||||
return distance;
|
||||
}
|
||||
public void hasDuplicate(Airport airport) throws DataException{
|
||||
if (!airport.getName().equals("") && airport.getName().equals(this.name)){
|
||||
if (airport.getName().equals("") || airport.getName().equals(this.name)){
|
||||
//System.out.println(airport.getName() + " "+ this.name);
|
||||
throw new DataException("Airport Name already Exists, Please Choose Another.");
|
||||
}
|
||||
if (!airport.getIATA_FFA().equals("") && airport.getIATA_FFA().equals(this.name)){
|
||||
|
||||
@@ -64,8 +64,6 @@ public class AirlineRDController extends Controller {
|
||||
|
||||
private Dataset theDataSet = null;
|
||||
|
||||
//Dummy function to test the add button.
|
||||
//Will edit when ID is added automatically.
|
||||
public void addAirlineSingle() {
|
||||
try {
|
||||
theDataSet.addAirline(
|
||||
@@ -83,6 +81,7 @@ public class AirlineRDController extends Controller {
|
||||
airlCallsignBox.clear();
|
||||
airlCountryBox.clear();
|
||||
airlActiveCBox.getSelectionModel().clearSelection();
|
||||
airlActiveCBox.setValue("Y");
|
||||
tableViewAirlineRD.setItems(FXCollections.observableArrayList(theDataSet.getAirlines()));
|
||||
} catch ( Exception e ) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
package seng202.group9.GUI;
|
||||
|
||||
import com.sun.javafx.collections.ObservableListWrapper;
|
||||
import javafx.beans.InvalidationListener;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.value.ObservableStringValue;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
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.AirportFilter;
|
||||
import seng202.group9.Controller.App;
|
||||
import seng202.group9.Controller.Dataset;
|
||||
import seng202.group9.Controller.SceneCode;
|
||||
import seng202.group9.Core.Airport;
|
||||
import seng202.group9.Core.City;
|
||||
import seng202.group9.Core.Country;
|
||||
|
||||
import static javafx.collections.FXCollections.observableArrayList;
|
||||
|
||||
/**
|
||||
* Created by Sunguin on 2016/09/13.
|
||||
@@ -116,7 +106,7 @@ public class AirportRDController extends Controller{
|
||||
airpTzcol.setCellValueFactory(new PropertyValueFactory<Airport, String>("Tz"));
|
||||
|
||||
theDataSet = getParent().getCurrentDataset();
|
||||
tableViewAirportRD.setItems(FXCollections.observableArrayList(theDataSet.getAirports()));
|
||||
tableViewAirportRD.setItems(observableArrayList(theDataSet.getAirports()));
|
||||
|
||||
airpDSTCBox.setValue("E");
|
||||
airpDSTCBox.getItems().addAll("E", "A", "S", "O", "Z", "N", "U");
|
||||
@@ -145,6 +135,7 @@ public class AirportRDController extends Controller{
|
||||
airpAltitudeBox.clear();
|
||||
airpTimezoneBox.clear();
|
||||
airpDSTCBox.getSelectionModel().clearSelection();
|
||||
airpDSTCBox.setValue("E");
|
||||
airpTzBox.clear();
|
||||
tableViewAirportRD.setItems(FXCollections.observableArrayList(theDataSet.getAirports()));
|
||||
} catch ( Exception e ) {
|
||||
@@ -162,7 +153,7 @@ public class AirportRDController extends Controller{
|
||||
public void deleteAirport(){
|
||||
Airport toDelete = tableViewAirportRD.getSelectionModel().getSelectedItem();
|
||||
theDataSet.deleteAirport(toDelete);
|
||||
tableViewAirportRD.setItems(FXCollections.observableArrayList(theDataSet.getAirports()));
|
||||
tableViewAirportRD.setItems(observableArrayList(theDataSet.getAirports()));
|
||||
}
|
||||
|
||||
public void filterAirports() {
|
||||
|
||||
@@ -4,16 +4,14 @@ import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import seng202.group9.Controller.App;
|
||||
import seng202.group9.Controller.DataException;
|
||||
import seng202.group9.Controller.Dataset;
|
||||
import seng202.group9.Controller.SceneCode;
|
||||
import seng202.group9.Controller.RouteFilter;
|
||||
import seng202.group9.Core.Route;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Controller class for the Routes Raw Data scene.
|
||||
* Created by Sunguin on 2016/09/14.
|
||||
*/
|
||||
public class RouteRDController extends Controller {
|
||||
@@ -64,9 +62,13 @@ public class RouteRDController extends Controller {
|
||||
private TextField rStopsFilter;
|
||||
@FXML
|
||||
private TextField rEquipmentFilter;
|
||||
@FXML
|
||||
|
||||
private Dataset theDataSet = null;
|
||||
|
||||
/**
|
||||
* Adds a single route to the Route database.
|
||||
* Takes in values written from the GUI.
|
||||
*/
|
||||
public void addRouteSingle() {
|
||||
try {
|
||||
theDataSet.addRoute(
|
||||
@@ -81,22 +83,16 @@ public class RouteRDController extends Controller {
|
||||
rSourceBox.clear();
|
||||
rDestBox.clear();
|
||||
rCodeshareCBox.getSelectionModel().clearSelection();
|
||||
rCodeshareCBox.setValue("");
|
||||
rStopsBox.clear();
|
||||
rEquipmentBox.clear();
|
||||
tableViewRouteRD.setItems(FXCollections.observableArrayList(theDataSet.getRoutes()));
|
||||
} catch (DataException e){
|
||||
} catch ( Exception e ) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle("Route Data Error");
|
||||
alert.setHeaderText("Error adding a custom route entry.");
|
||||
alert.setContentText(e.getMessage());
|
||||
alert.showAndWait();
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle("Route Error");
|
||||
alert.setHeaderText("Error adding a custom route entry.");
|
||||
alert.setContentText(e.getMessage());
|
||||
alert.showAndWait();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +124,6 @@ public class RouteRDController extends Controller {
|
||||
public void filterRoutes(){
|
||||
RouteFilter filter = new RouteFilter(theDataSet.getRoutes());
|
||||
if (rAirlineFilter.getText() != null) {
|
||||
//System.out.println("Hello over here");
|
||||
filter.filterAirline(rAirlineFilter.getText());
|
||||
}
|
||||
if (rSourceFilter.getText() != null) {
|
||||
@@ -146,8 +141,6 @@ public class RouteRDController extends Controller {
|
||||
if (rEquipmentFilter.getText() != null) {
|
||||
filter.filterEquipment(rEquipmentFilter.getText());
|
||||
}
|
||||
// System.out.println("Hello");
|
||||
// filter.printFilter();
|
||||
tableViewRouteRD.setItems(FXCollections.<Route>observableArrayList(filter.getFilteredData()));
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
</padding>
|
||||
</TextField>
|
||||
<Label layoutX="14.0" layoutY="6.0" prefHeight="25.0" prefWidth="84.0" text="Add Airline:" />
|
||||
<ComboBox fx:id="airlActiveCBox" layoutX="1330.0" layoutY="-1.0" prefHeight="31.0" prefWidth="102.0" promptText="Active" />
|
||||
<ComboBox fx:id="airlActiveCBox" layoutX="1330.0" layoutY="3.0" prefHeight="31.0" prefWidth="102.0" promptText="Active" />
|
||||
</children>
|
||||
</Pane>
|
||||
</content>
|
||||
|
||||
@@ -93,15 +93,9 @@
|
||||
</Pane>
|
||||
</content>
|
||||
</ScrollPane>
|
||||
<<<<<<< HEAD
|
||||
<Button layoutX="14.0" layoutY="526.0" mnemonicParsing="false" onAction="#airportAnalyserButton" prefHeight="25.0" prefWidth="125.0" text="Analyse" />
|
||||
<Button layoutX="662.0" layoutY="526.0" mnemonicParsing="false" onAction="#addAirportSingle" prefHeight="25.0" prefWidth="125.0" text="Add" />
|
||||
<Pane layoutX="15.0" layoutY="60.0" prefHeight="403.0" prefWidth="772.0">
|
||||
=======
|
||||
<Button layoutX="14.0" layoutY="526.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="125.0" text="Analyse" />
|
||||
<Button layoutX="653.0" layoutY="526.0" mnemonicParsing="false" onAction="#addAirportSingle" prefHeight="25.0" prefWidth="125.0" text="Add" />
|
||||
<Pane layoutX="15.0" layoutY="60.0" prefHeight="342.0" prefWidth="764.0">
|
||||
>>>>>>> raw_data_fixes
|
||||
<children>
|
||||
<TableView fx:id="tableViewAirportRD" prefHeight="340.0" prefWidth="765.0">
|
||||
<columns>
|
||||
|
||||
Reference in New Issue
Block a user