Coverage Report - org.kuali.rice.krms.api.repository.term.TermParameterDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
TermParameterDefinition
72%
18/25
50%
1/2
1.4
TermParameterDefinition$1
N/A
N/A
1.4
TermParameterDefinition$Builder
76%
26/34
50%
5/10
1.4
TermParameterDefinition$Builder$1
50%
1/2
N/A
1.4
TermParameterDefinition$Constants
50%
1/2
N/A
1.4
TermParameterDefinition$Elements
0%
0/1
N/A
1.4
 
 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.krms.api.repository.term;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Collection;
 20  
 
 21  
 import javax.xml.bind.annotation.XmlAccessType;
 22  
 import javax.xml.bind.annotation.XmlAccessorType;
 23  
 import javax.xml.bind.annotation.XmlAnyElement;
 24  
 import javax.xml.bind.annotation.XmlElement;
 25  
 import javax.xml.bind.annotation.XmlRootElement;
 26  
 import javax.xml.bind.annotation.XmlType;
 27  
 
 28  
 import org.apache.commons.lang.StringUtils;
 29  
 import org.apache.commons.lang.builder.EqualsBuilder;
 30  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 31  
 import org.apache.commons.lang.builder.ToStringBuilder;
 32  
 import org.kuali.rice.core.api.CoreConstants;
 33  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 34  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 35  
 import org.kuali.rice.krms.api.repository.BuilderUtils.Transformer;
 36  
 import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
 37  
 import org.kuali.rice.krms.api.repository.rule.RuleDefinition.Constants;
 38  
 
 39  
 /**
 40  
  * Immutable DTO for TermParameters.  An instance represents a single parameter on a Term. 
 41  
  * Construction must be done via the {@link Builder} inner class.
 42  
  * 
 43  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 44  
  *
 45  
  */
 46  
 @XmlRootElement(name = TermParameterDefinition.Constants.ROOT_ELEMENT_NAME)
 47  
 @XmlAccessorType(XmlAccessType.NONE)
 48  
 @XmlType(name = TermParameterDefinition.Constants.TYPE_NAME, propOrder = {
 49  
                 TermParameterDefinition.Elements.ID,
 50  
                 TermParameterDefinition.Elements.NAME,
 51  
                 TermParameterDefinition.Elements.VALUE,
 52  
         CoreConstants.CommonElements.VERSION_NUMBER,
 53  
                 CoreConstants.CommonElements.FUTURE_ELEMENTS
 54  
 })
 55  1
 public final class TermParameterDefinition implements TermParameterDefinitionContract, ModelObjectComplete {
 56  
 
 57  
         private static final long serialVersionUID = 1L;
 58  
         
 59  
         @XmlElement(name = Elements.ID, required=true)
 60  
         private final String id;
 61  
         
 62  
         private final String termId;
 63  
 
 64  
         @XmlElement(name = Elements.NAME, required=true)
 65  
         private final String name;
 66  
         
 67  
         @XmlElement(name = Elements.VALUE)
 68  
         private final String value;
 69  
         
 70  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 71  
     private final Long versionNumber;
 72  
 
 73  3
     @SuppressWarnings("unused")
 74  
     @XmlAnyElement
 75  
     private final Collection<org.w3c.dom.Element> _futureElements = null;
 76  
         
 77  
         // For JAXB use only, shouldn't be invoked directly
 78  2
         private TermParameterDefinition() {
 79  2
                 id = null;
 80  2
                 termId = null;
 81  2
                 name = null;
 82  2
                 value = null;
 83  2
         versionNumber = null;
 84  2
         }
 85  
         
 86  1
         private TermParameterDefinition(Builder builder) {
 87  1
                 id = builder.getId(); 
 88  1
                 termId = builder.getTermId();
 89  1
                 name = builder.getName();
 90  1
                 value = builder.getValue();
 91  1
                 versionNumber = builder.getVersionNumber();
 92  1
         }
 93  
         
 94  1
         public static class Builder implements TermParameterDefinitionContract, ModelBuilder, Serializable {
 95  
 
 96  
                 private static final long serialVersionUID = 1L;
 97  
                 
 98  
                 private String id;
 99  
                 private String termId;
 100  
                 private String name;
 101  
                 private String value;
 102  
         private Long versionNumber;
 103  
                 
 104  
                 private static final String NON_NULL_NON_EMPTY_ERROR =  
 105  
                         " must be non-null and must contain non-whitespace chars";
 106  
                 
 107  1
                 public static final Transformer<TermParameterDefinitionContract, TermParameterDefinition.Builder> toBuilder = 
 108  1
                         new Transformer<TermParameterDefinitionContract, TermParameterDefinition.Builder>() {
 109  
                         public Builder transform(TermParameterDefinitionContract input) {
 110  0
                                 return Builder.create(input);
 111  
                         };
 112  
                 };
 113  
                 
 114  1
                 private Builder(String id, String termId, String name, String value) {
 115  1
                         setId(id);
 116  1
                         setTermId(termId);
 117  1
                         setName(name);
 118  1
                         setValue(value);
 119  1
                 }
 120  
                 
 121  
                 /**
 122  
                  * static factory to create a {@link Builder} from fields
 123  
                  * 
 124  
                  * @param id must be null, or contain non-whitespace
 125  
                  * @param termId must be null, or contain non-whitespace
 126  
                  * @param name must be non-null
 127  
                  * @param value
 128  
                  */
 129  
                 public static Builder create(String id, String termId, String name, String value) {
 130  1
                         return new Builder(id, termId, name, value);
 131  
                 }
 132  
                 
 133  
                 /**
 134  
                  * static factory to create a {@link Builder} from a {@link TermParameterDefinitionContract} 
 135  
                  * 
 136  
                  * @param termParameterDefinition
 137  
                  */
 138  
                 public static Builder create(TermParameterDefinitionContract termParameterDefinition) {
 139  0
                         Builder builder = new Builder(termParameterDefinition.getId(), 
 140  
                                         termParameterDefinition.getTermId(),
 141  
                                         termParameterDefinition.getName(), 
 142  
                                         termParameterDefinition.getValue());
 143  0
                         builder.setVersionNumber(termParameterDefinition.getVersionNumber());
 144  0
                         return builder;
 145  
                 }
 146  
                 
 147  
                 // Setters:
 148  
                 
 149  
                 /**
 150  
                  * @param id the id to set.  for {@link TermParameterDefinition}s used in creational 
 151  
                  * service methods, it must be null.  Otherwise, it must be non-null and contain non-whitespace chars.
 152  
                  * @throws IllegalArgumentException if id is all whitespace chars
 153  
                  */
 154  
                 public void setId(String id) {
 155  1
                         if (id != null && StringUtils.isBlank(id)) {
 156  0
                                 throw new IllegalArgumentException("id must contain non-whitespace chars");
 157  
                         }
 158  1
                         this.id = id;
 159  1
                 }
 160  
                 
 161  
                 /**
 162  
                  * @param termId the termId to set
 163  
                  */
 164  
                 public void setTermId(String termId) {
 165  1
                         if (termId != null && StringUtils.isBlank(termId)) {
 166  0
                                 throw new IllegalArgumentException("termId must contain non-whitespace chars");
 167  
                         }
 168  1
                         this.termId = termId;
 169  1
                 }
 170  
                 
 171  
                 /**
 172  
                  * @param name the name to set.  Must be non-null and contain non-whitespace chars.
 173  
                  * @throws IllegalArgumentException if name is null or is all whitespace chars
 174  
                  */
 175  
                 public void setName(String name) {
 176  1
                         if (StringUtils.isBlank(name)) {
 177  0
                                 throw new IllegalArgumentException("name" + NON_NULL_NON_EMPTY_ERROR);
 178  
                         }
 179  1
                         this.name = name;
 180  1
                 }
 181  
                 
 182  
                 /**
 183  
                  * @param value the value to set.  May be null or empty.
 184  
                  */
 185  
                 public void setValue(String value) {
 186  1
                         this.value = value;
 187  1
                 }
 188  
                 
 189  
                 /**
 190  
                  * @param versionNumber the versionNumber to set.  May be null.
 191  
                  */
 192  
         public void setVersionNumber(Long versionNumber){
 193  0
             this.versionNumber = versionNumber;
 194  0
         }
 195  
         
 196  
                 // Getters:
 197  
                 
 198  
                 /**
 199  
                  * @return the id
 200  
                  */
 201  
                 @Override
 202  
                 public String getId() {
 203  1
                         return this.id;
 204  
                 }
 205  
                 
 206  
                 /**
 207  
                  * @return the termId
 208  
                  */
 209  
                 @Override
 210  
                 public String getTermId() {
 211  1
                         return this.termId;
 212  
                 }
 213  
                 
 214  
                 /**
 215  
                  * @return the name
 216  
                  */
 217  
                 @Override
 218  
                 public String getName() {
 219  1
                         return this.name;
 220  
                 }
 221  
                 
 222  
                 /**
 223  
                  * @return the value
 224  
                  */
 225  
                 @Override
 226  
                 public String getValue() {
 227  1
                         return this.value;
 228  
                 }                
 229  
                 
 230  
                 /**
 231  
                  * @return the version number
 232  
                  */
 233  
         @Override
 234  
         public Long getVersionNumber() {
 235  1
             return this.versionNumber;
 236  
         }
 237  
 
 238  
                 /**
 239  
                  * return a {@link TermParameterDefinition} instance constructed from this {@link Builder} 
 240  
                  * @see org.kuali.rice.core.api.mo.ModelBuilder#build()
 241  
                  */
 242  
                 @Override
 243  
                 public TermParameterDefinition build() {
 244  1
                         return new TermParameterDefinition(this);
 245  
                 }
 246  
                 
 247  
         }
 248  
         
 249  
         
 250  
         /**
 251  
          * @return the id
 252  
          */
 253  
         @Override
 254  
         public String getId() {
 255  0
                 return this.id;
 256  
         }
 257  
         /**
 258  
          * @return the termId
 259  
          */
 260  
         @Override
 261  
         public String getTermId() {
 262  0
                 return termId;
 263  
         }
 264  
         /**
 265  
          * @return the name
 266  
          */
 267  
         @Override
 268  
         public String getName() {
 269  0
                 return this.name;
 270  
         }
 271  
         /**
 272  
          * @return the value
 273  
          */
 274  
         @Override
 275  
         public String getValue() {
 276  0
                 return this.value;
 277  
         }
 278  
         
 279  
         /**
 280  
          * @see org.kuali.rice.core.api.mo.common.Versioned#getVersionNumber()
 281  
          */
 282  
     @Override
 283  
     public Long getVersionNumber() {
 284  0
         return versionNumber;
 285  
     }
 286  
     
 287  
         /**
 288  
          * @see java.lang.Object#equals(java.lang.Object)
 289  
          */
 290  
         @Override
 291  
         public boolean equals(Object obj) {
 292  1
                 if (obj == null) return false;
 293  1
                 return EqualsBuilder.reflectionEquals(this, obj, Constants.HASH_CODE_EQUALS_EXCLUDE);
 294  
         }
 295  
         
 296  
         /**
 297  
          * @see java.lang.Object#hashCode()
 298  
          */
 299  
         @Override
 300  
         public int hashCode() {
 301  0
                 return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 302  
         }
 303  
         
 304  
         /**
 305  
          * @see java.lang.Object#toString()
 306  
          */
 307  
         @Override
 308  
         public String toString() {
 309  0
                 return ToStringBuilder.reflectionToString(this);
 310  
         }
 311  
         
 312  0
         public static class Constants {
 313  
                 public static final String ROOT_ELEMENT_NAME = "TermParameterDefinition";
 314  
                 public static final String TYPE_NAME = "TermParameterDefinitionType";
 315  1
                 final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS };
 316  
         }
 317  
         
 318  0
         public static class Elements {
 319  
                 public static final String ID = "id";
 320  
                 public static final String TERM_ID = "termId";
 321  
                 public static final String NAME = "name";
 322  
                 public static final String VALUE = "value";
 323  
         }
 324  
 }