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