Rev 26 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 26 | Rev 27 | ||
---|---|---|---|
Line 33... | Line 33... | ||
33 | /**
|
33 | /**
|
34 | * Executes the DB query to save the user
|
34 | * Executes the DB query to save the user
|
35 | *
|
35 | *
|
36 | * @return
|
36 | * @return
|
37 | */
|
37 | */
|
38 | public String add() |
38 | public String addOrUpdate() |
39 | {
|
39 | {
|
40 | userDAO.saveUser(user); |
40 | userDAO.saveOrUpdateUser(user); |
41 | return SUCCESS; |
41 | return SUCCESS; |
42 | }
|
42 | }
|
43 | 43 | ||
44 | /**
|
44 | /**
|
45 | * DB query for userList
|
45 | * DB query for userList
|
Line 50... | Line 50... | ||
50 | {
|
50 | {
|
51 | userList = userDAO.listUser(); |
51 | userList = userDAO.listUser(); |
52 | return SUCCESS; |
52 | return SUCCESS; |
53 | }
|
53 | }
|
54 | 54 | ||
- | 55 | public String edit() |
|
- | 56 | {
|
|
- | 57 | int id = getIdParameter(); |
|
- | 58 | ||
- | 59 | if (id > 0) |
|
- | 60 | {
|
|
- | 61 | user = userDAO.listUserById(id); |
|
- | 62 | return SUCCESS; |
|
- | 63 | }
|
|
- | 64 | else
|
|
- | 65 | {
|
|
- | 66 | return ERROR; |
|
- | 67 | }
|
|
- | 68 | }
|
|
- | 69 | ||
55 | /**
|
70 | /**
|
56 | * deletes a user, gets the ID from the "id" parameter that was submitted
|
71 | * Gets the ID Parameter for update / delete requests
|
57 | * with the HTTP request
|
- | |
58 | *
|
72 | *
|
59 | * @return String - either SUCCESS or ERROR constant
|
73 | * @return int from the ID request. If not set or wrong, it gives back -1
|
60 | */
|
74 | */
|
61 | public String delete() |
75 | private int getIdParameter() |
62 | {
|
76 | {
|
63 | HttpServletRequest request = (HttpServletRequest) ActionContext |
77 | HttpServletRequest request = (HttpServletRequest) ActionContext |
64 | .getContext().get(ServletActionContext.HTTP_REQUEST); |
78 | .getContext().get(ServletActionContext.HTTP_REQUEST); |
65 | 79 | ||
66 | int id = 0; |
80 | int id = -1; |
67 | - | ||
68 | try
|
81 | try
|
69 | {
|
82 | {
|
70 | id = Integer.parseInt(request.getParameter("id")); |
83 | id = Integer.parseInt(request.getParameter("id")); |
71 | }
|
84 | }
|
72 | catch (Exception e) |
85 | catch (Exception e) |
73 | {
|
86 | {
|
74 | return ERROR; |
87 | // TODO: Logging - wrong parameter set
|
75 | }
|
88 | }
|
76 | 89 | ||
- | 90 | return id; |
|
- | 91 | }
|
|
- | 92 | ||
- | 93 | /**
|
|
- | 94 | * deletes a user, gets the ID from the "id" parameter that was submitted
|
|
- | 95 | * with the HTTP request
|
|
- | 96 | *
|
|
- | 97 | * @return String - either SUCCESS or ERROR constant
|
|
- | 98 | */
|
|
- | 99 | public String delete() |
|
- | 100 | {
|
|
- | 101 | ||
- | 102 | int id = getIdParameter(); |
|
- | 103 | ||
77 | // Check for malicious ID values
|
104 | // Check for malicious ID values
|
78 | if (id > 0) |
105 | if (id > 0) |
79 | {
|
106 | {
|
80 | userDAO.deleteUser(id); |
107 | userDAO.deleteUser(id); |
81 | return SUCCESS; |
108 | return SUCCESS; |