Coverage Report - org.kuali.rice.kew.rule.bo.RuleTemplateAttribute
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleTemplateAttribute
0%
0/72
0%
0/24
1.867
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.rule.bo;
 18  
 
 19  
 import org.hibernate.annotations.GenericGenerator;
 20  
 import org.hibernate.annotations.Parameter;
 21  
 import org.kuali.rice.core.api.reflect.ObjectDefinition;
 22  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 23  
 import org.kuali.rice.kew.api.WorkflowRuntimeException;
 24  
 import org.kuali.rice.kew.rule.RuleExtension;
 25  
 import org.kuali.rice.kew.rule.RuleValidationAttribute;
 26  
 import org.kuali.rice.kew.rule.WorkflowAttribute;
 27  
 import org.kuali.rice.kew.rule.service.RuleAttributeService;
 28  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 29  
 import org.kuali.rice.kew.util.KEWConstants;
 30  
 import org.kuali.rice.krad.bo.MutableInactivatable;
 31  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
 32  
 
 33  
 import javax.persistence.Column;
 34  
 import javax.persistence.Entity;
 35  
 import javax.persistence.FetchType;
 36  
 import javax.persistence.GeneratedValue;
 37  
 import javax.persistence.Id;
 38  
 import javax.persistence.JoinColumn;
 39  
 import javax.persistence.ManyToOne;
 40  
 import javax.persistence.OneToMany;
 41  
 import javax.persistence.Table;
 42  
 import java.util.List;
 43  
 
 44  
 
 45  
 /**
 46  
  * A model bean which services as the link between a {@link RuleTemplate} and
 47  
  * a {@link RuleAttribute}.
 48  
  *
 49  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 50  
  */
 51  0
 @Entity
 52  
 @Table(name="KREW_RULE_TMPL_ATTR_T")
 53  
 //@Sequence(name="KREW_RTE_TMPL_S", property="ruleTemplateAttributeId")
 54  
 public class RuleTemplateAttribute extends PersistableBusinessObjectBase implements Comparable<RuleTemplateAttribute>, MutableInactivatable {
 55  
 
 56  
     private static final long serialVersionUID = -3580049225424553828L;
 57  
     @Id
 58  
     @GeneratedValue(generator="KREW_RTE_TMPL_S")
 59  
         @GenericGenerator(name="KREW_RTE_TMPL_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
 60  
                         @Parameter(name="sequence_name",value="KREW_RTE_TMPL_S"),
 61  
                         @Parameter(name="value_column",value="id")
 62  
         })
 63  
         @Column(name="RULE_TMPL_ATTR_ID")
 64  
         private String ruleTemplateAttributeId;
 65  
     @Column(name="RULE_TMPL_ID", insertable=false, updatable=false)
 66  
         private String ruleTemplateId;
 67  
     @Column(name="RULE_ATTR_ID", insertable=false, updatable=false)
 68  
         private String ruleAttributeId;
 69  
     @Column(name="REQ_IND")
 70  
         private Boolean required;
 71  
     @Column(name="ACTV_IND")
 72  
         private Boolean active;
 73  
     @Column(name="DSPL_ORD")
 74  
         private Integer displayOrder;
 75  
     @Column(name="DFLT_VAL")
 76  
         private String defaultValue;
 77  
 
 78  
     @ManyToOne(fetch=FetchType.EAGER)
 79  
         @JoinColumn(name="RULE_TMPL_ID")
 80  
         private RuleTemplate ruleTemplate;
 81  
     @ManyToOne(fetch=FetchType.EAGER)
 82  
         @JoinColumn(name="RULE_ATTR_ID")
 83  
         private RuleAttribute ruleAttribute;
 84  
     @OneToMany(fetch=FetchType.LAZY,mappedBy="ruleTemplateAttribute")
 85  
         private List<RuleExtension> ruleExtensions;
 86  
     
 87  
     
 88  0
     public RuleTemplateAttribute() {
 89  0
         this.required = Boolean.FALSE;
 90  0
         this.active = Boolean.TRUE;
 91  0
     }
 92  
    
 93  
     public int compareTo(RuleTemplateAttribute ruleTemplateAttribute) {
 94  0
             if ((this.getDisplayOrder() != null) && (ruleTemplateAttribute.getDisplayOrder() != null)) {
 95  0
                     return this.getDisplayOrder().compareTo(ruleTemplateAttribute.getDisplayOrder());
 96  
             }
 97  0
             return 0;
 98  
     }
 99  
 
 100  
     public Object getAttribute() {
 101  
         try {
 102  0
             ObjectDefinition objectDefinition = new ObjectDefinition(getRuleAttribute().getClassName(), getRuleAttribute().getApplicationId());
 103  0
             Object attribute = GlobalResourceLoader.getObject(objectDefinition);
 104  0
             if (attribute == null) {
 105  0
                 throw new WorkflowRuntimeException("Could not find attribute " + objectDefinition);
 106  
             }
 107  0
             if (attribute instanceof WorkflowAttribute) {
 108  0
                 ((WorkflowAttribute) attribute).setRequired(required.booleanValue());
 109  
             }
 110  0
             return attribute;
 111  0
         } catch (Exception e) {
 112  0
             throw new RuntimeException("Caught error attempting to load attribute class: " + getRuleAttribute().getClassName(), e);
 113  
         }
 114  
     }
 115  
 
 116  
     public boolean isWorkflowAttribute() {
 117  
         try {
 118  0
             Object attributeObject = getAttribute();//GlobalResourceLoader.getResourceLoader().getObject(new ObjectDefinition(getRuleAttribute().getClassName()));
 119  0
             if (attributeObject == null) {
 120  0
                 return false;
 121  
             }
 122  0
             Class<?> attributeClass = attributeObject.getClass();
 123  0
             return WorkflowAttribute.class.isAssignableFrom(attributeClass);
 124  0
         } catch (Exception e) {
 125  0
             throw new RuntimeException("Caught error attempting to load WorkflowAttribute class: " + getRuleAttribute().getClassName(), e);
 126  
         }
 127  
     }
 128  
 
 129  
     public boolean isRuleValidationAttribute() {
 130  
         // just check the type here to avoid having to load the class from the class loader if it's not actually there
 131  0
         return KEWConstants.RULE_VALIDATION_ATTRIBUTE_TYPE.equals(getRuleAttribute().getType());
 132  
     }
 133  
 
 134  
     /**
 135  
      * Instantiates and returns a new instance of the WorkflowAttribute class configured on this template.
 136  
      * The calling code should be sure to call isWorkflowAttribute first to verify the type of this attribute
 137  
      * is that of a WorkflowAttribute.  Otherwise a RuntimeException will be thrown.
 138  
      */
 139  
     public WorkflowAttribute getWorkflowAttribute() {
 140  
         try {
 141  0
             ObjectDefinition objectDefinition = new ObjectDefinition(getRuleAttribute().getClassName(), getRuleAttribute().getApplicationId());
 142  0
             WorkflowAttribute workflowAttribute = (WorkflowAttribute) GlobalResourceLoader.getResourceLoader().getObject(objectDefinition);
 143  0
             if (workflowAttribute == null) {
 144  0
                 throw new WorkflowRuntimeException("Could not find workflow attribute " + objectDefinition);
 145  
             }
 146  0
             workflowAttribute.setRequired(required.booleanValue());
 147  0
             return workflowAttribute;
 148  0
         } catch (Exception e) {
 149  0
             throw new RuntimeException("Caught exception instantiating new " + getRuleAttribute().getClassName(), e);
 150  
         }
 151  
     }
 152  
 
 153  
     /**
 154  
      * Instantiates and returns a new instance of the RuleValidationAttribute class configured on this template.
 155  
      * The calling code should be sure to call isRuleValidationAttribute first to verify the type of this attribute
 156  
      * is that of a RuleValidationAttribute.  Otherwise a RuntimeException will be thrown.
 157  
      */
 158  
     public RuleValidationAttribute getRuleValidationAttribute() {
 159  
         try {
 160  0
             return (RuleValidationAttribute) getAttribute();
 161  0
         } catch (Exception e) {
 162  0
             throw new RuntimeException("Caught exception instantiating new " + getRuleAttribute().getClassName(), e);
 163  
         }
 164  
     }
 165  
 
 166  
     public List<RuleExtension> getRuleExtensions() {
 167  0
         return ruleExtensions;
 168  
     }
 169  
 
 170  
     public void setRuleExtensions(List<RuleExtension> ruleExtensions) {
 171  0
         this.ruleExtensions = ruleExtensions;
 172  0
     }
 173  
 
 174  
     public RuleAttribute getRuleAttribute() {
 175  0
         if (ruleAttribute == null && ruleAttributeId != null) {
 176  0
             ruleAttribute = ((RuleAttributeService) KEWServiceLocator.getService(KEWServiceLocator.RULE_ATTRIBUTE_SERVICE)).findByRuleAttributeId(ruleAttributeId);
 177  
         }
 178  0
         return ruleAttribute;
 179  
     }
 180  
 
 181  
     public void setRuleAttribute(RuleAttribute ruleAttribute) {
 182  0
         this.ruleAttribute = ruleAttribute;
 183  0
     }
 184  
 
 185  
     public RuleTemplate getRuleTemplate() {
 186  0
         return ruleTemplate;
 187  
     }
 188  
 
 189  
     public void setRuleTemplate(RuleTemplate ruleTemplate) {
 190  0
         this.ruleTemplate = ruleTemplate;
 191  0
     }
 192  
 
 193  
     public String getDefaultValue() {
 194  0
         return defaultValue;
 195  
     }
 196  
 
 197  
     public void setDefaultValue(String defaultValue) {
 198  0
         this.defaultValue = defaultValue;
 199  0
     }
 200  
 
 201  
     public Integer getDisplayOrder() {
 202  0
         return displayOrder;
 203  
     }
 204  
 
 205  
     public void setDisplayOrder(Integer displayOrder) {
 206  0
         this.displayOrder = displayOrder;
 207  0
     }
 208  
 
 209  
     public boolean isRequired() {
 210  0
         return (getRequired() == null) || (getRequired().booleanValue());
 211  
     }
 212  
 
 213  
     public Boolean getRequired() {
 214  0
         return required;
 215  
     }
 216  
 
 217  
     public void setRequired(Boolean required) {
 218  0
         this.required = required;
 219  0
     }
 220  
 
 221  
     public boolean isActive() {
 222  0
         return (getActive() == null) || (getActive().booleanValue());
 223  
     }
 224  
 
 225  
     public Boolean getActive() {
 226  0
         return active;
 227  
     }
 228  
 
 229  
     public void setActive(Boolean active) {
 230  0
         this.active = active;
 231  0
     }
 232  
     
 233  
     public void setActive(boolean active) {
 234  0
             this.active = active;
 235  0
     }
 236  
 
 237  
     public String getRuleAttributeId() {
 238  0
             return ruleAttributeId;
 239  
     }
 240  
 
 241  
     public void setRuleAttributeId(String ruleAttributeId) {
 242  0
             this.ruleAttributeId = ruleAttributeId;
 243  0
     }
 244  
 
 245  
     public String getRuleTemplateAttributeId() {
 246  0
             return ruleTemplateAttributeId;
 247  
     }
 248  
 
 249  
     public void setRuleTemplateAttributeId(String ruleTemplateAttributeId) {
 250  0
             this.ruleTemplateAttributeId = ruleTemplateAttributeId;
 251  0
     }
 252  
 
 253  
     public String getRuleTemplateId() {
 254  0
             return ruleTemplateId;
 255  
     }
 256  
 
 257  
     public void setRuleTemplateId(String ruleTemplateId) {
 258  0
             this.ruleTemplateId = ruleTemplateId;
 259  0
     }
 260  
 }