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