Rev 1283 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1283 | Rev 1306 | ||
---|---|---|---|
1 | package pt.estgp.estgweb.web.controllers.configuration; |
1 | package pt.estgp.estgweb.web.controllers.configuration; |
2 | 2 | ||
3 | import org.apache.log4j.Logger; |
3 | import org.apache.log4j.Logger; |
4 | import org.apache.struts.action.ActionForm; |
4 | import org.apache.struts.action.ActionForm; |
5 | import org.apache.struts.action.ActionForward; |
5 | import org.apache.struts.action.ActionForward; |
6 | import org.apache.struts.action.ActionMapping; |
6 | import org.apache.struts.action.ActionMapping; |
7 | import pt.estgp.estgweb.domain.DomainObjectFactory; |
7 | import pt.estgp.estgweb.domain.DomainObjectFactory; |
8 | import pt.estgp.estgweb.domain.UserRoleConfig; |
8 | import pt.estgp.estgweb.domain.UserRoleConfig; |
9 | import pt.estgp.estgweb.domain.UserRoleConfigImpl; |
9 | import pt.estgp.estgweb.domain.UserRoleConfigImpl; |
10 | import pt.estgp.estgweb.web.controllers.ApplicationDispatchController; |
10 | import pt.estgp.estgweb.web.controllers.ApplicationDispatchController; |
11 | import pt.estgp.estgweb.web.filters.UserRoleProxy; |
11 | import pt.estgp.estgweb.web.filters.UserRoleProxy; |
12 | import pt.estgp.estgweb.web.form.configuration.ConfigurationUserRolesForm; |
12 | import pt.estgp.estgweb.web.form.configuration.ConfigurationUserRolesForm; |
13 | import pt.estgp.estgweb.web.utils.RequestUtils; |
13 | import pt.estgp.estgweb.web.utils.RequestUtils; |
14 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
14 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
15 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
15 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
16 | import pt.utl.ist.berserk.logic.serviceManager.exceptions.FilterChainFailedException; |
16 | import pt.utl.ist.berserk.logic.serviceManager.exceptions.FilterChainFailedException; |
17 | 17 | ||
18 | import javax.servlet.ServletException; |
18 | import javax.servlet.ServletException; |
19 | import javax.servlet.http.HttpServletRequest; |
19 | import javax.servlet.http.HttpServletRequest; |
20 | import javax.servlet.http.HttpServletResponse; |
20 | import javax.servlet.http.HttpServletResponse; |
21 | 21 | ||
22 | /** |
22 | /** |
23 | * @author Jorge Machado |
23 | * @author Jorge Machado |
24 | * @date 26/Fev/2008 |
24 | * @date 26/Fev/2008 |
25 | * @time 18:01:54 |
25 | * @time 18:01:54 |
26 | * @see pt.estgp.estgweb.web |
26 | * @see pt.estgp.estgweb.web |
27 | */ |
27 | */ |
28 | public class UserRolesController extends ApplicationDispatchController |
28 | public class UserRolesController extends ApplicationDispatchController |
29 | { |
29 | { |
30 | 30 | ||
31 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(UserRolesController.class); |
31 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(UserRolesController.class); |
32 | 32 | ||
33 | 33 | ||
34 | 34 | ||
35 | 35 | ||
36 | 36 | ||
37 | public ActionForward addNew(ActionMapping mapping, |
37 | public ActionForward addNew(ActionMapping mapping, |
38 | ActionForm form, |
38 | ActionForm form, |
39 | HttpServletRequest request, |
39 | HttpServletRequest request, |
40 | HttpServletResponse response) |
40 | HttpServletResponse response) |
41 | throws ServletException |
41 | throws ServletException |
42 | { |
42 | { |
43 | 43 | ||
44 | UserRoleConfigImpl role = DomainObjectFactory.createUserRoleConfigImpl(); |
44 | UserRoleConfigImpl role = DomainObjectFactory.createUserRoleConfigImpl(); |
45 | role.setDirty(true); |
45 | role.setDirty(true); |
46 | ConfigurationUserRolesForm f = (ConfigurationUserRolesForm) form; |
46 | ConfigurationUserRolesForm f = (ConfigurationUserRolesForm) form; |
47 | f.getUserRolesConfig().add(0,role); |
47 | f.getUserRolesConfig().add(0,role); |
48 | return mapping.findForward("userRoles"); |
48 | return mapping.findForward("userRoles"); |
49 | } |
49 | } |
50 | 50 | ||
51 | 51 | ||
52 | public ActionForward saveAllDirty(ActionMapping mapping, |
52 | public ActionForward saveAllDirty(ActionMapping mapping, |
53 | ActionForm form, |
53 | ActionForm form, |
54 | HttpServletRequest request, |
54 | HttpServletRequest request, |
55 | HttpServletResponse response) |
55 | HttpServletResponse response) |
56 | throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
56 | throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
57 | 57 | ||
58 | ConfigurationUserRolesForm f = (ConfigurationUserRolesForm) form; |
58 | ConfigurationUserRolesForm f = (ConfigurationUserRolesForm) form; |
59 | IServiceManager sm = ServiceManager.getInstance(); |
59 | IServiceManager sm = ServiceManager.getInstance(); |
60 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
60 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
61 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{ |
61 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{ |
62 | f.getUserRolesConfig() |
62 | f.getUserRolesConfig() |
63 | }; |
63 | }; |
64 | 64 | ||
65 | try |
65 | try |
66 | { |
66 | { |
67 | sm.execute(RequestUtils.getRequester(request, response), "AddUpdateDirtyRolesTranslation", args, names); |
67 | sm.execute(RequestUtils.getRequester(request, response), "AddUpdateDirtyRolesTranslation", args, names); |
68 | UserRoleProxy.setDirty(); |
68 | UserRoleProxy.setDirty(); |
69 | f.setUserRoleConfigs(null); |
69 | f.setUserRoleConfigs(null); |
70 | addMessage(request, "configuration.roles.saved"); |
70 | addMessage(request, "configuration.roles.saved"); |
71 | } |
71 | } |
72 | catch (FilterChainFailedException e) |
72 | catch (FilterChainFailedException e) |
73 | { |
73 | { |
74 | return mapping.findForward("error401"); |
74 | return mapping.findForward("error401"); |
75 | } |
75 | } |
76 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
76 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
77 | { |
77 | { |
78 | logger.error(e, e); |
78 | logger.error(e, e); |
79 | throw e; |
79 | throw e; |
80 | } |
80 | } |
81 | return mapping.findForward("userRoles"); |
81 | return mapping.findForward("userRoles"); |
82 | } |
82 | } |
83 | 83 | ||
84 | public ActionForward saveUserRole(ActionMapping mapping, |
84 | public ActionForward saveUserRole(ActionMapping mapping, |
85 | ActionForm form, |
85 | ActionForm form, |
86 | HttpServletRequest request, |
86 | HttpServletRequest request, |
87 | HttpServletResponse response) |
87 | HttpServletResponse response) |
88 | throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
88 | throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
89 | 89 | ||
90 | ConfigurationUserRolesForm f = (ConfigurationUserRolesForm) form; |
90 | ConfigurationUserRolesForm f = (ConfigurationUserRolesForm) form; |
91 | UserRoleConfig userRoleConfig = null; |
91 | UserRoleConfig userRoleConfig = null; |
92 | long idPosChoosed = f.getId(); |
92 | long idPosChoosed = f.getId(); |
93 | for(UserRoleConfig u : f.getUserRolesConfig()) |
93 | for(UserRoleConfig u : f.getUserRolesConfig()) |
94 | { |
94 | { |
95 | UserRoleConfigImpl ur = (UserRoleConfigImpl) u; |
95 | UserRoleConfigImpl ur = (UserRoleConfigImpl) u; |
96 | if(ur.getPosForId() == idPosChoosed) |
96 | if(ur.getPosForId() == idPosChoosed) |
97 | { |
97 | { |
98 | userRoleConfig = ur; |
98 | userRoleConfig = ur; |
99 | break; |
99 | break; |
100 | } |
100 | } |
101 | } |
101 | } |
102 | if(userRoleConfig == null) |
102 | if(userRoleConfig == null) |
103 | return mapping.findForward("userRoles"); |
103 | return mapping.findForward("userRoles"); |
104 | 104 | ||
105 | IServiceManager sm = ServiceManager.getInstance(); |
105 | IServiceManager sm = ServiceManager.getInstance(); |
106 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
106 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
107 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{ |
107 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{ |
108 | userRoleConfig |
108 | userRoleConfig |
109 | }; |
109 | }; |
110 | 110 | ||
111 | try |
111 | try |
112 | { |
112 | { |
113 | sm.execute(RequestUtils.getRequester(request, response), "AddUpdateRoleTranslation", args, names); |
113 | sm.execute(RequestUtils.getRequester(request, response), "AddUpdateRoleTranslation", args, names); |
114 | UserRoleConfigImpl ur = (UserRoleConfigImpl) userRoleConfig; |
114 | UserRoleConfigImpl ur = (UserRoleConfigImpl) userRoleConfig; |
115 | ur.setDirty(false); |
115 | ur.setDirty(false); |
116 | UserRoleProxy.setDirty(); |
116 | UserRoleProxy.setDirty(); |
117 | //f.setUserRoleConfigs(null); |
117 | //f.setUserRoleConfigs(null); |
118 | addMessage(request, "configuration.role.saved",ur.getValue()); |
118 | addMessage(request, "configuration.role.saved",ur.getValue()); |
119 | } |
119 | } |
120 | catch (FilterChainFailedException e) |
120 | catch (FilterChainFailedException e) |
121 | { |
121 | { |
122 | return mapping.findForward("error401"); |
122 | return mapping.findForward("error401"); |
123 | } |
123 | } |
124 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
124 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
125 | { |
125 | { |
126 | logger.error(e, e); |
126 | logger.error(e, e); |
127 | throw e; |
127 | throw e; |
128 | } |
128 | } |
129 | return mapping.findForward("userRoles"); |
129 | return mapping.findForward("userRoles"); |
130 | } |
130 | } |
131 | 131 | ||
132 | 132 | ||
133 | 133 | ||
134 | } |
134 | } |
135 | 135 |