1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.openpermis.editor.policy.presenter; |
11 | |
|
12 | |
import java.net.URI; |
13 | |
import java.util.List; |
14 | |
|
15 | |
import org.jdesktop.observablecollections.ObservableList; |
16 | |
import org.jdesktop.observablecollections.ObservableListListener; |
17 | |
import org.slf4j.Logger; |
18 | |
import org.slf4j.LoggerFactory; |
19 | |
|
20 | |
import org.openpermis.basic.TimePeriodConstraint; |
21 | |
import org.openpermis.editor.policy.beans.PropertyChange; |
22 | |
import org.openpermis.editor.policy.command.AuthorityRemoveCommand; |
23 | |
import org.openpermis.editor.policy.command.CompositeCommand; |
24 | |
import org.openpermis.editor.policy.command.PoolRemoveCommand; |
25 | |
import org.openpermis.editor.policy.command.SubjectDomainRemoveCommand; |
26 | |
import org.openpermis.editor.policy.gui.binding.ObservableListAdapter; |
27 | |
import org.openpermis.editor.policy.view.EditPartCommand; |
28 | |
import org.openpermis.policy.Identifiable; |
29 | |
import org.openpermis.policy.Role; |
30 | |
import org.openpermis.policy.bean.AuthorityBean; |
31 | |
import org.openpermis.policy.bean.DomainBean; |
32 | |
import org.openpermis.policy.bean.RoleAssignmentRuleBean; |
33 | |
import org.openpermis.policy.bean.RoleCollection; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class RoleAssignmentRulePresenter |
40 | |
extends PartPresenter<RoleAssignmentRuleBean> |
41 | |
{ |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | 0 | private static final Logger LOGGER = |
49 | |
LoggerFactory.getLogger(RoleAssignmentRulePresenter.class); |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
private AuthorityBean activeAuthority; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
private DomainBean activeSubjectDomain; |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
private final ObservableList<Role> roles; |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
private final ObservableListListener rolesUpdater; |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
private int delegationDepth; |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
private TimePeriodConstraint constraint; |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
public RoleAssignmentRulePresenter ( |
94 | |
RoleAssignmentRuleBean model, PolicyContext context |
95 | |
) { |
96 | |
|
97 | 0 | super(model, context); |
98 | 0 | LOGGER.debug("Presenter for [{}].", model); |
99 | |
|
100 | 0 | this.roles = createRoleList(model); |
101 | 0 | this.rolesUpdater = new ObservableListAdapter<Role>() { |
102 | |
@Override |
103 | 0 | protected void listChanged (ObservableList<Role> list) { |
104 | 0 | updateRolesAtModel(); |
105 | 0 | } |
106 | |
}; |
107 | 0 | this.roles.addObservableListListener(this.rolesUpdater); |
108 | |
|
109 | 0 | updateAuthority(); |
110 | 0 | updateDelegationDepth(); |
111 | 0 | updateResourceDomain(); |
112 | 0 | updateResourceDomain(); |
113 | 0 | updateConstraint(); |
114 | 0 | } |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public DomainBean getActiveSubjectDomain () { |
122 | 0 | return this.activeSubjectDomain; |
123 | |
} |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public void setActiveResourceDomain (DomainBean activeSubjectDomainBean) { |
131 | 0 | if (activeSubjectDomainBean != null) { |
132 | 0 | LOGGER.debug("setActiveSubjectDomain [{}].", activeSubjectDomainBean); |
133 | 0 | final DomainBean current = getModel().getSubjectDomain(); |
134 | 0 | if (sameSerial(current, activeSubjectDomainBean)) { |
135 | 0 | updateActiveSubjectDomain(activeSubjectDomainBean); |
136 | |
} else { |
137 | 0 | change(getModel(), "subjectDomain", activeSubjectDomainBean); |
138 | |
} |
139 | |
} |
140 | 0 | } |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
private void updateActiveSubjectDomain (DomainBean activeSubjectDomainBean) { |
148 | 0 | final DomainBean oldValue = this.activeSubjectDomain; |
149 | 0 | this.activeSubjectDomain = activeSubjectDomainBean; |
150 | 0 | firePropertyChange("activeSubjectDomain", oldValue, this.activeSubjectDomain); |
151 | 0 | } |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
public void removeActiveSubjectDomain (DomainBean subjectDomain) { |
158 | 0 | execute( |
159 | |
new CompositeCommand( |
160 | |
new SubjectDomainRemoveCommand(subjectDomain), |
161 | |
new PoolRemoveCommand<DomainBean>( |
162 | |
this.getResourceDomainPool(), subjectDomain) |
163 | |
) |
164 | |
); |
165 | 0 | } |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
public void addSubjectDomain (EditPartCommand<DomainBean> editPartCommand) { |
173 | 0 | final DomainBean domain = getContext().getPartBeanFactory().createDomain(null); |
174 | 0 | editPartCommand.setPart(domain); |
175 | 0 | execute( |
176 | |
new CompositeCommand( |
177 | |
createChangeCommand(getModel(), "subjectDomain", domain), |
178 | |
editPartCommand |
179 | |
) |
180 | |
); |
181 | 0 | } |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
public AuthorityBean getActiveAuthority () { |
189 | 0 | return this.activeAuthority; |
190 | |
} |
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
public void setActiveAuthority (AuthorityBean newActiveAuthority) { |
198 | 0 | if (newActiveAuthority != null) { |
199 | 0 | LOGGER.debug("setActiveAuthority [{}].", newActiveAuthority); |
200 | 0 | final AuthorityBean current = getModel().getAuthority(); |
201 | 0 | if (sameSerial(current, newActiveAuthority)) { |
202 | 0 | updateActiveAuthority(newActiveAuthority); |
203 | |
} else { |
204 | 0 | change(getModel(), "authority", newActiveAuthority); |
205 | |
} |
206 | |
} |
207 | 0 | } |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
private void updateActiveAuthority (AuthorityBean newActiveAuthority) { |
215 | 0 | final AuthorityBean oldValue = this.activeAuthority; |
216 | 0 | this.activeAuthority = newActiveAuthority; |
217 | 0 | firePropertyChange("activeAuthority", oldValue, this.activeAuthority); |
218 | 0 | } |
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
public void removeActiveAuthority (AuthorityBean authority) { |
225 | 0 | execute( |
226 | |
new CompositeCommand( |
227 | |
new AuthorityRemoveCommand(authority), |
228 | |
new PoolRemoveCommand<AuthorityBean>( |
229 | |
this.getAuthorityPool(), authority) |
230 | |
) |
231 | |
); |
232 | 0 | } |
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
public void addAuthority (EditPartCommand<AuthorityBean> editPartCommand) { |
240 | 0 | final AuthorityBean authority = getContext().getPartBeanFactory().createAuthority(null); |
241 | 0 | editPartCommand.setPart(authority); |
242 | 0 | execute( |
243 | |
new CompositeCommand( |
244 | |
createChangeCommand(getModel(), "authority", authority), |
245 | |
editPartCommand |
246 | |
) |
247 | |
); |
248 | 0 | } |
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
private String getIdentity (Identifiable identifiable) { |
258 | 0 | if (identifiable != null) { |
259 | 0 | final URI identity = identifiable.getIdentity(); |
260 | 0 | if (identity != null) { |
261 | 0 | return identity.toString(); |
262 | |
} |
263 | |
} |
264 | 0 | return ""; |
265 | |
} |
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
private ObservableList<Role> createRoleList (RoleAssignmentRuleBean model) { |
274 | 0 | return createCollectionAtPresenter(model.getRoles()); |
275 | |
} |
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
private void updateRolesAtModel () { |
283 | 0 | LOGGER.debug("updateRolesAtModel"); |
284 | 0 | change("roles", RoleCollection.create(this.roles)); |
285 | 0 | } |
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
private void updateRolesAtPresenter () { |
292 | 0 | LOGGER.debug("updateRolesAtPresenter"); |
293 | 0 | this.roles.removeObservableListListener(this.rolesUpdater); |
294 | 0 | updateAddedRolesAtPresenter(getModel().getRoles(), this.roles); |
295 | 0 | updateDeletedRolesAtPresenter(getModel().getRoles(), this.roles); |
296 | 0 | this.roles.addObservableListListener(this.rolesUpdater); |
297 | 0 | } |
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
private void updateAddedRolesAtPresenter ( |
303 | |
RoleCollection modelRoles, ObservableList<Role> list) { |
304 | 0 | for (Role role : modelRoles) { |
305 | 0 | if (!list.contains(role)) { |
306 | 0 | list.add(role); |
307 | |
} |
308 | |
} |
309 | 0 | } |
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
private void updateDeletedRolesAtPresenter (RoleCollection modelRoles, ObservableList<Role> list |
315 | |
) { |
316 | 0 | final List<Role> roleList = modelRoles.toList(); |
317 | 0 | for (Role role : list) { |
318 | 0 | if (!roleList.contains(role)) { |
319 | 0 | list.remove(role); |
320 | |
} |
321 | |
} |
322 | 0 | } |
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
public ObservableList<Role> getRoles () { |
330 | 0 | return this.roles; |
331 | |
} |
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
public void updateDelegationDepthAtModel (int newDelegationDepth) { |
339 | 0 | change("delegationDepth", Integer.valueOf(newDelegationDepth)); |
340 | 0 | } |
341 | |
|
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
public int getDelegationDepth () { |
348 | 0 | return this.delegationDepth; |
349 | |
} |
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
public void updateDelegationDepth (int newDelegationDepth) { |
357 | 0 | final int oldValue = this.delegationDepth; |
358 | 0 | this.delegationDepth = newDelegationDepth; |
359 | 0 | firePropertyChange( |
360 | |
"delegationDepth", Integer.valueOf(oldValue), Integer.valueOf(this.delegationDepth) |
361 | |
); |
362 | 0 | } |
363 | |
|
364 | |
|
365 | |
|
366 | |
|
367 | |
public TimePeriodConstraint getConstraint () { |
368 | 0 | return this.constraint; |
369 | |
} |
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
public void updateConstraintAtModel (TimePeriodConstraint newConstraint) { |
377 | 0 | change("constraint", newConstraint); |
378 | 0 | } |
379 | |
|
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
public void updateConstraint (TimePeriodConstraint newConstraint) { |
386 | 0 | final TimePeriodConstraint oldValue = this.constraint; |
387 | 0 | this.constraint = newConstraint; |
388 | 0 | firePropertyChange( |
389 | |
"constraint", oldValue, this.constraint |
390 | |
); |
391 | 0 | } |
392 | |
|
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
@PropertyChange(bean = RoleAssignmentRuleBean.class, property = "authority") |
400 | |
public void updateAuthority () { |
401 | 0 | final AuthorityBean authority = getModel().getAuthority(); |
402 | 0 | LOGGER.debug("updateAuthority({}).", authority); |
403 | 0 | updateActiveAuthority(authority); |
404 | 0 | setTitleParameters(getIdentity(authority)); |
405 | 0 | } |
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
@PropertyChange(bean = RoleAssignmentRuleBean.class, property = "subjectDomain") |
412 | |
public void updateResourceDomain () { |
413 | 0 | final DomainBean domain = getModel().getSubjectDomain(); |
414 | 0 | LOGGER.debug("updateSubjectDomain({}).", domain); |
415 | 0 | updateActiveSubjectDomain(domain); |
416 | 0 | setTitleParameters(getIdentity(domain)); |
417 | 0 | } |
418 | |
|
419 | |
|
420 | |
|
421 | |
|
422 | |
|
423 | |
@PropertyChange(bean = RoleAssignmentRuleBean.class, property = "roles") |
424 | |
public void updateRoles () { |
425 | 0 | LOGGER.debug("updateRoles"); |
426 | 0 | updateRolesAtPresenter(); |
427 | 0 | } |
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
|
433 | |
@PropertyChange(bean = RoleAssignmentRuleBean.class, property = "delegationDepth") |
434 | |
public void updateDelegationDepth () { |
435 | 0 | this.updateDelegationDepth(getModel().getDelegationDepth()); |
436 | 0 | } |
437 | |
|
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
@PropertyChange(bean = RoleAssignmentRuleBean.class, property = "constraint") |
444 | |
public void updateConstraint () { |
445 | 0 | this.updateConstraint(getModel().getConstraint()); |
446 | 0 | } |
447 | |
|
448 | |
} |