Skip to content
Snippets Groups Projects
Commit 83ea7e73 authored by Syed OMAR's avatar Syed OMAR
Browse files

Added error handling for adding, deleting and editing services

parent 5ac75aa4
No related branches found
No related tags found
No related merge requests found
Pipeline #8516 canceled
......@@ -63,7 +63,33 @@ public class AddServiceSceneController {
String password = passwordField.getText().trim();
String confirmUser = confirmPasswordField.getText().trim();
if (password.equals(confirmUser)) {
StringBuilder checkString = new StringBuilder();
// Username validation
if (platform.isEmpty()) {
checkString.append("Please fill out the Name of Service box.\n");
}
if (username.isEmpty()) {
checkString.append("Please fill out the Username box.\n");
}
if (password.isEmpty()) {
checkString.append("Please fill out the Password box.\n");
}
if (confirmUser.isEmpty()) {
checkString.append("Please fill out the Confirm Password box.\n");
}
if (!password.equals(confirmUser)) {
checkString.append("Password and Confirm Password do not match.\n");
}
// Show alert if any issues were found
if (!checkString.isEmpty()) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Adding Service Failed");
alert.setHeaderText(null);
alert.setContentText(checkString.toString());
alert.showAndWait();
}else if (password.equals(confirmUser)) {
try {
DataStorage ds = new DataStorage("master_login.json");
......@@ -96,14 +122,15 @@ public class AddServiceSceneController {
} catch (Exception e) {
e.printStackTrace();
}
} else {
// Show error if passwords don't match
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Add Service");
alert.setHeaderText("Error");
alert.setContentText("Password does not match Confirm Password.");
alert.showAndWait();
}
// } else {
// // Show error if passwords don't match
// Alert alert = new Alert(Alert.AlertType.ERROR);
// alert.setTitle("Add Service");
// alert.setHeaderText("Error");
// alert.setContentText("Password does not match Confirm Password.");
// alert.showAndWait();
// }
}
......
......@@ -57,7 +57,28 @@ public class DeleteServiceSceneController {
String username = usernameField.getText().trim();
String confirmUser = confirmUsernameField.getText().trim();
if (username.equals(confirmUser)) {
StringBuilder checkString = new StringBuilder();
// Username validation
if (platform.isEmpty()) {
checkString.append("Please fill out the Name of Service box.\n");
}
if (username.isEmpty()) {
checkString.append("Please fill out the Username box.\n");
}
if (confirmUser.isEmpty()) {
checkString.append("Please fill out the Confirm Username box.\n");
}
if (!username.equals(confirmUser)) {
checkString.append("Username and Confirm Username do not match.\n");
}
if (!checkString.isEmpty()) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Deleting Service Failed");
alert.setHeaderText(null);
alert.setContentText(checkString.toString());
alert.showAndWait();
}else if (username.equals(confirmUser)) {
try {
DataStorage ds = new DataStorage("master_login.json");
......@@ -92,13 +113,14 @@ public class DeleteServiceSceneController {
} catch (Exception e) {
e.printStackTrace();
}
} else {
// If username does not match the confirm username field
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Delete Service");
alert.setHeaderText("Error");
alert.setContentText("Username does not match Confirm Username.");
alert.showAndWait();
}
// } else {
// // If username does not match the confirm username field
// Alert alert = new Alert(Alert.AlertType.ERROR);
// alert.setTitle("Delete Service");
// alert.setHeaderText("Error");
// alert.setContentText("Username does not match Confirm Username.");
// alert.showAndWait();
// }
}
}
......@@ -40,7 +40,29 @@ public class EditInfoSceneController {
String newUsername = editUsernameField.getText().trim();
String newPassword = editPasswordField.getText().trim();
try {
StringBuilder checkString = new StringBuilder();
if (platform.isEmpty()) {
checkString.append("Please fill out the Name of Service Name for Credential Changes box.\n");
}
if (username.isEmpty()) {
checkString.append("Please fill out the Username for Credential Changes box.\n");
}
if (newUsername.isEmpty()) {
checkString.append("Please fill out the New Username box.\n");
}
if (newPassword.isEmpty()) {
checkString.append("Please fill out the New Password box.\n");
}
if (!checkString.isEmpty()) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Deleting Service Failed");
alert.setHeaderText(null);
alert.setContentText(checkString.toString());
alert.showAndWait();
}else
try {
DataStorage ds = new DataStorage("master_login.json");
// Check if the service exists in the JSON file
......
......@@ -50,8 +50,8 @@
</children></AnchorPane>
<Label layoutX="88.0" layoutY="212.0" text="Service Name for Credential Changes" />
<TextField fx:id="serviceNameField" layoutX="56.0" layoutY="235.0" prefHeight="26.0" prefWidth="472.0" promptText="Service Name for Credential Changes" />
<Label layoutX="87.0" layoutY="440.0" prefHeight="17.0" prefWidth="179.0" text="Edit Password" />
<Label layoutX="85.0" layoutY="361.0" prefHeight="17.0" prefWidth="147.0" text="Edit Username" />
<Label layoutX="87.0" layoutY="440.0" prefHeight="17.0" prefWidth="179.0" text="New Password" />
<Label layoutX="85.0" layoutY="361.0" prefHeight="17.0" prefWidth="147.0" text="New Username" />
<TextField fx:id="editUsernameField" layoutX="56.0" layoutY="380.0" prefHeight="26.0" prefWidth="471.0" promptText="Edit Username" />
<ImageView fitHeight="25.0" fitWidth="17.0" layoutX="64.0" layoutY="439.0" pickOnBounds="true" preserveRatio="true">
<image>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment