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