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