Coverage Report - org.kuali.rice.krms.api.repository.proposition.PropositionParameter
 
Classes in this File Line Coverage Branch Coverage Complexity
PropositionParameter
95%
23/24
N/A
1.84
PropositionParameter$1
N/A
N/A
1.84
PropositionParameter$Builder
88%
45/51
73%
19/26
1.84
PropositionParameter$Constants
0%
0/1
N/A
1.84
PropositionParameter$Elements
0%
0/1
N/A
1.84
 
 1  
 package org.kuali.rice.krms.api.repository.proposition;
 2  
 
 3  
 import java.io.Serializable;
 4  
 import java.util.Collection;
 5  
 
 6  
 import javax.xml.bind.annotation.XmlAccessType;
 7  
 import javax.xml.bind.annotation.XmlAccessorType;
 8  
 import javax.xml.bind.annotation.XmlAnyElement;
 9  
 import javax.xml.bind.annotation.XmlElement;
 10  
 import javax.xml.bind.annotation.XmlRootElement;
 11  
 import javax.xml.bind.annotation.XmlType;
 12  
 
 13  
 import org.apache.commons.lang.StringUtils;
 14  
 import org.kuali.rice.core.api.CoreConstants;
 15  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 16  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 17  
 
 18  
 /**
 19  
  * Concrete model object implementation of KRMS Proposition Parameter 
 20  
  * immutable. 
 21  
  * Instances of PropositionParameter can be (un)marshalled to and from XML.
 22  
  *
 23  
  * @see PropositionParameterContract
 24  
  */
 25  
 @XmlRootElement(name = PropositionParameter.Constants.ROOT_ELEMENT_NAME)
 26  
 @XmlAccessorType(XmlAccessType.NONE)
 27  
 @XmlType(name = PropositionParameter.Constants.TYPE_NAME, propOrder = {
 28  
                 PropositionParameter.Elements.ID,
 29  
                 PropositionParameter.Elements.PROP_ID,
 30  
                 PropositionParameter.Elements.VALUE,
 31  
                 PropositionParameter.Elements.PARM_TYPE,
 32  
                 PropositionParameter.Elements.SEQUENCE,
 33  
         CoreConstants.CommonElements.VERSION_NUMBER,
 34  
                 CoreConstants.CommonElements.FUTURE_ELEMENTS
 35  
 })
 36  41
 public final class PropositionParameter extends AbstractDataTransferObject implements PropositionParameterContract {
 37  
         private static final long serialVersionUID = 2783959459503209577L;
 38  
 
 39  
         @XmlElement(name = Elements.ID, required=true)
 40  
         private String id;
 41  
         @XmlElement(name = Elements.PROP_ID, required=true)
 42  
         private String propId;
 43  
         @XmlElement(name = Elements.VALUE, required=true)
 44  
         private String value;
 45  
         @XmlElement(name = Elements.PARM_TYPE, required=true)
 46  
         private String parameterType;
 47  
         @XmlElement(name = Elements.SEQUENCE, required=true)
 48  
         private Integer sequenceNumber;
 49  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 50  
     private final Long versionNumber;
 51  
         
 52  98
         @SuppressWarnings("unused")
 53  
     @XmlAnyElement
 54  
     private final Collection<org.w3c.dom.Element> _futureElements = null;
 55  
         
 56  
          /** 
 57  
      * This constructor should never be called.  
 58  
      * It is only present for use during JAXB unmarshalling. 
 59  
      */
 60  57
     private PropositionParameter() {
 61  57
             this.id = null;
 62  57
             this.propId = null;
 63  57
             this.value = null;
 64  57
             this.parameterType = null;
 65  57
             this.sequenceNumber = null;
 66  57
         this.versionNumber = null;
 67  57
     }
 68  
     
 69  
     /**
 70  
          * Constructs a PropositionParameter from the given builder.  
 71  
          * This constructor is private and should only ever be invoked from the builder.
 72  
          * 
 73  
          * @param builder the Builder from which to construct the PropositionParameter
 74  
          */
 75  41
     private PropositionParameter(Builder builder) {
 76  41
         this.id = builder.getId();
 77  41
         this.propId = builder.getPropId();
 78  41
         this.value = builder.getValue();
 79  41
         this.parameterType = builder.getParameterType();
 80  41
         this.sequenceNumber = builder.getSequenceNumber();
 81  41
         this.versionNumber = builder.getVersionNumber();
 82  41
     }
 83  
     
 84  
         @Override
 85  
         public String getId() {
 86  1
                 return this.id;
 87  
         }
 88  
         
 89  
         @Override
 90  
         public String getPropId() {
 91  1
                 return this.propId;
 92  
         }
 93  
 
 94  
         @Override
 95  
         public String getValue() {
 96  1
                 return this.value;
 97  
         }
 98  
 
 99  
         @Override
 100  
         public String getParameterType() {
 101  1
                 return this.parameterType;
 102  
         }
 103  
         @Override
 104  
         public Integer getSequenceNumber() {
 105  1
                 return this.sequenceNumber; 
 106  
         }
 107  
 
 108  
     @Override
 109  
     public Long getVersionNumber() {
 110  0
         return versionNumber;
 111  
     }
 112  
         
 113  
         /**
 114  
      * This builder is used to construct instances of PropositionParameter.  
 115  
      * It enforces the constraints of the {@link PropositionParameterContract}.
 116  
      */
 117  5
     public static class Builder implements PropositionParameterContract, ModelBuilder, Serializable {
 118  
             private static final long serialVersionUID = -6889320709850568900L;
 119  
                 
 120  
                 private String id;
 121  
         private String propId;
 122  
         private String value;
 123  
         private String parameterType;
 124  
         private Integer sequenceNumber;
 125  
         private Long versionNumber;
 126  
         private PropositionDefinition.Builder proposition;
 127  
 
 128  
                 /**
 129  
                  * Private constructor for creating a builder with all of it's required attributes.
 130  
                  */
 131  54
         private Builder(String id, String propId, String value, String parameterType, Integer sequenceNumber) {
 132  54
             setId(id);
 133  52
             setPropId(propId);
 134  50
             setValue(value);
 135  46
             setParameterType(parameterType);
 136  42
                         setSequenceNumber(sequenceNumber);
 137  41
         }
 138  
 
 139  
         public static Builder create(String id, String propId, String value, String parameterType, Integer sequenceNumber) {
 140  18
                 return new Builder(id, propId, value, parameterType, sequenceNumber);
 141  
         }
 142  
 
 143  
         /**
 144  
          * Creates a builder by populating it with data from the given {@link PropositionParameterContract}.
 145  
          * 
 146  
          * @param contract the contract from which to populate this builder
 147  
          * @return an instance of the builder populated with data from the contract
 148  
          */
 149  
         public static Builder create(PropositionParameterContract contract) {
 150  36
                 if (contract == null) {
 151  0
                 throw new IllegalArgumentException("contract is null");
 152  
             }
 153  36
             Builder builder =  new Builder(contract.getId(), contract.getPropId(), contract.getValue(), contract.getParameterType(), contract.getSequenceNumber());
 154  36
             builder.setVersionNumber(contract.getVersionNumber());
 155  36
             return builder;
 156  
         }
 157  
 
 158  
                 /**
 159  
                  * Sets the value of the id on this builder to the given value.
 160  
                  * 
 161  
                  * @param id the id value to set, must not be null or blank
 162  
                  * @throws IllegalArgumentException if the id is null or blank
 163  
                  */
 164  
         public void setId(String id) {
 165  54
             if (id != null && StringUtils.isBlank(id)) {
 166  2
                 throw new IllegalArgumentException("id is blank");
 167  
             }
 168  52
             this.id = id;
 169  52
         }
 170  
 
 171  
                 public void setPropId(String propId) {
 172  
                     // have to be able to create it with a null propId for chicken/egg reasons.
 173  52
             if (null != propId && StringUtils.isBlank(propId)) {
 174  2
                 throw new IllegalArgumentException("propId must be null or non-blank");
 175  
             }
 176  50
                         this.propId = propId;
 177  50
                 }
 178  
 
 179  
                 public void setValue(String value) {
 180  
                         // TODO:  isBlank  or is null ???
 181  50
             if (StringUtils.isBlank(value)) {
 182  4
                 throw new IllegalArgumentException("value is blank");
 183  
             }
 184  46
                         this.value = value;
 185  46
                 }
 186  
                 
 187  
                 public void setParameterType(String parameterType) {
 188  46
                         if (StringUtils.isBlank(parameterType)){
 189  3
                         throw new IllegalArgumentException("parameter type is null or blank");
 190  
                         }
 191  43
                         if (!PropositionParameterType.VALID_TYPE_CODES.contains(parameterType)){
 192  1
                 throw new IllegalArgumentException("parameter type is invalid");                                
 193  
                         }
 194  
                         // TODO: check against valid values
 195  42
                         this.parameterType = parameterType;
 196  42
                 }
 197  
                 
 198  
                 public void setSequenceNumber(Integer sequenceNumber) {
 199  42
                         if (sequenceNumber == null) {
 200  1
                 throw new IllegalArgumentException("parameter type is blank");                                
 201  
                         }
 202  41
                         this.sequenceNumber = sequenceNumber;
 203  41
                 }
 204  
                 
 205  
                 public void setProposition(PropositionDefinition.Builder proposition) {
 206  0
                     if (proposition != null && !StringUtils.isBlank(proposition.getId())) {
 207  0
                         setPropId(proposition.getId());
 208  
                     }
 209  0
                     this.proposition = proposition;
 210  0
                 }
 211  
 
 212  
         public void setVersionNumber(Long versionNumber){
 213  36
             this.versionNumber = versionNumber;
 214  36
         }
 215  
         
 216  
                 @Override
 217  
                 public String getId() {
 218  65
                         return id;
 219  
                 }
 220  
 
 221  
                 @Override
 222  
                 public String getPropId() {
 223  65
                         return propId;
 224  
                 }
 225  
 
 226  
                 @Override
 227  
                 public String getValue() {
 228  65
                         return value;
 229  
                 }
 230  
 
 231  
                 @Override
 232  
                 public String getParameterType() {
 233  65
                         return parameterType;
 234  
                 }
 235  
 
 236  
                 @Override
 237  
                 public Integer getSequenceNumber() {
 238  65
                         return sequenceNumber;
 239  
                 }
 240  
 
 241  
         @Override
 242  
         public Long getVersionNumber() {
 243  65
             return versionNumber;
 244  
         }
 245  
 
 246  
                 /**
 247  
                  * Builds an instance of a PropositionParameter based on the current state of the builder.
 248  
                  * 
 249  
                  * @return the fully-constructed PropositionParameter
 250  
                  */
 251  
         @Override
 252  
         public PropositionParameter build() {
 253  41
             if (proposition == null && StringUtils.isBlank(propId)) {
 254  0
                 throw new IllegalStateException("either proposition must be non-null or propId must be non-blank");
 255  
             }
 256  41
             return new PropositionParameter(this);
 257  
         }
 258  
                 
 259  
     }
 260  
         
 261  
         /**
 262  
          * Defines some internal constants used on this class.
 263  
          */
 264  0
         static class Constants {
 265  
                 final static String ROOT_ELEMENT_NAME = "PropositionParameter";
 266  
                 final static String TYPE_NAME = "PropositionParameterType";
 267  
         }
 268  
         
 269  
         /**
 270  
          * A private class which exposes constants which define the XML element names to use
 271  
          * when this object is marshalled to XML.
 272  
          */
 273  0
         public static class Elements {
 274  
                 final static String ID = "id";
 275  
                 final static String PROP_ID = "propId";
 276  
                 final static String VALUE = "value";
 277  
                 final static String PARM_TYPE = "parameterType";
 278  
                 final static String SEQUENCE = "sequenceNumber";
 279  
         }
 280  
 
 281  
 }