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