Coverage Report - org.kuali.rice.kim.api.group.GroupMember
 
Classes in this File Line Coverage Branch Coverage Complexity
GroupMember
78%
30/38
0%
0/18
1.649
GroupMember$Builder
78%
43/55
17%
5/28
1.649
GroupMember$Constants
50%
1/2
N/A
1.649
GroupMember$Elements
0%
0/1
N/A
1.649
 
 1  
 /*
 2  
  * Copyright 2006-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  
 
 17  
 package org.kuali.rice.kim.api.group;
 18  
 
 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.jaxb.SqlTimestampAdapter;
 27  
 import org.w3c.dom.Element;
 28  
 
 29  
 import javax.xml.bind.annotation.XmlAccessType;
 30  
 import javax.xml.bind.annotation.XmlAccessorType;
 31  
 import javax.xml.bind.annotation.XmlAnyElement;
 32  
 import javax.xml.bind.annotation.XmlElement;
 33  
 import javax.xml.bind.annotation.XmlRootElement;
 34  
 import javax.xml.bind.annotation.XmlType;
 35  
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 36  
 import java.io.Serializable;
 37  
 import java.sql.Timestamp;
 38  
 import java.util.Collection;
 39  
 
 40  
 @XmlRootElement(name = GroupMember.Constants.ROOT_ELEMENT_NAME)
 41  
 @XmlAccessorType(XmlAccessType.NONE)
 42  
 @XmlType(name = GroupMember.Constants.TYPE_NAME, propOrder = {
 43  
         GroupMember.Elements.ID,
 44  
         GroupMember.Elements.GROUP_ID,
 45  
         GroupMember.Elements.MEMBER_ID,
 46  
         GroupMember.Elements.TYPE_CODE,
 47  
         CoreConstants.CommonElements.ACTIVE_FROM_DATE,
 48  
         CoreConstants.CommonElements.ACTIVE_TO_DATE,
 49  
         CoreConstants.CommonElements.VERSION_NUMBER,
 50  
         CoreConstants.CommonElements.OBJECT_ID,
 51  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 52  
 })
 53  
 public class GroupMember implements GroupMemberContract, ModelObjectComplete  {
 54  
 
 55  
     @XmlElement(name = Elements.ID, required = false)
 56  
     private final String id;
 57  
 
 58  
     @XmlElement(name = Elements.GROUP_ID, required = true)
 59  
     private final String groupId;
 60  
 
 61  
     @XmlElement(name = Elements.MEMBER_ID, required = true)
 62  
     private final String memberId;
 63  
 
 64  
     @XmlElement(name = Elements.TYPE_CODE, required = true)
 65  
     private final String typeCode;
 66  
 
 67  
     @XmlElement(name = CoreConstants.CommonElements.ACTIVE_FROM_DATE, required = false)
 68  
     @XmlJavaTypeAdapter(SqlTimestampAdapter.class)
 69  
     private final Timestamp activeFromDate;
 70  
 
 71  
     @XmlElement(name = CoreConstants.CommonElements.ACTIVE_TO_DATE, required = false)
 72  
     @XmlJavaTypeAdapter(SqlTimestampAdapter.class)
 73  
         private final Timestamp activeToDate;
 74  
 
 75  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 76  
     private final Long versionNumber;
 77  
 
 78  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 79  
     private final String objectId;
 80  
 
 81  4
     @SuppressWarnings("unused")
 82  
     @XmlAnyElement
 83  
     private final Collection<Element> _futureElements = null;
 84  
 
 85  3
     private GroupMember() {
 86  3
         this.id = null;
 87  3
         this.groupId = null;
 88  3
         this.memberId = null;
 89  3
         this.typeCode = null;
 90  3
         this.versionNumber = null;
 91  3
         this.objectId = null;
 92  3
         this.activeFromDate = null;
 93  3
         this.activeToDate = null;
 94  3
     }
 95  
 
 96  
 
 97  1
     public GroupMember(Builder builder) {
 98  1
         this.id = builder.getId();
 99  1
         this.groupId = builder.getGroupId();
 100  1
         this.memberId = builder.getMemberId();
 101  1
         this.typeCode = builder.getTypeCode();
 102  1
         this.versionNumber = builder.getVersionNumber();
 103  1
         this.objectId = builder.getObjectId();
 104  1
         this.activeFromDate = builder.getActiveFromDate();
 105  1
         this.activeToDate = builder.getActiveToDate();
 106  1
     }
 107  
 
 108  1
     public static class Builder implements GroupMemberContract, ModelBuilder, Serializable {
 109  
         private String id;
 110  
         private String groupId;
 111  
         private String memberId;
 112  
         private String typeCode;
 113  
         private Timestamp activeFromDate;
 114  
         private Timestamp activeToDate;
 115  
         private Long versionNumber;
 116  
         private String objectId;
 117  
 
 118  1
         private Builder(String groupId, String memberId, String typeCode) {
 119  1
             setGroupId(groupId);
 120  1
             setMemberId(memberId);
 121  1
             setTypeCode(typeCode);
 122  1
         }
 123  
 
 124  
         /**
 125  
          * creates a Parameter with the required fields.
 126  
          */
 127  
         public static Builder create(String groupId, String memberId, String typeCode) {
 128  0
             return new Builder(groupId, memberId, typeCode);
 129  
         }
 130  
 
 131  
         /**
 132  
          * creates a GroupMember from an existing {@link org.kuali.rice.kim.api.group.GroupMemberContract}.
 133  
          */
 134  
         public static Builder create(GroupMemberContract contract) {
 135  1
             if (contract == null) {
 136  0
                 throw new IllegalArgumentException("contract was null");
 137  
             }
 138  1
             Builder builder = new Builder(contract.getGroupId(), contract.getMemberId(), contract.getTypeCode());
 139  1
             builder.setId(contract.getId());
 140  1
             builder.setActiveFromDate(contract.getActiveFromDate());
 141  1
             builder.setActiveToDate(contract.getActiveToDate());
 142  1
             builder.setVersionNumber(contract.getVersionNumber());
 143  1
             builder.setObjectId(contract.getObjectId());
 144  1
             return builder;
 145  
         }
 146  
 
 147  
         @Override
 148  
         public String getId() {
 149  1
             return id;
 150  
         }
 151  
 
 152  
         public void setId(final String id) {
 153  1
             if (StringUtils.isWhitespace(id)) {
 154  0
                 throw new IllegalArgumentException("id is blank");
 155  
             }
 156  1
             this.id = id;
 157  1
         }
 158  
 
 159  
         @Override
 160  
         public String getGroupId() {
 161  1
             return groupId;
 162  
         }
 163  
 
 164  
         public void setGroupId(final String groupId) {
 165  1
             if (StringUtils.isEmpty(groupId)) {
 166  0
                 throw new IllegalArgumentException("groupId is empty");
 167  
             }
 168  1
             this.groupId = groupId;
 169  1
         }
 170  
 
 171  
         @Override
 172  
         public String getMemberId() {
 173  1
             return memberId;
 174  
         }
 175  
 
 176  
         public void setMemberId(final String memberId) {
 177  1
             if (StringUtils.isEmpty(memberId)) {
 178  0
                 throw new IllegalArgumentException("memberId is empty");
 179  
             }
 180  1
             this.memberId = memberId;
 181  1
         }
 182  
 
 183  
         @Override
 184  
         public String getTypeCode() {
 185  1
             return typeCode;
 186  
         }
 187  
 
 188  
         public void setTypeCode(final String typeCode) {
 189  1
             if (StringUtils.isEmpty(typeCode)) {
 190  0
                 throw new IllegalArgumentException("typeCode is empty");
 191  
             }
 192  1
             this.typeCode = typeCode;
 193  1
         }
 194  
 
 195  
         @Override
 196  
         public Timestamp getActiveFromDate() {
 197  1
             return activeFromDate;
 198  
         }
 199  
 
 200  
         public void setActiveFromDate(final Timestamp activeFromDate) {
 201  1
             this.activeFromDate = activeFromDate;
 202  1
         }
 203  
 
 204  
         @Override
 205  
         public Timestamp getActiveToDate() {
 206  1
             return activeToDate;
 207  
         }
 208  
 
 209  
         public void setActiveToDate(final Timestamp activeToDate) {
 210  1
             this.activeToDate = activeToDate;
 211  1
         }
 212  
 
 213  
         @Override
 214  
         public Long getVersionNumber() {
 215  1
             return versionNumber;
 216  
         }
 217  
 
 218  
         public void setVersionNumber(final Long versionNumber) {
 219  1
             this.versionNumber = versionNumber;
 220  1
         }
 221  
 
 222  
         @Override
 223  
         public String getObjectId() {
 224  1
             return objectId;
 225  
         }
 226  
 
 227  
         public void setObjectId(final String objectId) {
 228  1
             this.objectId = objectId;
 229  1
         }
 230  
 
 231  
         @Override
 232  
         public boolean isActive() {
 233  0
             long asOfDate = System.currentTimeMillis();
 234  
 
 235  0
                     return (activeFromDate == null || asOfDate >= activeFromDate.getTime()) && (activeToDate == null || asOfDate < activeToDate.getTime());
 236  
         }
 237  
 
 238  
         @Override
 239  
         public boolean isActive(Timestamp activeAsOf) {
 240  0
             long asOfDate = System.currentTimeMillis();
 241  0
             if (activeAsOf != null) {
 242  0
                 asOfDate = activeAsOf.getTime();
 243  
             }
 244  
 
 245  0
             return (activeFromDate == null || asOfDate >= activeFromDate.getTime()) && (activeToDate == null || asOfDate < activeToDate.getTime());
 246  
         }
 247  
 
 248  
         @Override
 249  
         public GroupMember build() {
 250  1
             return new GroupMember(this);
 251  
         }
 252  
     }
 253  
 
 254  
     public String getId() {
 255  1
         return id;
 256  
     }
 257  
 
 258  
     public String getGroupId() {
 259  1
         return groupId;
 260  
     }
 261  
 
 262  
     public String getMemberId() {
 263  1
         return memberId;
 264  
     }
 265  
 
 266  
     public String getTypeCode() {
 267  1
         return typeCode;
 268  
     }
 269  
 
 270  
     public Timestamp getActiveFromDate() {
 271  1
         return activeFromDate;
 272  
     }
 273  
 
 274  
     public Timestamp getActiveToDate() {
 275  1
         return activeToDate;
 276  
     }
 277  
 
 278  
     public Long getVersionNumber() {
 279  1
         return versionNumber;
 280  
     }
 281  
 
 282  
     public String getObjectId() {
 283  1
         return objectId;
 284  
     }
 285  
 
 286  
     @Override
 287  
     public boolean isActive() {
 288  0
         long asOfDate = System.currentTimeMillis();
 289  
 
 290  0
                 return (activeFromDate == null || asOfDate >= activeFromDate.getTime()) && (activeToDate == null || asOfDate < activeToDate.getTime());
 291  
     }
 292  
 
 293  
     @Override
 294  
     public boolean isActive(Timestamp activeAsOf) {
 295  0
         long asOfDate = System.currentTimeMillis();
 296  0
                 if (activeAsOf != null) {
 297  0
                         asOfDate = activeAsOf.getTime();
 298  
                 }
 299  
 
 300  0
                 return (activeFromDate == null || asOfDate >= activeFromDate.getTime()) && (activeToDate == null || asOfDate < activeToDate.getTime());
 301  
     }
 302  
 
 303  
     @Override
 304  
     public int hashCode() {
 305  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 306  
     }
 307  
 
 308  
     @Override
 309  
     public boolean equals(Object obj) {
 310  1
         return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 311  
     }
 312  
 
 313  
     @Override
 314  
     public String toString() {
 315  0
         return ToStringBuilder.reflectionToString(this);
 316  
     }
 317  
 
 318  
     /**
 319  
      * Defines some internal constants used on this class.
 320  
      */
 321  0
     static class Constants {
 322  
         final static String ROOT_ELEMENT_NAME = "groupMember";
 323  
         final static String TYPE_NAME = "GroupMemberType";
 324  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
 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 ID = "id";
 333  
         final static String GROUP_ID = "groupId";
 334  
         final static String MEMBER_ID = "memberId";
 335  
         final static String TYPE_CODE = "typeCode";
 336  
     }
 337  
 }