NOTICKET: Add Main Javadoc

This commit is contained in:
Dominik Säume 2024-05-15 00:27:10 +02:00
parent 9de598ef67
commit 2b6efbc618
Signed by: SZUT-Dominik
GPG key ID: DACB4B96EB59ABA8
15 changed files with 280 additions and 90 deletions

View file

@ -1,7 +1,6 @@
package de.hitec.nhplus; package de.hitec.nhplus;
import de.hitec.nhplus.datastorage.ConnectionBuilder; import de.hitec.nhplus.datastorage.ConnectionBuilder;
import javafx.application.Application; import javafx.application.Application;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
@ -12,18 +11,35 @@ import javafx.stage.Stage;
import java.io.IOException; import java.io.IOException;
/** /**
* @author dominik.saeume@hmmh.ag * The application main class, holding the {@link #main} entrypoint.
*
* @author Bernd Heideman
* @author Dominik Säume
*/ */
public class Main extends Application { public class Main extends Application {
private Stage primaryStage; private Stage primaryStage;
/**
* The main entry point.
*/
public static void main(String[] args) {
launch(args);
}
/**
* Implementation of the JavaFX start hook.
*/
@Override @Override
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
mainWindow(); executeMainApplication();
} }
public void mainWindow() { /**
* Executes the main application.
*/
private void executeMainApplication() {
try { try {
FXMLLoader loader = new FXMLLoader(Main.class.getResource("/de/hitec/nhplus/main/MainWindowView.fxml")); FXMLLoader loader = new FXMLLoader(Main.class.getResource("/de/hitec/nhplus/main/MainWindowView.fxml"));
TabPane pane = loader.load(); TabPane pane = loader.load();
@ -44,7 +60,4 @@ public class Main extends Application {
} }
} }
public static void main(String[] args) {
launch(args);
}
} }

View file

@ -7,7 +7,7 @@ import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
/** /**
* The {@link DaoFactory} allows a safe connection to the Database. * The {@link DaoFactory} allows a safe connection to the database.
* *
* @author Bernd Heidemann * @author Bernd Heidemann
* @author Dominik Säume * @author Dominik Säume
@ -21,7 +21,7 @@ public class ConnectionBuilder {
private static Connection connection; private static Connection connection;
/** /**
* @return A Thread-safe {@link Connection} to the Database. * @return A thread-safe {@link Connection} to the database.
*/ */
synchronized public static Connection getConnection() { synchronized public static Connection getConnection() {
try { try {
@ -38,7 +38,7 @@ public class ConnectionBuilder {
} }
/** /**
* Closes the Connection to the Database. * Closes the connection to the database.
*/ */
synchronized public static void closeConnection() { synchronized public static void closeConnection() {
try { try {

View file

@ -4,47 +4,48 @@ import java.sql.SQLException;
import java.util.List; import java.util.List;
/** /**
* {@link Dao} is the Abbreviation of Data-Access-Object. * {@link Dao} is the abbreviation for Data-Access-Object.
* This Interface has the Basic Methods which are needed on any {@link Dao} to work as expected. * This interface has the Basic Methods that are needed on any {@link Dao} to work as expected.
* *
* @param <T> The Model for which that {@link Dao} is implemented. * @param <T> The model for which that {@link Dao} is implemented.
* @author Bernd Heidemann * @author Bernd Heidemann
* @author Dominik Säume * @author Dominik Säume
* @version 1.0 * @version 1.0
* @implSpec The Implementations should be added to the {@link DaoFactory}. * @implSpec The implementations should be added to the {@link DaoFactory}.
*/ */
public interface Dao<T> { public interface Dao<T> {
/** /**
* Create a Database Entry from a Model object. * Create a database entry from a model object.
* *
* @param t The Model instance. * @param t The model instance.
*/ */
void create(T t) throws SQLException; void create(T t) throws SQLException;
/** /**
* Read a Database Entry to a Model object. * Read a database entry to a model object.
* *
* @param id The ID of the Element in the Database. * @param id The ID of the element in the database.
* @return a model instance of {@link T}.
*/ */
T read(int id) throws SQLException; T read(int id) throws SQLException;
/** /**
* @return All Database Entries as a {@link List} of Model instances * @return All database entries as a {@link List} of model instances.
*/ */
List<T> readAll() throws SQLException; List<T> readAll() throws SQLException;
/** /**
* Update the Database according to the Values of the Model object. * Update the database according to the values of the model object.
* *
* @param t The Model instance. * @param t The model instance.
*/ */
void update(T t) throws SQLException; void update(T t) throws SQLException;
/** /**
* Delete a Database Entry. * Delete a database entry.
* *
* @param id The ID of the Element in the Database. * @param id The ID of the element in the database.
*/ */
void delete(int id) throws SQLException; void delete(int id) throws SQLException;
} }

View file

@ -6,7 +6,7 @@ import de.hitec.nhplus.patient.database.PatientDao;
import de.hitec.nhplus.treatment.database.TreatmentDao; import de.hitec.nhplus.treatment.database.TreatmentDao;
/** /**
* The {@link DaoFactory} is a Singleton({@link #getInstance}) which should be used to get {@link Dao}s. * The {@link DaoFactory} is a singleton({@link #getInstance}) that should be used to get {@link Dao}s.
* *
* @author Bernd Heidemann * @author Bernd Heidemann
* @author Dominik Säume * @author Dominik Säume
@ -17,13 +17,13 @@ public class DaoFactory {
private static DaoFactory instance; private static DaoFactory instance;
/** /**
* A Private Constructor according to the Singleton Pattern. * A private constructor according to the singleton pattern.
*/ */
private DaoFactory() { private DaoFactory() {
} }
/** /**
* @return The Singleton Instance. * @return The singleton instance of {@link DaoFactory}.
*/ */
public static DaoFactory getInstance() { public static DaoFactory getInstance() {
if (DaoFactory.instance == null) { if (DaoFactory.instance == null) {
@ -33,7 +33,7 @@ public class DaoFactory {
} }
/** /**
* @return A new {@link TreatmentDao} Instance with a Database Connection. * @return A new {@link TreatmentDao} instance with a database connection.
* @see de.hitec.nhplus.treatment.Treatment Treatment * @see de.hitec.nhplus.treatment.Treatment Treatment
*/ */
public TreatmentDao createTreatmentDao() { public TreatmentDao createTreatmentDao() {
@ -41,7 +41,7 @@ public class DaoFactory {
} }
/** /**
* @return A new {@link PatientDao} Instance with a Database Connection. * @return A new {@link PatientDao} instance with a database connection.
* @see de.hitec.nhplus.patient.Patient Patient * @see de.hitec.nhplus.patient.Patient Patient
*/ */
public PatientDao createPatientDAO() { public PatientDao createPatientDAO() {
@ -49,7 +49,7 @@ public class DaoFactory {
} }
/** /**
* @return A new {@link NurseDao} Instance with a Database Connection. * @return A new {@link NurseDao} instance with a database connection.
* @see de.hitec.nhplus.nurse.Nurse Nurse * @see de.hitec.nhplus.nurse.Nurse Nurse
*/ */
public NurseDao createNurseDAO() { public NurseDao createNurseDAO() {
@ -57,7 +57,7 @@ public class DaoFactory {
} }
/** /**
* @return A new {@link MedicationDao} Instance with a Database Connection. * @return A new {@link MedicationDao} instance with a database connection.
* @see de.hitec.nhplus.medication.Medication Medication * @see de.hitec.nhplus.medication.Medication Medication
*/ */
public MedicationDao createMedicationDAO() { public MedicationDao createMedicationDAO() {

View file

@ -7,30 +7,30 @@ import java.sql.SQLException;
import java.util.List; import java.util.List;
/** /**
* The {@link DaoImp} is a Generic Base Implementation of the {@link Dao}, * The {@link DaoImp} is a generic base implementation of the {@link Dao},
* which should fit most use cases. * that should fit most use cases.
* *
* @param <T> The Model for which that {@link Dao} is implemented. * @param <T> The model for which that {@link Dao} is implemented.
* @author Bernd Heidemann * @author Bernd Heidemann
* @author Dominik Säume * @author Dominik Säume
* @version 1.0 * @version 1.0
* @implSpec The Implementations should be added to the {@link DaoFactory}. * @implSpec The implementations should be added to the {@link DaoFactory}.
*/ */
public abstract class DaoImp<T> implements Dao<T> { public abstract class DaoImp<T> implements Dao<T> {
protected final Connection connection; protected final Connection connection;
/** /**
* @param connection The Database Connection to use * @param connection The database {@link Connection} to use.
* @implSpec The Connection should be Received from the {@link ConnectionBuilder}. * @implSpec The {@link Connection} should be received from the {@link ConnectionBuilder}.
*/ */
public DaoImp(Connection connection) { public DaoImp(Connection connection) {
this.connection = connection; this.connection = connection;
} }
/** /**
* Creates a new Database Entry from a Model object. * Creates a new database entry from a model object.
* *
* @param t The Model instance. * @param t The model instance.
*/ */
@Override @Override
public void create(T t) throws SQLException { public void create(T t) throws SQLException {
@ -38,9 +38,10 @@ public abstract class DaoImp<T> implements Dao<T> {
} }
/** /**
* Read a Database Entry to a Model object. * Read a database entry to a model object.
* *
* @param id The ID of the Element in the Database. * @param id The ID of the element in the database.
* @return the model instance of type {@link T}, which was read.
*/ */
@Override @Override
public T read(int id) throws SQLException { public T read(int id) throws SQLException {
@ -53,7 +54,9 @@ public abstract class DaoImp<T> implements Dao<T> {
} }
/** /**
* Read all Database Entries to a {@link List} of Model objects. * Read all database entries to a {@link List} of model objects.
*
* @return a {@link List} of type {@link T} holding all database entries as model instances.
*/ */
@Override @Override
public List<T> readAll() throws SQLException { public List<T> readAll() throws SQLException {
@ -61,9 +64,9 @@ public abstract class DaoImp<T> implements Dao<T> {
} }
/** /**
* Update the Database according to the Values of the Model object. * Update the database according to the values of the model object.
* *
* @param t The Model instance. * @param t The model instance.
*/ */
@Override @Override
public void update(T t) throws SQLException { public void update(T t) throws SQLException {
@ -71,26 +74,62 @@ public abstract class DaoImp<T> implements Dao<T> {
} }
/** /**
* Delete a Database Entry. * Delete a database entry.
* *
* @param id The ID of the Element in the Database. * @param id The ID of the element in the database.
*/ */
@Override @Override
public void delete(int id) throws SQLException { public void delete(int id) throws SQLException {
getDeleteStatement(id).executeUpdate(); getDeleteStatement(id).executeUpdate();
} }
/**
* @param result The {@link ResultSet} from execution of the statement received from {@link #getReadByIDStatement}.
* @return The model instance of type {@link T}.
* @implSpec This will be called in {@link #read}.
*/
protected abstract T getInstanceFromResultSet(ResultSet result) throws SQLException; protected abstract T getInstanceFromResultSet(ResultSet result) throws SQLException;
protected abstract List<T> getListFromResultSet(ResultSet result) throws SQLException; /**
* @param id The ID of the database entry to read.
protected abstract PreparedStatement getCreateStatement(T t) throws SQLException; * @return A {@link PreparedStatement} to read a specific entry by its ID.
* @implSpec This will be called in {@link #read}.
* The output of the execution will be used in {@link #getInstanceFromResultSet}.
*/
protected abstract PreparedStatement getReadByIDStatement(int id) throws SQLException; protected abstract PreparedStatement getReadByIDStatement(int id) throws SQLException;
/**
* @param result The {@link ResultSet} from execution of the statement received from {@link #getReadAllStatement}.
* @return A {@link List} of type {@link T} holding all database entries as model instances.
* @implSpec This will be called in {@link #readAll}.
*/
protected abstract List<T> getListFromResultSet(ResultSet result) throws SQLException;
/**
* @return A {@link PreparedStatement} to read all entries of this model.
* @implSpec This will be called in {@link #readAll}.
* The output of the execution will be used in {@link #getListFromResultSet}.
*/
protected abstract PreparedStatement getReadAllStatement() throws SQLException; protected abstract PreparedStatement getReadAllStatement() throws SQLException;
/**
* @param t The model instance of type {@link T} for which an entry should be created.
* @return a {@link PreparedStatement} which can be used to create a new database entry for the model instance.
* @implSpec This will be called in {@link #create}.
*/
protected abstract PreparedStatement getCreateStatement(T t) throws SQLException;
/**
* @param t The model instance of type {@link T} for which the entry should be updated.
* @return a {@link PreparedStatement} which can be used to update the database entry for the model instance.
* @implSpec This will be called in {@link #update}.
*/
protected abstract PreparedStatement getUpdateStatement(T t) throws SQLException; protected abstract PreparedStatement getUpdateStatement(T t) throws SQLException;
/**
* @param id The ID of the database entry which should be deleted.
* @return a {@link PreparedStatement} which can be used to delete the database entry.
* @implSpec This will be called in {@link #delete}.
*/
protected abstract PreparedStatement getDeleteStatement(int id) throws SQLException; protected abstract PreparedStatement getDeleteStatement(int id) throws SQLException;
} }

View file

@ -7,36 +7,36 @@ import java.sql.SQLException;
import java.util.Map; import java.util.Map;
/** /**
* A Fixture is a Class, which can be used to set up a specific set of Data. * A fixture is a class, which can be used to set up a specific set of data.
* *
* @param <T> The Model for which the {@link Fixture} is implemented. * @param <T> The model for which the {@link Fixture} is implemented.
* @author Dominik Säume * @author Dominik Säume
* @version 1.0 * @version 1.0
* @implSpec The Implementations should be added to the {@link Fixtures#main}. * @implSpec The implementations should be added to the {@link Fixtures#main}.
*/ */
public interface Fixture<T> { public interface Fixture<T> {
/** /**
* Drop all Dependent Tables. * Drop all dependent tables.
* *
* @param connection A Database {@link Connection}, which should be received from * @param connection A database {@link Connection}, which should be received from
* the {@link ConnectionBuilder#getConnection} * the {@link ConnectionBuilder#getConnection}
* @implSpec Use {@code IF EXISTS}, to ensure that it doesn't throw an {@link Exception}. * @implSpec Use {@code IF EXISTS}, to ensure that it doesn't throw an {@link Exception}.
*/ */
void dropTable(Connection connection) throws SQLException; void dropTable(Connection connection) throws SQLException;
/** /**
* Set up the Empty Tables with the Schema. * Set up the empty tables with the schema.
* *
* @param connection A Database {@link Connection}, which should be received from * @param connection A database {@link Connection}, which should be received from
* the {@link ConnectionBuilder#getConnection} * the {@link ConnectionBuilder#getConnection}
*/ */
void setupTable(Connection connection) throws SQLException; void setupTable(Connection connection) throws SQLException;
/** /**
* Loads all Model specific Data to the Database. * Loads all model specific data to the database.
* *
* @return A Map of Models with a {@link String} key, to be used by other {@link Fixture} * @return A map of models with a {@link String} key, to be used by other {@link Fixture}
* @implSpec The {@link de.hitec.nhplus.datastorage.Dao Dao} should be received * @implSpec The {@link de.hitec.nhplus.datastorage.Dao Dao} should be received
* from {@link de.hitec.nhplus.datastorage.DaoFactory DaoFactory}. * from {@link de.hitec.nhplus.datastorage.DaoFactory DaoFactory}.
*/ */

View file

@ -7,7 +7,7 @@ import java.sql.Connection;
import java.util.Map; import java.util.Map;
/** /**
* A Class, Implementing an Entrypoint({@link #main}), for loading a Specific set of Data. * A class, implementing an entrypoint({@link #main}), for loading a specific set of data.
* *
* @author Dominik Säume * @author Dominik Säume
* @version 1.0 * @version 1.0
@ -15,7 +15,7 @@ import java.util.Map;
public class Fixtures { public class Fixtures {
/** /**
* An Entrypoint, for loading a Specific set of Data. * An entrypoint, for loading a specific set of data.
* *
* @param args unused. * @param args unused.
*/ */

View file

@ -5,6 +5,7 @@ import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.medication.Ingredient; import de.hitec.nhplus.medication.Ingredient;
import de.hitec.nhplus.medication.Medication; import de.hitec.nhplus.medication.Medication;
import de.hitec.nhplus.medication.database.MedicationDao; import de.hitec.nhplus.medication.database.MedicationDao;
import de.hitec.nhplus.treatment.Treatment;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -12,7 +13,11 @@ import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.*;
/**
* {@link Fixture} for {@link Medication}.
*
* @author Dominik Säume
*/
public class MedicationFixture implements Fixture<Medication> { public class MedicationFixture implements Fixture<Medication> {
private static final String SCHEMA = "/de/hitec/nhplus/medication/database/Medication.sql"; private static final String SCHEMA = "/de/hitec/nhplus/medication/database/Medication.sql";
private static final String INGREDIENT_SCHEMA = "/de/hitec/nhplus/medication/database/Medication_Ingredient.sql"; private static final String INGREDIENT_SCHEMA = "/de/hitec/nhplus/medication/database/Medication_Ingredient.sql";

View file

@ -4,6 +4,7 @@ import de.hitec.nhplus.Main;
import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.nurse.Nurse; import de.hitec.nhplus.nurse.Nurse;
import de.hitec.nhplus.nurse.database.NurseDao; import de.hitec.nhplus.nurse.database.NurseDao;
import de.hitec.nhplus.treatment.Treatment;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -11,6 +12,11 @@ import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.*;
/**
* {@link Fixture} for {@link Nurse}.
*
* @author Dominik Säume
*/
public class NurseFixture implements Fixture<Nurse> { public class NurseFixture implements Fixture<Nurse> {
@Override @Override
public void dropTable(Connection connection) throws SQLException { public void dropTable(Connection connection) throws SQLException {

View file

@ -4,6 +4,7 @@ import de.hitec.nhplus.Main;
import de.hitec.nhplus.datastorage.DaoFactory; import de.hitec.nhplus.datastorage.DaoFactory;
import de.hitec.nhplus.patient.Patient; import de.hitec.nhplus.patient.Patient;
import de.hitec.nhplus.patient.database.PatientDao; import de.hitec.nhplus.patient.database.PatientDao;
import de.hitec.nhplus.treatment.Treatment;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -13,6 +14,11 @@ import java.util.*;
import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalDate; import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalDate;
/**
* {@link Fixture} for {@link Patient}.
*
* @author Dominik Säume
*/
public class PatientFixture implements Fixture<Patient> { public class PatientFixture implements Fixture<Patient> {
@Override @Override
public void dropTable(Connection connection) throws SQLException { public void dropTable(Connection connection) throws SQLException {

View file

@ -15,6 +15,12 @@ import java.util.*;
import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalDate; import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalDate;
import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalTime; import static de.hitec.nhplus.utils.DateConverter.convertStringToLocalTime;
/**
* {@link Fixture} for {@link Treatment}.
*
* @author Dominik Säume
*/
public class TreatmentFixture implements Fixture<Treatment> { public class TreatmentFixture implements Fixture<Treatment> {
private final Map<String, Patient> patientsByName; private final Map<String, Patient> patientsByName;

View file

@ -11,6 +11,12 @@ import javafx.scene.layout.BorderPane;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
/**
* Controller for the main window of the application, which holds all tabs.
*
* @author Bernd Heideman
* @author Dominik Säume
*/
public class MainWindowController { public class MainWindowController {
@FXML @FXML
private TabPane mainTabPane; private TabPane mainTabPane;
@ -42,6 +48,9 @@ public class MainWindowController {
medicationTab.setOnSelectionChanged(event -> loadMedicationPage()); medicationTab.setOnSelectionChanged(event -> loadMedicationPage());
} }
/**
* Loads the patient page into its tab.
*/
private void loadPatientPage() { private void loadPatientPage() {
try { try {
BorderPane patientsPane = FXMLLoader.load( BorderPane patientsPane = FXMLLoader.load(
@ -57,6 +66,9 @@ public class MainWindowController {
} }
} }
/**
* Loads the treatment page into its tab.
*/
private void loadTreatmentsPage() { private void loadTreatmentsPage() {
try { try {
BorderPane treatmentsPane = FXMLLoader.load( BorderPane treatmentsPane = FXMLLoader.load(
@ -72,6 +84,9 @@ public class MainWindowController {
} }
} }
/**
* Loads the nurse page into its tab.
*/
private void loadNursePage() { private void loadNursePage() {
try { try {
BorderPane nursePane = FXMLLoader.load( BorderPane nursePane = FXMLLoader.load(
@ -87,6 +102,9 @@ public class MainWindowController {
} }
} }
/**
* Loads the medication page into its tab.
*/
private void loadMedicationPage() { private void loadMedicationPage() {
try { try {
BorderPane medicationPane = FXMLLoader.load( BorderPane medicationPane = FXMLLoader.load(

View file

@ -2,6 +2,12 @@ package de.hitec.nhplus.main;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
/**
* A simple base model for a {@link Person} that can be extended.
*
* @author Bernd Heideman
* @author Dominik Säume
*/
public abstract class Person { public abstract class Person {
private final SimpleStringProperty firstName; private final SimpleStringProperty firstName;
private final SimpleStringProperty surName; private final SimpleStringProperty surName;

View file

@ -4,23 +4,44 @@ import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
/**
* A utility class that holds utility methods for date conversion.
*
* @author Bernd Heideman
*/
public class DateConverter { public class DateConverter {
private static final String DATE_FORMAT = "yyyy-MM-dd"; private static final String DATE_FORMAT = "yyyy-MM-dd";
private static final String TIME_FORMAT = "HH:mm"; private static final String TIME_FORMAT = "HH:mm";
/**
* @param date A date {@link String} in the format: yyyy-MM-dd.
* @return The converted date {@link String} as {@link LocalDate}.
*/
public static LocalDate convertStringToLocalDate(String date) { public static LocalDate convertStringToLocalDate(String date) {
return LocalDate.parse(date, DateTimeFormatter.ofPattern(DATE_FORMAT)); return LocalDate.parse(date, DateTimeFormatter.ofPattern(DATE_FORMAT));
} }
/**
* @param time A time {@link String} in the format: HH:mm.
* @return The converted time {@link String} as {@link LocalTime}.
*/
public static LocalTime convertStringToLocalTime(String time) { public static LocalTime convertStringToLocalTime(String time) {
return LocalTime.parse(time, DateTimeFormatter.ofPattern(TIME_FORMAT)); return LocalTime.parse(time, DateTimeFormatter.ofPattern(TIME_FORMAT));
} }
/**
* @param date A {@link LocalDate} which should be converted to a {@link String}.
* @return The converted {@link LocalDate} in the format: yyy-MM-dd.
*/
public static String convertLocalDateToString(LocalDate date) { public static String convertLocalDateToString(LocalDate date) {
return date.format(DateTimeFormatter.ofPattern(DATE_FORMAT)); return date.format(DateTimeFormatter.ofPattern(DATE_FORMAT));
} }
/**
* @param time A {@link LocalTime} which should be converted to a {@link String}.
* @return The converted {@link LocalTime} in the format: HH:mm.
*/
public static String convertLocalTimeToString(LocalTime time) { public static String convertLocalTimeToString(LocalTime time) {
return time.format(DateTimeFormatter.ofPattern(TIME_FORMAT)); return time.format(DateTimeFormatter.ofPattern(TIME_FORMAT));
} }

View file

@ -5,17 +5,34 @@ import javafx.scene.control.Alert;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
public class Validator /**
{ * A utility class for validating all kinds of data.
public static void showValidationError(String type){ *
* @author Dominik Säume
* @author Ole Kück
*/
public class Validator {
/**
* Shows a modal with a specific validation error.
*
* @param type The type for which a validation error should be shown as {@link String}.
*/
public static void showValidationError(String type) {
Alert alert = new Alert(Alert.AlertType.ERROR); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error"); alert.setTitle("Error");
alert.setHeaderText(null); alert.setHeaderText(null);
alert.setContentText("Invalid " + type + " !"); alert.setContentText("Invalid " + type + " !");
alert.showAndWait(); alert.showAndWait();
} }
/**
* Validate that a {@link String} is a valid date.
*
* @param text The date {@link String} to validate.
*/
public static boolean isValidDate(String text) { public static boolean isValidDate(String text) {
if(text.isBlank()){ if (text.isBlank()) {
return false; return false;
} }
try { try {
@ -25,8 +42,14 @@ public class Validator
} }
return true; return true;
} }
/**
* Validate that a {@link LocalDate} is a valid date for storage in the database.
*
* @param date The {@link LocalDate} to validate.
*/
public static boolean isValidDate(LocalDate date) { public static boolean isValidDate(LocalDate date) {
if(date == null){ if (date == null) {
return false; return false;
} }
try { try {
@ -36,21 +59,34 @@ public class Validator
} }
return true; return true;
} }
public static boolean isValidTime(String text){
if(text.isBlank()){ /**
* Validate that a {@link String} is a valid time.
*
* @param text The time {@link String} to validate.
*/
public static boolean isValidTime(String text) {
if (text.isBlank()) {
return false; return false;
} }
try { try {
DateConverter.convertStringToLocalTime(text); DateConverter.convertStringToLocalTime(text);
}catch (Exception exception){ } catch (Exception exception) {
return false; return false;
} }
return true; return true;
} }
public static boolean isValidTimeRange(String start, String end){
if( /**
* Validate that two time {@link String}s are a valid time range.
*
* @param start The starting time {@link String}.
* @param end The ending time {@link String}.
*/
public static boolean isValidTimeRange(String start, String end) {
if (
!isValidTime(start) || !isValidTime(end) !isValidTime(start) || !isValidTime(end)
){ ) {
return false; return false;
} }
LocalTime startTime = DateConverter.convertStringToLocalTime(start); LocalTime startTime = DateConverter.convertStringToLocalTime(start);
@ -59,24 +95,57 @@ public class Validator
} }
/**
* Validate that a {@link String} is a valid description.
*
* @param text The {@link String} to validate.
*/
public static boolean isValidDescription(String text) { public static boolean isValidDescription(String text) {
return !text.isBlank(); return !text.isBlank();
} }
public static boolean isValidFirstName(String text){
return !text.isBlank(); /**
} * Validate that a {@link String} is a valid first name.
public static boolean isValidSurName(String text){ *
return !text.isBlank(); * @param text The {@link String} to validate.
} */
public static boolean isValidPhoneNumber(String text){ public static boolean isValidFirstName(String text) {
return !text.isBlank();
}
public static boolean isValidCareLevel(String text){
return !text.isBlank();
}
public static boolean isValidRoomNumber(String text){
return !text.isBlank(); return !text.isBlank();
} }
/**
* Validate that a {@link String} is a valid surname.
*
* @param text The {@link String} to validate.
*/
public static boolean isValidSurName(String text) {
return !text.isBlank();
}
/**
* Validate that a {@link String} is a valid phone number.
*
* @param text The {@link String} to validate.
*/
public static boolean isValidPhoneNumber(String text) {
return !text.isBlank();
}
/**
* Validate that a {@link String} is a valid care level.
*
* @param text The {@link String} to validate.
*/
public static boolean isValidCareLevel(String text) {
return !text.isBlank();
}
/**
* Validate that a {@link String} is a valid room number.
*
* @param text The {@link String} to validate.
*/
public static boolean isValidRoomNumber(String text) {
return !text.isBlank();
}
} }