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