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