Coverage Report - org.kuali.rice.kew.api.rule.RuleTemplateAttribute
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleTemplateAttribute
0%
0/40
0%
0/6
1.405
RuleTemplateAttribute$1
N/A
N/A
1.405
RuleTemplateAttribute$Builder
0%
0/58
0%
0/12
1.405
RuleTemplateAttribute$Constants
0%
0/1
N/A
1.405
RuleTemplateAttribute$Elements
0%
0/1
N/A
1.405
 
 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.rule;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Collection;
 20  
 import java.util.Map;
 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  
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 28  
 
 29  
 import org.apache.commons.lang.StringUtils;
 30  
 import org.kuali.rice.core.api.CoreConstants;
 31  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 32  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 33  
 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
 34  
 import org.kuali.rice.kew.api.extension.ExtensionDefinition;
 35  
 import org.w3c.dom.Element;
 36  
 
 37  0
 @XmlRootElement(name = RuleTemplateAttribute.Constants.ROOT_ELEMENT_NAME)
 38  
 @XmlAccessorType(XmlAccessType.NONE)
 39  
 @XmlType(name = RuleTemplateAttribute.Constants.TYPE_NAME, propOrder = {
 40  
     RuleTemplateAttribute.Elements.DEFAULT_VALUE,
 41  
     RuleTemplateAttribute.Elements.RULE_TEMPLATE_ID,
 42  
     RuleTemplateAttribute.Elements.REQUIRED,
 43  
     RuleTemplateAttribute.Elements.DISPLAY_ORDER,
 44  
     RuleTemplateAttribute.Elements.RULE_ATTRIBUTE,
 45  
     RuleTemplateAttribute.Elements.RULE_EXTENSIONS,
 46  
     RuleTemplateAttribute.Elements.ID,
 47  
     CoreConstants.CommonElements.VERSION_NUMBER,
 48  
     CoreConstants.CommonElements.OBJECT_ID,
 49  
     RuleTemplateAttribute.Elements.ACTIVE,
 50  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 51  
 })
 52  0
 public final class RuleTemplateAttribute
 53  
     extends AbstractDataTransferObject
 54  
     implements RuleTemplateAttributeContract,
 55  
         Comparable<RuleTemplateAttribute>
 56  
 {
 57  
 
 58  
     @XmlElement(name = Elements.DEFAULT_VALUE, required = false)
 59  
     private final String defaultValue;
 60  
     @XmlElement(name = Elements.RULE_TEMPLATE_ID, required = true)
 61  
     private final String ruleTemplateId;
 62  
     @XmlElement(name = Elements.REQUIRED, required = true)
 63  
     private final boolean required;
 64  
     @XmlElement(name = Elements.DISPLAY_ORDER, required = true)
 65  
     private final Integer displayOrder;
 66  
     @XmlElement(name = Elements.RULE_ATTRIBUTE, required = true)
 67  
     private final ExtensionDefinition ruleAttribute;
 68  
     @XmlElement(name = Elements.RULE_EXTENSIONS, required = false)
 69  
     @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
 70  
     private final Map<String, String> ruleExtensionMap;
 71  
     @XmlElement(name = Elements.ID, required = false)
 72  
     private final String id;
 73  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 74  
     private final Long versionNumber;
 75  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 76  
     private final String objectId;
 77  
     @XmlElement(name = Elements.ACTIVE, required = true)
 78  
     private final boolean active;
 79  0
     @SuppressWarnings("unused")
 80  
     @XmlAnyElement
 81  
     private final Collection<Element> _futureElements = null;
 82  
 
 83  
     /**
 84  
      * Private constructor used only by JAXB.
 85  
      * 
 86  
      */
 87  0
     private RuleTemplateAttribute() {
 88  0
         this.defaultValue = null;
 89  0
         this.ruleTemplateId = null;
 90  0
         this.required = false;
 91  0
         this.displayOrder = null;
 92  0
         this.ruleAttribute = null;
 93  0
         this.ruleExtensionMap = null;
 94  0
         this.id = null;
 95  0
         this.versionNumber = null;
 96  0
         this.objectId = null;
 97  0
         this.active = false;
 98  0
     }
 99  
 
 100  0
     private RuleTemplateAttribute(Builder builder) {
 101  0
         this.defaultValue = builder.getDefaultValue();
 102  0
         this.ruleTemplateId = builder.getRuleTemplateId();
 103  0
         this.required = builder.isRequired();
 104  0
         this.displayOrder = builder.getDisplayOrder();
 105  0
         this.ruleAttribute = builder.getRuleAttribute() == null ? null : builder.getRuleAttribute().build();
 106  0
         this.ruleExtensionMap = builder.getRuleExtensionMap();
 107  0
         this.id = builder.getId();
 108  0
         this.versionNumber = builder.getVersionNumber();
 109  0
         this.objectId = builder.getObjectId();
 110  0
         this.active = builder.isActive();
 111  0
     }
 112  
 
 113  
     @Override
 114  
     public String getDefaultValue() {
 115  0
         return this.defaultValue;
 116  
     }
 117  
 
 118  
     @Override
 119  
     public String getRuleTemplateId() {
 120  0
         return this.ruleTemplateId;
 121  
     }
 122  
 
 123  
     @Override
 124  
     public boolean isRequired() {
 125  0
         return this.required;
 126  
     }
 127  
 
 128  
     @Override
 129  
     public Integer getDisplayOrder() {
 130  0
         return this.displayOrder;
 131  
     }
 132  
 
 133  
     @Override
 134  
     public ExtensionDefinition getRuleAttribute() {
 135  0
         return this.ruleAttribute;
 136  
     }
 137  
 
 138  
     @Override
 139  
     public Map<String, String> getRuleExtensionMap() {
 140  0
         return this.ruleExtensionMap;
 141  
     }
 142  
 
 143  
     @Override
 144  
     public String getId() {
 145  0
         return this.id;
 146  
     }
 147  
 
 148  
     @Override
 149  
     public Long getVersionNumber() {
 150  0
         return this.versionNumber;
 151  
     }
 152  
 
 153  
     @Override
 154  
     public String getObjectId() {
 155  0
         return this.objectId;
 156  
     }
 157  
 
 158  
     @Override
 159  
     public boolean isActive() {
 160  0
         return this.active;
 161  
     }
 162  
 
 163  
     public int compareTo(RuleTemplateAttribute ruleTemplateAttribute) {
 164  0
         if ((this.getDisplayOrder() != null) && (ruleTemplateAttribute.getDisplayOrder() != null)) {
 165  0
             return this.getDisplayOrder().compareTo(ruleTemplateAttribute.getDisplayOrder());
 166  
         }
 167  0
         return 0;
 168  
     }
 169  
 
 170  
 
 171  
     /**
 172  
      * A builder which can be used to construct {@link RuleTemplateAttribute} instances.  Enforces the constraints of the {@link RuleTemplateAttributeContract}.
 173  
      * 
 174  
      */
 175  0
     public final static class Builder
 176  
         implements Serializable, ModelBuilder, RuleTemplateAttributeContract
 177  
     {
 178  
 
 179  
         private String defaultValue;
 180  
         private String ruleTemplateId;
 181  
         private boolean required;
 182  
         private Integer displayOrder;
 183  
         private ExtensionDefinition.Builder ruleAttribute;
 184  
         private Map<String, String> ruleExtensionMap;
 185  
         private String id;
 186  
         private Long versionNumber;
 187  
         private String objectId;
 188  
         private boolean active;
 189  
 
 190  
         private Builder(String ruleTemplateId,
 191  
                 ExtensionDefinition.Builder ruleAttribute,
 192  
                 boolean required,
 193  0
                 Integer displayOrder) {
 194  0
             setActive(true);
 195  0
             setRuleTemplateId(ruleTemplateId);
 196  0
             setRuleAttribute(ruleAttribute);
 197  0
             setRequired(required);
 198  0
             setDisplayOrder(displayOrder);
 199  0
         }
 200  
 
 201  
         public static Builder create(String ruleTemplateId,
 202  
                 ExtensionDefinition.Builder ruleAttribute,
 203  
                 boolean required,
 204  
                 Integer displayOrder) {
 205  0
             return new Builder(ruleTemplateId, ruleAttribute, required, displayOrder);
 206  
         }
 207  
 
 208  
         public static Builder create(RuleTemplateAttributeContract contract) {
 209  0
             if (contract == null) {
 210  0
                 throw new IllegalArgumentException("contract was null");
 211  
             }
 212  0
             Builder builder = create(contract.getRuleTemplateId(),
 213  
                 contract.getRuleAttribute()  == null ? null : ExtensionDefinition.Builder.create(contract.getRuleAttribute()),
 214  
                 contract.isRequired(),
 215  
                 contract.getDisplayOrder());
 216  0
             builder.setDefaultValue(contract.getDefaultValue());
 217  0
             builder.setRuleExtensionMap(contract.getRuleExtensionMap());
 218  0
             builder.setId(contract.getId());
 219  0
             builder.setVersionNumber(contract.getVersionNumber());
 220  0
             builder.setObjectId(contract.getObjectId());
 221  0
             builder.setActive(contract.isActive());
 222  0
             return builder;
 223  
         }
 224  
 
 225  
         @Override
 226  
         public RuleTemplateAttribute build() {
 227  0
             return new RuleTemplateAttribute(this);
 228  
         }
 229  
 
 230  
         @Override
 231  
         public String getDefaultValue() {
 232  0
             return this.defaultValue;
 233  
         }
 234  
 
 235  
         @Override
 236  
         public String getRuleTemplateId() {
 237  0
             return this.ruleTemplateId;
 238  
         }
 239  
 
 240  
         @Override
 241  
         public boolean isRequired() {
 242  0
             return this.required;
 243  
         }
 244  
 
 245  
         @Override
 246  
         public Integer getDisplayOrder() {
 247  0
             return this.displayOrder;
 248  
         }
 249  
 
 250  
         @Override
 251  
         public ExtensionDefinition.Builder getRuleAttribute() {
 252  0
             return this.ruleAttribute;
 253  
         }
 254  
 
 255  
         @Override
 256  
         public Map<String, String> getRuleExtensionMap() {
 257  0
             return this.ruleExtensionMap;
 258  
         }
 259  
 
 260  
         @Override
 261  
         public String getId() {
 262  0
             return this.id;
 263  
         }
 264  
 
 265  
         @Override
 266  
         public Long getVersionNumber() {
 267  0
             return this.versionNumber;
 268  
         }
 269  
 
 270  
         @Override
 271  
         public String getObjectId() {
 272  0
             return this.objectId;
 273  
         }
 274  
 
 275  
         @Override
 276  
         public boolean isActive() {
 277  0
             return this.active;
 278  
         }
 279  
 
 280  
         public void setDefaultValue(String defaultValue) {
 281  0
             this.defaultValue = defaultValue;
 282  0
         }
 283  
 
 284  
         public void setRuleTemplateId(String ruleTemplateId) {
 285  0
             if (StringUtils.isBlank(ruleTemplateId)) {
 286  0
                 throw new IllegalArgumentException("ruleTemplateId was null or blank");
 287  
             }
 288  0
             this.ruleTemplateId = ruleTemplateId;
 289  0
         }
 290  
 
 291  
         public void setRequired(boolean required) {
 292  0
             this.required = required;
 293  0
         }
 294  
 
 295  
         public void setDisplayOrder(Integer displayOrder) {
 296  0
             if (displayOrder == null) {
 297  0
                 throw new IllegalArgumentException("displayOrder was null");
 298  
             }
 299  0
             this.displayOrder = displayOrder;
 300  0
         }
 301  
 
 302  
         public void setRuleAttribute(ExtensionDefinition.Builder ruleAttribute) {
 303  0
             if (ruleAttribute == null) {
 304  0
                 throw new IllegalArgumentException("ruleAttribute was null");
 305  
             }
 306  0
             this.ruleAttribute = ruleAttribute;
 307  0
         }
 308  
 
 309  
         public void setRuleExtensionMap(Map<String, String> ruleExtensionMap) {
 310  0
             this.ruleExtensionMap = ruleExtensionMap;
 311  0
         }
 312  
 
 313  
         public void setId(String id) {
 314  0
             if (StringUtils.isWhitespace(id)) {
 315  0
                 throw new IllegalArgumentException("id was whitespace");
 316  
             }
 317  0
             this.id = id;
 318  0
         }
 319  
 
 320  
         public void setVersionNumber(Long versionNumber) {
 321  0
             this.versionNumber = versionNumber;
 322  0
         }
 323  
 
 324  
         public void setObjectId(String objectId) {
 325  0
             this.objectId = objectId;
 326  0
         }
 327  
 
 328  
         public void setActive(boolean active) {
 329  0
             this.active = active;
 330  0
         }
 331  
 
 332  
     }
 333  
 
 334  
 
 335  
     /**
 336  
      * Defines some internal constants used on this class.
 337  
      * 
 338  
      */
 339  0
     static class Constants {
 340  
 
 341  
         final static String ROOT_ELEMENT_NAME = "ruleTemplateAttribute";
 342  
         final static String TYPE_NAME = "RuleTemplateAttributeType";
 343  
 
 344  
     }
 345  
 
 346  
 
 347  
     /**
 348  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 349  
      * 
 350  
      */
 351  0
     static class Elements {
 352  
 
 353  
         final static String DEFAULT_VALUE = "defaultValue";
 354  
         final static String RULE_TEMPLATE_ID = "ruleTemplateId";
 355  
         final static String RULE_ATTRIBUTE_ID = "ruleAttributeId";
 356  
         final static String REQUIRED = "required";
 357  
         final static String DISPLAY_ORDER = "displayOrder";
 358  
         final static String RULE_ATTRIBUTE = "ruleAttribute";
 359  
         final static String RULE_EXTENSIONS = "ruleExtensionMap";
 360  
         final static String ID = "id";
 361  
         final static String ACTIVE = "active";
 362  
 
 363  
     }
 364  
 
 365  
 }