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