Skip to content
Snippets Groups Projects
Commit ddeb74e2 authored by Eilert Tunheim's avatar Eilert Tunheim
Browse files

Added notification popup for output parameter sql injection

parent 5a6fbcda
Branches
No related tags found
No related merge requests found
......@@ -31,6 +31,8 @@ public class HelpingFunctions {
// Number of manual moisture checks
public static int NUMBER_OF_CHECKS = 1;
public static int MAX_USER_INPUT_CHARACTERS = 10;
// Today's date
public static String CURRENT_DATE = "";
public static String TIME_LEFT = "";
......
......@@ -16,6 +16,7 @@ import java.util.Map;
import static com.application.DB.Constants.*;
import static com.application.DB.DB.getCurrentDrying;
import static com.application.DB.HelpingFunctions.MAX_USER_INPUT_CHARACTERS;
import static com.application.DB.HelpingFunctions.setLoadedData;
import static com.application.GUI.LineChartFunctionality.*;
import static com.application.Main.*;
......@@ -30,8 +31,6 @@ import static com.application.DB.DB.setInputParameters;
*/
public class InputPopUpWindow {
private static boolean err = false;
public static void display() {
Stage window = new Stage();
......@@ -114,7 +113,6 @@ public class InputPopUpWindow {
startButton.setId("inputButtonStart");
startButton.setOnAction(e -> {
// Sets the start time
HelpingFunctions.CURRENT_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
HelpingFunctions.START_TIME = HelpingFunctions.CURRENT_DATE;
......@@ -129,50 +127,39 @@ public class InputPopUpWindow {
HelpingFunctions.MOISTURE_GOAL = moistureList.getValue();
}
boolean err = false;
// If the input is null, sets the value to be empty
if (treeSpeciesList.getValue() == null) {
HelpingFunctions.TREE_SPECIES = "";
err = false;
} else if (treeSpeciesList.getValue().length() > 10) {
NotificationPopUp.displayNotificationWindow("Maximum 10 characters is allowed for input parameters!");
} else if (treeSpeciesList.getValue().length() > MAX_USER_INPUT_CHARACTERS) {
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
treeSpeciesList.setValue("");
err = true;
} else {
err = false;
}
if (dimensionsList.getValue() == null) {
HelpingFunctions.DIMENSIONS = "";
err = false;
} else if (dimensionsList.getValue().length() > 10) {
NotificationPopUp.displayNotificationWindow("Maximum 10 characters is allowed for input parameters!");
} else if (dimensionsList.getValue().length() > MAX_USER_INPUT_CHARACTERS) {
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
dimensionsList.setValue("");
err = true;
} else {
err = false;
}
if (sawsetList.getValue() == null) {
HelpingFunctions.SAWSET = "";
err = false;
} else if (sawsetList.getValue().length() > 10) {
NotificationPopUp.displayNotificationWindow("Maximum 10 characters is allowed for input parameters!");
} else if (sawsetList.getValue().length() > MAX_USER_INPUT_CHARACTERS) {
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
sawsetList.setValue("");
err = true;
} else {
err = false;
}
if (moistureList.getValue() == null) {
HelpingFunctions.MOISTURE_GOAL = "";
err = false;
} else if (moistureList.getValue().length() > 10) {
NotificationPopUp.displayNotificationWindow("Maximum 10 characters is allowed for input parameters!");
} else if (moistureList.getValue().length() > MAX_USER_INPUT_CHARACTERS) {
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
moistureList.setValue("");
err = true;
} else {
err = false;
}
......
......@@ -15,6 +15,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import static com.application.DB.HelpingFunctions.IS_FINISHED;
import static com.application.DB.HelpingFunctions.MAX_USER_INPUT_CHARACTERS;
public class OutputPopUpWindow {
......@@ -30,12 +31,10 @@ public class OutputPopUpWindow {
moistureCheckLabelHuge.setAlignment(Pos.TOP_CENTER);
// Center - Output field
Label moistureCheckLabelSmall = new Label("Moisture Check:");
moistureCheckLabelSmall.setId("inputLabel");
moistureCheckLabelSmall.setAlignment(Pos.CENTER);
TextField moistureCheckTextField = new TextField();
moistureCheckTextField.setId("inputLabel");
moistureCheckTextField.setAlignment(Pos.CENTER);
moistureCheckTextField.setPromptText("Please enter a value");
......@@ -45,16 +44,32 @@ public class OutputPopUpWindow {
countinueButton.setAlignment(Pos.BOTTOM_CENTER);
countinueButton.setOnAction(e -> {
try {
if(!moistureCheckTextField.getCharacters().toString().isEmpty() &&
!moistureCheckTextField.getCharacters().toString().equals("Please enter a value")) {
HelpingFunctions.STOP_TIME = null;
DB.pushManMoisture(moistureCheckTextField.getCharacters().toString());
HelpingFunctions.NUMBER_OF_CHECKS++;
window.close();
boolean err = false;
if(moistureCheckTextField.getCharacters().length() > MAX_USER_INPUT_CHARACTERS){
err = true;
}
if(!err){
if(!moistureCheckTextField.getCharacters().toString().isEmpty() &&
!moistureCheckTextField.getCharacters().toString().equals("Please enter a value")) {
HelpingFunctions.STOP_TIME = null;
DB.pushManMoisture(moistureCheckTextField.getCharacters().toString());
HelpingFunctions.NUMBER_OF_CHECKS++;
window.close();
} else {
NotificationPopUp.displayNotificationWindow("Please enter a value!");
moistureCheckTextField.setPromptText("Please enter a value");
}
} else {
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
moistureCheckTextField.setText("");
moistureCheckTextField.setPromptText("Please enter a value");
}
} catch (Exception ex) {
ex.printStackTrace();
}
......@@ -64,13 +79,27 @@ public class OutputPopUpWindow {
finishButton.setAlignment(Pos.BOTTOM_CENTER);
finishButton.setOnAction(e -> {
try {
if(!moistureCheckTextField.getCharacters().toString().isEmpty() &&
!moistureCheckTextField.getCharacters().toString().equals("Please enter a value")) {
IS_FINISHED = true;
HelpingFunctions.STOP_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
DB.pushManMoisture(moistureCheckTextField.getCharacters().toString());
window.close();
boolean err = false;
if(moistureCheckTextField.getCharacters().length() > MAX_USER_INPUT_CHARACTERS){
err = true;
}
if(!err) {
if (!moistureCheckTextField.getCharacters().toString().isEmpty() &&
!moistureCheckTextField.getCharacters().toString().equals("Please enter a value")) {
IS_FINISHED = true;
HelpingFunctions.STOP_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
DB.pushManMoisture(moistureCheckTextField.getCharacters().toString());
window.close();
} else {
NotificationPopUp.displayNotificationWindow("Please enter a value!");
moistureCheckTextField.setPromptText("Please enter a value");
}
} else {
NotificationPopUp.displayNotificationWindow("A maximum of "+MAX_USER_INPUT_CHARACTERS+" characters is allowed!");
moistureCheckTextField.setText("");
moistureCheckTextField.setPromptText("Please enter a value");
}
} catch (Exception ex) {
......@@ -81,7 +110,8 @@ public class OutputPopUpWindow {
VBox layout = new VBox(10);
layout.setAlignment(Pos.CENTER);
layout.getChildren().addAll(moistureCheckLabelHuge,moistureCheckLabelSmall,moistureCheckTextField,countinueButton,finishButton);
layout.setSpacing(10);
layout.getChildren().addAll(moistureCheckLabelHuge,moistureCheckTextField,countinueButton,finishButton);
Scene scene = new Scene(layout, 600, 500);
scene.getStylesheets().add(InputPopUpWindow.class.getResource("/com.application/CSS/styleSheet.css").toExternalForm());
......
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment