diff --git a/res/userdb.db b/res/userdb.db deleted file mode 100644 index 617c8ba..0000000 Binary files a/res/userdb.db and /dev/null differ diff --git a/src/main/java/seng202/group9/Controller/Dataset.java b/src/main/java/seng202/group9/Controller/Dataset.java index f8b0334..64d3732 100644 --- a/src/main/java/seng202/group9/Controller/Dataset.java +++ b/src/main/java/seng202/group9/Controller/Dataset.java @@ -23,13 +23,13 @@ public class Dataset { private ArrayList flightPaths; private ArrayList countries; private ArrayList cities; - private LinkedHashMap airlineDictionary; - private LinkedHashMap airportDictionary; - private LinkedHashMap routeDictionary; - private LinkedHashMap flightPathDictionary; - private LinkedHashMap flightPointDictionary; - private LinkedHashMap countryDictionary; - private LinkedHashMap cityDictionary; + private LinkedHashMap airlineDictionary;//key name + private LinkedHashMap airportDictionary;//key name + private LinkedHashMap routeDictionary;//key routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip + private LinkedHashMap flightPathDictionary;//key path id + private LinkedHashMap countryDictionary;//key name + private LinkedHashMap cityDictionary;//key city name + private LinkedHashMap flightPointDictionary;//key point id /** * @@ -1545,7 +1545,12 @@ public class Dataset { public void deleteFlightPath(FlightPath flightPath){ //delete all flight points with the id while(flightPath.getFlightPoints().size() > 0){ - deleteFlightPoint(flightPath.getFlightPoints().get(0), flightPath); + try { + flightPointDictionary.remove(flightPath.getFlightPoints().get(0).getID()); + flightPath.getFlightPoints().remove(0); + } catch (DataException e) { + e.printStackTrace(); + } } //drop the entries Connection c = null; @@ -1595,17 +1600,50 @@ public class Dataset { String deleteQuery = "DELETE FROM `"+this.name+"_Flight_Points` WHERE `Point_ID` = " + flightPoint.getID() + ";"; stmt = c.createStatement(); stmt.execute(deleteQuery); + + stmt = c.createStatement(); + String updatePointOrderQuery = ""; + for (int i = 0; i < flightPath.getFlightPoints().size(); i ++){ + updatePointOrderQuery = "UPDATE `"+this.name+"_Flight_Points` SET `Order` = "+i+" WHERE `Point_ID` = "+flightPath.getFlightPoints().get(i).getID()+";"; + stmt.execute(updatePointOrderQuery); + } + stmt.close(); + + int index = flightPath.getFlightPoints().indexOf(flightPoint); + System.out.println(index); + + if (index == 0){ + try { + stmt = c.createStatement(); + String query = "UPDATE `"+this.name+"_Flight_Path` SET `Source_Airport` = \""+flightPoint.getName().replace("\"", "\"\"")+"\" " + + "WHERE `Path_ID` = "+flightPoint.getIndex(); + stmt.execute(query); + c.close(); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + } + flightPath.setDepartureAirport(flightPoint.getName()); + }else if (index == flightPath.getFlightPoints().size() - 1){ + try { + stmt = c.createStatement(); + String query = "UPDATE `"+this.name+"_Flight_Path` SET `Destination_Airport` = \""+flightPoint.getName().replace("\"", "\"\"")+"\" " + + "WHERE `Path_ID` = "+flightPoint.getIndex(); + stmt.execute(query); + c.close(); + } catch ( Exception e ) { + System.err.println( e.getClass().getName() + ": " + e.getMessage() ); + } + flightPath.setArrivalAirport(flightPoint.getName()); + } + c.close(); } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); System.exit(0); } flightPath.getFlightPoints().remove(flightPoint); - try { - flightPointDictionary.remove(flightPoint.getID()); - } catch (DataException e) { - e.printStackTrace(); - } + flightPointDictionary.remove(flightPoint); + updateFlightPointInfo(flightPath); } /** @@ -1752,6 +1790,7 @@ public class Dataset { public void editAirline(Airline airline, String name, String alias, String IATA, String ICAO, String callsign, String country, String active ) throws DataException { //check the data errors EntryParser parser = new EntryParser(); + airlineDictionary.remove(airline); parser.parseAirline(name, alias, IATA,ICAO, callsign, country, active); airline.setName(name); airline.setAlias(alias); @@ -1775,6 +1814,7 @@ public class Dataset { } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); } + airlineDictionary.put(airline.getName(), airline); createDataLinks(); } @@ -1816,6 +1856,7 @@ public class Dataset { */ public void editAirport(Airport airport, String name, String city, String country, String IATA_FFA, String ICAO, String lat, String lng, String alt, String timezone, String DST, String olson) throws DataException { EntryParser parser = new EntryParser(); + airportDictionary.remove(airport.getName()); Airport newAirport = parser.parseAirport(name, city, country, IATA_FFA, ICAO, lat, lng, alt, timezone, DST, olson); airport.setName(name); airport.setCityName(city); @@ -1897,6 +1938,7 @@ public class Dataset { } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); } + airportDictionary.put(airport.getName(), airport); createDataLinks(); } @@ -1928,6 +1970,8 @@ public class Dataset { */ public void editRoute(Route route, String airline, String source, String dest, String code, String stops, String equip) throws DataException { EntryParser entryParser = new EntryParser(); + //routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip + routeDictionary.remove(route.getAirlineName()+route.getDepartureAirport()+route.getArrivalAirport()+route.getCode()+route.getStops() + route.getEquipment()); Route newRoute = entryParser.parseRoute(airline, source, dest, code, stops, equip); route.setAirlineName(newRoute.getAirlineName()); route.setDepartureAirport(newRoute.getDepartureAirport()); @@ -1951,6 +1995,8 @@ public class Dataset { } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); } + //routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip + routeDictionary.put(route.getAirlineName()+route.getDepartureAirport()+route.getArrivalAirport()+route.getCode()+route.getStops() + route.getEquipment(), route); createDataLinks(); } diff --git a/src/main/java/seng202/group9/GUI/FlightRDController.java b/src/main/java/seng202/group9/GUI/FlightRDController.java index 23a8e2c..e3e37ce 100644 --- a/src/main/java/seng202/group9/GUI/FlightRDController.java +++ b/src/main/java/seng202/group9/GUI/FlightRDController.java @@ -261,7 +261,7 @@ public class FlightRDController extends Controller { /** * Will link to the flight analyser when implemented. */ - private void flightAnalyser(){ + public void flightAnalyser(){ JOptionPane.showMessageDialog(null, "This is not Implemented yet"); }