Everything has now been personalised to the person
This commit is contained in:
@@ -46,7 +46,7 @@ public class MainController extends Controller{
|
||||
}
|
||||
|
||||
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){
|
||||
for (String s: notifications){
|
||||
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 {
|
||||
//validate login
|
||||
if (validateLogin(username.getText(), password.getText())){
|
||||
Session.session.getDataManager().newLogged();//sets new arrays for new log ins
|
||||
getNotifications();
|
||||
changeScene(SceneCode.HOME);
|
||||
}else{
|
||||
|
||||
@@ -13,10 +13,7 @@ import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.RowConstraints;
|
||||
import javafx.stage.Popup;
|
||||
import javafx.stage.Stage;
|
||||
import model.SharedTrip;
|
||||
import model.Stop;
|
||||
import model.Trip;
|
||||
import model.TripStop;
|
||||
import model.*;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
@@ -132,7 +129,7 @@ public class SharedTripsController extends Controller{
|
||||
//book button
|
||||
Button bookRide = new Button("Book Ride");
|
||||
bookRide.setOnAction(e->{
|
||||
trip.bookSeat(parent.getSession().session.getUser());
|
||||
trip.bookSeat(Session.session.getUser());
|
||||
tripDetails.close();
|
||||
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.");
|
||||
@@ -161,7 +158,7 @@ public class SharedTripsController extends Controller{
|
||||
Pattern stopNamePattern = Pattern.compile(".*"+stopName.getText()+".*", Pattern.CASE_INSENSITIVE);
|
||||
//ignore direction
|
||||
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()){
|
||||
continue;
|
||||
}
|
||||
@@ -192,7 +189,7 @@ public class SharedTripsController extends Controller{
|
||||
|
||||
@Override
|
||||
public void runLater(){
|
||||
sharedTrips = FXCollections.observableArrayList(parent.getSession().getDataManager().getSharedTrips());
|
||||
sharedTrips = FXCollections.observableArrayList(Session.session.getDataManager().getAllSharedTrips());
|
||||
sharedTripsTable.setItems(sharedTrips);
|
||||
tripNameColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().name));
|
||||
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<Route>> routes;
|
||||
private Map<String, ObservableList<Trip>> trips;
|
||||
private ObservableList<SharedTrip> sharedTrips;
|
||||
private Map<String, ObservableList<SharedTrip>> sharedTrips;
|
||||
private Map<String, User> users;
|
||||
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
|
||||
|
||||
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.stops = convertStopMapToObserver(stops);
|
||||
this.routes = convertRouteMapToObserver(routes);
|
||||
this.trips = convertTripMapToObserver(trips);
|
||||
this.sharedTrips = FXCollections.observableArrayList(sharedTrips);
|
||||
this.sharedTrips = convertSharedTripMapToObserver(sharedTrips);
|
||||
this.users = users;
|
||||
this.drivers = drivers;
|
||||
this.notifications = notifications;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
//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(){
|
||||
rides.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList());
|
||||
stops.putIfAbsent(Session.session.getUser().getID(), FXCollections.observableArrayList());
|
||||
routes.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());
|
||||
}
|
||||
//////////////////////////////
|
||||
@@ -200,17 +224,25 @@ public class DataManager {
|
||||
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() {
|
||||
return sharedTrips;
|
||||
return sharedTrips.get(Session.session.getUser().getID());
|
||||
}
|
||||
|
||||
public boolean addSharedTrip(SharedTrip sharedTrip){
|
||||
for (SharedTrip t: sharedTrips){
|
||||
for (SharedTrip t: sharedTrips.get(Session.session.getUser().getID())){
|
||||
if (sharedTrip.equals(t)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sharedTrips.add(sharedTrip);
|
||||
sharedTrips.get(Session.session.getUser().getID()).add(sharedTrip);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class DataManagerSerialiser extends Serialiser {
|
||||
Map<String, List<Stop>> stops = dataManager.stopsMapSerialised();
|
||||
Map<String, List<Route>> routes = dataManager.routesMapSerialised();
|
||||
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 serialStopsSuccess = serialise(stops, "serialisation/stops.json");
|
||||
boolean serialRoutesSuccess = serialiseRoutes(routes, "serialisation/routes.json");
|
||||
@@ -100,9 +100,12 @@ public class DataManagerSerialiser extends Serialiser {
|
||||
* @param filepath File path to serialise it to.
|
||||
* @return
|
||||
*/
|
||||
public boolean serialiseSharedTrips(ArrayList<SharedTrip> trips, String filepath){
|
||||
for (Trip trip: trips){
|
||||
trip.serialise();
|
||||
public boolean serialiseSharedTrips(Map<String, List<SharedTrip>> trips, String filepath){
|
||||
for (String key: trips.keySet()) {
|
||||
List<SharedTrip> tripsList = trips.get(key);
|
||||
for (Trip trip : tripsList) {
|
||||
trip.serialise();
|
||||
}
|
||||
}
|
||||
try{
|
||||
String path = getClass().getClassLoader().getResource(filepath).getPath();
|
||||
@@ -202,11 +205,14 @@ public class DataManagerSerialiser extends Serialiser {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
for (SharedTrip trip: sharedTrips){
|
||||
trip.deserialise();
|
||||
for (String key: sharedTrips.keySet()) {
|
||||
List<SharedTrip> sharedTripList = sharedTrips.get(key);
|
||||
for (SharedTrip trip : sharedTripList) {
|
||||
trip.deserialise();
|
||||
}
|
||||
}
|
||||
|
||||
Reader reader6 = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("serialisation/users.json"), "UTF-8");
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
[]
|
||||
{}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user