Coverage Report - org.openpermis.editor.policy.presenter.PolicyPresenter
 
Classes in this File Line Coverage Branch Coverage Complexity
PolicyPresenter
0%
0/39
0%
0/4
1.143
 
 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 org.jdesktop.application.ResourceMap;
 13  
 import org.slf4j.Logger;
 14  
 import org.slf4j.LoggerFactory;
 15  
 
 16  
 import org.openpermis.editor.policy.beans.PropertyChange;
 17  
 import org.openpermis.editor.policy.command.Command;
 18  
 import org.openpermis.editor.policy.command.CommandDispatcher;
 19  
 import org.openpermis.editor.policy.command.CommandManager;
 20  
 import org.openpermis.policy.bean.ActionBean;
 21  
 import org.openpermis.policy.bean.AuthorityBean;
 22  
 import org.openpermis.policy.bean.DomainBean;
 23  
 import org.openpermis.policy.bean.ObligationBean;
 24  
 import org.openpermis.policy.bean.PartBeanFactory;
 25  
 import org.openpermis.policy.bean.PolicyBean;
 26  
 import org.openpermis.policy.bean.TargetBean;
 27  
 
 28  
 /**
 29  
  * Presenter for a {@link PolicyBean}.
 30  
  * @since 0.1.0
 31  
  */
 32  
 public class PolicyPresenter
 33  
         extends PartPresenter<PolicyBean>
 34  
         implements PolicyContext
 35  
 {
 36  
 
 37  
         //---- Static
 38  
 
 39  
         /**
 40  
          * The logger object of this class.
 41  
          * @since 0.1.0
 42  
          */
 43  0
         private static final Logger LOGGER =
 44  
                 LoggerFactory.getLogger(PolicyPresenter.class);
 45  
 
 46  
         //---- State
 47  
 
 48  
         /**
 49  
          * The filename of the current policy.
 50  
          * @since 0.1.0
 51  
          */
 52  
         private String filename;
 53  
 
 54  
         /**
 55  
          * The command dispatcher of the policy of this presenter.
 56  
          * @since 0.1.0
 57  
          */
 58  
         private final CommandManager commandManager;
 59  
 
 60  
         /**
 61  
          * The factory of this presenter.
 62  
          * @since 0.1.0
 63  
          */
 64  
         private final PartBeanFactory policyFactory;
 65  
 
 66  
         /**
 67  
          * A pool of this presenter.
 68  
          * @since 0.1.0
 69  
          */
 70  
         private final PolicyPool policyPool;
 71  
 
 72  
         /**
 73  
          * A pool of this presenter.
 74  
          * @since 0.1.0
 75  
          */
 76  
         private final PolicyProblemReporter policyProblemReporter;
 77  
 
 78  
 
 79  
         //---- Constructors
 80  
 
 81  
         /**
 82  
          * Creates a new presenter for the specified policy.
 83  
          * @param model the policy to create the presenter for, must not be {@code null}.
 84  
          * @param policyFactory the factory that created the policy bean specified.
 85  
          * @since 0.1.0
 86  
          */
 87  
         public PolicyPresenter (PolicyBean model, PartBeanFactory policyFactory) {
 88  0
                 super(model, null);
 89  0
                 this.commandManager = new CommandManager(model);
 90  0
                 this.policyFactory = policyFactory;
 91  0
                 this.filename = null;
 92  0
                 this.policyPool = new PolicyPool(model);
 93  0
                 this.policyProblemReporter = new PolicyProblemReporter();
 94  0
         }
 95  
 
 96  
         //---- Methods
 97  
 
 98  
         /**
 99  
          * Returns the policy of this policy presenter.
 100  
          * @return the policy of this policy presenter.
 101  
          * @since 0.1.0
 102  
          */
 103  
         public PolicyBean getPolicy () {
 104  0
                 return getModel();
 105  
         }
 106  
 
 107  
         /**
 108  
          * Returns the command manager of this policy presenter.
 109  
          * @return the command manager of this policy presenter, never {@code null}.
 110  
          * @since 0.1.0
 111  
          */
 112  
         public CommandManager getCommandManager () {
 113  0
                 return this.commandManager;
 114  
         }
 115  
 
 116  
         /**
 117  
          * @return the filename.
 118  
          * @since 0.1.0
 119  
          */
 120  
         public String getFilename () {
 121  0
                 return this.filename;
 122  
         }
 123  
 
 124  
         /**
 125  
          * @param filename filename to set.
 126  
          * the filename to set.
 127  
          * @since 0.1.0
 128  
          */
 129  
         public void setFilename (String filename) {
 130  0
                 this.filename = filename;
 131  0
         }
 132  
 
 133  
         /**
 134  
          * Returns the policy pool.
 135  
          * @return Returns the policy pool.
 136  
          * @since 0.1.0
 137  
          */
 138  
         public boolean policyIsValid () {
 139  0
                 if (this.getModel() == null) {
 140  0
                         return false;
 141  
                 }
 142  0
                 this.policyProblemReporter.clear();
 143  0
                 return this.getModel().isValid(this.policyProblemReporter);
 144  
         }
 145  
 
 146  
         /**
 147  
          * Returns the policy pool.
 148  
          * @return Returns the policy pool.
 149  
          * @since 0.1.0
 150  
          */
 151  
         public String getPolicyProblems (ResourceMap resourceMap) {
 152  0
                 return this.getModel() == null
 153  
                         ? null
 154  
                         : this.policyProblemReporter.renderString(resourceMap);
 155  
         }
 156  
 
 157  
         //---- PolicyContext
 158  
 
 159  
         /**
 160  
          * @since 0.1.0
 161  
          */
 162  
         public PolicyBean getPolicyBean () {
 163  0
                 return getModel();
 164  
         }
 165  
 
 166  
         /**
 167  
          * @since 0.1.0
 168  
          */
 169  
         @Override
 170  
         public PartBeanFactory getPartBeanFactory () {
 171  0
                 return this.policyFactory;
 172  
         }
 173  
 
 174  
         /**
 175  
          * @since 0.1.0
 176  
          */
 177  
         public CommandDispatcher getCommandDispatcher () {
 178  0
                 return this.commandManager;
 179  
         }
 180  
 
 181  
         /**
 182  
          * Returns the policy pool.
 183  
          * @return Returns the policy pool.
 184  
          * @since 0.1.0
 185  
          */
 186  
         @Override
 187  
         public PolicyPartPool<ActionBean> getActionPool () {
 188  0
                 return this.policyPool.getActionPool();
 189  
         }
 190  
         
 191  
         /**
 192  
          * @since 0.3.0
 193  
          */
 194  
         @Override
 195  
         public PolicyPartPool<AuthorityBean> getAuthorityPool () {
 196  0
                 return this.policyPool.getAuthorityPool();
 197  
         }
 198  
 
 199  
         /**
 200  
          * Returns the policy pool.
 201  
          * @return Returns the policy pool.
 202  
          * @since 0.1.0
 203  
          */
 204  
         @Override
 205  
         public PolicyPartPool<DomainBean> getResourceDomainPool () {
 206  0
                 return this.policyPool.getResourceDomainPool();
 207  
         }
 208  
         
 209  
         /**
 210  
          * Returns the subject domain pool.
 211  
          * @return Returns the subject domain pool.
 212  
          * @since 0.3.0
 213  
          */
 214  
         @Override
 215  
         public PolicyPartPool<DomainBean> getSubjectDomainPool () {
 216  0
                 return this.policyPool.getSubjectDomainPool();
 217  
         }
 218  
 
 219  
         /**
 220  
          * Returns the policy pool.
 221  
          * @return Returns the policy pool.
 222  
          * @since 0.1.0
 223  
          */
 224  
         @Override
 225  
         public PolicyPartPool<TargetBean> getTargetPool () {
 226  0
                 return this.policyPool.getTargetPool();
 227  
         }
 228  
         
 229  
         /**
 230  
          * Returns the policy pool.
 231  
          * @return Returns the policy pool.
 232  
          * @since 0.3.0
 233  
          */
 234  
         @Override
 235  
         public PolicyPartPool<ObligationBean> getObligationPool () {
 236  0
                 return this.policyPool.getObligationPool();
 237  
         }
 238  
 
 239  
         /**
 240  
          * Returns the policy pool.
 241  
          * @return Returns the policy pool.
 242  
          * @since 0.3.0
 243  
          */
 244  
         @Override
 245  
         public PolicyRoleRefPool getRolePool () {
 246  0
                 return this.policyPool.getRolePool();
 247  
         }
 248  
 
 249  
         //---- PropertyChange
 250  
 
 251  
         /**
 252  
          * Handles property changes of roleAssignmentRules.
 253  
          * @param source the policy that has changed.
 254  
          * @since 0.1.0
 255  
          */
 256  
         @PropertyChange(bean = PolicyBean.class, property = "roleAssignmentRules")
 257  
         public void roleAssignmentRulesChanged (PolicyBean source) {
 258  0
                 LOGGER.debug("Merging all pools.");
 259  0
                 this.policyPool.mergePool(source, false);
 260  0
         }
 261  
 
 262  
         /**
 263  
          * Handles property changes of targetAccessRules.
 264  
          * @param source the policy that has changed.
 265  
          * @since 0.1.0
 266  
          */
 267  
         @PropertyChange(bean = PolicyBean.class, property = "targetAccessRules")
 268  
         public void targetAccessRulesChanged (PolicyBean source) {
 269  0
                 LOGGER.debug("Merging all pools.");
 270  0
                 this.policyPool.mergePool(source, false);
 271  0
         }
 272  
 
 273  
         /**
 274  
          * Handles property changes of roleHierarchies.
 275  
          * @param source the policy that has changed.
 276  
          * @since 0.3.0
 277  
          */
 278  
         @PropertyChange(bean = PolicyBean.class, property = "roleHierarchies")
 279  
         public void roleHierarchiesChanged (PolicyBean source) {
 280  0
                 LOGGER.debug("Merging role pool.");
 281  0
                 this.policyPool.mergeRolePool(source, false);
 282  0
         }
 283  
 
 284  
         //---- PartPresenter
 285  
 
 286  
         /**
 287  
          * @since 0.1.0
 288  
          */
 289  
         @Override
 290  
         protected void execute (Command command) {
 291  0
                 this.commandManager.execute(command);
 292  0
         }
 293  
 
 294  
 }