#8: Cleanup & Javadoc
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
This commit is contained in:
parent
7db1c83a08
commit
1f9226064d
8 changed files with 98 additions and 12 deletions
|
@ -37,10 +37,18 @@ public class Main extends Application {
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
this.primaryStage = primaryStage;
|
this.primaryStage = primaryStage;
|
||||||
executePassword();
|
User user = executeLogin();
|
||||||
|
if(user != null){
|
||||||
|
executeMainApplication(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executePassword() {
|
/**
|
||||||
|
* Executes the login.
|
||||||
|
* @return User The {@link User} object for the logged-in {@link User}.
|
||||||
|
* Is {@code null}, if the login was not successful,
|
||||||
|
*/
|
||||||
|
private User executeLogin() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
FXMLLoader loader = new FXMLLoader(Main.class.getResource("/de/hitec/nhplus/login/LoginView.fxml"));
|
FXMLLoader loader = new FXMLLoader(Main.class.getResource("/de/hitec/nhplus/login/LoginView.fxml"));
|
||||||
|
@ -55,12 +63,10 @@ public class Main extends Application {
|
||||||
controller.initialize(loginStage);
|
controller.initialize(loginStage);
|
||||||
|
|
||||||
loginStage.showAndWait();
|
loginStage.showAndWait();
|
||||||
|
return controller.user;
|
||||||
if(controller.user != null){
|
|
||||||
executeMainApplication(controller.user);
|
|
||||||
}
|
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,12 @@ import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class UserFixture implements Fixture<User>{
|
/**
|
||||||
|
* {@link Fixture} for {@link User}.
|
||||||
|
*
|
||||||
|
* @author Dominik Säume
|
||||||
|
*/
|
||||||
|
public class UserFixture implements Fixture<User> {
|
||||||
private static final String SCHEMA = "/de/hitec/nhplus/login/database/User.sql";
|
private static final String SCHEMA = "/de/hitec/nhplus/login/database/User.sql";
|
||||||
private static final String PERMISSION_SCHEMA = "/de/hitec/nhplus/login/database/UserPermission.sql";
|
private static final String PERMISSION_SCHEMA = "/de/hitec/nhplus/login/database/UserPermission.sql";
|
||||||
private static final String TO_NURSE_SCHEMA = "/de/hitec/nhplus/login/database/UserToNurse.sql";
|
private static final String TO_NURSE_SCHEMA = "/de/hitec/nhplus/login/database/UserToNurse.sql";
|
||||||
|
@ -94,7 +99,7 @@ public class UserFixture implements Fixture<User>{
|
||||||
|
|
||||||
UserDao dao = DaoFactory.getInstance().createUserDAO();
|
UserDao dao = DaoFactory.getInstance().createUserDAO();
|
||||||
Map<String, User> usersByUsername = new HashMap<>();
|
Map<String, User> usersByUsername = new HashMap<>();
|
||||||
for (User user : users){
|
for (User user : users) {
|
||||||
dao.create(user);
|
dao.create(user);
|
||||||
usersByUsername.put(user.getUsername(), user);
|
usersByUsername.put(user.getUsername(), user);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,11 @@ import java.security.NoSuchAlgorithmException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller for handling the login of {@link User}s.
|
||||||
|
*
|
||||||
|
* @author Dominik Säume
|
||||||
|
*/
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
|
|
||||||
public User user;
|
public User user;
|
||||||
|
@ -29,11 +34,18 @@ public class LoginController {
|
||||||
private Stage stage;
|
private Stage stage;
|
||||||
private int loginTries = 0;
|
private int loginTries = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaFX Initialization method that is called after the binding of all the fields.
|
||||||
|
*
|
||||||
|
* @param stage The {@link Stage}, so the modal can close itself, when finished.
|
||||||
|
*/
|
||||||
public void initialize(Stage stage) {
|
public void initialize(Stage stage) {
|
||||||
this.stage = stage;
|
this.stage = stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal method to handle actions on wrong logins, like a shake, timout and total tries.
|
||||||
|
*/
|
||||||
private void handleWrongPasswordOrUsername() {
|
private void handleWrongPasswordOrUsername() {
|
||||||
loginTries++;
|
loginTries++;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package de.hitec.nhplus.login;
|
package de.hitec.nhplus.login;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple class holding the bitmasks for all permissions.
|
||||||
|
* This is a class instead of an enum, for ease of use.
|
||||||
|
*
|
||||||
|
* @author Dominiok Säume
|
||||||
|
*/
|
||||||
public class Permissions {
|
public class Permissions {
|
||||||
public final static int EVERYBODY = 0b0;
|
public final static int EVERYBODY = 0b0;
|
||||||
public final static int NURSE = 0b1;
|
public final static int NURSE = 0b1;
|
||||||
|
|
|
@ -7,8 +7,13 @@ import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
public class User {
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The model for a {@link User}.
|
||||||
|
*
|
||||||
|
* @author Dominik Säume
|
||||||
|
*/
|
||||||
|
public class User {
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private String username;
|
private String username;
|
||||||
|
@ -17,6 +22,10 @@ public class User {
|
||||||
private int permissions = 0;
|
private int permissions = 0;
|
||||||
private Nurse nurse;
|
private Nurse nurse;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructor allows instantiating a {@link User} object with all existing fields.
|
||||||
|
*/
|
||||||
public User(
|
public User(
|
||||||
int id,
|
int id,
|
||||||
String username,
|
String username,
|
||||||
|
@ -33,6 +42,9 @@ public class User {
|
||||||
this.nurse = nurse;
|
this.nurse = nurse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructor allows instantiating a {@link User} object.
|
||||||
|
*/
|
||||||
public User(
|
public User(
|
||||||
String username,
|
String username,
|
||||||
int permissions,
|
int permissions,
|
||||||
|
@ -42,6 +54,12 @@ public class User {
|
||||||
this.permissions = permissions;
|
this.permissions = permissions;
|
||||||
this.nurse = nurse;
|
this.nurse = nurse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@link User} password. The {@link User} will need to be manually stored with the
|
||||||
|
* {@link de.hitec.nhplus.login.database.UserDao UserDao}, for changes to persists.
|
||||||
|
* @param password The new Password
|
||||||
|
*/
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
try {
|
try {
|
||||||
SecureRandom random = new SecureRandom();
|
SecureRandom random = new SecureRandom();
|
||||||
|
@ -59,6 +77,7 @@ public class User {
|
||||||
public boolean hasNursePermissions(){
|
public boolean hasNursePermissions(){
|
||||||
return (permissions & Permissions.NURSE) != 0;
|
return (permissions & Permissions.NURSE) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAdminPermissions(){
|
public boolean hasAdminPermissions(){
|
||||||
return (permissions & Permissions.MANAGEMENT) != 0;
|
return (permissions & Permissions.MANAGEMENT) != 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class Nurse extends Person {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor allows instantiating a {@link Nurse} object with
|
* This constructor allows instantiating a {@link Nurse} object with
|
||||||
* specifying if the nurse is locked or not.
|
* specifying whether the {@link Nurse} is locked or not.
|
||||||
*/
|
*/
|
||||||
public Nurse(
|
public Nurse(
|
||||||
String firstName,
|
String firstName,
|
||||||
|
|
|
@ -15,6 +15,12 @@ import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A utility class to construct {@link Tab}s from views. This also supports sub {@link Tab}s.
|
||||||
|
*
|
||||||
|
* @author Dominiok Säume
|
||||||
|
* @see TabManager
|
||||||
|
*/
|
||||||
public class TabManager {
|
public class TabManager {
|
||||||
private final User user;
|
private final User user;
|
||||||
|
|
||||||
|
@ -22,11 +28,21 @@ public class TabManager {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal method to check permissions
|
||||||
|
* @param requiredPermissions The permissions the {@link User} requires.
|
||||||
|
* @param permissions The permissions the {@link User} has.
|
||||||
|
*/
|
||||||
private boolean hasPermissions(int requiredPermissions, int permissions) {
|
private boolean hasPermissions(int requiredPermissions, int permissions) {
|
||||||
return requiredPermissions == Permissions.EVERYBODY
|
return requiredPermissions == Permissions.EVERYBODY
|
||||||
|| (permissions & requiredPermissions) != 0;
|
|| (permissions & requiredPermissions) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to set up a single tab and register it to its {@link TabPane}.
|
||||||
|
* @param tabPane The {@link TabPane} to register to.
|
||||||
|
* @param tabStruct The data needed to construct the new tab.
|
||||||
|
*/
|
||||||
public void setupTab(TabPane tabPane, TabStruct tabStruct) {
|
public void setupTab(TabPane tabPane, TabStruct tabStruct) {
|
||||||
if (!hasPermissions(tabStruct.requiredPermissions, user.getPermissions())) {
|
if (!hasPermissions(tabStruct.requiredPermissions, user.getPermissions())) {
|
||||||
return;
|
return;
|
||||||
|
@ -39,6 +55,11 @@ public class TabManager {
|
||||||
tabPane.getTabs().add(tab);
|
tabPane.getTabs().add(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link EventHandler} to handle the loading of a {@link Tab}.
|
||||||
|
* @param tabStruct The {@link TabStruct} holding the path of the view.
|
||||||
|
* @param pane The main pane of the {@link Tab}.
|
||||||
|
*/
|
||||||
private EventHandler<Event> loadTabEventHandler(TabStruct tabStruct, AnchorPane pane) {
|
private EventHandler<Event> loadTabEventHandler(TabStruct tabStruct, AnchorPane pane) {
|
||||||
return event -> {
|
return event -> {
|
||||||
try {
|
try {
|
||||||
|
@ -56,6 +77,13 @@ public class TabManager {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to set up a sub tab and register it to its parent {@link TabPane}.
|
||||||
|
* @param parentTabPane The {@link TabPane} to register to.
|
||||||
|
* @param title The title of the {@link Tab}.
|
||||||
|
* @param requiredPermissions The permissions required to see the sub {@link Tab}.
|
||||||
|
* @param subTabs A {@link List} of {@link TabStruct}s to create in the sub {@link Tab}.
|
||||||
|
*/
|
||||||
public void setupSubTabPane(TabPane parentTabPane, String title, int requiredPermissions, List<TabStruct> subTabs) {
|
public void setupSubTabPane(TabPane parentTabPane, String title, int requiredPermissions, List<TabStruct> subTabs) {
|
||||||
if (!hasPermissions(requiredPermissions, user.getPermissions())) {
|
if (!hasPermissions(requiredPermissions, user.getPermissions())) {
|
||||||
return;
|
return;
|
||||||
|
@ -73,6 +101,10 @@ public class TabManager {
|
||||||
parentTabPane.getTabs().add(tab);
|
parentTabPane.getTabs().add(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link EventHandler} to handle the loading of a sub {@link TabPane}.
|
||||||
|
* @param tabPane The {@link TabPane} of the sub {@link Tab} to handle loading.
|
||||||
|
*/
|
||||||
private EventHandler<Event> loadSubTabPaneEventHandler(TabPane tabPane) {
|
private EventHandler<Event> loadSubTabPaneEventHandler(TabPane tabPane) {
|
||||||
return event -> {
|
return event -> {
|
||||||
Tab tab = tabPane.getSelectionModel().getSelectedItem();
|
Tab tab = tabPane.getSelectionModel().getSelectedItem();
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package de.hitec.nhplus.utils.tab;
|
package de.hitec.nhplus.utils.tab;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple class holding the data needed for constructing a {@link javafx.scene.control.Tab Tab}.
|
||||||
|
*
|
||||||
|
* @author Dominiok Säume
|
||||||
|
* @see TabManager
|
||||||
|
*/
|
||||||
public class TabStruct {
|
public class TabStruct {
|
||||||
public String title;
|
public String title;
|
||||||
public String view;
|
public String view;
|
||||||
|
@ -10,4 +16,4 @@ public class TabStruct {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.requiredPermissions = requiredPermissions;
|
this.requiredPermissions = requiredPermissions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue