Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
IncludeRoleCommand |
|
| 2.3333333333333335;2.333 |
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.command; | |
11 | ||
12 | import org.openpermis.policy.bean.PolicyBean; | |
13 | import org.openpermis.policy.bean.RoleHierarchyBean; | |
14 | ||
15 | ||
16 | /** | |
17 | * Given a parent role, include a role among its children. | |
18 | * @since 0.3.0 | |
19 | */ | |
20 | public class IncludeRoleCommand extends AbstractRoleCommand { | |
21 | ||
22 | //---- State | |
23 | ||
24 | /** | |
25 | * @since 0.3.0 | |
26 | */ | |
27 | private final String parentRoleName; | |
28 | ||
29 | //---- Constructors | |
30 | ||
31 | /** | |
32 | * Creates a {@link IncludeRoleCommand}. | |
33 | * @since 0.3.0 | |
34 | */ | |
35 | public IncludeRoleCommand ( | |
36 | String name, | |
37 | String parentRoleName, | |
38 | String roleName, | |
39 | RoleHierarchyBean roleHierarchyBean) { | |
40 | ||
41 | 0 | super( |
42 | name, | |
43 | roleName, | |
44 | roleHierarchyBean | |
45 | ); | |
46 | ||
47 | 0 | this.parentRoleName = parentRoleName; |
48 | 0 | } |
49 | ||
50 | //---- AbstractHierarchyCommand | |
51 | ||
52 | /** | |
53 | * @since 0.3.0 | |
54 | */ | |
55 | @Override | |
56 | public void execute (PolicyBean policy) throws Exception { | |
57 | 0 | if (this.parentRoleName == null) { |
58 | 0 | return; |
59 | } | |
60 | 0 | getRoleHierarchyBean().connectRoles(this.parentRoleName, getRoleName()); |
61 | 0 | } |
62 | ||
63 | /** | |
64 | * @since 0.3.0 | |
65 | */ | |
66 | @Override | |
67 | public void undo (PolicyBean policy) throws Exception { | |
68 | 0 | if (this.parentRoleName == null) { |
69 | 0 | return; |
70 | } | |
71 | 0 | getRoleHierarchyBean().disconnectRoles(this.parentRoleName, getRoleName()); |
72 | 0 | } |
73 | } |