Coverage Report - org.kuali.rice.kim.api.group.Group
 
Classes in this File Line Coverage Branch Coverage Complexity
Group
88%
31/35
50%
1/2
1.333
Group$Builder
89%
49/55
50%
6/12
1.333
Group$Constants
50%
1/2
N/A
1.333
Group$Elements
0%
0/1
N/A
1.333
 
 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 com.google.common.collect.Maps;
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.apache.commons.lang.builder.EqualsBuilder;
 22  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 23  
 import org.apache.commons.lang.builder.ToStringBuilder;
 24  
 import org.kuali.rice.core.api.CoreConstants;
 25  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 26  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 27  
 import org.kuali.rice.core.util.jaxb.MapStringStringAdapter;
 28  
 import org.w3c.dom.Element;
 29  
 
 30  
 import javax.xml.bind.annotation.XmlAccessType;
 31  
 import javax.xml.bind.annotation.XmlAccessorType;
 32  
 import javax.xml.bind.annotation.XmlAnyElement;
 33  
 import javax.xml.bind.annotation.XmlElement;
 34  
 import javax.xml.bind.annotation.XmlRootElement;
 35  
 import javax.xml.bind.annotation.XmlType;
 36  
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 37  
 import java.io.Serializable;
 38  
 import java.util.Collection;
 39  
 import java.util.Collections;
 40  
 import java.util.Map;
 41  
 
 42  
 @XmlRootElement(name = Group.Constants.ROOT_ELEMENT_NAME)
 43  
 @XmlAccessorType(XmlAccessType.NONE)
 44  
 @XmlType(name = Group.Constants.TYPE_NAME, propOrder = {
 45  
         Group.Elements.ID,
 46  
         Group.Elements.NAMESPACE_CODE,
 47  
         Group.Elements.NAME,
 48  
         Group.Elements.DESCRIPTION,
 49  
         Group.Elements.KIM_TYPE_ID,
 50  
         Group.Elements.ATTRIBUTES,
 51  
         Group.Elements.ACTIVE,
 52  
         CoreConstants.CommonElements.VERSION_NUMBER,
 53  
         CoreConstants.CommonElements.OBJECT_ID,
 54  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 55  
 })
 56  
 public final class Group implements GroupContract, ModelObjectComplete {
 57  
     @XmlElement(name = Elements.ID, required = false)
 58  
     private final String id;
 59  
 
 60  
     @XmlElement(name = Elements.NAMESPACE_CODE, required = true)
 61  
     private final String namespaceCode;
 62  
 
 63  
     @XmlElement(name = Elements.NAME, required = true)
 64  
     private final String name;
 65  
 
 66  
     @XmlElement(name = Elements.DESCRIPTION, required = false)
 67  
     private final String description;
 68  
 
 69  
     @XmlElement(name = Elements.KIM_TYPE_ID, required = true)
 70  
     private final String kimTypeId;
 71  
 
 72  
     @XmlElement(name = Elements.ATTRIBUTES, required = false)
 73  
     @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
 74  
     private final Map<String, String> attributes;
 75  
 
 76  
     @XmlElement(name = Elements.ACTIVE, required = false)
 77  
     private final boolean active;
 78  
 
 79  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 80  
     private final Long versionNumber;
 81  
 
 82  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 83  
     private final String objectId;
 84  
 
 85  4
     @SuppressWarnings("unused")
 86  
     @XmlAnyElement
 87  
     private final Collection<Element> _futureElements = null;
 88  
 
 89  3
     private Group() {
 90  3
         this.id = null;
 91  3
         this.namespaceCode = null;
 92  3
         this.name = null;
 93  3
         this.description = null;
 94  3
         this.kimTypeId = null;
 95  3
         this.attributes = null;
 96  3
         this.versionNumber = null;
 97  3
         this.objectId = null;
 98  3
         this.active = false;
 99  3
     }
 100  
 
 101  1
     public Group(Builder builder) {
 102  1
         id = builder.getId();
 103  1
         namespaceCode = builder.getNamespaceCode();
 104  1
         name = builder.getName();
 105  1
         description = builder.getDescription();
 106  1
         kimTypeId = builder.getKimTypeId();
 107  1
         this.attributes = builder.getAttributes() != null ? builder.getAttributes() : Collections.<String, String>emptyMap();
 108  1
         versionNumber = builder.getVersionNumber();
 109  1
         objectId = builder.getObjectId();
 110  1
         active = builder.isActive();
 111  1
     }
 112  
 
 113  
 
 114  
     /**
 115  
      * This builder constructs an Group enforcing the constraints of the {@link org.kuali.rice.kim.api.group.GroupContract}.
 116  
      */
 117  1
     public static class Builder implements GroupContract, ModelBuilder, Serializable {
 118  
         private String id;
 119  
         private String namespaceCode;
 120  
         private String name;
 121  
         private String description;
 122  
         private String kimTypeId;
 123  1
         private Map<String, String> attributes = Collections.emptyMap();
 124  
         private boolean active;
 125  
         private Long versionNumber;
 126  
         private String objectId;
 127  
 
 128  1
         private Builder(String namespaceCode, String name, String kimTypeId) {
 129  1
             setNamespaceCode(namespaceCode);
 130  1
             setName(name);
 131  1
             setKimTypeId(kimTypeId);
 132  1
         }
 133  
 
 134  
         /**
 135  
          * creates a Group with the required fields.
 136  
          */
 137  
         public static Builder create(String namespaceCode, String name, String kimTypeId) {
 138  0
             return new Builder(namespaceCode, name, kimTypeId);
 139  
         }
 140  
 
 141  
         /**
 142  
          * creates a Group from an existing {@link org.kuali.rice.kim.api.group.GroupContract}.
 143  
          */
 144  
         public static Builder create(GroupContract contract) {
 145  1
             if (contract == null) {
 146  0
                 throw new IllegalArgumentException("GroupContract is null");
 147  
             }
 148  1
             Builder builder = new Builder(contract.getNamespaceCode(), contract.getName(), contract.getKimTypeId());
 149  1
             builder.setId(contract.getId());
 150  1
             builder.setDescription(contract.getDescription());
 151  
 
 152  1
             if (contract.getAttributes() != null) {
 153  1
                 builder.setAttributes(contract.getAttributes());
 154  
             }
 155  
 
 156  1
             builder.setActive(contract.isActive());
 157  1
             builder.setVersionNumber(contract.getVersionNumber());
 158  1
             builder.setObjectId(contract.getObjectId());
 159  1
             return builder;
 160  
         }
 161  
 
 162  
         @Override
 163  
         public String getId() {
 164  1
             return id;
 165  
         }
 166  
 
 167  
         public void setId(String id) {
 168  1
             if (StringUtils.isWhitespace(id)) {
 169  0
                 throw new IllegalArgumentException("id is blank");
 170  
             }
 171  1
             this.id = id;
 172  1
         }
 173  
 
 174  
         @Override
 175  
         public String getNamespaceCode() {
 176  1
             return namespaceCode;
 177  
         }
 178  
 
 179  
         public void setNamespaceCode(String namespaceCode) {
 180  1
             if (StringUtils.isEmpty(namespaceCode)) {
 181  0
                 throw new IllegalArgumentException("namespaceCode is empty");
 182  
             }
 183  1
             this.namespaceCode = namespaceCode;
 184  1
         }
 185  
 
 186  
         @Override
 187  
         public String getName() {
 188  1
             return name;
 189  
         }
 190  
 
 191  
         public void setName(String name) {
 192  1
             if (StringUtils.isEmpty(name)) {
 193  0
                 throw new IllegalArgumentException("name is empty");
 194  
             }
 195  1
             this.name = name;
 196  1
         }
 197  
 
 198  
         @Override
 199  
         public String getDescription() {
 200  1
             return description;
 201  
         }
 202  
 
 203  
         public void setDescription(String description) {
 204  1
             this.description = description;
 205  1
         }
 206  
 
 207  
         @Override
 208  
         public String getKimTypeId() {
 209  1
             return kimTypeId;
 210  
         }
 211  
 
 212  
         public void setKimTypeId(String kimTypeId) {
 213  1
             if (StringUtils.isEmpty(kimTypeId)) {
 214  0
                 throw new IllegalArgumentException("kimTypeId is empty");
 215  
             }
 216  1
             this.kimTypeId = kimTypeId;
 217  1
         }
 218  
 
 219  
         @Override
 220  
         public Map<String, String> getAttributes() {
 221  2
             return attributes;
 222  
         }
 223  
 
 224  
         public void setAttributes(Map<String, String> attributes) {
 225  1
             this.attributes = Collections.unmodifiableMap(Maps.newHashMap(attributes));
 226  1
         }
 227  
 
 228  
         @Override
 229  
         public boolean isActive() {
 230  1
             return active;
 231  
         }
 232  
 
 233  
         public void setActive(boolean active) {
 234  1
             this.active = active;
 235  1
         }
 236  
 
 237  
         @Override
 238  
         public Long getVersionNumber() {
 239  1
             return versionNumber;
 240  
         }
 241  
 
 242  
         public void setVersionNumber(Long versionNumber) {
 243  1
             this.versionNumber = versionNumber;
 244  1
         }
 245  
 
 246  
         @Override
 247  
         public String getObjectId() {
 248  1
             return objectId;
 249  
         }
 250  
 
 251  
         public void setObjectId(String objectId) {
 252  1
             this.objectId = objectId;
 253  1
         }
 254  
 
 255  
         @Override
 256  
         public Group build() {
 257  1
             return new Group(this);
 258  
         }
 259  
     }
 260  
 
 261  
     @Override
 262  
     public int hashCode() {
 263  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 264  
     }
 265  
 
 266  
     @Override
 267  
     public boolean equals(Object obj) {
 268  1
         return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 269  
     }
 270  
 
 271  
     @Override
 272  
     public String toString() {
 273  0
         return ToStringBuilder.reflectionToString(this);
 274  
     }
 275  
 
 276  
     @Override
 277  
     public String getId() {
 278  1
         return id;
 279  
     }
 280  
 
 281  
     @Override
 282  
     public String getNamespaceCode() {
 283  1
         return namespaceCode;
 284  
     }
 285  
 
 286  
     @Override
 287  
     public String getName() {
 288  1
         return name;
 289  
     }
 290  
 
 291  
     @Override
 292  
     public String getDescription() {
 293  0
         return description;
 294  
     }
 295  
 
 296  
     @Override
 297  
     public String getKimTypeId() {
 298  0
         return kimTypeId;
 299  
     }
 300  
 
 301  
     @Override
 302  
     public Map<String, String> getAttributes() {
 303  3
         return attributes;
 304  
     }
 305  
 
 306  
     @Override
 307  
     public boolean isActive() {
 308  1
         return active;
 309  
     }
 310  
 
 311  
     @Override
 312  
     public Long getVersionNumber() {
 313  1
         return versionNumber;
 314  
     }
 315  
 
 316  
     @Override
 317  
     public String getObjectId() {
 318  1
         return objectId;
 319  
     }
 320  
 
 321  
     /**
 322  
      * Defines some internal constants used on this class.
 323  
      */
 324  0
     static class Constants {
 325  
         final static String ROOT_ELEMENT_NAME = "group";
 326  
         final static String TYPE_NAME = "GroupType";
 327  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
 328  
     }
 329  
 
 330  
     /**
 331  
      * A private class which exposes constants which define the XML element names to use
 332  
      * when this object is marshalled to XML.
 333  
      */
 334  0
     static class Elements {
 335  
         final static String ID = "id";
 336  
         final static String NAMESPACE_CODE = "namespaceCode";
 337  
         final static String NAME = "name";
 338  
         final static String DESCRIPTION = "description";
 339  
         final static String KIM_TYPE_ID = "kimTypeId";
 340  
         final static String ATTRIBUTES = "attributes";
 341  
         final static String ACTIVE = "active";
 342  
     }
 343  
 }