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