Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RoleHierarchyPresenter |
|
| 1.1818181818181819;1.182 |
1 | /* | |
2 | * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport | |
3 | * (http://www.vbs.admin.ch) | |
4 | * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch) | |
5 | * All rights reserved. | |
6 | * | |
7 | * Licensed under the Open Permis License which accompanies this distribution, | |
8 | * and is available at http://www.openpermis.org/BSDlicenceKent.txt | |
9 | */ | |
10 | package org.openpermis.editor.policy.presenter; | |
11 | ||
12 | import java.net.URI; | |
13 | ||
14 | import org.slf4j.Logger; | |
15 | import org.slf4j.LoggerFactory; | |
16 | ||
17 | import org.openpermis.editor.policy.beans.PropertyChange; | |
18 | import org.openpermis.editor.policy.command.AddRoleCommand; | |
19 | import org.openpermis.editor.policy.command.DetachRoleCommand; | |
20 | import org.openpermis.editor.policy.command.IncludeRoleCommand; | |
21 | import org.openpermis.editor.policy.command.RemoveRoleCommand; | |
22 | import org.openpermis.editor.policy.command.RenameRoleCommand; | |
23 | import org.openpermis.policy.bean.RoleHierarchyBean; | |
24 | import org.openpermis.policy.bean.basic.BasicPartBeanFactory; | |
25 | ||
26 | /** | |
27 | * Presenter for a single {@link RoleHierarchyBean}. | |
28 | * @since 0.3.0 | |
29 | */ | |
30 | public class RoleHierarchyPresenter extends PartPresenter<RoleHierarchyBean> { | |
31 | ||
32 | //---- Static | |
33 | ||
34 | /** | |
35 | * The logger object of this class. | |
36 | * @since 0.3.0 | |
37 | */ | |
38 | 0 | private static final Logger LOGGER = |
39 | LoggerFactory.getLogger(RoleHierarchyPresenter.class); | |
40 | ||
41 | //---- State | |
42 | ||
43 | /** | |
44 | * @since 0.3.0 | |
45 | */ | |
46 | private URI identity; | |
47 | ||
48 | /** | |
49 | * @since 0.3.0 | |
50 | */ | |
51 | 0 | private BasicPartBeanFactory basicPartBeanFactory = new BasicPartBeanFactory(); |
52 | ||
53 | //---- Constructors | |
54 | ||
55 | /** | |
56 | * Creates a new {@link RoleHierarchyPresenter}. | |
57 | * @param model the action to work on. | |
58 | * @param context policy context that provides additional information. | |
59 | * @since 0.3.0 | |
60 | */ | |
61 | public RoleHierarchyPresenter (RoleHierarchyBean model, PolicyContext context) | |
62 | { | |
63 | 0 | super(model, context); |
64 | ||
65 | 0 | LOGGER.debug("Presenter for [{}].", model); |
66 | ||
67 | 0 | updateIdentity(); |
68 | 0 | } |
69 | ||
70 | //---- Methods | |
71 | ||
72 | /** | |
73 | * Gets the identity. | |
74 | * @return the identity. | |
75 | * @since 0.3.0 | |
76 | */ | |
77 | public URI getIdentity () { | |
78 | 0 | return this.identity; |
79 | } | |
80 | ||
81 | /** | |
82 | * Sets the identity of the model. | |
83 | * @param identity the new identity to set. | |
84 | * @since 0.3.0 | |
85 | */ | |
86 | public void setIdentity (URI identity) { | |
87 | try { | |
88 | // update presenter | |
89 | 0 | this.identity = identity; |
90 | ||
91 | // trigger model | |
92 | 0 | change("identity", this.identity); |
93 | 0 | } catch (final Exception e) { |
94 | 0 | LOGGER.warn("Cannot set role hierarchy identity [" + identity + "].", e); |
95 | 0 | } |
96 | 0 | } |
97 | ||
98 | /** | |
99 | * Given a parent role, include a role among its children. | |
100 | * @param parentName name of the role to which the sub role is added. | |
101 | * @param subRoleName name of the added sub role. | |
102 | * @since 0.3.0 | |
103 | */ | |
104 | public void includeRole (String parentName, String subRoleName) { | |
105 | 0 | this.getContext().getCommandDispatcher().execute( |
106 | new IncludeRoleCommand( | |
107 | "includeRole", parentName, subRoleName, getModel() | |
108 | ) | |
109 | ); | |
110 | 0 | } |
111 | ||
112 | /** | |
113 | * Detaches a role from its parent. | |
114 | * @param parentName the parent name. | |
115 | * @param subRoleName the sub-role name. | |
116 | * @since 0.3.0 | |
117 | */ | |
118 | public void detachRole (String parentName, String subRoleName) { | |
119 | 0 | this.getContext().getCommandDispatcher().execute( |
120 | new DetachRoleCommand( | |
121 | "detachRole", parentName, subRoleName, getModel() | |
122 | ) | |
123 | ); | |
124 | 0 | } |
125 | ||
126 | /** | |
127 | * Adds a new role in the hierarchy. | |
128 | * @param subRoleName name of the added sub role. | |
129 | * @since 0.3.0 | |
130 | */ | |
131 | public void addNewRole (String subRoleName) { | |
132 | 0 | this.getContext().getCommandDispatcher().execute( |
133 | new AddRoleCommand("addNewRole", subRoleName, getModel()) | |
134 | ); | |
135 | 0 | } |
136 | ||
137 | /** | |
138 | * Removes a role from the hierarchy. | |
139 | * @param subRoleName the sub-role name. | |
140 | * @since 0.3.0 | |
141 | */ | |
142 | public void removeRole (String subRoleName) { | |
143 | // TODO Any Cleanup. | |
144 | // fabian's notes fuer pietro: | |
145 | // This could be done in the future. | |
146 | // | |
147 | // hier k�nnte ein CompositeCommand her mit | |
148 | // a) RoleRemoveCommand's fuer alle target-access-rules, die diese rolle | |
149 | // referenzieren | |
150 | // hinweis: dmit bekommt man diese referenzen: | |
151 | // PolicyBean policy = this.getPresenter().getContext().getPolicyBean(); | |
152 | // List<TargetAccessRuleBean> parents = policy.getParentTargetAccessRules(<role>); | |
153 | // b) dem PoolRemoveCommand dieser rolle | |
154 | // hinweis: man koennte auch mergeRolePool mit expunge=true setzen | |
155 | // dann waere das hier ueberfluessig, aber weniger explizit, nicht schoen | |
156 | // c) dem Role2RemoveCommand | |
157 | // | |
158 | // hier als reminder der code aus dem alten TargetAccessRulePresenter: | |
159 | // public void removeActiveRole (RoleBean activeRole) { | |
160 | // if (activeRole != null) { | |
161 | // execute( | |
162 | // new CompositeCommand( | |
163 | // new RoleRemoveCommand(activeRole), | |
164 | // new PoolRemoveCommand<RoleBean>(this.getRolePool(), activeRole) | |
165 | // ) | |
166 | // ); | |
167 | // } | |
168 | // } | |
169 | ||
170 | 0 | this.getContext().getCommandDispatcher().execute( |
171 | new RemoveRoleCommand("removeRole", subRoleName, getModel()) | |
172 | ); | |
173 | 0 | } |
174 | ||
175 | /** | |
176 | * Renames a role. | |
177 | * @param oldName old role name. | |
178 | * @param newName new role name. | |
179 | * @since 0.3.0 | |
180 | */ | |
181 | public void renameRole (String oldName, String newName) { | |
182 | // fabian's notes fuer pietro: | |
183 | // This could be done in the future, see above in removeRole. | |
184 | // | |
185 | 0 | this.getContext().getCommandDispatcher().execute( |
186 | new RenameRoleCommand( | |
187 | "renameRole", oldName, newName, getModel() | |
188 | ) | |
189 | ); | |
190 | 0 | } |
191 | ||
192 | /** | |
193 | * Gets the model consisting in a {@link RoleHierarchyBean}. | |
194 | * @return the model. | |
195 | * @since 0.3.0 | |
196 | */ | |
197 | public RoleHierarchyBean getRoleHierarchyBean () { | |
198 | 0 | return getModel(); |
199 | } | |
200 | ||
201 | /** | |
202 | * Gets the {@link BasicPartBeanFactory}. | |
203 | * @return the {@link BasicPartBeanFactory}. | |
204 | * @since 0.3.0 | |
205 | */ | |
206 | public BasicPartBeanFactory getBasicPartBeanFactory () { | |
207 | 0 | return this.basicPartBeanFactory; |
208 | } | |
209 | ||
210 | //---- PropertyChange | |
211 | ||
212 | /** | |
213 | * Handles property changes of identity. | |
214 | * @since 0.3.0 | |
215 | */ | |
216 | @PropertyChange(bean = RoleHierarchyBean.class, property = "identity") | |
217 | public void updateIdentity () { | |
218 | 0 | final URI oldIdentity = this.identity; |
219 | 0 | this.identity = getModel().getIdentity(); |
220 | 0 | firePropertyChange("name", oldIdentity, this.identity); |
221 | 0 | setTitleParameters(this.identity == null ? "" : this.identity.toString()); |
222 | 0 | } |
223 | } |