Coverage Report - org.kuali.rice.krms.api.repository.type.KrmsTypeAttribute
 
Classes in this File Line Coverage Branch Coverage Complexity
KrmsTypeAttribute
100%
26/26
100%
2/2
1.56
KrmsTypeAttribute$1
N/A
N/A
1.56
KrmsTypeAttribute$Builder
84%
38/45
75%
12/16
1.56
KrmsTypeAttribute$Constants
0%
0/1
N/A
1.56
KrmsTypeAttribute$Elements
0%
0/1
N/A
1.56
 
 1  
 package org.kuali.rice.krms.api.repository.type;
 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 KrmsTypeAttribute. 
 20  
  * immutable. 
 21  
  * Instances of KrmsTypeAttribute can be (un)marshalled to and from XML.
 22  
  *
 23  
  */
 24  1
 @XmlRootElement(name = KrmsTypeAttribute.Constants.ROOT_ELEMENT_NAME)
 25  
 @XmlAccessorType(XmlAccessType.NONE)
 26  
 @XmlType(name = KrmsTypeAttribute.Constants.TYPE_NAME, propOrder = {
 27  
                 KrmsTypeAttribute.Elements.ID,
 28  
                 KrmsTypeAttribute.Elements.TYPE_ID,
 29  
                 KrmsTypeAttribute.Elements.ATTR_DEFN_ID,
 30  
                 KrmsTypeAttribute.Elements.SEQ_NO,
 31  
                 KrmsTypeAttribute.Elements.ACTIVE,
 32  
                 KrmsTypeAttribute.Elements.ATTR_DEFN,
 33  
                 CoreConstants.CommonElements.FUTURE_ELEMENTS
 34  
 })
 35  9
 public final class KrmsTypeAttribute extends AbstractDataTransferObject implements KrmsTypeAttributeContract {
 36  
         private static final long serialVersionUID = -304265575559412478L;
 37  
         
 38  
         @XmlElement(name = Elements.ID, required=true)
 39  
         private String id;
 40  
         @XmlElement(name = Elements.TYPE_ID, required=true)
 41  
         private String typeId;
 42  
         @XmlElement(name = Elements.ATTR_DEFN_ID, required=true)
 43  
         private String attributeDefinitionId;
 44  
         @XmlElement(name = Elements.SEQ_NO, required=true)
 45  
         private Integer sequenceNumber;
 46  
         @XmlElement(name = Elements.ACTIVE, required=false)
 47  
         private boolean active;
 48  
         @XmlElement(name = Elements.ATTR_DEFN, required=false)
 49  
         private KrmsAttributeDefinition attributeDefinition;
 50  
         
 51  20
         @SuppressWarnings("unused")
 52  
     @XmlAnyElement
 53  
     private final Collection<org.w3c.dom.Element> _futureElements = null;
 54  
         
 55  
          /** 
 56  
      * This constructor should never be called.  It is only present for use during JAXB unmarshalling. 
 57  
      */
 58  11
     private KrmsTypeAttribute() {
 59  11
             this.id = null;
 60  11
             this.typeId = null;
 61  11
             this.attributeDefinitionId = null;
 62  11
             this.sequenceNumber = null;
 63  11
             this.active = false;
 64  11
             this.attributeDefinition = null;
 65  11
     }
 66  
     
 67  
     /**
 68  
          * Constructs a KRMS KrmsTypeAttribute from the given builder.  
 69  
          * This constructor is private and should only ever be invoked from the builder.
 70  
          * 
 71  
          * @param builder the Builder from which to construct the KrmsTypeAttribute
 72  
          */
 73  9
     private KrmsTypeAttribute(Builder builder) {
 74  9
         this.id = builder.getId();
 75  9
         this.typeId = builder.getTypeId();
 76  9
         this.attributeDefinitionId = builder.getAttributeDefinitionId();
 77  9
         this.sequenceNumber = builder.getSequenceNumber();
 78  9
         this.active = builder.isActive();
 79  9
         if (builder.getAttributeDefinition() != null) {
 80  2
                 this.attributeDefinition = builder.getAttributeDefinition().build();
 81  
         }
 82  9
     }
 83  
     
 84  
         public String getId() {
 85  3
                 return this.id;
 86  
         }
 87  
         
 88  
         public String getTypeId() {
 89  3
                 return this.typeId;
 90  
         }
 91  
 
 92  
         public String getAttributeDefinitionId() {
 93  3
                 return this.attributeDefinitionId;
 94  
         }
 95  
 
 96  
         public Integer getSequenceNumber() {
 97  3
                 return this.sequenceNumber;
 98  
         }
 99  
         
 100  
         public boolean isActive() {
 101  4
                 return this.active; 
 102  
         }
 103  
 
 104  
         public KrmsAttributeDefinition getAttributeDefinition() {
 105  1
                 return this.attributeDefinition;
 106  
         }
 107  
         
 108  
         /**
 109  
      * This builder is used to construct instances of KrmsTypeAttribute.  
 110  
      */
 111  5
     public static class Builder implements KrmsTypeAttributeContract, ModelBuilder, Serializable {
 112  
                 private static final long serialVersionUID = 2729964674427296346L;
 113  
 
 114  
                 private String id;
 115  
         private String typeId;
 116  
         private String attributeDefinitionId;
 117  
         private Integer sequenceNumber;
 118  
         private boolean active;
 119  
         private KrmsAttributeDefinition.Builder attributeDefinition;
 120  
 
 121  
                 /**
 122  
                  * Private constructor for creating a builder with all of it's required attributes.
 123  
                  */
 124  21
         private Builder(String id, String typeId, String attributeDefinitionId, Integer sequenceNumber) {
 125  21
             setId(id);
 126  19
             setTypeId(typeId);
 127  17
             setAttributeDefinitionId(attributeDefinitionId);
 128  13
             setSequenceNumber(sequenceNumber);
 129  12
                         setActive(true);
 130  12
         }
 131  
 
 132  
         public Builder attributeDefinition(KrmsAttributeDefinition.Builder attributeDefinition){
 133  2
                 setAttributeDefinition(attributeDefinition);
 134  2
                 return this;
 135  
         }
 136  
         
 137  
         /**
 138  
          * Creates a builder from the given parameters.
 139  
          * 
 140  
          * @param id the KrmsTypeAtribute id
 141  
          * @param typeId the KrmsType Id 
 142  
          * @param attributeDefinitionId The attributeDefinitionId
 143  
          * @param sequenceNumber 
 144  
          * @return an instance of the builder with the fields already populated
 145  
          * @throws IllegalArgumentException if the either the id, name or namespace is null or blank
 146  
          */
 147  
         public static Builder create(String id, String typeId, String attributeDefinitionId, Integer sequenceNumber) {
 148  21
             return new Builder(id, typeId, attributeDefinitionId, sequenceNumber);
 149  
         }
 150  
         
 151  
         public static Builder create(KrmsTypeAttributeContract contract){
 152  0
                 if (contract == null) {
 153  0
                 throw new IllegalArgumentException("contract is null");
 154  
             }
 155  0
                 Builder builder = new Builder(contract.getId(), 
 156  
                                 contract.getTypeId(),
 157  
                                 contract.getAttributeDefinitionId(),
 158  
                                 contract.getSequenceNumber());
 159  0
                 if (contract.getAttributeDefinition() != null){
 160  0
                         KrmsAttributeDefinition.Builder attrBuilder = 
 161  
                                 KrmsAttributeDefinition.Builder.create(contract.getAttributeDefinition());
 162  0
                         builder.setAttributeDefinition(attrBuilder);
 163  
                 }
 164  0
                 return builder;
 165  
         }
 166  
 
 167  
                 /**
 168  
                  * Sets the value of the id on this builder to the given value.
 169  
                  * 
 170  
                  * @param id the id value to set, must  be null or non-blank
 171  
                  * @throws IllegalArgumentException if the id is not null and blank
 172  
                  */
 173  
         public void setId(String id) {
 174  21
             if (null != id && StringUtils.isBlank(id)) {
 175  2
                 throw new IllegalArgumentException("id must be null or non-blank");
 176  
             }
 177  19
             this.id = id;
 178  19
         }
 179  
 
 180  
                 public void setTypeId(String typeId) {
 181  19
             if (null != typeId && StringUtils.isBlank(typeId)) {
 182  2
                 throw new IllegalArgumentException("typeId must be null or non-blank");
 183  
             }
 184  17
                         this.typeId = typeId;
 185  17
                 }
 186  
 
 187  
                 public void setAttributeDefinitionId(String attributeDefinitionId) {
 188  17
             if (StringUtils.isBlank(attributeDefinitionId)) {
 189  4
                 throw new IllegalArgumentException("the attribute definition id is blank");
 190  
             }
 191  13
                         this.attributeDefinitionId = attributeDefinitionId;
 192  13
                 }
 193  
                 
 194  
                 public void setSequenceNumber(Integer sequenceNumber) {
 195  13
                         if (sequenceNumber == null){
 196  1
                                  throw new IllegalArgumentException("the sequence number is null");
 197  
                         }
 198  12
                         this.sequenceNumber = sequenceNumber;
 199  12
                 }
 200  
                 
 201  
                 public void setAttributeDefinition(KrmsAttributeDefinition.Builder attributeDefinition) {
 202  2
                         this.attributeDefinition = attributeDefinition;
 203  
                         //TODO: verify that the attributeDefinitionID field matches the id field in the builder
 204  2
                 }
 205  
                 
 206  
                 public void setActive(boolean active) {
 207  12
                         this.active = active;
 208  12
                 }
 209  
 
 210  
                 public String getId() {
 211  9
                         return id;
 212  
                 }
 213  
 
 214  
                 public String getTypeId() {
 215  9
                         return typeId;
 216  
                 }
 217  
 
 218  
                 public String getAttributeDefinitionId() {
 219  9
                         return attributeDefinitionId;
 220  
                 }
 221  
                 
 222  
                 public Integer getSequenceNumber() {
 223  9
                         return sequenceNumber;
 224  
                 }
 225  
 
 226  
                 public KrmsAttributeDefinition.Builder getAttributeDefinition() {
 227  11
                         return attributeDefinition;
 228  
                 }
 229  
 
 230  
 
 231  
                 public boolean isActive() {
 232  9
                         return active;
 233  
                 }
 234  
 
 235  
                 /**
 236  
                  * Builds an instance of a KrmsTypeAttribute based on the current state of the builder.
 237  
                  * 
 238  
                  * @return the fully-constructed KrmsTypeAttribute
 239  
                  */
 240  
         @Override
 241  
         public KrmsTypeAttribute build() {
 242  9
             return new KrmsTypeAttribute(this);
 243  
         }
 244  
                 
 245  
     }
 246  
 
 247  
         /**
 248  
          * Defines some internal constants used on this class.
 249  
          */
 250  0
         static class Constants {
 251  
                 final static String ROOT_ELEMENT_NAME = "KrmsTypeAttribute";
 252  
                 final static String TYPE_NAME = "KrmsTypeAttributeType";
 253  
         }
 254  
         
 255  
         /**
 256  
          * A private class which exposes constants which define the XML element names to use
 257  
          * when this object is marshalled to XML.
 258  
          */
 259  0
         public static class Elements {
 260  
                 final static String ID = "id";
 261  
                 final static String TYPE_ID = "typeId";
 262  
                 final static String ATTR_DEFN_ID = "attributeDefinitionId";
 263  
                 final static String SEQ_NO = "sequenceNumber";
 264  
                 final static String ACTIVE = "active";
 265  
                 final static String ATTR_DEFN = "attributeDefinition";
 266  
         }
 267  
 }