Coverage Report - org.kuali.rice.kim.api.role.RoleMember
 
Classes in this File Line Coverage Branch Coverage Complexity
RoleMember
89%
34/38
25%
1/4
1.216
RoleMember$1
N/A
N/A
1.216
RoleMember$Builder
89%
51/57
62%
5/8
1.216
RoleMember$Constants
50%
1/2
N/A
1.216
RoleMember$Elements
0%
0/1
N/A
1.216
 
 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.api.mo.common.active.InactivatableFromToUtils;
 27  
 import org.kuali.rice.core.util.jaxb.MapStringStringAdapter;
 28  
 import org.kuali.rice.core.util.jaxb.SqlTimestampAdapter;
 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 javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 38  
 import java.sql.Timestamp;
 39  
 import java.util.ArrayList;
 40  
 import java.util.Collection;
 41  
 import java.util.List;
 42  
 import java.util.Map;
 43  
 
 44  
 @XmlRootElement(name = RoleMember.Constants.ROOT_ELEMENT_NAME)
 45  
 @XmlAccessorType(XmlAccessType.NONE)
 46  
 @XmlType(name = RoleMember.Constants.TYPE_NAME, propOrder = {
 47  
         RoleMember.Elements.ROLE_MEMBER_ID,
 48  
         RoleMember.Elements.ROLE_ID,
 49  
         RoleMember.Elements.ATTRIBUTES,
 50  
         RoleMember.Elements.ROLE_RESPONSIBILITY_ACTIONS,
 51  
         RoleMember.Elements.MEMBER_ID,
 52  
         RoleMember.Elements.MEMBER_TYPE_CODE,
 53  
         CoreConstants.CommonElements.ACTIVE_FROM_DATE,
 54  
         CoreConstants.CommonElements.ACTIVE_TO_DATE,
 55  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 56  
 })
 57  6
 public class RoleMember implements RoleMemberContract, ModelObjectComplete {
 58  
 
 59  
     private static final long serialVersionUID = 1L;
 60  
 
 61  
     @XmlElement(name = Elements.ROLE_MEMBER_ID)
 62  
     private final String roleMemberId;
 63  
 
 64  
     @XmlElement(name = Elements.ROLE_ID)
 65  
     private final String roleId;
 66  
 
 67  
     @XmlElement(name = Elements.ATTRIBUTES, required = false)
 68  
     @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
 69  
     private final Map<String, String> attributes;
 70  
 
 71  
     @XmlElement(name = Elements.ROLE_RESPONSIBILITY_ACTIONS)
 72  
     private final List<RoleResponsibilityAction> roleResponsibilityActions;
 73  
 
 74  
     @XmlElement(name = Elements.MEMBER_ID)
 75  
     private final String memberId;
 76  
 
 77  
     @XmlElement(name = Elements.MEMBER_TYPE_CODE)
 78  
     private final String memberTypeCode;
 79  
 
 80  
     @XmlJavaTypeAdapter(SqlTimestampAdapter.class)
 81  
     @XmlElement(name = CoreConstants.CommonElements.ACTIVE_FROM_DATE)
 82  
     private final Timestamp activeFromDate;
 83  
 
 84  
     @XmlJavaTypeAdapter(SqlTimestampAdapter.class)
 85  
     @XmlElement(name = CoreConstants.CommonElements.ACTIVE_TO_DATE)
 86  
     private final Timestamp activeToDate;
 87  
 
 88  7
     @SuppressWarnings("unused")
 89  
     @XmlAnyElement
 90  
     private final Collection<Element> _futureElements = null;
 91  
 
 92  
     /**
 93  
      * Private constructor for JAXB
 94  
      */
 95  
     @SuppressWarnings("unused")
 96  1
     private RoleMember() {
 97  1
         roleMemberId = null;
 98  1
         roleId = null;
 99  1
         attributes = null;
 100  1
         roleResponsibilityActions = null;
 101  1
         memberId = null;
 102  1
         memberTypeCode = null;
 103  1
         activeFromDate = null;
 104  1
         activeToDate = null;
 105  1
     }
 106  
 
 107  6
     private RoleMember(Builder b) {
 108  6
         roleMemberId = b.getRoleMemberId();
 109  6
         roleId = b.getRoleId();
 110  6
         attributes = b.getAttributes();
 111  
 
 112  6
         List<RoleResponsibilityAction> roleResponsibilityActions = new ArrayList<RoleResponsibilityAction>();
 113  6
         if (!CollectionUtils.isEmpty(b.getRoleRspActions())) {
 114  0
             for (RoleResponsibilityAction.Builder rraBuilder : b.getRoleRspActions()) {
 115  0
                 roleResponsibilityActions.add(rraBuilder.build());
 116  
             }
 117  
         }
 118  6
         this.roleResponsibilityActions = roleResponsibilityActions;
 119  
 
 120  6
         memberId = b.getMemberId();
 121  6
         memberTypeCode = b.getMemberTypeCode();
 122  6
         activeFromDate = b.getActiveFromDate();
 123  6
         activeToDate = b.getActiveToDate();
 124  6
     }
 125  
 
 126  
 
 127  
     public String getMemberId() {
 128  2
         return this.memberId;
 129  
     }
 130  
 
 131  
     public String getMemberTypeCode() {
 132  2
         return this.memberTypeCode;
 133  
     }
 134  
 
 135  
 
 136  
     public String getRoleMemberId() {
 137  2
         return this.roleMemberId;
 138  
     }
 139  
 
 140  
     public String getRoleId() {
 141  2
         return this.roleId;
 142  
     }
 143  
 
 144  
     /**
 145  
      * @return the attributes
 146  
      */
 147  
     public Map<String, String> getAttributes() {
 148  2
         return this.attributes;
 149  
     }
 150  
 
 151  
     /**
 152  
      * @return the roleResponsibilityActions
 153  
      */
 154  
     public List<RoleResponsibilityAction> getRoleRspActions() {
 155  2
         return this.roleResponsibilityActions;
 156  
     }
 157  
 
 158  
     public Timestamp getActiveFromDate() {
 159  2
         return activeFromDate;
 160  
     }
 161  
 
 162  
     public Timestamp getActiveToDate() {
 163  2
         return activeToDate;
 164  
     }
 165  
 
 166  
     @Override
 167  
     public boolean isActive(Timestamp activeAsOfDate) {
 168  3
         return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOfDate);
 169  
     }
 170  
 
 171  
     @Override
 172  
     public int hashCode() {
 173  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 174  
     }
 175  
 
 176  
     @Override
 177  
     public boolean equals(Object obj) {
 178  1
         return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 179  
     }
 180  
 
 181  
     @Override
 182  
     public String toString() {
 183  0
         return ToStringBuilder.reflectionToString(this);
 184  
     }
 185  
 
 186  
 
 187  16
     public static final class Builder implements ModelBuilder, RoleMemberContract, ModelObjectComplete {
 188  
 
 189  
         private String roleMemberId;
 190  
         private String roleId;
 191  
         private Map<String, String> attributes;
 192  
         private List<RoleResponsibilityAction.Builder> roleRspActions;
 193  
         private String memberId;
 194  
         private String memberTypeCode;
 195  
         private Timestamp activeFromDate;
 196  
         private Timestamp activeToDate;
 197  
 
 198  
         public static Builder create(String roleId, String roleMemberId, String memberId,
 199  
                                      String memberTypeCode, Timestamp activeFromDate, Timestamp activeToDate, Map<String, String> attributes) {
 200  9
             Builder b = new Builder();
 201  9
             b.setRoleId(roleId);
 202  9
             b.setRoleMemberId(roleMemberId);
 203  9
             b.setMemberId(memberId);
 204  9
             b.setMemberTypeCode(memberTypeCode);
 205  9
             b.setActiveFromDate(activeFromDate);
 206  9
             b.setActiveToDate(activeToDate);
 207  9
             b.setAttributes(attributes);
 208  9
             return b;
 209  
         }
 210  
 
 211  
         public static Builder create(RoleMemberContract contract) {
 212  1
             Builder b = new Builder();
 213  1
             b.setRoleMemberId(contract.getRoleMemberId());
 214  1
             b.setRoleId(contract.getRoleId());
 215  1
             b.setAttributes(contract.getAttributes());
 216  
 
 217  1
             List<RoleResponsibilityAction.Builder> rraBuilders = new ArrayList<RoleResponsibilityAction.Builder>();
 218  1
             if (!CollectionUtils.isEmpty(contract.getRoleRspActions())) {
 219  0
                 for (RoleResponsibilityActionContract rrac : contract.getRoleRspActions()) {
 220  0
                     rraBuilders.add(RoleResponsibilityAction.Builder.create(rrac));
 221  
                 }
 222  
             }
 223  1
             b.setRoleRspActions(rraBuilders);
 224  
 
 225  1
             b.setMemberId(contract.getMemberId());
 226  1
             b.setMemberTypeCode(contract.getMemberTypeCode());
 227  1
             b.setActiveFromDate(contract.getActiveFromDate());
 228  1
             b.setActiveToDate(contract.getActiveToDate());
 229  1
             return b;
 230  
         }
 231  
 
 232  
         public RoleMember build() {
 233  6
             return new RoleMember(this);
 234  
         }
 235  
 
 236  
         public String getRoleMemberId() {
 237  6
             return roleMemberId;
 238  
         }
 239  
 
 240  
         public void setRoleMemberId(String roleMemberId) {
 241  10
             this.roleMemberId = roleMemberId;
 242  10
         }
 243  
 
 244  
         public String getRoleId() {
 245  6
             return roleId;
 246  
         }
 247  
 
 248  
         public void setRoleId(String roleId) {
 249  10
             this.roleId = roleId;
 250  10
         }
 251  
 
 252  
         public Map<String, String> getAttributes() {
 253  6
             return attributes;
 254  
         }
 255  
 
 256  
         public void setAttributes(Map<String, String> attributes) {
 257  10
             this.attributes = attributes;
 258  10
         }
 259  
 
 260  
         public List<RoleResponsibilityAction.Builder> getRoleRspActions() {
 261  6
             return roleRspActions;
 262  
         }
 263  
 
 264  
         public void setRoleRspActions(List<RoleResponsibilityAction.Builder> roleRspActions) {
 265  1
             this.roleRspActions = roleRspActions;
 266  1
         }
 267  
 
 268  
         public String getMemberId() {
 269  6
             return memberId;
 270  
         }
 271  
 
 272  
         public void setMemberId(String memberId) {
 273  12
             if (StringUtils.isBlank(memberId)) {
 274  2
                 throw new IllegalArgumentException("memberId may not be null");
 275  
             }
 276  10
             this.memberId = memberId;
 277  10
         }
 278  
 
 279  
         public String getMemberTypeCode() {
 280  6
             return memberTypeCode;
 281  
         }
 282  
 
 283  
         public void setMemberTypeCode(String memberTypeCode) {
 284  12
             if (StringUtils.isBlank(memberTypeCode)) {
 285  2
                 throw new IllegalArgumentException("memberTypeCode may not be null");
 286  
             }
 287  10
             this.memberTypeCode = memberTypeCode;
 288  10
         }
 289  
 
 290  
         public Timestamp getActiveFromDate() {
 291  6
             return activeFromDate;
 292  
         }
 293  
 
 294  
         public void setActiveFromDate(Timestamp activeFromDate) {
 295  10
             this.activeFromDate = activeFromDate;
 296  10
         }
 297  
 
 298  
         public Timestamp getActiveToDate() {
 299  6
             return activeToDate;
 300  
         }
 301  
 
 302  
         public void setActiveToDate(Timestamp activeToDate) {
 303  10
             this.activeToDate = activeToDate;
 304  10
         }
 305  
 
 306  
         @Override
 307  
         public boolean isActive(Timestamp activeAsOfDate) {
 308  0
             return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOfDate);
 309  
         }
 310  
 
 311  
         @Override
 312  
         public int hashCode() {
 313  0
             return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 314  
         }
 315  
 
 316  
         @Override
 317  
         public boolean equals(Object obj) {
 318  0
             return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 319  
         }
 320  
 
 321  
         @Override
 322  
         public String toString() {
 323  0
             return ToStringBuilder.reflectionToString(this);
 324  
         }
 325  
     }
 326  
 
 327  
     /**
 328  
      * A private class which exposes constants which define the XML element names to use
 329  
      * when this object is marshalled to XML.
 330  
      */
 331  0
     static class Elements {
 332  
         final static String ROLE_MEMBER_ID = "roleMemberId";
 333  
         final static String ROLE_ID = "roleId";
 334  
         final static String ATTRIBUTES = "attributes";
 335  
         final static String ROLE_RESPONSIBILITY_ACTIONS = "roleResponsibilityActions";
 336  
         final static String MEMBER_ID = "memberId";
 337  
         final static String MEMBER_TYPE_CODE = "memberTypeCode";
 338  
     }
 339  
 
 340  
     /**
 341  
      * Defines some internal constants used on this class.
 342  
      */
 343  0
     static class Constants {
 344  
         final static String ROOT_ELEMENT_NAME = "roleMember";
 345  
         final static String TYPE_NAME = "RoleMemberType";
 346  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
 347  
     }
 348  
 }