Coverage Report - org.openpermis.editor.policy.presenter.RoleHierarchyPresenter
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleHierarchyPresenter
0%
0/30
0%
0/2
1.182
 
 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.presenter;
 11  
 
 12  
 import java.net.URI;
 13  
 
 14  
 import org.slf4j.Logger;
 15  
 import org.slf4j.LoggerFactory;
 16  
 
 17  
 import org.openpermis.editor.policy.beans.PropertyChange;
 18  
 import org.openpermis.editor.policy.command.AddRoleCommand;
 19  
 import org.openpermis.editor.policy.command.DetachRoleCommand;
 20  
 import org.openpermis.editor.policy.command.IncludeRoleCommand;
 21  
 import org.openpermis.editor.policy.command.RemoveRoleCommand;
 22  
 import org.openpermis.editor.policy.command.RenameRoleCommand;
 23  
 import org.openpermis.policy.bean.RoleHierarchyBean;
 24  
 import org.openpermis.policy.bean.basic.BasicPartBeanFactory;
 25  
 
 26  
 /**
 27  
  * Presenter for a single {@link RoleHierarchyBean}.
 28  
  * @since 0.3.0
 29  
  */
 30  
 public class RoleHierarchyPresenter extends PartPresenter<RoleHierarchyBean> {
 31  
 
 32  
         //---- Static
 33  
 
 34  
         /**
 35  
          * The logger object of this class.
 36  
          * @since 0.3.0
 37  
          */
 38  0
         private static final Logger LOGGER =
 39  
                 LoggerFactory.getLogger(RoleHierarchyPresenter.class);
 40  
 
 41  
         //---- State
 42  
 
 43  
         /**
 44  
          * @since 0.3.0
 45  
          */
 46  
         private URI identity;
 47  
 
 48  
         /**
 49  
          * @since 0.3.0
 50  
          */
 51  0
         private BasicPartBeanFactory basicPartBeanFactory = new BasicPartBeanFactory();
 52  
 
 53  
         //---- Constructors
 54  
 
 55  
         /**
 56  
          * Creates a new {@link RoleHierarchyPresenter}.
 57  
          * @param model the action to work on.
 58  
          * @param context policy context that provides additional information.
 59  
          * @since 0.3.0
 60  
          */
 61  
         public RoleHierarchyPresenter (RoleHierarchyBean model, PolicyContext context)
 62  
         {
 63  0
                 super(model, context);
 64  
 
 65  0
                 LOGGER.debug("Presenter for [{}].", model);
 66  
 
 67  0
                 updateIdentity();
 68  0
         }
 69  
 
 70  
         //---- Methods
 71  
 
 72  
         /**
 73  
          * Gets the identity.
 74  
          * @return the identity.
 75  
          * @since 0.3.0
 76  
          */
 77  
         public URI getIdentity () {
 78  0
                 return this.identity;
 79  
         }
 80  
 
 81  
         /**
 82  
          * Sets the identity of the model.
 83  
          * @param identity the new identity to set.
 84  
          * @since 0.3.0
 85  
          */
 86  
         public void setIdentity (URI identity) {
 87  
                 try {
 88  
                         // update presenter
 89  0
                         this.identity = identity;
 90  
 
 91  
                         // trigger model
 92  0
                         change("identity", this.identity);
 93  0
                 } catch (final Exception e) {
 94  0
                         LOGGER.warn("Cannot set role hierarchy identity [" + identity + "].", e);
 95  0
                 }
 96  0
         }
 97  
 
 98  
         /**
 99  
          * Given a parent role, include a role among its children.
 100  
          * @param parentName name of the role to which the sub role is added.
 101  
          * @param subRoleName name of the added sub role.
 102  
          * @since 0.3.0
 103  
          */
 104  
         public void includeRole (String parentName, String subRoleName) {
 105  0
                 this.getContext().getCommandDispatcher().execute(
 106  
                         new IncludeRoleCommand(
 107  
                                 "includeRole", parentName, subRoleName, getModel()
 108  
                         )
 109  
                 );
 110  0
         }
 111  
 
 112  
         /**
 113  
          * Detaches a role from its parent.
 114  
          * @param parentName the parent name.
 115  
          * @param subRoleName the sub-role name.
 116  
          * @since 0.3.0
 117  
          */
 118  
         public void detachRole (String parentName, String subRoleName) {
 119  0
                 this.getContext().getCommandDispatcher().execute(
 120  
                         new DetachRoleCommand(
 121  
                                 "detachRole", parentName, subRoleName, getModel()
 122  
                         )
 123  
                 );
 124  0
         }
 125  
 
 126  
         /**
 127  
          * Adds a new role in the hierarchy.
 128  
          * @param subRoleName name of the added sub role.
 129  
          * @since 0.3.0
 130  
          */
 131  
         public void addNewRole (String subRoleName) {
 132  0
                 this.getContext().getCommandDispatcher().execute(
 133  
                         new AddRoleCommand("addNewRole", subRoleName, getModel())
 134  
                 );
 135  0
         }
 136  
 
 137  
         /**
 138  
          * Removes a role from the hierarchy.
 139  
          * @param subRoleName the sub-role name.
 140  
          * @since 0.3.0
 141  
          */
 142  
         public void removeRole (String subRoleName) {
 143  0
                 this.getContext().getCommandDispatcher().execute(
 144  
                         new RemoveRoleCommand("removeRole", subRoleName, getModel())
 145  
                 );
 146  0
         }
 147  
 
 148  
         /**
 149  
          * Renames a role.
 150  
          * @param oldName old role name.
 151  
          * @param newName new role name.
 152  
          * @since 0.3.0
 153  
          */
 154  
         public void renameRole (String oldName, String newName) {
 155  0
                 this.getContext().getCommandDispatcher().execute(
 156  
                         new RenameRoleCommand(
 157  
                                 "renameRole", oldName, newName, getModel()
 158  
                         )
 159  
                 );
 160  0
         }
 161  
 
 162  
         /**
 163  
          * Gets the model consisting in a {@link RoleHierarchyBean}.
 164  
          * @return the model.
 165  
          * @since 0.3.0
 166  
          */
 167  
         public RoleHierarchyBean getRoleHierarchyBean () {
 168  0
                 return getModel();
 169  
         }
 170  
 
 171  
         /**
 172  
          * Gets the {@link BasicPartBeanFactory}.
 173  
          * @return the {@link BasicPartBeanFactory}.
 174  
          * @since 0.3.0
 175  
          */
 176  
         public BasicPartBeanFactory getBasicPartBeanFactory () {
 177  0
                 return this.basicPartBeanFactory;
 178  
         }
 179  
 
 180  
         //---- PropertyChange
 181  
 
 182  
         /**
 183  
          * Handles property changes of identity.
 184  
          * @since 0.3.0
 185  
          */
 186  
         @PropertyChange(bean = RoleHierarchyBean.class, property = "identity")
 187  
         public void updateIdentity () {
 188  0
                 final URI oldIdentity = this.identity;
 189  0
                 this.identity = getModel().getIdentity();
 190  0
                 firePropertyChange("name", oldIdentity, this.identity);
 191  0
                 setTitleParameters(this.identity == null ? "" : this.identity.toString());
 192  0
         }
 193  
 }