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