|
|
|
|
@ -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()){
|
|
|
|
|
countryCount += countCountryRes.getInt("COUNT(*)");
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|