Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ActionRemoveCommand |
|
| 1.3333333333333333;1.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 java.util.List; | |
13 | ||
14 | import org.openpermis.policy.bean.ActionBean; | |
15 | import org.openpermis.policy.bean.ActionBeanCollection; | |
16 | import org.openpermis.policy.bean.PolicyBean; | |
17 | import org.openpermis.policy.bean.TargetBean; | |
18 | ||
19 | ||
20 | /** | |
21 | * Command that deletes a action allover the model. | |
22 | * @since 0.1.0 | |
23 | */ | |
24 | public class ActionRemoveCommand extends PartRemoveCommand<ActionBean> | |
25 | { | |
26 | //---- Constructors | |
27 | ||
28 | /** | |
29 | * Creates a command. | |
30 | * @param action the action to modify, must not be {@code null}. | |
31 | * @since 0.1.0 | |
32 | */ | |
33 | public ActionRemoveCommand (ActionBean action) { | |
34 | 0 | super(action); |
35 | 0 | } |
36 | ||
37 | //---- Methods | |
38 | ||
39 | /** | |
40 | * Remove the specified child action from the given target. | |
41 | * @param target the target on which to remove the child. | |
42 | * @param action the child action to remove. | |
43 | * @since 0.3.0 | |
44 | */ | |
45 | private void removeTargetAction (TargetBean target, ActionBean action) { | |
46 | 0 | final ActionBeanCollection oldCollection = target.getActions(); |
47 | 0 | final List<ActionBean> list = oldCollection.toList(); |
48 | 0 | list.remove(action); |
49 | 0 | target.setActions(oldCollection.create(list)); |
50 | 0 | } |
51 | ||
52 | /** | |
53 | * @since 0.1.0 | |
54 | */ | |
55 | @Override | |
56 | public void removePart (PolicyBean policyBean, boolean doExec) { | |
57 | 0 | List<TargetBean> parents = policyBean.getParentTargets(this.getPart()); |
58 | 0 | for (final TargetBean target : parents) { |
59 | 0 | removeTargetAction(target, this.getPart()); |
60 | } | |
61 | 0 | } |
62 | ||
63 | ||
64 | } |