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