Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
904 | dev | 1 | package ak.hostcaptain.core.action; |
899 | dev | 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.strutsx.ErrorHandlerX; |
||
21 | import ak.backpath.BackPath; |
||
22 | |||
904 | dev | 23 | import ak.hostcaptain.util.StringConverter; |
24 | import ak.hostcaptain.core.model.User; |
||
25 | import ak.hostcaptain.core.model.UserManager; |
||
26 | import ak.hostcaptain.core.model.InetDomain; |
||
27 | import ak.hostcaptain.core.model.InetDomainManager; |
||
899 | dev | 28 | |
29 | public final class InetDomainAction |
||
30 | extends Action |
||
31 | implements ErrorHandlerX |
||
32 | { |
||
33 | public void handleErrors(ActionMapping mapping, ActionForm form, |
||
34 | HttpServletRequest request, HttpServletResponse response) |
||
35 | throws Exception |
||
36 | { |
||
37 | if("submit".equals(mapping.getParameter())) { |
||
915 | dev | 38 | User user = (User)request.getSession().getAttribute("user"); |
39 | initUserList(request, user); |
||
899 | dev | 40 | } |
41 | } |
||
42 | |||
43 | public ActionForward execute(ActionMapping mapping, ActionForm form, |
||
44 | HttpServletRequest request, HttpServletResponse response) |
||
45 | throws Exception |
||
46 | { |
||
47 | User user = (User)request.getSession().getAttribute("user"); |
||
48 | |||
49 | if("list".equals(mapping.getParameter())) { |
||
914 | dev | 50 | List list = new ArrayList(InetDomainManager.getInstance().listInetDomains(user)); |
899 | dev | 51 | Collections.sort(list, InetDomainManager.NAME_COMPARATOR); |
52 | request.setAttribute("domains", list); |
||
914 | dev | 53 | request.setAttribute("allowedToCreate", |
54 | new Boolean(InetDomainManager.getInstance().allowedToCreate(user))); |
||
899 | dev | 55 | |
56 | return mapping.findForward("default"); |
||
57 | } |
||
58 | else if("edit".equals(mapping.getParameter())) { |
||
59 | DynaActionForm theForm = (DynaActionForm)form; |
||
60 | Long domainId = StringConverter.parseLong(theForm.get("id")); |
||
61 | DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
||
904 | dev | 62 | this, request, "ak.hostcaptain.core.form.InetDomainEditForm"); |
899 | dev | 63 | |
64 | if(domainId == null) { |
||
913 | dev | 65 | showForm.set("enabled", new Boolean(true)); |
899 | dev | 66 | } |
67 | else { |
||
914 | dev | 68 | InetDomain domain = InetDomainManager.getInstance().get(user, domainId); |
899 | dev | 69 | showForm.set("name", domain.getName()); |
70 | if(domain.getOwner() != null) |
||
71 | showForm.set("owner", StringConverter.toString(domain.getOwner().getId())); |
||
913 | dev | 72 | showForm.set("enabled", domain.getEnabled()); |
73 | showForm.set("comment", domain.getComment()); |
||
899 | dev | 74 | } |
75 | |||
915 | dev | 76 | initUserList(request, user); |
899 | dev | 77 | return mapping.findForward("default"); |
78 | } |
||
79 | else if("delete".equals(mapping.getParameter())) { |
||
80 | DynaActionForm theForm = (DynaActionForm)form; |
||
81 | Long domainId = StringConverter.parseLong(theForm.get("id")); |
||
914 | dev | 82 | InetDomain domain = InetDomainManager.getInstance().get(user, domainId); |
899 | dev | 83 | |
914 | dev | 84 | InetDomainManager.getInstance().delete(user, domain); |
899 | dev | 85 | response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
86 | return null; |
||
87 | } |
||
88 | else if("submit".equals(mapping.getParameter())) { |
||
89 | DynaActionForm theForm = (DynaActionForm)form; |
||
90 | Long domainId = StringConverter.parseLong(theForm.get("id")); |
||
91 | InetDomain domain; |
||
92 | |||
93 | if(domainId == null) { |
||
914 | dev | 94 | domain = InetDomainManager.getInstance().create(user); |
899 | dev | 95 | } |
96 | else { |
||
914 | dev | 97 | domain = InetDomainManager.getInstance().get(user, domainId); |
899 | dev | 98 | } |
99 | |||
100 | domain.setName((String)theForm.get("name")); |
||
915 | dev | 101 | domain.setOwner(UserManager.getInstance().get(user, |
899 | dev | 102 | StringConverter.parseLong(theForm.get("owner")))); |
103 | |||
913 | dev | 104 | domain.setEnabled((Boolean)theForm.get("enabled")); |
105 | domain.setComment((String)theForm.get("comment")); |
||
106 | |||
914 | dev | 107 | InetDomainManager.getInstance().save(user, domain); |
899 | dev | 108 | response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
109 | return null; |
||
110 | } |
||
111 | else { |
||
112 | throw new Exception("unknown mapping parameter"); |
||
113 | } |
||
114 | } |
||
115 | |||
915 | dev | 116 | private void initUserList(HttpServletRequest request, User user) |
899 | dev | 117 | throws Exception |
118 | { |
||
915 | dev | 119 | List list = new ArrayList(UserManager.getInstance().listUsers(user)); |
899 | dev | 120 | Collections.sort(list, UserManager.LOGIN_COMPARATOR); |
121 | request.setAttribute("users", list); |
||
122 | } |
||
123 | } |