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