Coverage Report - org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
TermSpecificationDefinition
87%
29/33
50%
3/6
1.621
TermSpecificationDefinition$1
N/A
N/A
1.621
TermSpecificationDefinition$Builder
73%
33/45
50%
8/16
1.621
TermSpecificationDefinition$Builder$1
50%
1/2
N/A
1.621
TermSpecificationDefinition$Constants
50%
1/2
N/A
1.621
TermSpecificationDefinition$Elements
0%
0/1
N/A
1.621
 
 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.ArrayList;
 20  
 import java.util.Collection;
 21  
 import java.util.Collections;
 22  
 import java.util.List;
 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.XmlElementWrapper;
 29  
 import javax.xml.bind.annotation.XmlRootElement;
 30  
 import javax.xml.bind.annotation.XmlType;
 31  
 
 32  
 import org.apache.commons.lang.StringUtils;
 33  
 import org.apache.commons.lang.builder.EqualsBuilder;
 34  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 35  
 import org.apache.commons.lang.builder.ToStringBuilder;
 36  
 import org.kuali.rice.core.api.CoreConstants;
 37  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 38  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 39  
 import org.kuali.rice.krms.api.repository.BuilderUtils;
 40  
 import org.kuali.rice.krms.api.repository.BuilderUtils.Transformer;
 41  
 import org.kuali.rice.krms.api.repository.category.CategoryDefinition;
 42  
 import org.kuali.rice.krms.api.repository.category.CategoryDefinitionContract;
 43  
 
 44  
 /**
 45  
  * Immutable DTO for TermSpecifications.  Construction must be done via the {@link Builder} inner class.
 46  
  * 
 47  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 48  
  *
 49  
  */
 50  
 @XmlRootElement(name = TermSpecificationDefinition.Constants.ROOT_ELEMENT_NAME)
 51  
 @XmlAccessorType(XmlAccessType.NONE)
 52  
 @XmlType(name = TermSpecificationDefinition.Constants.TYPE_NAME, propOrder = {
 53  
                 TermSpecificationDefinition.Elements.ID,
 54  
                 TermSpecificationDefinition.Elements.CONTEXT_ID,
 55  
                 TermSpecificationDefinition.Elements.NAME,
 56  
                 TermSpecificationDefinition.Elements.TYPE,
 57  
         CoreConstants.CommonElements.VERSION_NUMBER,
 58  
         TermSpecificationDefinition.Elements.CATEGORIES,
 59  
                 CoreConstants.CommonElements.FUTURE_ELEMENTS
 60  
 })
 61  5
 public final class TermSpecificationDefinition implements TermSpecificationDefinitionContract, ModelObjectComplete {
 62  
         
 63  
         private static final long serialVersionUID = 1L;
 64  
         
 65  
         @XmlElement(name = Elements.ID, required=false)
 66  
         private final String id;
 67  
         @XmlElement(name = Elements.CONTEXT_ID, required=true)
 68  
         private final String contextId;
 69  
         @XmlElement(name = Elements.NAME, required=true)
 70  
         private final String name;
 71  
         @XmlElement(name = Elements.TYPE, required=true)
 72  
         private final String type;
 73  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 74  
     private final Long versionNumber;
 75  
 
 76  
     @XmlElementWrapper(name = Elements.CATEGORIES, required = false)
 77  
     @XmlElement(name = Elements.CATEGORY, required = false)
 78  
     private final List<CategoryDefinition> categories;
 79  
 
 80  
         
 81  13
         @SuppressWarnings("unused")
 82  
     @XmlAnyElement
 83  
     private final Collection<org.w3c.dom.Element> _futureElements = null;
 84  
         
 85  
         /**
 86  
          * For JAXB use only, shouldn't ever be invoked directly
 87  
          */
 88  8
         private TermSpecificationDefinition() {
 89  8
                 id = null;
 90  8
                 contextId = null;
 91  8
                 name = null;
 92  8
                 type = null;
 93  8
         versionNumber = null;
 94  8
         this.categories = null;
 95  8
         }
 96  
         
 97  
         /**
 98  
          * Private constructor enforces use of Builder
 99  
          * 
 100  
          * @param b the builder to use
 101  
          */
 102  5
         private TermSpecificationDefinition(Builder b) {
 103  5
                 id = b.getId();
 104  5
                 contextId = b.getContextId();
 105  5
                 name = b.getName();
 106  5
                 type = b.getType();
 107  5
                 versionNumber = b.getVersionNumber();
 108  5
         this.categories = constructCategories(b.getCategories());
 109  5
         }
 110  
 
 111  
     private static List<CategoryDefinition> constructCategories(List<CategoryDefinition.Builder> categoryBuilders) {
 112  5
             List<CategoryDefinition> categories = new ArrayList<CategoryDefinition>();
 113  5
             if (categoryBuilders != null) {
 114  5
                     for (CategoryDefinition.Builder categoryBuilder : categoryBuilders) {
 115  0
                             categories.add(categoryBuilder.build());
 116  
                     }
 117  
             }
 118  5
             return categories;
 119  
     }
 120  
 
 121  
         /**
 122  
          * Builder for the {@link TermSpecificationDefinition} immutable DTO.  Instantiate using static factory method(s).
 123  
          * 
 124  
          * @author Kuali Rice Team (rice.collab@kuali.org)
 125  
          */
 126  3
         public static class Builder implements TermSpecificationDefinitionContract, ModelBuilder, Serializable {
 127  
                 
 128  
                 private static final long serialVersionUID = 1L;
 129  
                 
 130  
                 private String termSpecificationId;
 131  
                 private String contextId;
 132  
                 private String name;
 133  
                 private String type;
 134  
         private Long versionNumber;
 135  
         private List<CategoryDefinition.Builder> categories;
 136  
 
 137  
                 private static final String NON_NULL_NON_EMPTY_ERROR =  " must be non-null and must contain non-whitespace chars"; 
 138  
 
 139  
                 /**
 140  
                  * {@link Transformer} to ease converting lists to Builder types
 141  
                  */
 142  
                 public static final Transformer<TermSpecificationDefinitionContract, TermSpecificationDefinition.Builder>
 143  1
                 toBuilder = new BuilderUtils.Transformer<TermSpecificationDefinitionContract, TermSpecificationDefinition.Builder>() {
 144  
                         public TermSpecificationDefinition.Builder transform(TermSpecificationDefinitionContract input) {
 145  0
                                 return TermSpecificationDefinition.Builder.create(input);
 146  
                         }
 147  
                 };
 148  
                 
 149  8
                 private Builder(String termSpecificationId, String contextId, String name, String type) {
 150  
                         // weird to use setters in constructor .. oh well.
 151  8
                         setId(termSpecificationId);
 152  8
                         setContextId(contextId);
 153  5
                         setName(name);
 154  5
                         setType(type);
 155  5
             setCategories(new ArrayList<CategoryDefinition.Builder>());
 156  5
                 }
 157  
                 
 158  
                 /**
 159  
                  * static factory for a {@link Builder} from a complete set of field values for this object.
 160  
                  * 
 161  
                  * @param termSpecificationId the primary key field.  Must be null for service methods that 
 162  
                  * create {@link TermSpecificationDefinitionContract}s, and must be non-null & contain non-whitespace 
 163  
                  * chars otherwise.
 164  
                  * @param contextId key relates the {@link TermSpecificationDefinition} to a context.
 165  
                  * @param name the name for the {@link TermSpecificationDefinition}.  Must be non-null;.
 166  
                  * @param type the type for the {@link TermSpecificationDefinition}
 167  
                  * @return a {@link Builder} object
 168  
                  * @throws IllegalArgumentException if invalid parameters are supplied.
 169  
                  */
 170  
                 public static Builder create(String termSpecificationId, String contextId, String name, String type) {
 171  8
                         return new Builder(termSpecificationId, contextId, name, type);
 172  
                 }
 173  
                 
 174  
                 /**
 175  
                  * static factory for a {@link Builder} from a {@link TermSpecificationDefinitionContract}.
 176  
                  * 
 177  
                  * @param termSpecification may not be null;
 178  
                  * @throws IllegalArgumentException if termSpecification is null, or violates the field invariants of the {@link Builder}.
 179  
                  */
 180  
                 public static Builder create(TermSpecificationDefinitionContract termSpecification) {
 181  0
                         if (termSpecification == null) throw new IllegalArgumentException("termSpecification must be non-null");
 182  0
                         Builder builder =new Builder(termSpecification.getId(), 
 183  
                                         termSpecification.getContextId(), 
 184  
                                         termSpecification.getName(), 
 185  
                                         termSpecification.getType());
 186  0
                         builder.setVersionNumber(termSpecification.getVersionNumber());
 187  0
             for (CategoryDefinitionContract category : termSpecification.getCategories()) {
 188  0
                 builder.getCategories().add(CategoryDefinition.Builder.create(category));
 189  
             }
 190  
 
 191  0
                         return builder;
 192  
                 }
 193  
                 
 194  
                 // Setters
 195  
                 
 196  
                 /**
 197  
                  * @param termSpecificationId the key for this {@link TermSpecificationDefinition}.  Must be null for
 198  
                  * service methods that create {@link TermSpecificationDefinitionContract}s, and otherwise must be non-null & contain 
 199  
                  * non-whitespace chars.
 200  
                  */
 201  
                 public void setId(String termSpecificationId) {
 202  8
                         if (termSpecificationId != null && StringUtils.isBlank(termSpecificationId))
 203  0
                                 throw new IllegalArgumentException("termSpecificationId must contain non-whitespace chars");
 204  8
                         this.termSpecificationId = termSpecificationId;
 205  8
                 }
 206  
                 
 207  
                 /**
 208  
                  * @param contextId the contextId to set.  Must be non-null and contain non-whitespace chars;
 209  
                  */
 210  
                 public void setContextId(String contextId) {
 211  8
                         if (StringUtils.isBlank(contextId)) {
 212  3
                                 throw new IllegalArgumentException("contextId" + NON_NULL_NON_EMPTY_ERROR);
 213  
                         }
 214  5
                         this.contextId = contextId;
 215  5
                 }
 216  
                 
 217  
                 /**
 218  
                  * @param name the name to set.  Must be non-null and contain non-whitespace chars;
 219  
                  */
 220  
                 public void setName(String name) {
 221  5
                         if (StringUtils.isBlank(name)) {
 222  0
                                 throw new IllegalArgumentException("name" + NON_NULL_NON_EMPTY_ERROR);
 223  
                         }
 224  5
                         this.name = name;
 225  5
                 }
 226  
                 /**
 227  
                  * @param type the type to set. Must be non-null and contain non-whitespace chars;
 228  
                  */
 229  
                 public void setType(String type) {
 230  5
                         if (StringUtils.isBlank(type)) {
 231  0
                                 throw new IllegalArgumentException("type" + NON_NULL_NON_EMPTY_ERROR);
 232  
                         }
 233  5
                         this.type = type;
 234  5
                 }
 235  
                 
 236  
                 /**
 237  
                  * @param versionNumber the versionNumber to set.  May be null.
 238  
                  */
 239  
         public void setVersionNumber(Long versionNumber){
 240  0
             this.versionNumber = versionNumber;
 241  0
         }
 242  
 
 243  
         /**
 244  
          * @param categories the categories to set.  May not be null but can be an empty set.
 245  
          */
 246  
         public void setCategories(List<CategoryDefinition.Builder> categories) {
 247  5
             if (categories == null) {
 248  0
                 throw new IllegalArgumentException("categories was null");
 249  
             }
 250  5
             this.categories = categories;
 251  5
         }
 252  
         
 253  
                 // Getters
 254  
                 
 255  
                 /**
 256  
                  * @return the termSpecificationId
 257  
                  */
 258  
                 @Override
 259  
                 public String getId() {
 260  5
                         return this.termSpecificationId;
 261  
                 }
 262  
 
 263  
                 /**
 264  
                  * @return the contextId
 265  
                  */
 266  
                 @Override
 267  
                 public String getContextId() {
 268  5
                         return this.contextId;
 269  
                 }
 270  
 
 271  
                 /**
 272  
                  * @return the name
 273  
                  */
 274  
                 @Override
 275  
                 public String getName() {
 276  5
                         return this.name;
 277  
                 }
 278  
 
 279  
                 /**
 280  
                  * @return the type
 281  
                  */
 282  
                 @Override
 283  
                 public String getType() {
 284  5
                         return this.type;
 285  
                 }
 286  
 
 287  
                 /**
 288  
                  * @return the version number
 289  
                  */
 290  
         @Override
 291  
         public Long getVersionNumber() {
 292  5
             return this.versionNumber;
 293  
         }
 294  
 
 295  
         /**
 296  
          * @return the categories
 297  
          */
 298  
         @Override
 299  
         public List<CategoryDefinition.Builder> getCategories() {
 300  5
             return this.categories;
 301  
         }
 302  
 
 303  
 
 304  
                 /**
 305  
                  * Constructs a {@link TermSpecificationDefinition}
 306  
                  * @see org.kuali.rice.core.api.mo.ModelBuilder#build()
 307  
                  */
 308  
                 @Override
 309  
                 public TermSpecificationDefinition build() {
 310  5
                         return new TermSpecificationDefinition(this);
 311  
                 }
 312  
         }
 313  
 
 314  
         /**
 315  
          * This value will be non-null for persisted  
 316  
          * @see org.kuali.rice.krms.api.repository.term.TermSpecificationDefinitionContract#getId()
 317  
          */
 318  
         @Override
 319  
         public String getId() {
 320  1
                 return id;
 321  
         }
 322  
 
 323  
         /**
 324  
          * This overridden method ...
 325  
          * 
 326  
          * @see org.kuali.rice.krms.api.repository.term.TermSpecificationDefinitionContract#getContextId()
 327  
          */
 328  
         @Override
 329  
         public String getContextId() {
 330  1
                 return contextId;
 331  
         }
 332  
 
 333  
         /**
 334  
          * @see org.kuali.rice.krms.api.repository.term.TermSpecificationDefinitionContract#getName()
 335  
          */
 336  
         @Override
 337  
         public String getName() {
 338  1
                 return name;
 339  
         }
 340  
 
 341  
         /**
 342  
          * @see org.kuali.rice.krms.api.repository.term.TermSpecificationDefinitionContract#getType()
 343  
          */
 344  
         @Override
 345  
         public String getType() {
 346  1
                 return type;
 347  
         }
 348  
         
 349  
         /**
 350  
          * @see org.kuali.rice.core.api.mo.common.Versioned#getVersionNumber()
 351  
          */
 352  
     @Override
 353  
     public Long getVersionNumber() {
 354  0
         return versionNumber;
 355  
     }
 356  
 
 357  
     /**
 358  
      * @see TermSpecificationDefinitionContract#getCategories()
 359  
      */
 360  
     @Override
 361  
     public List<CategoryDefinition> getCategories() {
 362  0
         return Collections.unmodifiableList(categories);
 363  
     }
 364  
 
 365  
         /**
 366  
         * @see java.lang.Object#equals(java.lang.Object)
 367  
         */
 368  
         @Override
 369  
         public boolean equals(Object obj) {
 370  4
                 if (obj == null) return false;
 371  4
                 return EqualsBuilder.reflectionEquals(this, obj, Constants.HASH_CODE_EQUALS_EXCLUDE);
 372  
         }
 373  
         
 374  
         /**
 375  
         * @see java.lang.Object#hashCode()
 376  
         */
 377  
         @Override
 378  
         public int hashCode() {
 379  4
                 return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 380  
         }
 381  
         
 382  
         /**
 383  
         * @see java.lang.Object#toString()
 384  
         */
 385  
         @Override
 386  
         public String toString() {
 387  0
                 return ToStringBuilder.reflectionToString(this);
 388  
         }
 389  
         
 390  
         /**
 391  
          * Defines some internal constants used on this class.
 392  
          */
 393  0
         static class Constants {
 394  
                 final static String ROOT_ELEMENT_NAME = "TermSpecification";
 395  
                 final static String TYPE_NAME = "TermSpecificationType";
 396  1
                 final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS };
 397  
         }
 398  
         
 399  0
         static class Elements {
 400  
                 public static final String ID = "id";
 401  
                 public static final String CONTEXT_ID = "contextId";
 402  
                 public static final String NAME = "name";
 403  
                 public static final String TYPE = "type";
 404  
         public final static String CATEGORIES = "categories";
 405  
         public final static String CATEGORY = "category";
 406  
         }
 407  
         
 408  
 
 409  
 }