Coverage Report - org.kuali.rice.kim.api.permission.Permission
 
Classes in this File Line Coverage Branch Coverage Complexity
Permission
94%
35/37
N/A
1.25
Permission$1
N/A
N/A
1.25
Permission$Builder
94%
49/52
70%
7/10
1.25
Permission$Constants
50%
1/2
N/A
1.25
Permission$Elements
0%
0/1
N/A
1.25
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kim.api.permission;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.apache.commons.lang.builder.EqualsBuilder;
 20  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 21  
 import org.apache.commons.lang.builder.ToStringBuilder;
 22  
 import org.kuali.rice.core.api.CoreConstants;
 23  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 24  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 25  
 import org.kuali.rice.core.api.mo.common.Attributes;
 26  
 import org.kuali.rice.kim.api.common.template.Template;
 27  
 import org.w3c.dom.Element;
 28  
 
 29  
 import javax.xml.bind.annotation.XmlAccessType;
 30  
 import javax.xml.bind.annotation.XmlAccessorType;
 31  
 import javax.xml.bind.annotation.XmlAnyElement;
 32  
 import javax.xml.bind.annotation.XmlElement;
 33  
 import javax.xml.bind.annotation.XmlRootElement;
 34  
 import javax.xml.bind.annotation.XmlType;
 35  
 import java.io.Serializable;
 36  
 import java.util.Collection;
 37  
 
 38  
 /**
 39  
  * An immutable representation of a {@link PermissionContract}.
 40  
  *
 41  
  * <p>To construct an instance of a Permission, use the {@link Permission.Builder} class.<p/>
 42  
  *
 43  
  * @see PermissionContract
 44  
  */
 45  1
 @XmlRootElement(name = Permission.Constants.ROOT_ELEMENT_NAME)
 46  
 @XmlAccessorType(XmlAccessType.NONE)
 47  
 @XmlType(name = Permission.Constants.TYPE_NAME, propOrder = {
 48  
                 Permission.Elements.ID,
 49  
                 Permission.Elements.NAMESPACE_CODE,
 50  
                 Permission.Elements.NAME,
 51  
                 Permission.Elements.DESCRIPTION,
 52  
                 Permission.Elements.TEMPLATE,
 53  
         Permission.Elements.ACTIVE,
 54  
         Permission.Elements.ATTRIBUTES,
 55  
         CoreConstants.CommonElements.VERSION_NUMBER,
 56  
         CoreConstants.CommonElements.OBJECT_ID,
 57  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 58  
 })
 59  3
 public final class Permission implements PermissionContract, ModelObjectComplete{
 60  
 
 61  
         private static final long serialVersionUID = 1L;
 62  
 
 63  
     @XmlElement(name = Permission.Elements.ID, required = true)
 64  
     private final String id;
 65  
 
 66  
     @XmlElement(name = Permission.Elements.NAMESPACE_CODE, required = true)
 67  
     private final String namespaceCode;
 68  
 
 69  
     @XmlElement(name = Permission.Elements.NAME, required = true)
 70  
     private final String name;
 71  
 
 72  
     @XmlElement(name = Permission.Elements.DESCRIPTION, required = false)
 73  
     private final String description;
 74  
 
 75  
     @XmlElement(name = Permission.Elements.TEMPLATE, required = true)
 76  
     private final Template template;
 77  
 
 78  
     @XmlElement(name = Permission.Elements.ATTRIBUTES, required = false)
 79  
     private final Attributes attributes;
 80  
 
 81  
     @XmlElement(name = Permission.Elements.ACTIVE, required = false)
 82  
     private boolean active;
 83  
 
 84  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 85  
     private final Long versionNumber;
 86  
 
 87  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 88  
     private final String objectId;
 89  
 
 90  5
     @SuppressWarnings("unused")
 91  
     @XmlAnyElement
 92  
     private final Collection<Element> _futureElements = null;
 93  
 
 94  
     /**
 95  
          *  A constructor to be used only by JAXB unmarshalling.
 96  
          *
 97  
          */
 98  2
         private Permission() {
 99  2
                 this.id = null;
 100  2
         this.namespaceCode = null;
 101  2
         this.name = null;
 102  2
         this.description = null;
 103  2
         this.template = null;
 104  2
         this.attributes = null;
 105  2
         this.active = false;
 106  2
         this.versionNumber = Long.valueOf(1L);
 107  2
         this.objectId = null;
 108  2
         }
 109  
 
 110  
     /**
 111  
          * A constructor using the Builder.
 112  
          *
 113  
          * @param builder
 114  
          */
 115  3
         private Permission(Builder builder) {
 116  3
                 this.id = builder.getId();
 117  3
         this.namespaceCode = builder.getNamespaceCode();
 118  3
         this.name = builder.getName();
 119  3
         this.description = builder.getDescription();
 120  3
         this.template = builder.getTemplate().build();
 121  3
         this.attributes = builder.getAttributes();
 122  3
         this.active = builder.isActive();
 123  3
         this.versionNumber = builder.getVersionNumber();
 124  3
         this.objectId = builder.getObjectId();
 125  3
         }
 126  
 
 127  
         /**
 128  
          * @see org.kuali.rice.kim.api.permission.PermissionContract#getId()
 129  
          */
 130  
         @Override
 131  
         public String getId() {
 132  1
                 return id;
 133  
         }
 134  
 
 135  
         /**
 136  
          * @see org.kuali.rice.kim.api.permission.PermissionContract#getNamespaceCode()
 137  
          */
 138  
         @Override
 139  
         public String getNamespaceCode() {
 140  1
                 return namespaceCode;
 141  
         }
 142  
 
 143  
         /**
 144  
          * @see org.kuali.rice.kim.api.permission.PermissionContract#getName()
 145  
          */
 146  
         @Override
 147  
         public String getName() {
 148  1
                 return name;
 149  
         }
 150  
 
 151  
         /**
 152  
          * @see org.kuali.rice.kim.api.permission.PermissionContract#getDescription()
 153  
          */
 154  
         @Override
 155  
         public String getDescription() {
 156  1
                 return description;
 157  
         }
 158  
 
 159  
         /**
 160  
          * @see org.kuali.rice.kim.api.permission.PermissionContract#getTemplate()
 161  
          */
 162  
         @Override
 163  
         public Template getTemplate() {
 164  1
                 return template;
 165  
         }
 166  
 
 167  
         /**
 168  
          * @see org.kuali.rice.core.api.mo.common.active.Inactivatable#isActive()
 169  
          */
 170  
         @Override
 171  
         public boolean isActive() {
 172  1
                 return active;
 173  
         }
 174  
 
 175  
         /**
 176  
          *
 177  
          * @see org.kuali.rice.kim.api.permission.PermissionContract#getAttributes()
 178  
          */
 179  
         @Override
 180  
         public Attributes getAttributes() {
 181  1
                 return this.attributes;
 182  
         }
 183  
 
 184  
         /**
 185  
          * @see org.kuali.rice.core.api.mo.common.Versioned#getVersionNumber()
 186  
          */
 187  
         @Override
 188  
         public Long getVersionNumber() {
 189  1
                 return versionNumber;
 190  
         }
 191  
 
 192  
         /**
 193  
          * @see org.kuali.rice.core.api.mo.common.GloballyUnique#getObjectId()
 194  
          */
 195  
         @Override
 196  
         public String getObjectId() {
 197  1
                 return objectId;
 198  
         }
 199  
 
 200  
     @Override
 201  
     public int hashCode() {
 202  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 203  
     }
 204  
 
 205  
     @Override
 206  
     public boolean equals(Object obj) {
 207  2
         return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 208  
     }
 209  
 
 210  
     @Override
 211  
     public String toString() {
 212  0
         return ToStringBuilder.reflectionToString(this);
 213  
     }
 214  
 
 215  
     /**
 216  
      * This builder constructs a Permission enforcing the constraints of the {@link PermissionContract}.
 217  
      */
 218  3
     public static final class Builder implements PermissionContract, ModelBuilder, Serializable {
 219  
         private String id;
 220  
         private String namespaceCode;
 221  
         private String name;
 222  
         private String description;
 223  
         private Template.Builder template;
 224  
         private Attributes attributes;
 225  6
         private Long versionNumber = 1L;
 226  
         private String objectId;
 227  
         private boolean active;
 228  
 
 229  6
         private Builder(String namespaceCode, String name, Template.Builder template) {
 230  6
             setNamespaceCode(namespaceCode);
 231  6
             setName(name);
 232  6
             setTemplate(template);
 233  6
         }
 234  
 
 235  
         /**
 236  
          * Creates a Permission with the required fields.
 237  
          */
 238  
         public static Builder create(String namespaceCode, String name, Template.Builder template) {
 239  4
             return new Builder(namespaceCode, name, template);
 240  
         }
 241  
 
 242  
         /**
 243  
          * Creates a Permission from an existing {@link PermissionContract}.
 244  
          */
 245  
         public static Builder create(PermissionContract contract) {
 246  2
             Builder builder = new Builder(contract.getNamespaceCode(), contract.getName(), Template.Builder.create(contract.getTemplate()));
 247  2
             builder.setId(contract.getId());
 248  2
             builder.setDescription(contract.getDescription());
 249  2
             builder.setAttributes(contract.getAttributes());
 250  2
             builder.setActive(contract.isActive());
 251  2
             builder.setVersionNumber(contract.getVersionNumber());
 252  2
             builder.setObjectId(contract.getObjectId());
 253  
 
 254  2
             return builder;
 255  
         }
 256  
 
 257  
         @Override
 258  
         public String getId() {
 259  3
             return id;
 260  
         }
 261  
 
 262  
         public void setId(final String id) {
 263  2
                 this.id = id;
 264  2
         }
 265  
         
 266  
         @Override
 267  
         public String getNamespaceCode() {
 268  3
             return namespaceCode;
 269  
         }
 270  
 
 271  
         public void setNamespaceCode(final String namespaceCode) {
 272  6
                 if (StringUtils.isBlank(namespaceCode)) {
 273  0
                 throw new IllegalArgumentException("namespaceCode is blank");
 274  
             }
 275  6
                 this.namespaceCode = namespaceCode;
 276  6
         }
 277  
 
 278  
         @Override
 279  
         public String getName() {
 280  3
             return name;
 281  
         }
 282  
 
 283  
         public void setName(final String name) {
 284  6
                 if (StringUtils.isBlank(name)) {
 285  0
                 throw new IllegalArgumentException("name is blank");
 286  
             }
 287  6
                 this.name = name;
 288  6
         }
 289  
 
 290  
                 @Override
 291  
                 public String getDescription() {
 292  3
                         return description;
 293  
                 }
 294  
                 
 295  
                 public void setDescription(final String description) {
 296  3
                         this.description = description;
 297  3
                 }
 298  
 
 299  
                 @Override
 300  
                 public Template.Builder getTemplate() {
 301  3
                         return template;
 302  
                 }
 303  
                 
 304  
                 public void setTemplate(final Template.Builder template) {
 305  6
                         if (template == null) {
 306  0
                 throw new IllegalArgumentException("template is null");
 307  
             }
 308  6
                         this.template = template;
 309  6
                 }
 310  
                 
 311  
                 @Override
 312  
                 public boolean isActive() {
 313  3
                         return active;
 314  
                 }
 315  
                 
 316  
                 public void setActive(final boolean active) {
 317  2
             this.active = active;
 318  2
         }
 319  
 
 320  
                 @Override
 321  
                 public Long getVersionNumber() {
 322  3
                         return versionNumber;
 323  
                 }
 324  
 
 325  
                 public void setVersionNumber(final Long versionNumber) {
 326  4
                         if (versionNumber == null || versionNumber <= 0) {
 327  2
                     throw new IllegalArgumentException("versionNumber is invalid");
 328  
                 }
 329  2
                         this.versionNumber = versionNumber;
 330  2
             }
 331  
                  
 332  
                 @Override
 333  
                 public String getObjectId() {
 334  3
                         return objectId;
 335  
                 }
 336  
 
 337  
         public void setObjectId(final String objectId) {
 338  2
             this.objectId = objectId;
 339  2
         }
 340  
 
 341  
                 @Override
 342  
                 public Attributes getAttributes() {
 343  3
                         return attributes;
 344  
                 }
 345  
                 
 346  
                 public void setAttributes(Attributes attributes) {
 347  2
             this.attributes = attributes;
 348  2
         }
 349  
                 
 350  
         @Override
 351  
         public Permission build() {
 352  3
             return new Permission(this);
 353  
         }
 354  
     }
 355  
     
 356  
     /**
 357  
      * Defines some internal constants used on this class.
 358  
      */
 359  0
     static class Constants {
 360  
         static final String ROOT_ELEMENT_NAME = "permission";
 361  
         static final String TYPE_NAME = "PermissionType";
 362  1
         static final String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
 363  
     }
 364  
 
 365  
     /**
 366  
      * A private class which exposes constants which define the XML element names to use
 367  
      * when this object is marshalled to XML.
 368  
      */
 369  0
     static class Elements {
 370  
         static final String ID = "id";
 371  
         static final String NAMESPACE_CODE = "namespaceCode";
 372  
         static final String NAME = "name";
 373  
         static final String DESCRIPTION = "description";
 374  
         static final String TEMPLATE = "template";
 375  
         static final String ATTRIBUTES = "attributes";
 376  
         static final String ACTIVE = "active";
 377  
     }
 378  
 }