Coverage Report - org.kuali.rice.kim.api.role.Role
 
Classes in this File Line Coverage Branch Coverage Complexity
Role
93%
28/30
N/A
1.353
Role$1
N/A
N/A
1.353
Role$Builder
75%
44/58
83%
10/12
1.353
Role$Constants
50%
1/2
N/A
1.353
Role$Elements
0%
0/1
N/A
1.353
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 4  
  * you may not use this file except in compliance with the License.
 5  
  * You may obtain a copy of the License at
 6  
  *
 7  
  * http://www.opensource.org/licenses/ecl2.php
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing, software
 10  
  * distributed under the License is distributed on an "AS IS" BASIS,
 11  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
  * See the License for the specific language governing permissions and
 13  
  * limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.rice.kim.api.role;
 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.w3c.dom.Element;
 26  
 
 27  
 import javax.xml.bind.annotation.XmlAccessType;
 28  
 import javax.xml.bind.annotation.XmlAccessorType;
 29  
 import javax.xml.bind.annotation.XmlAnyElement;
 30  
 import javax.xml.bind.annotation.XmlElement;
 31  
 import javax.xml.bind.annotation.XmlRootElement;
 32  
 import javax.xml.bind.annotation.XmlType;
 33  
 import java.util.Collection;
 34  
 
 35  
 
 36  
 /**
 37  
  * This is a description of what this class does - shyu don't forget to fill this in.
 38  
  *
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  */
 41  
 @XmlRootElement(name = Role.Constants.ROOT_ELEMENT_NAME)
 42  
 @XmlAccessorType(XmlAccessType.NONE)
 43  
 @XmlType(name = Role.Constants.TYPE_NAME, propOrder = {
 44  
         Role.Elements.ID,
 45  
         Role.Elements.NAME,
 46  
         Role.Elements.NAMESPACE_CODE,
 47  
         Role.Elements.DESCRIPTION,
 48  
         Role.Elements.KIM_TYPE_ID,
 49  
         Role.Elements.ACTIVE,
 50  
         CoreConstants.CommonElements.VERSION_NUMBER,
 51  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 52  
 })
 53  1
 public class Role implements RoleContract, ModelObjectComplete {
 54  
     private static final long serialVersionUID = 1L;
 55  
 
 56  
     public static final String GROUP_MEMBER_TYPE = "G";
 57  
     public static final String PRINCIPAL_MEMBER_TYPE = "P";
 58  
     public static final String ROLE_MEMBER_TYPE = "R";
 59  
 
 60  
 
 61  
     @XmlElement(name = Role.Elements.ID, required = true)
 62  
     private final String id;
 63  
 
 64  
     @XmlElement(name = Role.Elements.NAME, required = true)
 65  
     private final String name;
 66  
 
 67  
     @XmlElement(name = Role.Elements.NAMESPACE_CODE, required = true)
 68  
     private final String namespaceCode;
 69  
 
 70  
     @XmlElement(name = Role.Elements.DESCRIPTION)
 71  
     private final String description;
 72  
 
 73  
     @XmlElement(name = Role.Elements.KIM_TYPE_ID, required = true)
 74  
     private final String kimTypeId;
 75  
 
 76  
     @XmlElement(name = CoreConstants.CommonElements.ACTIVE, required = true)
 77  
     private final boolean active;
 78  
 
 79  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER)
 80  
     private final Long versionNumber;
 81  
 
 82  4
     @SuppressWarnings("unused")
 83  
     @XmlAnyElement
 84  
     private final Collection<Element> _futureElements = null;
 85  
 
 86  
 
 87  
     /**
 88  
      * This constructor should never be called except during JAXB unmarshalling.
 89  
      */
 90  
     @SuppressWarnings("unused")
 91  3
     private Role() {
 92  3
         id = null;
 93  3
         name = null;
 94  3
         namespaceCode = null;
 95  3
         description = null;
 96  3
         kimTypeId = null;
 97  3
         active = false;
 98  3
         versionNumber = null;
 99  3
     }
 100  
 
 101  1
     private Role(Builder builder) {
 102  1
         id = builder.getId();
 103  1
         name = builder.getName();
 104  1
         namespaceCode = builder.getNamespaceCode();
 105  1
         description = builder.getDescription();
 106  1
         kimTypeId = builder.getKimTypeId();
 107  1
         active = builder.isActive();
 108  1
         versionNumber = builder.getVersionNumber();
 109  1
     }
 110  
 
 111  
 
 112  
     /**
 113  
      * Unique identifier for this role.
 114  
      */
 115  
     @Override
 116  
     public String getId() {
 117  1
         return id;
 118  
     }
 119  
 
 120  
     /**
 121  
      * Namespace for this role - identifies the system/module to which this role applies
 122  
      */
 123  
     @Override
 124  
     public String getNamespaceCode() {
 125  1
         return namespaceCode;
 126  
     }
 127  
 
 128  
     /**
 129  
      * Name for this role.  This value will be seen by the users.
 130  
      */
 131  
     @Override
 132  
     public String getName() {
 133  1
         return name;
 134  
     }
 135  
 
 136  
     /**
 137  
      * Verbose description of the role and functionally what permissions it implies.
 138  
      */
 139  
     @Override
 140  
     public String getDescription() {
 141  1
         return description;
 142  
     }
 143  
 
 144  
     /**
 145  
      * Type identifier for this role.  This will control what additional attributes are available
 146  
      */
 147  
     @Override
 148  
     public String getKimTypeId() {
 149  1
         return kimTypeId;
 150  
     }
 151  
 
 152  
     @Override
 153  
     public Long getVersionNumber() {
 154  1
         return versionNumber;
 155  
     }
 156  
 
 157  
     @Override
 158  
     public boolean isActive() {
 159  1
         return active;
 160  
     }
 161  
 
 162  
     @Override
 163  
     public int hashCode() {
 164  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 165  
     }
 166  
 
 167  
     @Override
 168  
     public boolean equals(Object obj) {
 169  1
         return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 170  
     }
 171  
 
 172  
     @Override
 173  
     public String toString() {
 174  0
         return ToStringBuilder.reflectionToString(this);
 175  
     }
 176  
 
 177  
 
 178  1
     public static final class Builder implements RoleContract, ModelBuilder, ModelObjectComplete {
 179  
 
 180  
         private String id;
 181  
         private String name;
 182  
         private String namespaceCode;
 183  
         private String description;
 184  
         private String kimTypeId;
 185  
         private boolean active;
 186  
         private Long versionNumber;
 187  
 
 188  9
         private Builder() {
 189  9
         }
 190  
 
 191  
         public static Builder create() {
 192  8
             return new Builder();
 193  
         }
 194  
 
 195  
         public static Builder create(String id, String name, String namespaceCode, String description, String kimTypeId) {
 196  1
             Builder b = new Builder();
 197  1
             b.setId(id);
 198  1
             b.setName(name);
 199  1
             b.setNamespaceCode(namespaceCode);
 200  1
             b.setDescription(description);
 201  1
             b.setKimTypeId(kimTypeId);
 202  1
             b.setActive(true);
 203  
 
 204  1
             return b;
 205  
         }
 206  
 
 207  
         public static Builder create(RoleContract roleContract) {
 208  0
             Builder b = new Builder();
 209  0
             b.setId(roleContract.getId());
 210  0
             b.setName(roleContract.getName());
 211  0
             b.setNamespaceCode(roleContract.getNamespaceCode());
 212  0
             b.setDescription(roleContract.getDescription());
 213  0
             b.setKimTypeId(roleContract.getKimTypeId());
 214  0
             b.setActive(roleContract.isActive());
 215  0
             b.setVersionNumber(roleContract.getVersionNumber());
 216  
 
 217  0
             return b;
 218  
         }
 219  
 
 220  
         @Override
 221  
         public Role build() {
 222  1
             return new Role(this);
 223  
         }
 224  
 
 225  
         public void setId(String id) {
 226  3
             if (StringUtils.isBlank(id)) {
 227  2
                 throw new IllegalArgumentException("id cannot be blank or null");
 228  
             }
 229  1
             this.id = id;
 230  1
         }
 231  
 
 232  
         @Override
 233  
         public String getId() {
 234  1
             return id;
 235  
         }
 236  
 
 237  
         public void setNamespaceCode(String namespaceCode) {
 238  3
             if (StringUtils.isBlank(namespaceCode)) {
 239  2
                 throw new IllegalArgumentException("namespaceCode cannot be blank or null");
 240  
             }
 241  1
             this.namespaceCode = namespaceCode;
 242  1
         }
 243  
 
 244  
         @Override
 245  
         public String getNamespaceCode() {
 246  1
             return namespaceCode;
 247  
         }
 248  
 
 249  
         public void setName(String name) {
 250  3
             if (StringUtils.isBlank(name)) {
 251  2
                 throw new IllegalArgumentException("name cannot be blank or null");
 252  
             }
 253  1
             this.name = name;
 254  1
         }
 255  
 
 256  
         @Override
 257  
         public String getName() {
 258  1
             return name;
 259  
         }
 260  
 
 261  
         public void setDescription(String description) {
 262  1
             if (StringUtils.isBlank(description)) {
 263  0
                 throw new IllegalArgumentException("description cannot be blank or null");
 264  
             }
 265  1
             this.description = description;
 266  1
         }
 267  
 
 268  
         @Override
 269  
         public String getDescription() {
 270  1
             return description;
 271  
         }
 272  
 
 273  
         public void setKimTypeId(String kimTypeId) {
 274  3
             if (StringUtils.isBlank(kimTypeId)) {
 275  2
                 throw new IllegalArgumentException("kimTypeId cannot be blank or null");
 276  
             }
 277  1
             this.kimTypeId = kimTypeId;
 278  1
         }
 279  
 
 280  
         @Override
 281  
         public String getKimTypeId() {
 282  1
             return kimTypeId;
 283  
         }
 284  
 
 285  
         public void setActive(boolean active) {
 286  1
             this.active = active;
 287  1
         }
 288  
 
 289  
         @Override
 290  
         public boolean isActive() {
 291  1
             return active;
 292  
         }
 293  
 
 294  
         public void setVersionNumber(Long versionNumber) {
 295  1
             if (versionNumber == null) {
 296  0
                 throw new IllegalArgumentException("versionNumber must be non-null");
 297  
             }
 298  1
             this.versionNumber = versionNumber;
 299  1
         }
 300  
 
 301  
         @Override
 302  
         public Long getVersionNumber() {
 303  1
             return versionNumber;
 304  
         }
 305  
 
 306  
         @Override
 307  
         public int hashCode() {
 308  0
             return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 309  
         }
 310  
 
 311  
         @Override
 312  
         public boolean equals(Object obj) {
 313  0
             return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 314  
         }
 315  
 
 316  
         @Override
 317  
         public String toString() {
 318  0
             return ToStringBuilder.reflectionToString(this);
 319  
         }
 320  
     }
 321  
 
 322  
     /**
 323  
      * A private class which exposes constants which define the XML element names to use
 324  
      * when this object is marshalled to XML.
 325  
      */
 326  0
     static class Elements {
 327  
         final static String ID = "id";
 328  
         final static String NAME = "name";
 329  
         final static String DESCRIPTION = "description";
 330  
         final static String KIM_TYPE_ID = "kimTypeId";
 331  
         final static String NAMESPACE_CODE = "namespaceCode";
 332  
         final static String ACTIVE = "active";
 333  
     }
 334  
 
 335  
     /**
 336  
      * Defines some internal constants used on this class.
 337  
      */
 338  0
     static class Constants {
 339  
         final static String ROOT_ELEMENT_NAME = "role";
 340  
         final static String TYPE_NAME = "RoleType";
 341  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
 342  
     }
 343  
 }