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