1 package org
.cvut
.skischool
.back
;
3 import java
.io
.Serializable
;
4 import java
.util
.ArrayList
;
7 import javax
.faces
.bean
.ManagedBean
;
8 import javax
.faces
.bean
.SessionScoped
;
9 import javax
.faces
.model
.SelectItem
;
10 import org
.cvut
.skischool
.Messages
;
11 import org
.cvut
.skischool
.beans
.AccountManagementLocal
;
12 import org
.cvut
.skischool
.beans
.UserManagementLocal
;
13 import org
.cvut
.skischool
.core
.DigestTools
;
14 import org
.cvut
.skischool
.core
.NamingConstants
;
15 import org
.cvut
.skischool
.model
.Account
;
16 import org
.cvut
.skischool
.model
.Instructor
;
22 @ManagedBean(name
= "instructorsBean")
24 public class InstructorsBean
implements Serializable
{
27 private AccountManagementLocal accountManagement
;
29 private UserManagementLocal instructorManagement
;
30 private Instructor instructor
;
31 private boolean isNewInstructor
;
32 private String accountPassword
;
34 public InstructorsBean() {
35 isNewInstructor
= true;
38 public boolean isNewInstructor() {
39 return isNewInstructor
;
42 public String
getAccountPassword() {
43 return accountPassword
;
46 public void setAccountPassword(String password
) {
47 this.accountPassword
= password
;
50 public Instructor
getInstructor() {
54 public void setInstructor(Instructor instructor
) {
55 this.instructor
= instructor
;
58 public List
<Instructor
> getAllInstructors() {
59 return instructorManagement
.getAllInstructors();
62 public String
newInstructor() {
63 isNewInstructor
= true;
64 instructor
= new Instructor();
65 Account account
= new Account();
67 account
.setPerson(instructor
);
68 instructor
.setAccount(account
);
69 instructor
.setDisabled(false);
70 instructor
.setActive(true);
72 return "createinstructor?faces-redirect=true";
75 public String
editInstructor(Instructor instructor
) {
76 isNewInstructor
= false;
77 this.instructor
= instructor
;
79 return "createinstructor?faces-redirect=true";
82 public String
saveInstructor() {
83 // check whether username exists
84 Account conflictAccount
= accountManagement
.getAccount(instructor
.getAccount().getLogin());
85 if (isNewInstructor
&& (conflictAccount
!= null)) {
86 Messages
.showErrorMessage("Zadané užívateľské meno už existuje");
87 //Messages.showErrorMessage("Username already exists");
90 // check whether user changed password
91 if ((accountPassword
!= null) && (!accountPassword
.isEmpty())) {
92 String passwordHash
= DigestTools
.SHA1(accountPassword
);
93 instructor
.getAccount().setPassword(passwordHash
);
94 accountPassword
= null;
95 } else if (isNewInstructor
) {
96 Messages
.showErrorMessage("Zabudli ste vypniť heslo užívateľa");
97 //Messages.showErrorMessage("You must specify user password");
101 if (!isNewInstructor
) {
102 accountManagement
.updateAccount(instructor
.getAccount());
104 instructorManagement
.updateInstructor(instructor
);
106 return "index?faces-redirect=true";
109 public List
<SelectItem
> getRoles() {
110 List
<SelectItem
> roles
= new ArrayList
<SelectItem
>(2);
112 roles
.add(new SelectItem(NamingConstants
.ROLE_INSTRUCTOR
, "Instructor"));
113 roles
.add(new SelectItem(NamingConstants
.ROLE_ADMINISTRATOR
, "Administrator"));