From ab0f0849129e84c0e0d454006759de8961da966a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Wed, 22 May 2024 09:49:52 +0200 Subject: [PATCH] #8: Cleanup & Javadoc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominik Säume --- src/main/java/de/hitec/nhplus/Main.java | 17 +++++++++------ .../de/hitec/nhplus/fixtures/UserFixture.java | 9 ++++++-- .../hitec/nhplus/login/LoginController.java | 14 ++++++++++++- .../de/hitec/nhplus/login/Permissions.java | 6 ++++++ src/main/java/de/hitec/nhplus/login/User.java | 21 ++++++++++++++++++- .../java/de/hitec/nhplus/nurse/Nurse.java | 2 +- .../de/hitec/nhplus/utils/tab/TabStruct.java | 6 ++++++ 7 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/hitec/nhplus/Main.java b/src/main/java/de/hitec/nhplus/Main.java index 2393731..fb533ea 100644 --- a/src/main/java/de/hitec/nhplus/Main.java +++ b/src/main/java/de/hitec/nhplus/Main.java @@ -37,10 +37,17 @@ public class Main extends Application { @Override public void start(Stage 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 { FXMLLoader loader = new FXMLLoader(Main.class.getResource("/de/hitec/nhplus/login/LoginView.fxml")); @@ -55,12 +62,10 @@ public class Main extends Application { controller.initialize(loginStage); loginStage.showAndWait(); - - if(controller.user != null){ - executeMainApplication(controller.user); - } + return controller.user; } catch (IOException exception) { exception.printStackTrace(); + return null; } } diff --git a/src/main/java/de/hitec/nhplus/fixtures/UserFixture.java b/src/main/java/de/hitec/nhplus/fixtures/UserFixture.java index 7b3550f..bb75d7d 100644 --- a/src/main/java/de/hitec/nhplus/fixtures/UserFixture.java +++ b/src/main/java/de/hitec/nhplus/fixtures/UserFixture.java @@ -13,7 +13,12 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.*; -public class UserFixture implements Fixture{ +/** + * {@link Fixture} for {@link User}. + * + * @author Dominik Säume + */ +public class UserFixture implements Fixture { 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 TO_NURSE_SCHEMA = "/de/hitec/nhplus/login/database/UserToNurse.sql"; @@ -94,7 +99,7 @@ public class UserFixture implements Fixture{ UserDao dao = DaoFactory.getInstance().createUserDAO(); Map usersByUsername = new HashMap<>(); - for (User user : users){ + for (User user : users) { dao.create(user); usersByUsername.put(user.getUsername(), user); } diff --git a/src/main/java/de/hitec/nhplus/login/LoginController.java b/src/main/java/de/hitec/nhplus/login/LoginController.java index bec7101..29cad23 100644 --- a/src/main/java/de/hitec/nhplus/login/LoginController.java +++ b/src/main/java/de/hitec/nhplus/login/LoginController.java @@ -17,6 +17,11 @@ import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.Arrays; +/** + * Controller for handling the login of {@link User}s. + * + * @author Dominik Säume + */ public class LoginController { public User user; @@ -29,11 +34,18 @@ public class LoginController { private Stage stage; 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) { this.stage = stage; } + /** + * Internal method to handle actions on wrong logins, like a shake, timout and total tries. + */ private void handleWrongPasswordOrUsername() { loginTries++; diff --git a/src/main/java/de/hitec/nhplus/login/Permissions.java b/src/main/java/de/hitec/nhplus/login/Permissions.java index 8420986..2f53369 100644 --- a/src/main/java/de/hitec/nhplus/login/Permissions.java +++ b/src/main/java/de/hitec/nhplus/login/Permissions.java @@ -1,5 +1,11 @@ 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 final static int EVERYBODY = 0b0; public final static int NURSE = 0b1; diff --git a/src/main/java/de/hitec/nhplus/login/User.java b/src/main/java/de/hitec/nhplus/login/User.java index 50e604f..b58e6f2 100644 --- a/src/main/java/de/hitec/nhplus/login/User.java +++ b/src/main/java/de/hitec/nhplus/login/User.java @@ -7,8 +7,13 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; -public class User { +/** + * The model for a {@link User}. + * + * @author Dominik Säume + */ +public class User { private int id; private String username; @@ -17,6 +22,10 @@ public class User { private int permissions = 0; private Nurse nurse; + + /** + * This constructor allows instantiating a {@link User} object with all existing fields. + */ public User( int id, String username, @@ -33,6 +42,9 @@ public class User { this.nurse = nurse; } + /** + * This constructor allows instantiating a {@link User} object. + */ public User( String username, int permissions, @@ -42,6 +54,12 @@ public class User { this.permissions = permissions; 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) { try { SecureRandom random = new SecureRandom(); @@ -59,6 +77,7 @@ public class User { public boolean hasNursePermissions(){ return (permissions & Permissions.NURSE) != 0; } + public boolean hasAdminPermissions(){ return (permissions & Permissions.MANAGEMENT) != 0; } diff --git a/src/main/java/de/hitec/nhplus/nurse/Nurse.java b/src/main/java/de/hitec/nhplus/nurse/Nurse.java index 22c4b49..7fa94b9 100644 --- a/src/main/java/de/hitec/nhplus/nurse/Nurse.java +++ b/src/main/java/de/hitec/nhplus/nurse/Nurse.java @@ -44,7 +44,7 @@ public class Nurse extends Person { /** * 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( String firstName, diff --git a/src/main/java/de/hitec/nhplus/utils/tab/TabStruct.java b/src/main/java/de/hitec/nhplus/utils/tab/TabStruct.java index 9a49919..ad1325d 100644 --- a/src/main/java/de/hitec/nhplus/utils/tab/TabStruct.java +++ b/src/main/java/de/hitec/nhplus/utils/tab/TabStruct.java @@ -1,5 +1,11 @@ package de.hitec.nhplus.utils.tab; +/** + * A simple class holding the data needed for constructing a tab. + * + * @author Dominiok Säume + * @see TabManager + */ public class TabStruct { public String title; public String view;