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