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