Coverage Report - org.kuali.rice.krms.api.repository.action.ActionDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionDefinition
73%
28/38
50%
1/2
1.5
ActionDefinition$1
N/A
N/A
1.5
ActionDefinition$Builder
81%
50/61
75%
15/20
1.5
ActionDefinition$Constants
50%
1/2
N/A
1.5
ActionDefinition$Elements
0%
0/1
N/A
1.5
 
 1  
 package org.kuali.rice.krms.api.repository.action;
 2  
 
 3  
 import java.io.Serializable;
 4  
 import java.util.Collection;
 5  
 import java.util.Collections;
 6  
 import java.util.HashMap;
 7  
 import java.util.Map;
 8  
 
 9  
 import javax.xml.bind.annotation.XmlAccessType;
 10  
 import javax.xml.bind.annotation.XmlAccessorType;
 11  
 import javax.xml.bind.annotation.XmlAnyElement;
 12  
 import javax.xml.bind.annotation.XmlElement;
 13  
 import javax.xml.bind.annotation.XmlRootElement;
 14  
 import javax.xml.bind.annotation.XmlType;
 15  
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 16  
 
 17  
 import org.apache.commons.lang.StringUtils;
 18  
 import org.apache.commons.lang.builder.EqualsBuilder;
 19  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 20  
 import org.apache.commons.lang.builder.ToStringBuilder;
 21  
 import org.kuali.rice.core.api.CoreConstants;
 22  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 23  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 24  
 import org.kuali.rice.core.util.jaxb.MapStringStringAdapter;
 25  
 
 26  
 /**
 27  
  * Concrete model object implementation of KRMS Repository Action 
 28  
  * immutable. 
 29  
  * Instances of Action can be (un)marshalled to and from XML.
 30  
  *
 31  
  * @see ActionDefinitionContract
 32  
  */
 33  
 @XmlRootElement(name = ActionDefinition.Constants.ROOT_ELEMENT_NAME)
 34  
 @XmlAccessorType(XmlAccessType.NONE)
 35  
 @XmlType(name = ActionDefinition.Constants.TYPE_NAME, propOrder = {
 36  
                 ActionDefinition.Elements.ID,
 37  
                 ActionDefinition.Elements.NAME,
 38  
                 ActionDefinition.Elements.NAMESPACE,
 39  
                 ActionDefinition.Elements.DESC,
 40  
                 ActionDefinition.Elements.TYPE_ID,
 41  
                 ActionDefinition.Elements.RULE_ID,
 42  
                 ActionDefinition.Elements.SEQUENCE_NUMBER,
 43  
                 ActionDefinition.Elements.ATTRIBUTES,
 44  
         CoreConstants.CommonElements.VERSION_NUMBER,
 45  
                 CoreConstants.CommonElements.FUTURE_ELEMENTS
 46  
 })
 47  3
 public final class ActionDefinition implements ActionDefinitionContract, ModelObjectComplete{
 48  
         private static final long serialVersionUID = 2783959459503209577L;
 49  
 
 50  
         @XmlElement(name = Elements.ID, required=true)
 51  
         private String id;
 52  
         @XmlElement(name = Elements.NAME, required=true)
 53  
         private String name;
 54  
         @XmlElement(name = Elements.NAMESPACE, required=true)
 55  
         private String namespace;
 56  
         @XmlElement(name = Elements.DESC, required=true)
 57  
         private String description;
 58  
         @XmlElement(name = Elements.TYPE_ID, required=true)
 59  
         private String typeId;
 60  
         @XmlElement(name = Elements.RULE_ID, required=true)
 61  
         private String ruleId;
 62  
         @XmlElement(name = Elements.SEQUENCE_NUMBER, required=true)
 63  
         private Integer sequenceNumber;
 64  
         
 65  
         @XmlElement(name = Elements.ATTRIBUTES, required = false)
 66  
         @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
 67  
         private final Map<String, String> attributes;
 68  
         
 69  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 70  
     private final Long versionNumber;
 71  
             
 72  6
         @SuppressWarnings("unused")
 73  
     @XmlAnyElement
 74  
     private final Collection<org.w3c.dom.Element> _futureElements = null;
 75  
         
 76  
         
 77  
          /** 
 78  
      * This constructor should never be called.  
 79  
      * It is only present for use during JAXB unmarshalling. 
 80  
      */
 81  3
     private ActionDefinition() {
 82  3
             this.id = null;
 83  3
             this.name = null;
 84  3
             this.namespace = null;
 85  3
             this.description = null;
 86  3
             this.typeId = null;
 87  3
             this.ruleId = null;
 88  3
             this.sequenceNumber = null;
 89  3
             this.attributes = null;
 90  3
         this.versionNumber = null;
 91  3
     }
 92  
     
 93  
     /**
 94  
          * Constructs a KRMS Repository Action object from the given builder.  
 95  
          * This constructor is private and should only ever be invoked from the builder.
 96  
          * 
 97  
          * @param builder the Builder from which to construct the Action
 98  
          */
 99  3
     private ActionDefinition(Builder builder) {
 100  3
         this.id = builder.getId();
 101  3
         this.name = builder.getName();
 102  3
         this.namespace = builder.getNamespace();
 103  3
         this.description = builder.getDescription();
 104  3
         this.typeId = builder.getTypeId();
 105  3
         this.ruleId = builder.getRuleId();
 106  3
         this.sequenceNumber = builder.getSequenceNumber();
 107  3
         if (builder.attributes != null){
 108  3
                 this.attributes = Collections.unmodifiableMap(builder.getAttributes());
 109  
         } else {
 110  0
                 this.attributes = null;
 111  
         }
 112  3
         this.versionNumber = builder.getVersionNumber();
 113  3
     }
 114  
     
 115  
         @Override
 116  
         public String getId() {
 117  1
                 return this.id;
 118  
         }
 119  
 
 120  
         @Override
 121  
         public String getName() {
 122  0
                 return this.name;
 123  
         }
 124  
 
 125  
         @Override
 126  
         public String getNamespace() {
 127  0
                 return this.namespace;
 128  
         }
 129  
 
 130  
         @Override
 131  
         public String getDescription() {
 132  0
                 return this.description;
 133  
         }
 134  
 
 135  
         @Override
 136  
         public String getTypeId() {
 137  0
                 return this.typeId;
 138  
         }
 139  
 
 140  
         @Override
 141  
         public String getRuleId() {
 142  1
                 return this.ruleId;
 143  
         }
 144  
 
 145  
         @Override
 146  
         public Integer getSequenceNumber() {
 147  0
                 return this.sequenceNumber;
 148  
         }
 149  
 
 150  
         @Override
 151  
         public Map<String, String> getAttributes() {
 152  0
                 return this.attributes; 
 153  
         }
 154  
 
 155  
     @Override
 156  
     public Long getVersionNumber() {
 157  0
         return versionNumber;
 158  
     }
 159  
         
 160  
         /**
 161  
      * This builder is used to construct instances of KRMS Repository Action.  It enforces the constraints of the {@link ActionDefinitionContract}.
 162  
      */
 163  6
     public static class Builder implements ActionDefinitionContract, ModelBuilder, Serializable {
 164  
         private static final long serialVersionUID = -6773634512570180267L;
 165  
 
 166  
         private String id;
 167  
         private String name;
 168  
         private String namespace;
 169  
         private String description;
 170  
         private String typeId;
 171  
         private String ruleId;
 172  
         private Integer sequenceNumber;
 173  
         private Map<String, String> attributes;
 174  
         private Long versionNumber;
 175  
 
 176  
                 /**
 177  
                  * Private constructor for creating a builder with all of it's required attributes.
 178  
                  */
 179  22
         private Builder(String actionId, String name, String namespace, String typeId, String ruleId, Integer sequenceNumber) {
 180  22
             setId(actionId);
 181  20
             setName(name);
 182  16
             setNamespace(namespace);
 183  13
             setTypeId(typeId);
 184  10
             setRuleId(ruleId);
 185  7
             setSequenceNumber(sequenceNumber);
 186  6
             setAttributes(new HashMap<String, String>());
 187  6
         }
 188  
         
 189  
         public static Builder create(String actionId, String name, String namespace, String typeId, String ruleId, Integer sequenceNumber){
 190  22
                 return new Builder(actionId, name, namespace, typeId, ruleId, sequenceNumber);
 191  
         }
 192  
         /**
 193  
          * Creates a builder by populating it with data from the given {@link ActionDefinitionContract}.
 194  
          * 
 195  
          * @param contract the contract from which to populate this builder
 196  
          * @return an instance of the builder populated with data from the contract
 197  
          */
 198  
         public static Builder create(ActionDefinitionContract contract) {
 199  0
                 if (contract == null) {
 200  0
                 throw new IllegalArgumentException("contract is null");
 201  
             }
 202  0
             Builder builder =  new Builder(contract.getId(), contract.getName(),
 203  
                             contract.getNamespace(), contract.getTypeId(), contract.getRuleId(),
 204  
                             contract.getSequenceNumber());
 205  0
             builder.setDescription(contract.getDescription());
 206  0
                 if (contract.getAttributes() != null){
 207  0
                 builder.setAttributes(new HashMap<String, String>(contract.getAttributes()));
 208  
                 }
 209  0
             builder.setVersionNumber(contract.getVersionNumber());
 210  0
             return builder;
 211  
         }
 212  
 
 213  
                 /**
 214  
                  * Sets the value of the id on this builder to the given value.
 215  
                  * 
 216  
                  * @param id the id value to set, must be null or non-blank
 217  
                  * @throws IllegalArgumentException if the id is non-null and blank
 218  
                  */
 219  
 
 220  
         public void setId(String actionId) {
 221  22
             if (actionId != null && StringUtils.isBlank(actionId)) {
 222  2
                 throw new IllegalArgumentException("action ID must be null or non-blank");
 223  
             }
 224  20
                         this.id = actionId;
 225  20
                 }
 226  
 
 227  
      
 228  
         public void setName(String name) {
 229  20
             if (StringUtils.isBlank(name)) {
 230  4
                 throw new IllegalArgumentException("name is blank");
 231  
             }
 232  16
                         this.name = name;
 233  16
                 }
 234  
      
 235  
         public void setNamespace(String namespace) {
 236  16
             if (StringUtils.isBlank(namespace)) {
 237  3
                 throw new IllegalArgumentException("namespace is blank");
 238  
             }
 239  13
                         this.namespace = namespace;
 240  13
                 }
 241  
      
 242  
                 public void setDescription(String desc) {
 243  4
                         this.description = desc;
 244  4
                 }
 245  
                 
 246  
                 public void setTypeId(String typeId) {
 247  13
                         if (StringUtils.isBlank(typeId)) {
 248  3
                         throw new IllegalArgumentException("KRMS type id is blank");
 249  
                         }
 250  10
                         this.typeId = typeId;
 251  10
                 }
 252  
                 
 253  
                 public void setRuleId(String ruleId) {
 254  10
                         if (StringUtils.isBlank(ruleId)) {
 255  3
                         throw new IllegalArgumentException("rule id is blank");
 256  
                         }
 257  7
                         this.ruleId = ruleId;
 258  7
                 }
 259  
                 
 260  
                 public void setSequenceNumber(Integer sequenceNumber) {
 261  7
                         if (sequenceNumber == null) {
 262  1
                         throw new IllegalArgumentException("sequence number is null");
 263  
                         }
 264  6
                         this.sequenceNumber = sequenceNumber;
 265  6
                 }
 266  
                 
 267  
                 public void setAttributes(Map<String, String> attributes){
 268  9
                         if (attributes == null){
 269  0
                                 this.attributes = Collections.emptyMap();
 270  
                         }
 271  9
                         this.attributes = Collections.unmodifiableMap(attributes);
 272  9
                 }
 273  
                 
 274  
         public void setVersionNumber(Long versionNumber){
 275  0
             this.versionNumber = versionNumber;
 276  0
         }
 277  
         
 278  
                 @Override
 279  
                 public String getId() {
 280  3
                         return id;
 281  
                 }
 282  
 
 283  
                 @Override
 284  
                 public String getName() {
 285  3
                         return name;
 286  
                 }
 287  
 
 288  
                 @Override
 289  
                 public String getNamespace() {
 290  3
                         return namespace;
 291  
                 }
 292  
 
 293  
                 @Override
 294  
                 public String getDescription() {
 295  3
                         return description;
 296  
                 }
 297  
 
 298  
                 @Override
 299  
                 public String getTypeId() {
 300  3
                         return typeId;
 301  
                 }
 302  
 
 303  
                 @Override
 304  
                 public String getRuleId() {
 305  3
                         return ruleId;
 306  
                 }
 307  
 
 308  
                 @Override
 309  
                 public Integer getSequenceNumber() {
 310  3
                         return sequenceNumber;
 311  
                 }
 312  
 
 313  
                 @Override
 314  
                 public Map<String, String> getAttributes() {
 315  3
                         return attributes;
 316  
                 }
 317  
 
 318  
         @Override
 319  
         public Long getVersionNumber() {
 320  3
             return versionNumber;
 321  
         }
 322  
 
 323  
                 /**
 324  
                  * Builds an instance of a Action based on the current state of the builder.
 325  
                  * 
 326  
                  * @return the fully-constructed Action
 327  
                  */
 328  
         @Override
 329  
         public ActionDefinition build() {
 330  3
             return new ActionDefinition(this);
 331  
         }
 332  
                 
 333  
     }
 334  
         @Override
 335  
         public int hashCode() {
 336  0
                 return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 337  
         }
 338  
 
 339  
         @Override
 340  
         public boolean equals(Object obj) {
 341  1
                 return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 342  
         }
 343  
 
 344  
         @Override
 345  
         public String toString() {
 346  0
                 return ToStringBuilder.reflectionToString(this);
 347  
         }
 348  
         
 349  
         /**
 350  
          * Defines some internal constants used on this class.
 351  
          */
 352  0
         static class Constants {
 353  
                 final static String ROOT_ELEMENT_NAME = "action";
 354  
                 final static String TYPE_NAME = "ActionType";
 355  1
                 final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS };
 356  
         }
 357  
         
 358  
         /**
 359  
          * A private class which exposes constants which define the XML element names to use
 360  
          * when this object is marshalled to XML.
 361  
          */
 362  0
         public static class Elements {
 363  
                 final static String ID = "id";
 364  
                 final static String NAME = "name";
 365  
                 final static String NAMESPACE = "namespace";
 366  
                 final static String DESC = "description";
 367  
                 final static String TYPE_ID = "typeId";
 368  
                 final static String RULE_ID = "ruleId";
 369  
                 final static String SEQUENCE_NUMBER = "sequenceNumber";
 370  
                 final static String ATTRIBUTES = "attributes";
 371  
         }
 372  
 
 373  
 }