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