Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

admin view fix #40

Merged
merged 6 commits into from
Oct 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ private Staff parseUser(Map<String, Object> inputMap){
String lastname = (String) inputMap.get("lastname");
String department = (String) inputMap.get("department");
String position = (String) inputMap.get("position");
Permission permission = (Permission) inputMap.get("permission");
Permission permission;
try{
permission = Permission.valueOf((String) inputMap.get("permission"));
}
catch(IllegalArgumentException e){
permission = null;
}
Staff staff = new Staff(username, firstname, lastname, department, position, permission);
return staff;
}
Expand Down Expand Up @@ -111,8 +117,9 @@ private InputToModelParseResult validate(Map<String, Object> inputMap){
for(Map.Entry<String, Object> entry : inputMap.entrySet()){
if(entry.getKey().equals("firstname")) continue;
if(entry.getKey().equals("position")) continue;
if(entry.getKey().equals("permission")&& entry.getValue() instanceof Permission) continue;

IValidator validator = new StringValidator();

if(validator.validate(entry.getValue())){
continue;
} else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,17 @@ private void addUser() {
alert.setHeaderText("New user added succesfully");
alert.setContentText("Click OK to proceed");
alert.showAndWait();
resetPassword(txfAddUsername.getText());
resetAddUserTab();
initStaffTable();
} else{
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Error adding new user");
alert.setContentText(result.getReason());
alert.showAndWait();
}
resetAddUserTab();
}

}

private void editUser(){
Expand Down Expand Up @@ -218,14 +221,15 @@ private void deleteUser() {
alert.showAndWait();
break;
}
initStaffTable();
}

public void setStage(Stage stage) {
this.stage = stage;
}

@SuppressWarnings("unchecked")
private void initStaffTable(){
protected void initStaffTable(){

logger.info("Initiating staff list table");
staffList = FXCollections.observableArrayList(administratorService.getInspectors());
Expand Down Expand Up @@ -278,7 +282,7 @@ private void resetAddUserTab(){

private void initPermissionCombobox(){
ObservableList<String> permissions =
FXCollections.observableArrayList("All", Permission.ADMIN.toString(),
FXCollections.observableArrayList(Permission.ADMIN.toString(),
Permission.EDITOR.toString(), Permission.VIEWER.toString());
cbxAddPermission.setItems(permissions);
}
Expand Down Expand Up @@ -322,6 +326,31 @@ private void resetPassword(){
alert.showAndWait();
break;

case 500 :
alert = new Alert(AlertType.ERROR);
alert.setTitle("Password reset");
alert.setHeaderText("Error during password reset");
alert.setContentText("Error occured on the server side");
alert.showAndWait();
break;
}
}

private void resetPassword(String username){
Alert alert;
String randomPass = administratorService.randomPassword();
int hashedRandomPass = randomPass.hashCode();
int result = administratorService.resetPassword(
username, hashedRandomPass);
switch(result){
case 200 :
alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Password");
alert.setHeaderText("Password for user "+username+" set succesfully");
alert.setContentText("new password: "+randomPass);
alert.showAndWait();
break;

case 500 :
alert = new Alert(AlertType.ERROR);
alert.setTitle("Password reset");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ private void updateUser(){
inputMap.put("lastname", lastNameField.getText());
inputMap.put("department", departmentCombobox.getValue());
inputMap.put("position", positionField.getText());
inputMap.put("permission", permissionCombobox.getValue());
inputMap.put("permission", permissionCombobox.getValue().toString());

InputToModelParseResult result = administratorService.editUser(inputMap);
if(result.isSuccessful()){
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Editing user");
alert.setHeaderText("User "+usernameField.getText()+" edited successfully");
alert.setContentText("Click OK to proceed");
c.updateTable();
c.initStaffTable();
alert.showAndWait();
}
else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ public void testAddUser_allFieldsFilled() {
String lastname = "Doe";
String department = "IT";
String position = "admin";
Permission permission = Permission.ADMIN;
String permission = "ADMIN";

Staff staff = new Staff(username, firstname, lastname, department, position, permission);
Staff staff = new Staff(username, firstname, lastname, department, position, Permission.valueOf(permission));

inputMap.put("username", username);
inputMap.put("firstname", firstname);
Expand All @@ -261,9 +261,9 @@ public void testEditUser_allFieldsFilled() {
String lastname = "Doe";
String department = "IT";
String position = "admin";
Permission permission = Permission.ADMIN;
String permission = "ADMIN";

Staff staff = new Staff(username, firstname, lastname, department, position, permission);
Staff staff = new Staff(username, firstname, lastname, department, position, Permission.valueOf(permission));

inputMap.put("username", username);
inputMap.put("firstname", firstname);
Expand Down