Coverage Report - org.kuali.rice.kew.api.repository.type.KewTypeDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
KewTypeDefinition
0%
0/38
0%
0/12
1.733
KewTypeDefinition$1
N/A
N/A
1.733
KewTypeDefinition$Builder
0%
0/59
0%
0/18
1.733
KewTypeDefinition$Constants
0%
0/1
N/A
1.733
KewTypeDefinition$Elements
0%
0/1
N/A
1.733
 
 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.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.XmlRootElement;
 29  
 import javax.xml.bind.annotation.XmlType;
 30  
 
 31  
 import org.apache.commons.collections.CollectionUtils;
 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  
 
 37  
 /**
 38  
  * Concrete model object implementation of KEW KewType. 
 39  
  * immutable. 
 40  
  * Instances of KewType can be (un)marshalled to and from XML.
 41  
  *
 42  
  * @see KewTypeDefinitionContract
 43  
  */
 44  
 @XmlRootElement(name = KewTypeDefinition.Constants.ROOT_ELEMENT_NAME)
 45  
 @XmlAccessorType(XmlAccessType.NONE)
 46  
 @XmlType(name = KewTypeDefinition.Constants.TYPE_NAME, propOrder = {
 47  
                 KewTypeDefinition.Elements.ID,
 48  
                 KewTypeDefinition.Elements.NAME,
 49  
                 KewTypeDefinition.Elements.NAMESPACE,
 50  
                 KewTypeDefinition.Elements.SERVICENAME,
 51  
                 KewTypeDefinition.Elements.ACTIVE,
 52  
                 KewTypeDefinition.Elements.ATTRIBUTES,
 53  
         CoreConstants.CommonElements.VERSION_NUMBER,
 54  
                 CoreConstants.CommonElements.FUTURE_ELEMENTS
 55  
 })
 56  0
 public final class KewTypeDefinition extends AbstractDataTransferObject implements KewTypeDefinitionContract{
 57  
         private static final long serialVersionUID = -8314397393380856301L;
 58  
 
 59  
         @XmlElement(name = Elements.ID, required=true)
 60  
         private String id;
 61  
         @XmlElement(name = Elements.NAME, required=true)
 62  
         private String name;
 63  
         @XmlElement(name = Elements.NAMESPACE, required=true)
 64  
         private String namespace;
 65  
         @XmlElement(name = Elements.SERVICENAME, required=false)
 66  
         private String serviceName;
 67  
         @XmlElement(name = Elements.ACTIVE, required=false)
 68  
         private boolean active;
 69  
         @XmlElement(name = Elements.ATTRIBUTE, required=false)
 70  
         private List<KewTypeAttribute> attributes;
 71  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 72  
     private final Long versionNumber;
 73  
         
 74  0
         @SuppressWarnings("unused")
 75  
     @XmlAnyElement
 76  
     private final Collection<org.w3c.dom.Element> _futureElements = null;
 77  
         
 78  
          /** 
 79  
      * This constructor should never be called.  It is only present for use during JAXB unmarshalling. 
 80  
      */
 81  0
     private KewTypeDefinition() {
 82  0
             this.id = null;
 83  0
             this.name = null;
 84  0
             this.namespace = null;
 85  0
             this.serviceName = null;
 86  0
             this.active = false;
 87  0
             this.attributes = null;
 88  0
         this.versionNumber = null;
 89  0
     }
 90  
     
 91  
     /**
 92  
          * Constructs a KEW KewType from the given builder.  This constructor is private and should only
 93  
          * ever be invoked from the builder.
 94  
          * 
 95  
          * @param builder the Builder from which to construct the KEW type
 96  
          */
 97  0
     private KewTypeDefinition(Builder builder) {
 98  0
         this.id = builder.getId();
 99  0
         this.name = builder.getName();
 100  0
         this.namespace = builder.getNamespace();
 101  0
         this.serviceName = builder.getServiceName();
 102  0
         this.active = builder.isActive();
 103  0
         List<KewTypeAttribute> attrList = new ArrayList<KewTypeAttribute>();
 104  0
         if (builder.attributes != null){
 105  0
                         for (KewTypeAttribute.Builder b : builder.attributes){
 106  0
                                 attrList.add(b.build());
 107  
                         }
 108  
         }
 109  0
         this.attributes = Collections.unmodifiableList(attrList);
 110  0
         this.versionNumber = builder.getVersionNumber();
 111  0
     }
 112  
     
 113  
         @Override
 114  
         public String getId() {
 115  0
                 return this.id;
 116  
         }
 117  
         
 118  
         @Override
 119  
         public String getName() {
 120  0
                 return this.name;
 121  
         }
 122  
 
 123  
         @Override
 124  
         public String getNamespace() {
 125  0
                 return this.namespace;
 126  
         }
 127  
 
 128  
         @Override
 129  
         public String getServiceName() {
 130  0
                 return this.serviceName;
 131  
         }
 132  
         
 133  
         @Override
 134  
         public boolean isActive() {
 135  0
                 return this.active; 
 136  
         }
 137  
 
 138  
         @Override
 139  
         public List<KewTypeAttribute> getAttributes() {
 140  0
                 return this.attributes; 
 141  
         }
 142  
 
 143  
     @Override
 144  
     public Long getVersionNumber() {
 145  0
         return versionNumber;
 146  
     }
 147  
 
 148  
     /**
 149  
      * Gets the KewTypeAttribute matching the name of it's KewAttribute.  If no attribute definition exists with that
 150  
      * name then null is returned.
 151  
      *
 152  
      * <p>
 153  
      * If multiple exist with the same name then the first match is returned.  Since name
 154  
      * is supposed to be unique this should not be a problem in practice.
 155  
      * </p>
 156  
      *
 157  
      * @param name the KewTypeAttribute's name
 158  
      * @return the KewTypeAttribute or null
 159  
      * @throws IllegalArgumentException if the name is blank
 160  
      */
 161  
         public KewAttributeDefinition getAttributeDefinitionByName(String name) {
 162  0
         if (StringUtils.isBlank(name)) {
 163  0
             throw new IllegalArgumentException("name was a null or blank value");
 164  
         }
 165  0
         if (CollectionUtils.isNotEmpty(getAttributes())) {
 166  0
             for (KewTypeAttribute attribute : getAttributes()) {
 167  0
                 if (name.equals(attribute.getAttributeDefinition().getName())) {
 168  0
                     return attribute.getAttributeDefinition();
 169  
                 }
 170  
             }
 171  
         }
 172  0
         return null;
 173  
         }
 174  
 
 175  
         /**
 176  
      * This builder is used to construct instances of KEW KewType.  It enforces the constraints of the {@link KewTypeDefinitionContract}.
 177  
      */
 178  0
     public static class Builder implements KewTypeDefinitionContract, ModelBuilder, Serializable {                
 179  
                 private static final long serialVersionUID = -3469525730879441547L;
 180  
                 
 181  
                 private String id;
 182  
         private String name;
 183  
         private String namespace;
 184  0
         private String serviceName = "";
 185  
         private boolean active;
 186  
         private List<KewTypeAttribute.Builder> attributes;
 187  
         private Long versionNumber;
 188  
         
 189  
                 /**
 190  
                  * Private constructor for creating a builder with all of it's required attributes.
 191  
                  */
 192  0
         private Builder(String id, String name, String namespace) {
 193  0
             setId(id);
 194  0
             setName(name);
 195  0
             setNamespace(namespace);
 196  0
                         setActive(true);
 197  0
         }
 198  
 
 199  
         public Builder serviceName(String serviceName){
 200  0
                 this.serviceName = serviceName;
 201  0
                 return this;
 202  
         }
 203  
         
 204  
         public Builder attributes(List<KewTypeAttribute.Builder> attributes){
 205  0
                 setAttributes(attributes);
 206  0
                 return this;
 207  
         }
 208  
 
 209  
         /**
 210  
          * Creates a builder from the given parameters.
 211  
          * 
 212  
          * @param id the KEW type id
 213  
          * @param name the KEW type name
 214  
          * @param namespace the KEW type namespace
 215  
          * @return an instance of the builder with the fields already populated
 216  
          * @throws IllegalArgumentException if the either the id, name or namespace is null or blank
 217  
          */
 218  
         public static Builder create(String id, String name, String namespace) {
 219  0
             return new Builder(id, name, namespace);
 220  
         }
 221  
 
 222  
         /**
 223  
          * Creates a builder by populating it with data from the given {@link KewTypeDefinitionContract}.
 224  
          * 
 225  
          * @param contract the contract from which to populate this builder
 226  
          * @return an instance of the builder populated with data from the contract
 227  
          */
 228  
         public static Builder create(KewTypeDefinitionContract contract) {
 229  0
                 if (contract == null) {
 230  0
                 throw new IllegalArgumentException("contract is null");
 231  
             }
 232  0
             Builder builder =  new Builder(contract.getId(), contract.getName(), contract.getNamespace());
 233  0
             builder.setNamespace(contract.getNamespace());
 234  0
             builder.setActive(contract.isActive());
 235  0
             builder.setServiceName(contract.getServiceName());
 236  0
             List <KewTypeAttribute.Builder> attrBuilderList = new ArrayList<KewTypeAttribute.Builder>();
 237  0
             if (contract.getAttributes() != null) {
 238  0
                     for(KewTypeAttributeContract attr : contract.getAttributes()){
 239  0
                             KewTypeAttribute.Builder myBuilder = 
 240  
                                     KewTypeAttribute.Builder.create(attr);
 241  0
                             attrBuilderList.add(myBuilder);
 242  0
                     }
 243  
             }
 244  0
             builder.setAttributes(attrBuilderList);
 245  0
             builder.setVersionNumber(contract.getVersionNumber());
 246  0
             return builder;
 247  
         }
 248  
 
 249  
                 /**
 250  
                  * Sets the value of the id on this builder to the given value.
 251  
                  * 
 252  
                  * @param id the id value to set, must not be blank
 253  
                  * @throws IllegalArgumentException if the id is blank
 254  
                  */
 255  
         public void setId(String id) {
 256  0
             if (id != null && StringUtils.isBlank(id)) {
 257  0
                 throw new IllegalArgumentException("id is blank");
 258  
             }
 259  0
             this.id = id;
 260  0
         }
 261  
 
 262  
                 public void setName(String name) {
 263  0
             if (StringUtils.isBlank(name)) {
 264  0
                 throw new IllegalArgumentException("name is blank");
 265  
             }
 266  0
                         this.name = name;
 267  0
                 }
 268  
 
 269  
                 public void setNamespace(String namespace) {
 270  0
             if (StringUtils.isBlank(namespace)) {
 271  0
                 throw new IllegalArgumentException("namespace is blank");
 272  
             }
 273  0
                         this.namespace = namespace;
 274  0
                 }
 275  
                 
 276  
                 public void setServiceName(String serviceName) {
 277  0
                         this.serviceName = serviceName;
 278  0
                 }
 279  
                 
 280  
                 public void setAttributes(List<KewTypeAttribute.Builder> attributes){
 281  0
                         if (attributes == null || attributes.isEmpty()){
 282  0
                                 this.attributes = Collections.unmodifiableList(new ArrayList<KewTypeAttribute.Builder>());
 283  0
                                 return;
 284  
                         }
 285  0
                         this.attributes = Collections.unmodifiableList(attributes);
 286  0
                 }
 287  
                 
 288  
                 public void setActive(boolean active) {
 289  0
                         this.active = active;
 290  0
                 }
 291  
 
 292  
         public void setVersionNumber(Long versionNumber){
 293  0
             this.versionNumber = versionNumber;
 294  0
         }
 295  
         
 296  
                 @Override
 297  
                 public String getId() {
 298  0
                         return id;
 299  
                 }
 300  
 
 301  
                 @Override
 302  
                 public String getName() {
 303  0
                         return name;
 304  
                 }
 305  
 
 306  
                 @Override
 307  
                 public String getNamespace() {
 308  0
                         return namespace;
 309  
                 }
 310  
 
 311  
                 @Override
 312  
                 public String getServiceName() {
 313  0
                         return serviceName;
 314  
                 }
 315  
                 
 316  
                 @Override
 317  
                 public List<KewTypeAttribute.Builder> getAttributes(){
 318  0
                         return attributes;
 319  
                 }
 320  
 
 321  
                 @Override
 322  
                 public boolean isActive() {
 323  0
                         return active;
 324  
                 }
 325  
 
 326  
         @Override
 327  
         public Long getVersionNumber() {
 328  0
             return versionNumber;
 329  
         }
 330  
 
 331  
                 /**
 332  
                  * Builds an instance of a KewType based on the current state of the builder.
 333  
                  * 
 334  
                  * @return the fully-constructed KewType
 335  
                  */
 336  
         @Override
 337  
         public KewTypeDefinition build() {
 338  0
             return new KewTypeDefinition(this);
 339  
         }
 340  
                 
 341  
     }
 342  
 
 343  
         /**
 344  
          * Defines some internal constants used on this class.
 345  
          */
 346  0
         static class Constants {
 347  
                 final static String ROOT_ELEMENT_NAME = "KEWType";
 348  
                 final static String TYPE_NAME = "KEWTypeType";
 349  
         }
 350  
         
 351  
         /**
 352  
          * A private class which exposes constants which define the XML element names to use
 353  
          * when this object is marshalled to XML.
 354  
          */
 355  0
         public static class Elements {
 356  
                 final static String ID = "id";
 357  
                 final static String NAME = "name";
 358  
                 final static String NAMESPACE = "namespace";
 359  
                 final static String SERVICENAME = "serviceName";
 360  
                 final static String ACTIVE = "active";
 361  
                 final static String ATTRIBUTE = "attribute";
 362  
                 final static String ATTRIBUTES = "attributes";
 363  
         }
 364  
 }