Notifications will can now appear
This commit is contained in:
@@ -10,6 +10,7 @@ import model.Session;
|
|||||||
import model.User;
|
import model.User;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,18 +31,29 @@ public class MainController extends Controller{
|
|||||||
|
|
||||||
public boolean validateLogin(String user, String pass){
|
public boolean validateLogin(String user, String pass){
|
||||||
if (Session.session.getDataManager().getUsers().get(user).checkPassword(pass) && User.AccountType.getValueOf(accountType.getValue()) == User.AccountType.PASSENGER){
|
if (Session.session.getDataManager().getUsers().get(user).checkPassword(pass) && User.AccountType.getValueOf(accountType.getValue()) == User.AccountType.PASSENGER){
|
||||||
|
Session.session.setUser(Session.session.getDataManager().getUsers().get(user));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (Session.session.getDataManager().getDrivers().get(user).checkPassword(pass) && User.AccountType.getValueOf(accountType.getValue()) == User.AccountType.DRIVER){
|
if (Session.session.getDataManager().getDrivers().get(user).checkPassword(pass) && User.AccountType.getValueOf(accountType.getValue()) == User.AccountType.DRIVER){
|
||||||
|
Session.session.setUser(Session.session.getDataManager().getDrivers().get(user));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void getNotifications(){
|
||||||
|
List<String> notifications = Session.session.getDataManager().getNotifications().get(Session.session.getUser().getStudentNumber());
|
||||||
|
if (notifications != null){
|
||||||
|
for (String s: notifications){
|
||||||
|
popUp(Alert.AlertType.INFORMATION, "Notification!", "You have received a Notification", s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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())){
|
||||||
parent.getSession().setUserCode(username.getText());
|
getNotifications();
|
||||||
changeScene(SceneCode.HOME);
|
changeScene(SceneCode.HOME);
|
||||||
}else{
|
}else{
|
||||||
popUp(Alert.AlertType.WARNING, "Warning!", "Invalid Login!", "Your password and username do not match a record in our database.");
|
popUp(Alert.AlertType.WARNING, "Warning!", "Invalid Login!", "Your password and username do not match a record in our database.");
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ public class DataManager {
|
|||||||
private ObservableList<SharedTrip> sharedTrips;
|
private 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
|
||||||
|
|
||||||
public DataManager(List rides, List stops, List routes, List trips, List sharedTrips, Map users, Map drivers){
|
public DataManager(List rides, List stops, List routes, List trips, List sharedTrips, Map users, Map drivers, Map<String, List<String>> notifications){
|
||||||
this.rides = FXCollections.observableArrayList(rides);
|
this.rides = FXCollections.observableArrayList(rides);
|
||||||
this.stops = FXCollections.observableArrayList(stops);
|
this.stops = FXCollections.observableArrayList(stops);
|
||||||
this.routes = FXCollections.observableArrayList(routes);
|
this.routes = FXCollections.observableArrayList(routes);
|
||||||
@@ -30,10 +31,11 @@ public class DataManager {
|
|||||||
this.sharedTrips = FXCollections.observableArrayList(sharedTrips);
|
this.sharedTrips = FXCollections.observableArrayList(sharedTrips);
|
||||||
this.users = users;
|
this.users = users;
|
||||||
this.drivers = drivers;
|
this.drivers = drivers;
|
||||||
|
this.notifications = notifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataManager(){
|
public DataManager(){
|
||||||
this(FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), new HashMap<String, User>(), new HashMap<String, Driver>());
|
this(FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), FXCollections.observableArrayList(), new HashMap<String, User>(), new HashMap<String, Driver>(), new HashMap<String, List<String>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableList<Ride> getRides() {
|
public ObservableList<Ride> getRides() {
|
||||||
@@ -132,5 +134,7 @@ public class DataManager {
|
|||||||
return drivers;
|
return drivers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, List<String>> getNotifications() {
|
||||||
|
return notifications;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package model;
|
|||||||
*/
|
*/
|
||||||
public class Session {
|
public class Session {
|
||||||
|
|
||||||
private String userCode;//this is like fwy13
|
private User user;//this is like fwy13
|
||||||
DataManager dataManager;
|
DataManager dataManager;
|
||||||
public static Session session = new Session();
|
public static Session session = new Session();
|
||||||
|
|
||||||
@@ -14,12 +14,12 @@ public class Session {
|
|||||||
dataManager = new DataManager();
|
dataManager = new DataManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserCode() {
|
public User getUser() {
|
||||||
return userCode;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserCode(String userCode) {
|
public void setUser(User user) {
|
||||||
this.userCode = userCode;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataManager getDataManager() {
|
public DataManager getDataManager() {
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ public class User {
|
|||||||
return p.equals(password);
|
return p.equals(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getStudentNumber() {
|
||||||
|
return studentNumber;
|
||||||
|
}
|
||||||
|
|
||||||
public void serialise(){
|
public void serialise(){
|
||||||
try {
|
try {
|
||||||
BufferedImage bi = SwingFXUtils.fromFXImage(photo, null);
|
BufferedImage bi = SwingFXUtils.fromFXImage(photo, null);
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ public class DataManagerSerialiser extends Serialiser {
|
|||||||
boolean serialSharedTripsSuccess = serialiseSharedTrips(sharedTrips, "serialisation/sharedtrips.json");
|
boolean serialSharedTripsSuccess = serialiseSharedTrips(sharedTrips, "serialisation/sharedtrips.json");
|
||||||
boolean serialUsersSuccess = serialiseUsers(dataManager.getUsers(), "serialisation/users.json");
|
boolean serialUsersSuccess = serialiseUsers(dataManager.getUsers(), "serialisation/users.json");
|
||||||
boolean serialDriversSuccess = serialiseDrivers(dataManager.getDrivers(), "serialisation/drivers.json");
|
boolean serialDriversSuccess = serialiseDrivers(dataManager.getDrivers(), "serialisation/drivers.json");
|
||||||
return (serialRidesSuccess && serialStopsSuccess && serialRoutesSuccess && serialTripsSuccess && serialSharedTripsSuccess && serialUsersSuccess && serialDriversSuccess);
|
boolean serialNotificationsSuccess = serialiseNotifications(dataManager.getNotifications(), "serialisation/notification.json");
|
||||||
|
return (serialRidesSuccess && serialStopsSuccess && serialRoutesSuccess && serialTripsSuccess && serialSharedTripsSuccess && serialUsersSuccess && serialDriversSuccess && serialNotificationsSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,6 +140,20 @@ public class DataManagerSerialiser extends Serialiser {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean serialiseNotifications(Map<String, List<String>> notifications, String filepath){
|
||||||
|
try{
|
||||||
|
String path = getClass().getClassLoader().getResource(filepath).getPath();
|
||||||
|
Writer writer = new OutputStreamWriter(new FileOutputStream(path), "UTF-8");
|
||||||
|
gson.toJson(notifications, writer);
|
||||||
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* loads the data manager from file
|
* loads the data manager from file
|
||||||
* @return whether the data was loaded properly or not
|
* @return whether the data was loaded properly or not
|
||||||
@@ -195,7 +210,11 @@ public class DataManagerSerialiser extends Serialiser {
|
|||||||
drivers.get(driverkey).deserialise();
|
drivers.get(driverkey).deserialise();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DataManager(rides, stops, routes, trips, sharedTrips, users, drivers);
|
Reader reader8 = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("serialisation/notifications.json"), "UTF-8");
|
||||||
|
HashMap<String, List<String>> notifications = gson.fromJson(reader8, new TypeToken<HashMap<String, List<String>>>(){}.getType());
|
||||||
|
reader8.close();
|
||||||
|
|
||||||
|
return new DataManager(rides, stops, routes, trips, sharedTrips, users, drivers, notifications);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
Reference in New Issue
Block a user