Everything has now been personalised to the person

main
Fan-Wu Yang 9 years ago
parent b48041242e
commit 20816a08b9

@ -46,7 +46,7 @@ public class MainController extends Controller{
} }
public void getNotifications(){ public void getNotifications(){
List<String> notifications = Session.session.getDataManager().getNotifications().get(Session.session.getUser().getStudentNumber()); List<String> notifications = Session.session.getDataManager().getNotifications().get(Session.session.getUser().getID());
if (notifications != null){ if (notifications != null){
for (String s: notifications){ for (String s: notifications){
popUp(Alert.AlertType.INFORMATION, "Notification!", "You have received a Notification", s); popUp(Alert.AlertType.INFORMATION, "Notification!", "You have received a Notification", s);
@ -57,7 +57,6 @@ public class MainController extends Controller{
public void login() throws Exception { public void login() throws Exception {
//validate login //validate login
if (validateLogin(username.getText(), password.getText())){ if (validateLogin(username.getText(), password.getText())){
Session.session.getDataManager().newLogged();//sets new arrays for new log ins
getNotifications(); getNotifications();
changeScene(SceneCode.HOME); changeScene(SceneCode.HOME);
}else{ }else{

@ -13,10 +13,7 @@ import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints; import javafx.scene.layout.RowConstraints;
import javafx.stage.Popup; import javafx.stage.Popup;
import javafx.stage.Stage; import javafx.stage.Stage;
import model.SharedTrip; import model.*;
import model.Stop;
import model.Trip;
import model.TripStop;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
@ -132,7 +129,7 @@ public class SharedTripsController extends Controller{
//book button //book button
Button bookRide = new Button("Book Ride"); Button bookRide = new Button("Book Ride");
bookRide.setOnAction(e->{ bookRide.setOnAction(e->{
trip.bookSeat(parent.getSession().session.getUser()); trip.bookSeat(Session.session.getUser());
tripDetails.close(); tripDetails.close();
search(); search();
popUp(Alert.AlertType.CONFIRMATION, "Success!", "You have Successfully booked a ride!", "The ride has been successfully booked and can be viewed in your booked rides."); popUp(Alert.AlertType.CONFIRMATION, "Success!", "You have Successfully booked a ride!", "The ride has been successfully booked and can be viewed in your booked rides.");
@ -161,7 +158,7 @@ public class SharedTripsController extends Controller{
Pattern stopNamePattern = Pattern.compile(".*"+stopName.getText()+".*", Pattern.CASE_INSENSITIVE); Pattern stopNamePattern = Pattern.compile(".*"+stopName.getText()+".*", Pattern.CASE_INSENSITIVE);
//ignore direction //ignore direction
boolean ignoreDirection = directionBox.getSelectionModel().isSelected(0) || directionBox.getValue() == null; boolean ignoreDirection = directionBox.getSelectionModel().isSelected(0) || directionBox.getValue() == null;
for(SharedTrip sharedTrip: parent.getSession().getDataManager().getSharedTrips()){ for(SharedTrip sharedTrip: Session.session.getDataManager().getAllSharedTrips()){
if (sharedTrip.isFull()){ if (sharedTrip.isFull()){
continue; continue;
} }
@ -192,7 +189,7 @@ public class SharedTripsController extends Controller{
@Override @Override
public void runLater(){ public void runLater(){
sharedTrips = FXCollections.observableArrayList(parent.getSession().getDataManager().getSharedTrips()); sharedTrips = FXCollections.observableArrayList(Session.session.getDataManager().getAllSharedTrips());
sharedTripsTable.setItems(sharedTrips); sharedTripsTable.setItems(sharedTrips);
tripNameColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().name)); tripNameColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().name));
directionColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().direction)); directionColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().direction));

@ -18,24 +18,24 @@ public class DataManager {
private Map<String, ObservableList<Stop>> stops; private Map<String, ObservableList<Stop>> stops;
private Map<String, ObservableList<Route>> routes; private Map<String, ObservableList<Route>> routes;
private Map<String, ObservableList<Trip>> trips; private Map<String, ObservableList<Trip>> trips;
private ObservableList<SharedTrip> sharedTrips; private Map<String, ObservableList<SharedTrip>> sharedTrips;
private Map<String, User> users; private Map<String, User> users;
private Map<String, Driver> drivers;//seperated from users as they are two different types of accounts private Map<String, Driver> drivers;//seperated from users as they are two different types of accounts
private Map<String, List<String>> notifications; //indexed by user name private Map<String, List<String>> notifications; //indexed by user name
public DataManager(Map<String, List<Ride>> rides, Map<String, List<Stop>> stops, Map<String, List<Route>> routes, Map<String, List<Trip>> trips, List sharedTrips, Map users, Map drivers, Map<String, List<String>> notifications){ public DataManager(Map<String, List<Ride>> rides, Map<String, List<Stop>> stops, Map<String, List<Route>> routes, Map<String, List<Trip>> trips, Map<String, List<SharedTrip>> sharedTrips, Map users, Map drivers, Map<String, List<String>> notifications){
this.rides = convertRideMapToObserver(rides); this.rides = convertRideMapToObserver(rides);
this.stops = convertStopMapToObserver(stops); this.stops = convertStopMapToObserver(stops);
this.routes = convertRouteMapToObserver(routes); this.routes = convertRouteMapToObserver(routes);
this.trips = convertTripMapToObserver(trips); this.trips = convertTripMapToObserver(trips);
this.sharedTrips = FXCollections.observableArrayList(sharedTrips); this.sharedTrips = convertSharedTripMapToObserver(sharedTrips);
this.users = users; this.users = users;
this.drivers = drivers; this.drivers = drivers;
this.notifications = notifications; this.notifications = notifications;
} }
public DataManager(){ public DataManager(){
this(new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), FXCollections.observableArrayList(), new HashMap<String, User>(), new HashMap<String, Driver>(), new HashMap<String, List<String>>()); this(new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<String, User>(), new HashMap<String, Driver>(), new HashMap<>());
} }
//////////////////////////////////////// ////////////////////////////////////////
@ -132,11 +132,35 @@ public class DataManager {
return convertTripMapToList(trips); return convertTripMapToList(trips);
} }
//////////////////////////////////
//Route
//////////////////////////////////
private Map<String, ObservableList<SharedTrip>> convertSharedTripMapToObserver(Map<String, List<SharedTrip>> trips){
HashMap<String, ObservableList<SharedTrip>> ob = new HashMap<>();
for (String key: trips.keySet()){
ob.put(key, FXCollections.observableArrayList(trips.get(key)));
}
return ob;
}
private Map<String, List<SharedTrip>> convertSharedTripMapToList(Map<String, ObservableList<SharedTrip>> trips){
HashMap<String, List<SharedTrip>> ob = new HashMap<>();
for (String key: trips.keySet()){
ob.put(key, new ArrayList<>(trips.get(key)));
}
return ob;
}
public Map<String, List<SharedTrip>> sharedTripsMapSerialised(){
return convertSharedTripMapToList(sharedTrips);
}
public void newLogged(){ public void newLogged(){
rides.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList()); rides.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList());
stops.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList()); stops.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList());
routes.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList()); routes.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList());
trips.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList()); trips.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList());
sharedTrips.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList());
notifications.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList()); notifications.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList());
} }
////////////////////////////// //////////////////////////////
@ -200,17 +224,25 @@ public class DataManager {
return true; return true;
} }
public ObservableList<SharedTrip> getAllSharedTrips(){
ObservableList<SharedTrip> allTrips = FXCollections.observableArrayList();
for (String key: sharedTrips.keySet()){
allTrips.addAll(sharedTrips.get(key));
}
return allTrips;
}
public ObservableList<SharedTrip> getSharedTrips() { public ObservableList<SharedTrip> getSharedTrips() {
return sharedTrips; return sharedTrips.get(Session.session.getUser().getID());
} }
public boolean addSharedTrip(SharedTrip sharedTrip){ public boolean addSharedTrip(SharedTrip sharedTrip){
for (SharedTrip t: sharedTrips){ for (SharedTrip t: sharedTrips.get(Session.session.getUser().getID())){
if (sharedTrip.equals(t)){ if (sharedTrip.equals(t)){
return false; return false;
} }
} }
sharedTrips.add(sharedTrip); sharedTrips.get(Session.session.getUser().getID()).add(sharedTrip);
return true; return true;
} }

@ -31,7 +31,7 @@ public class DataManagerSerialiser extends Serialiser {
Map<String, List<Stop>> stops = dataManager.stopsMapSerialised(); Map<String, List<Stop>> stops = dataManager.stopsMapSerialised();
Map<String, List<Route>> routes = dataManager.routesMapSerialised(); Map<String, List<Route>> routes = dataManager.routesMapSerialised();
Map<String, List<Trip>> trips = dataManager.tripsMapSerialised(); Map<String, List<Trip>> trips = dataManager.tripsMapSerialised();
ArrayList<SharedTrip> sharedTrips = new ArrayList<>(dataManager.getSharedTrips()); Map<String, List<SharedTrip>> sharedTrips = dataManager.sharedTripsMapSerialised();
boolean serialRidesSuccess = serialise(rides, "serialisation/rides.json"); boolean serialRidesSuccess = serialise(rides, "serialisation/rides.json");
boolean serialStopsSuccess = serialise(stops, "serialisation/stops.json"); boolean serialStopsSuccess = serialise(stops, "serialisation/stops.json");
boolean serialRoutesSuccess = serialiseRoutes(routes, "serialisation/routes.json"); boolean serialRoutesSuccess = serialiseRoutes(routes, "serialisation/routes.json");
@ -100,10 +100,13 @@ public class DataManagerSerialiser extends Serialiser {
* @param filepath File path to serialise it to. * @param filepath File path to serialise it to.
* @return * @return
*/ */
public boolean serialiseSharedTrips(ArrayList<SharedTrip> trips, String filepath){ public boolean serialiseSharedTrips(Map<String, List<SharedTrip>> trips, String filepath){
for (Trip trip: trips){ for (String key: trips.keySet()) {
List<SharedTrip> tripsList = trips.get(key);
for (Trip trip : tripsList) {
trip.serialise(); trip.serialise();
} }
}
try{ try{
String path = getClass().getClassLoader().getResource(filepath).getPath(); String path = getClass().getClassLoader().getResource(filepath).getPath();
Writer writer = new OutputStreamWriter(new FileOutputStream(path), "UTF-8"); Writer writer = new OutputStreamWriter(new FileOutputStream(path), "UTF-8");
@ -202,12 +205,15 @@ public class DataManagerSerialiser extends Serialiser {
} }
Reader reader5 = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("serialisation/sharedtrips.json"), "UTF-8"); Reader reader5 = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("serialisation/sharedtrips.json"), "UTF-8");
ArrayList<SharedTrip> sharedTrips = gson.fromJson(reader5, new TypeToken<ArrayList<SharedTrip>>(){}.getType()); HashMap<String, List<SharedTrip>> sharedTrips = gson.fromJson(reader5, new TypeToken<HashMap<String, ArrayList<SharedTrip>>>(){}.getType());
reader5.close(); reader5.close();
for (SharedTrip trip: sharedTrips){ for (String key: sharedTrips.keySet()) {
List<SharedTrip> sharedTripList = sharedTrips.get(key);
for (SharedTrip trip : sharedTripList) {
trip.deserialise(); trip.deserialise();
} }
}
Reader reader6 = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("serialisation/users.json"), "UTF-8"); Reader reader6 = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("serialisation/users.json"), "UTF-8");
HashMap<String, User> users = gson.fromJson(reader6, new TypeToken<HashMap<String, User>>(){}.getType()); HashMap<String, User> users = gson.fromJson(reader6, new TypeToken<HashMap<String, User>>(){}.getType());

Loading…
Cancel
Save