Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AddRoleCommand |
|
| 1.6666666666666667;1.667 |
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 | * Add a new role. | |
18 | * @since 0.3.0 | |
19 | */ | |
20 | public class AddRoleCommand extends AbstractRoleCommand { | |
21 | ||
22 | //---- State | |
23 | ||
24 | /** | |
25 | * @since 0.3.0 | |
26 | */ | |
27 | private boolean roleCreated; | |
28 | ||
29 | //---- Constructors | |
30 | ||
31 | /** | |
32 | * Creates a {@link AddRoleCommand}. | |
33 | * @since 0.3.0 | |
34 | */ | |
35 | public AddRoleCommand ( | |
36 | String name, | |
37 | String roleName, | |
38 | RoleHierarchyBean roleHierarchyBean | |
39 | ) { | |
40 | 0 | super(name, roleName, roleHierarchyBean); |
41 | 0 | } |
42 | ||
43 | //---- AbstractHierarchyCommand | |
44 | ||
45 | /** | |
46 | * @since 0.3.0 | |
47 | */ | |
48 | @Override | |
49 | public void execute (PolicyBean policy) throws Exception { | |
50 | 0 | if (!getRoleHierarchyBean().roleExists(getRoleName())) { |
51 | 0 | getRoleHierarchyBean().addRole(getRoleName()); |
52 | 0 | this.roleCreated = true; |
53 | } | |
54 | 0 | } |
55 | ||
56 | /** | |
57 | * @since 0.3.0 | |
58 | */ | |
59 | @Override | |
60 | public void undo (PolicyBean policy) throws Exception { | |
61 | 0 | if (this.roleCreated) { |
62 | 0 | getRoleHierarchyBean().removeRole(getRoleName()); |
63 | 0 | this.roleCreated = false; |
64 | } | |
65 | 0 | } |
66 | ||
67 | } |