Coverage Report - org.kuali.rice.kim.api.role.RolePermission
 
Classes in this File Line Coverage Branch Coverage Complexity
RolePermission
92%
24/26
N/A
1.37
RolePermission$Builder
90%
36/40
50%
6/12
1.37
RolePermission$Constants
50%
1/2
N/A
1.37
RolePermission$Elements
0%
0/1
N/A
1.37
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.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/ecl2.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  
 
 17  
 package org.kuali.rice.kim.api.role;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.apache.commons.lang.builder.EqualsBuilder;
 21  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 22  
 import org.apache.commons.lang.builder.ToStringBuilder;
 23  
 import org.kuali.rice.core.api.CoreConstants;
 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.io.Serializable;
 35  
 import java.util.Collection;
 36  
 
 37  
 
 38  
 @XmlRootElement(name = RolePermission.Constants.ROOT_ELEMENT_NAME)
 39  
 @XmlAccessorType(XmlAccessType.NONE)
 40  
 @XmlType(name = RolePermission.Constants.TYPE_NAME, propOrder = {
 41  
         RolePermission.Elements.ID,
 42  
         RolePermission.Elements.ROLE_ID,
 43  
         RolePermission.Elements.PERMISSION_ID,
 44  
         RolePermission.Elements.ACTIVE,
 45  
         CoreConstants.CommonElements.VERSION_NUMBER,
 46  
         CoreConstants.CommonElements.OBJECT_ID,
 47  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 48  
 })
 49  
 public class RolePermission implements RolePermissionContract, ModelObjectComplete {
 50  
     @XmlElement(name = Elements.ID, required = false)
 51  
     private final String id;
 52  
 
 53  
     @XmlElement(name = RolePermission.Elements.ROLE_ID, required = false)
 54  
     private final String roleId;
 55  
 
 56  
     @XmlElement(name = RolePermission.Elements.PERMISSION_ID, required = false)
 57  
     private final String permissionId;
 58  
 
 59  
     @XmlElement(name = RolePermission.Elements.ACTIVE, required = false)
 60  
     private final boolean active;
 61  
 
 62  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 63  
     private final Long versionNumber;
 64  
 
 65  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 66  
     private final String objectId;
 67  
 
 68  5
     @SuppressWarnings("unused")
 69  
     @XmlAnyElement
 70  
     private final Collection<Element> _futureElements = null;
 71  
 
 72  
     /**
 73  
      * A constructor to be used only by JAXB unmarshalling.
 74  
      */
 75  2
     private RolePermission() {
 76  2
         this.id = null;
 77  2
         this.roleId = null;
 78  2
         this.permissionId = null;
 79  2
         this.active = false;
 80  2
         this.versionNumber = null;
 81  2
         this.objectId = null;
 82  2
     }
 83  
 
 84  
     /**
 85  
      * A constructor using the Builder.
 86  
      *
 87  
      * @param builder
 88  
      */
 89  3
     public RolePermission(Builder builder) {
 90  3
         this.id = builder.getId();
 91  3
         this.roleId = builder.getRoleId();
 92  3
         this.permissionId = builder.getPermissionId();
 93  3
         this.active = builder.isActive();
 94  3
         this.versionNumber = builder.getVersionNumber();
 95  3
         this.objectId = builder.getObjectId();
 96  3
     }
 97  
 
 98  
     @Override
 99  
     public String getId() {
 100  1
         return id;
 101  
     }
 102  
 
 103  
     @Override
 104  
     public String getPermissionId() {
 105  1
         return permissionId;
 106  
     }
 107  
 
 108  
     @Override
 109  
     public String getRoleId() {
 110  1
         return roleId;
 111  
     }
 112  
 
 113  
     @Override
 114  
     public boolean isActive() {
 115  1
         return active;
 116  
     }
 117  
 
 118  
     @Override
 119  
     public Long getVersionNumber() {
 120  1
         return versionNumber;
 121  
     }
 122  
 
 123  
     @Override
 124  
     public String getObjectId() {
 125  1
         return objectId;
 126  
     }
 127  
 
 128  
     @Override
 129  
     public int hashCode() {
 130  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 131  
     }
 132  
 
 133  
     @Override
 134  
     public boolean equals(Object obj) {
 135  2
         return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 136  
     }
 137  
 
 138  
     @Override
 139  
     public String toString() {
 140  0
         return ToStringBuilder.reflectionToString(this);
 141  
     }
 142  
 
 143  
     /**
 144  
      * This builder constructs a RolePermission enforcing the constraints of the {@link RolePermissionContract}.
 145  
      */
 146  3
     public static final class Builder implements RolePermissionContract, ModelBuilder, Serializable {
 147  
         private String id;
 148  
         private String roleId;
 149  
         private String permissionId;
 150  4
         private Long versionNumber = 1L;
 151  
         private String objectId;
 152  
         private boolean active;
 153  
 
 154  4
         private Builder(String id, String roleId, String permissionId) {
 155  4
             setId(id);
 156  4
             setRoleId(roleId);
 157  4
             setPermissionId(permissionId);
 158  4
         }
 159  
 
 160  
         /**
 161  
          * Creates a RolePermission with the required fields.
 162  
          */
 163  
         public static Builder create(String id, String roleId, String permissionId) {
 164  2
             return new Builder(id, roleId, permissionId);
 165  
         }
 166  
 
 167  
         /**
 168  
          * Creates a RolePermission from an existing {@link RolePermissionContract}.
 169  
          */
 170  
         public static Builder create(RolePermissionContract contract) {
 171  2
             Builder builder = new Builder(contract.getId(), contract.getRoleId(), contract.getPermissionId());
 172  2
             builder.setActive(contract.isActive());
 173  2
             builder.setVersionNumber(contract.getVersionNumber());
 174  2
             builder.setObjectId(contract.getObjectId());
 175  
 
 176  2
             return builder;
 177  
         }
 178  
 
 179  
         @Override
 180  
         public String getId() {
 181  3
             return id;
 182  
         }
 183  
 
 184  
         public void setId(final String id) {
 185  4
             if (StringUtils.isWhitespace(id)) {
 186  0
                 throw new IllegalArgumentException("id is blank");
 187  
             }
 188  4
             this.id = id;
 189  4
         }
 190  
 
 191  
         @Override
 192  
         public String getPermissionId() {
 193  3
             return permissionId;
 194  
         }
 195  
 
 196  
         public void setPermissionId(final String permissionId) {
 197  4
             this.permissionId = permissionId;
 198  4
         }
 199  
 
 200  
         @Override
 201  
         public String getRoleId() {
 202  3
             return roleId;
 203  
         }
 204  
 
 205  
         public void setRoleId(final String roleId) {
 206  4
             this.roleId = roleId;
 207  4
         }
 208  
 
 209  
         @Override
 210  
         public Long getVersionNumber() {
 211  3
             return versionNumber;
 212  
         }
 213  
 
 214  
         public void setVersionNumber(Long versionNumber) {
 215  2
             if (versionNumber == null || versionNumber <= 0) {
 216  0
                 throw new IllegalArgumentException("versionNumber is invalid");
 217  
             }
 218  2
             this.versionNumber = versionNumber;
 219  2
         }
 220  
 
 221  
         @Override
 222  
         public String getObjectId() {
 223  3
             return objectId;
 224  
         }
 225  
 
 226  
         public void setObjectId(final String objectId) {
 227  2
             this.objectId = objectId;
 228  2
         }
 229  
 
 230  
         @Override
 231  
         public boolean isActive() {
 232  3
             return active;
 233  
         }
 234  
 
 235  
         public void setActive(final boolean active) {
 236  2
             this.active = active;
 237  2
         }
 238  
 
 239  
         @Override
 240  
         public RolePermission build() {
 241  3
             if (versionNumber == null || versionNumber <= 0) {
 242  0
                 throw new IllegalStateException("versionNumber is invalid");
 243  
             }
 244  3
             if (StringUtils.isWhitespace(id)) {
 245  0
                 throw new IllegalStateException("id is blank");
 246  
             }
 247  3
             return new RolePermission(this);
 248  
         }
 249  
     }
 250  
 
 251  
     /**
 252  
      * Defines some internal constants used on this class.
 253  
      */
 254  0
     static class Constants {
 255  
         final static String ROOT_ELEMENT_NAME = "rolePermission";
 256  
         final static String TYPE_NAME = "RolePermissionType";
 257  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
 258  
     }
 259  
 
 260  
     /**
 261  
      * A private class which exposes constants which define the XML element names to use
 262  
      * when this object is marshalled to XML.
 263  
      */
 264  0
     static class Elements {
 265  
         final static String ID = "id";
 266  
         final static String PERMISSION_ID = "permissionId";
 267  
         final static String ROLE_ID = "roleId";
 268  
         final static String ACTIVE = "active";
 269  
     }
 270  
 }