Coverage Report - org.kuali.rice.kim.api.role.RoleMembership
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleMembership
94%
34/36
100%
4/4
1.222
RoleMembership$1
N/A
N/A
1.222
RoleMembership$Builder
91%
51/56
62%
5/8
1.222
RoleMembership$Constants
50%
1/2
N/A
1.222
RoleMembership$Elements
0%
0/1
N/A
1.222
 
 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.collections.CollectionUtils;
 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.kuali.rice.core.util.AttributeSet;
 27  
 import org.kuali.rice.kim.api.common.delegate.Delegate;
 28  
 import org.kuali.rice.kim.api.common.delegate.DelegateContract;
 29  
 import org.w3c.dom.Element;
 30  
 
 31  
 import javax.xml.bind.annotation.XmlAccessType;
 32  
 import javax.xml.bind.annotation.XmlAccessorType;
 33  
 import javax.xml.bind.annotation.XmlAnyElement;
 34  
 import javax.xml.bind.annotation.XmlElement;
 35  
 import javax.xml.bind.annotation.XmlRootElement;
 36  
 import javax.xml.bind.annotation.XmlType;
 37  
 import java.util.ArrayList;
 38  
 import java.util.Collection;
 39  
 import java.util.Collections;
 40  
 import java.util.List;
 41  
 
 42  
 
 43  
 @XmlRootElement(name = RoleMembership.Constants.ROOT_ELEMENT_NAME)
 44  
 @XmlAccessorType(XmlAccessType.NONE)
 45  
 @XmlType(name = RoleMembership.Constants.TYPE_NAME, propOrder = {
 46  
         RoleMembership.Elements.ROLE_ID,
 47  
         RoleMembership.Elements.ROLE_MEMBER_ID,
 48  
         RoleMembership.Elements.EMBEDDED_ROLE_ID,
 49  
         RoleMembership.Elements.MEMBER_ID,
 50  
         RoleMembership.Elements.MEMBER_TYPE_CODE,
 51  
         RoleMembership.Elements.ROLE_SORTING_CODE,
 52  
         RoleMembership.Elements.QUALIFIER,
 53  
         RoleMembership.Elements.DELEGATES,
 54  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 55  
 })
 56  5
 public class RoleMembership implements RoleMembershipContract, ModelObjectComplete {
 57  
     private static final long serialVersionUID = 1L;
 58  
 
 59  
     @XmlElement(name=Elements.ROLE_ID)
 60  
     private final String roleId;
 61  
 
 62  
     @XmlElement(name=Elements.ROLE_MEMBER_ID)
 63  
     private final String roleMemberId;
 64  
 
 65  
     @XmlElement(name=Elements.EMBEDDED_ROLE_ID)
 66  
     private final String embeddedRoleId;
 67  
 
 68  
     @XmlElement(name=Elements.MEMBER_ID, required = true)
 69  
     private final String memberId;
 70  
 
 71  
     @XmlElement(name=Elements.MEMBER_TYPE_CODE, required = true)
 72  
     private final String memberTypeCode;
 73  
 
 74  
     @XmlElement(name=Elements.ROLE_SORTING_CODE)
 75  
     private final String roleSortingCode;
 76  
 
 77  
     @XmlElement(name=Elements.QUALIFIER)
 78  
     private final AttributeSet qualifier;
 79  
 
 80  
     @XmlElement(name=Elements.DELEGATES)
 81  
     private final List<Delegate> delegates;
 82  
 
 83  8
     @SuppressWarnings("unused")
 84  
     @XmlAnyElement
 85  
     private final Collection<Element> _futureElements = null;
 86  
 
 87  
     /**
 88  
      * Private constructor for JAXB only
 89  
      */
 90  
     @SuppressWarnings("unused")
 91  3
     private RoleMembership() {
 92  3
         roleId = null;
 93  3
         roleMemberId = null;
 94  3
         embeddedRoleId = null;
 95  3
         memberId = null;
 96  3
         memberTypeCode = null;
 97  3
         roleSortingCode = null;
 98  3
         qualifier = null;
 99  3
         delegates = null;
 100  3
     }
 101  
 
 102  5
     private RoleMembership(Builder b) {
 103  5
         roleId = b.getRoleId();
 104  5
         roleMemberId = b.getRoleMemberId();
 105  5
         embeddedRoleId = b.getEmbeddedRoleId();
 106  5
         memberId = b.getMemberId();
 107  5
         memberTypeCode = b.getMemberTypeCode();
 108  5
         roleSortingCode = b.getRoleSortingCode();
 109  5
         qualifier = b.getQualifier();
 110  
 
 111  5
         delegates = new ArrayList<Delegate>();
 112  5
         if (!CollectionUtils.isEmpty(b.getDelegates())) {
 113  2
             for (Delegate.Builder delegateBuilder : b.getDelegates()) {
 114  2
                 delegates.add(delegateBuilder.build());
 115  
             }
 116  
         }
 117  5
     }
 118  
 
 119  
     public String getRoleId() {
 120  2
         return roleId;
 121  
     }
 122  
 
 123  
     public String getRoleMemberId() {
 124  2
         return roleMemberId;
 125  
     }
 126  
 
 127  
     public String getEmbeddedRoleId() {
 128  2
         return embeddedRoleId;
 129  
     }
 130  
 
 131  
     public String getMemberId() {
 132  2
         return memberId;
 133  
     }
 134  
 
 135  
     public String getMemberTypeCode() {
 136  2
         return memberTypeCode;
 137  
     }
 138  
 
 139  
     public String getRoleSortingCode() {
 140  2
         return roleSortingCode;
 141  
     }
 142  
 
 143  
     public AttributeSet getQualifier() {
 144  2
         return qualifier;
 145  
     }
 146  
 
 147  
     public List<Delegate> getDelegates() {
 148  3
         return Collections.unmodifiableList(delegates);
 149  
     }
 150  
 
 151  
     @Override
 152  
     public int hashCode() {
 153  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 154  
     }
 155  
 
 156  
     @Override
 157  
     public boolean equals(Object obj) {
 158  2
         return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 159  
     }
 160  
 
 161  
     @Override
 162  
     public String toString() {
 163  0
         return ToStringBuilder.reflectionToString(this);
 164  
     }
 165  
 
 166  
 
 167  5
     public static final class Builder implements ModelBuilder, RoleMembershipContract, ModelObjectComplete {
 168  
         private String roleId;
 169  
         private String roleMemberId;
 170  
         private String embeddedRoleId;
 171  
         private String memberId;
 172  
         private String memberTypeCode;
 173  
         private String roleSortingCode;
 174  
         private AttributeSet qualifier;
 175  
         private List<Delegate.Builder> delegates;
 176  
 
 177  9
         private Builder() {
 178  9
         }
 179  
 
 180  
         public static Builder create(String roleId, String roleMemberId, String memberId, String memberTypeCode,
 181  
                                      AttributeSet qualifier) {
 182  
 
 183  8
             Builder b = new Builder();
 184  8
             b.setRoleId(roleId);
 185  8
             b.setRoleMemberId(roleMemberId);
 186  8
             b.setMemberId(memberId);
 187  8
             b.setMemberTypeCode(memberTypeCode);
 188  8
             b.setQualifier(qualifier);
 189  8
             return b;
 190  
         }
 191  
 
 192  
         public static Builder create(RoleMembershipContract contract) {
 193  1
             Builder b = new Builder();
 194  1
             b.setRoleId(contract.getRoleId());
 195  1
             b.setRoleMemberId(contract.getRoleMemberId());
 196  1
             b.setEmbeddedRoleId(contract.getEmbeddedRoleId());
 197  1
             b.setMemberId(contract.getMemberId());
 198  1
             b.setMemberTypeCode(contract.getMemberTypeCode());
 199  1
             b.setRoleSortingCode(contract.getRoleSortingCode());
 200  1
             b.setQualifier(contract.getQualifier());
 201  
 
 202  1
             List<Delegate.Builder> delegateBuilders = new ArrayList<Delegate.Builder>();
 203  1
             if (!CollectionUtils.isEmpty(contract.getDelegates())) {
 204  0
                 for (DelegateContract delegateContract : contract.getDelegates()) {
 205  0
                     delegateBuilders.add(Delegate.Builder.create(delegateContract));
 206  
                 }
 207  
             }
 208  1
             b.setDelegates(delegateBuilders);
 209  
 
 210  1
             return b;
 211  
         }
 212  
 
 213  
         @Override
 214  
         public RoleMembership build() {
 215  5
             return new RoleMembership(this);
 216  
         }
 217  
 
 218  
         public String getRoleId() {
 219  5
             return this.roleId;
 220  
         }
 221  
 
 222  
         public void setRoleId(String roleId) {
 223  9
             this.roleId = roleId;
 224  9
         }
 225  
 
 226  
         public AttributeSet getQualifier() {
 227  5
             return this.qualifier;
 228  
         }
 229  
 
 230  
         public void setQualifier(AttributeSet qualifier) {
 231  9
             this.qualifier = qualifier;
 232  9
         }
 233  
 
 234  
         public List<Delegate.Builder> getDelegates() {
 235  7
             return this.delegates;
 236  
         }
 237  
 
 238  
         public void setDelegates(List<Delegate.Builder> delegates) {
 239  3
             this.delegates = delegates;
 240  3
         }
 241  
 
 242  
         public String getRoleMemberId() {
 243  5
             return this.roleMemberId;
 244  
         }
 245  
 
 246  
         public void setRoleMemberId(String roleMemberId) {
 247  9
             this.roleMemberId = roleMemberId;
 248  9
         }
 249  
 
 250  
         public String getMemberId() {
 251  5
             return this.memberId;
 252  
         }
 253  
 
 254  
         public void setMemberId(String memberId) {
 255  11
             if (StringUtils.isEmpty(memberId)) {
 256  2
                 throw new IllegalArgumentException("memberId cannot be empty or null");
 257  
             }
 258  9
             this.memberId = memberId;
 259  9
         }
 260  
 
 261  
         public String getMemberTypeCode() {
 262  5
             return this.memberTypeCode;
 263  
         }
 264  
 
 265  
         public void setMemberTypeCode(String memberTypeCode) {
 266  11
             if (StringUtils.isEmpty(memberTypeCode)) {
 267  2
                 throw new IllegalArgumentException("memberTypeCode cannot be empty or null");
 268  
             }
 269  9
             this.memberTypeCode = memberTypeCode;
 270  9
         }
 271  
 
 272  
         public String getEmbeddedRoleId() {
 273  5
             return this.embeddedRoleId;
 274  
         }
 275  
 
 276  
         public void setEmbeddedRoleId(String embeddedRoleId) {
 277  2
             this.embeddedRoleId = embeddedRoleId;
 278  2
         }
 279  
 
 280  
         public String getRoleSortingCode() {
 281  5
             return this.roleSortingCode;
 282  
         }
 283  
 
 284  
         public void setRoleSortingCode(String roleSortingCode) {
 285  2
             this.roleSortingCode = roleSortingCode;
 286  2
         }
 287  
 
 288  
         @Override
 289  
         public int hashCode() {
 290  0
             return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 291  
         }
 292  
 
 293  
         @Override
 294  
         public boolean equals(Object obj) {
 295  0
             return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 296  
         }
 297  
 
 298  
         @Override
 299  
         public String toString() {
 300  0
             return ToStringBuilder.reflectionToString(this);
 301  
         }
 302  
 
 303  
 
 304  
     }
 305  
 
 306  
     /**
 307  
      * A private class which exposes constants which define the XML element names to use
 308  
      * when this object is marshalled to XML.
 309  
      */
 310  0
     static class Elements {
 311  
         final static String ROLE_ID = "roleId";
 312  
         final static String ROLE_MEMBER_ID = "roleMemberId";
 313  
         final static String EMBEDDED_ROLE_ID = "embeddedRoleId";
 314  
         final static String MEMBER_ID = "memberId";
 315  
         final static String MEMBER_TYPE_CODE = "memberTypeCode";
 316  
         final static String ROLE_SORTING_CODE = "roleSortingCode";
 317  
         final static String QUALIFIER = "qualifier";
 318  
         final static String DELEGATES = "delegates";
 319  
     }
 320  
 
 321  
     /**
 322  
      * Defines some internal constants used on this class.
 323  
      */
 324  0
     static class Constants {
 325  
         final static String ROOT_ELEMENT_NAME = "roleMembership";
 326  
         final static String TYPE_NAME = "RoleMembershipType";
 327  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
 328  
     }
 329  
 }