Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
899 | dev | 1 | package ak.webcontrol.core.action; |
2 | |||
3 | import java.util.List; |
||
4 | import java.util.Collections; |
||
5 | import java.util.ArrayList; |
||
6 | |||
7 | import javax.servlet.http.HttpServletRequest; |
||
8 | import javax.servlet.http.HttpServletResponse; |
||
9 | |||
10 | import org.apache.struts.action.Action; |
||
11 | import org.apache.struts.action.ActionMapping; |
||
12 | import org.apache.struts.action.ActionForm; |
||
13 | import org.apache.struts.action.DynaActionForm; |
||
14 | import org.apache.struts.action.ActionForward; |
||
15 | import org.apache.struts.action.ActionMessages; |
||
16 | import org.apache.struts.action.ActionErrors; |
||
17 | import org.apache.struts.action.ActionError; |
||
18 | |||
19 | import ak.strutsx.RequestUtilsX; |
||
20 | import ak.backpath.BackPath; |
||
21 | |||
22 | import ak.webcontrol.util.StringConverter; |
||
23 | import ak.webcontrol.core.model.User; |
||
24 | import ak.webcontrol.core.model.SystemUser; |
||
25 | import ak.webcontrol.core.model.SystemUserManager; |
||
26 | |||
27 | public final class SystemUserAction |
||
28 | extends Action |
||
29 | { |
||
30 | public ActionForward execute(ActionMapping mapping, ActionForm form, |
||
31 | HttpServletRequest request, HttpServletResponse response) |
||
32 | throws Exception |
||
33 | { |
||
34 | User user = (User)request.getSession().getAttribute("user"); |
||
35 | |||
36 | if("list".equals(mapping.getParameter())) { |
||
37 | List list = new ArrayList(SystemUserManager.getInstance().listSystemUsers()); |
||
38 | Collections.sort(list, SystemUserManager.NAME_COMPARATOR); |
||
39 | request.setAttribute("users", list); |
||
40 | |||
41 | return mapping.findForward("default"); |
||
42 | } |
||
43 | else if("edit".equals(mapping.getParameter())) { |
||
44 | DynaActionForm theForm = (DynaActionForm)form; |
||
45 | Long userId = StringConverter.parseLong(theForm.get("id")); |
||
46 | DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
||
47 | this, request, "ak.webcontrol.core.form.SystemUserEditForm"); |
||
48 | |||
49 | if(userId == null) { |
||
50 | |||
51 | } |
||
52 | else { |
||
53 | SystemUser u = SystemUserManager.getInstance().get(userId); |
||
54 | showForm.set("uid", StringConverter.toString(u.getUid())); |
||
55 | showForm.set("name", u.getName()); |
||
56 | } |
||
57 | |||
58 | return mapping.findForward("default"); |
||
59 | } |
||
60 | else if("delete".equals(mapping.getParameter())) { |
||
61 | DynaActionForm theForm = (DynaActionForm)form; |
||
62 | Long userId = StringConverter.parseLong(theForm.get("id")); |
||
63 | SystemUser u = SystemUserManager.getInstance().get(userId); |
||
64 | |||
65 | SystemUserManager.getInstance().delete(u); |
||
66 | response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
||
67 | return null; |
||
68 | } |
||
69 | else if("submit".equals(mapping.getParameter())) { |
||
70 | DynaActionForm theForm = (DynaActionForm)form; |
||
71 | Long userId = StringConverter.parseLong(theForm.get("id")); |
||
72 | SystemUser u; |
||
73 | |||
74 | if(userId == null) { |
||
75 | u = SystemUserManager.getInstance().create(); |
||
76 | } |
||
77 | else { |
||
78 | u = SystemUserManager.getInstance().get(userId); |
||
79 | } |
||
80 | |||
81 | u.setUid(StringConverter.parseInteger(theForm.get("uid"))); |
||
82 | u.setName((String)theForm.get("name")); |
||
83 | |||
84 | SystemUserManager.getInstance().save(u); |
||
85 | response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
||
86 | return null; |
||
87 | } |
||
88 | else { |
||
89 | throw new Exception("unknown mapping parameter"); |
||
90 | } |
||
91 | } |
||
92 | } |