Coverage Report - org.kuali.rice.kew.rule.RuleDelegation
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleDelegation
0%
0/37
0%
0/12
1.467
 
 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;
 18  
 
 19  
 import javax.persistence.CascadeType;
 20  
 import javax.persistence.Column;
 21  
 import javax.persistence.Entity;
 22  
 import javax.persistence.FetchType;
 23  
 import javax.persistence.GeneratedValue;
 24  
 import javax.persistence.Id;
 25  
 import javax.persistence.JoinColumn;
 26  
 import javax.persistence.OneToOne;
 27  
 import javax.persistence.Table;
 28  
 
 29  
 import org.hibernate.annotations.GenericGenerator;
 30  
 import org.hibernate.annotations.Parameter;
 31  
 import org.kuali.rice.kew.api.action.DelegationType;
 32  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 33  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 34  
 import org.kuali.rice.kew.util.KEWConstants;
 35  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
 36  
 
 37  
 
 38  
 /**
 39  
  * A model bean representing the delegation of a rule from a responsibility to
 40  
  * another rule.  Specifies the delegation type which can be either
 41  
  * {@link KEWConstants#DELEGATION_PRIMARY} or {@link KEWConstants#DELEGATION_SECONDARY}.
 42  
  *
 43  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 44  
  */
 45  
 @Entity
 46  
 @Table(name="KREW_DLGN_RSP_T")
 47  
 //@Sequence(name="KREW_RTE_TMPL_S", property="ruleDelegationId")
 48  
 public class RuleDelegation extends PersistableBusinessObjectBase {
 49  
 
 50  
         private static final long serialVersionUID = 7989203310473741293L;
 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="DLGN_RULE_ID")
 58  
         private String ruleDelegationId;
 59  
     @Column(name="RSP_ID")
 60  
         private String responsibilityId;
 61  
     @Column(name="DLGN_RULE_BASE_VAL_ID", insertable=false, updatable=false)
 62  
         private String delegateRuleId;
 63  0
     @Column(name="DLGN_TYP")
 64  
     private String delegationType = DelegationType.PRIMARY.getCode();
 65  
 
 66  
     @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
 67  
         @JoinColumn(name="DLGN_RULE_BASE_VAL_ID")
 68  
         private RuleBaseValues delegationRuleBaseValues;
 69  
 //    @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
 70  
 //        @JoinColumn(name="RULE_RSP_ID")
 71  
 //        private RuleResponsibility ruleResponsibility;
 72  
 
 73  0
     public RuleDelegation() {
 74  0
     }
 75  
 
 76  
     public Object copy(boolean preserveKeys) {
 77  0
         RuleDelegation clone = new RuleDelegation();
 78  0
         if (ruleDelegationId != null && preserveKeys) {
 79  0
             clone.setRuleDelegationId(ruleDelegationId);
 80  
         }
 81  0
         clone.setDelegationRuleBaseValues(delegationRuleBaseValues);
 82  0
         clone.setDelegateRuleId(delegationRuleBaseValues.getRuleBaseValuesId());
 83  0
         if (delegationType != null) {
 84  0
             clone.setDelegationType(new String(delegationType));
 85  
         }
 86  0
         return clone;
 87  
     }
 88  
 
 89  
     public String getDelegateRuleId() {
 90  0
         return delegateRuleId;
 91  
     }
 92  
     public void setDelegateRuleId(String delegateRuleId) {
 93  0
         this.delegateRuleId = delegateRuleId;
 94  0
     }
 95  
     public RuleBaseValues getDelegationRuleBaseValues() {
 96  0
         return delegationRuleBaseValues;
 97  
     }
 98  
     public void setDelegationRuleBaseValues(RuleBaseValues delegationRuleBaseValues) {
 99  0
         this.delegationRuleBaseValues = delegationRuleBaseValues;
 100  0
     }
 101  
     public String getDelegationType() {
 102  0
         return delegationType;
 103  
     }
 104  
     public void setDelegationType(String delegationType) {
 105  0
         this.delegationType = delegationType;
 106  0
     }
 107  
     public String getRuleDelegationId() {
 108  0
         return ruleDelegationId;
 109  
     }
 110  
     public void setRuleDelegationId(String ruleDelegationId) {
 111  0
         this.ruleDelegationId = ruleDelegationId;
 112  0
     }
 113  
 
 114  
     /**
 115  
      * Returns the most recent RuleResponsibility for the responsibility
 116  
      * id on this RuleDelegation.
 117  
      */
 118  
     public RuleResponsibility getRuleResponsibility() {
 119  0
             if ( getResponsibilityId() == null ) {
 120  0
                     return null;
 121  
             }
 122  0
             return KEWServiceLocator.getRuleService().findRuleResponsibility(getResponsibilityId());
 123  
     }
 124  
 
 125  
     public DocumentType getDocumentType() {
 126  0
         return this.getDelegationRuleBaseValues().getDocumentType();
 127  
     }
 128  
 
 129  
     public String getResponsibilityId() {
 130  0
         return responsibilityId;
 131  
     }
 132  
     public void setResponsibilityId(String ruleResponsibilityId) {
 133  0
         this.responsibilityId = ruleResponsibilityId;
 134  0
     }
 135  
 
 136  
         /**
 137  
          * An override of the refresh() method that properly preserves the RuleBaseValues instance. If the delegationRuleBaseValues property
 138  
          * becomes null as a result of the refresh() method on the PersistableBusinessObjectBase superclass, an attempt is made to retrieve
 139  
          * it by calling refreshReferenceObject() for the property. If that also fails, then the RuleBaseValues instance that was in-place
 140  
          * prior to the refresh() superclass call will be used as the delegationRuleBaseValues property's value. This override is necessary
 141  
          * in order to prevent certain exceptions during the cancellation of a rule delegation maintenance document.
 142  
          * 
 143  
          * @see org.kuali.rice.krad.bo.PersistableBusinessObjectBase#refresh()
 144  
          * @see org.kuali.rice.krad.bo.PersistableBusinessObjectBase#refreshReferenceObject(java.lang.String)
 145  
          */
 146  
         @Override
 147  
         public void refresh() {
 148  0
                 RuleBaseValues oldRuleBaseValues = this.getDelegationRuleBaseValues();
 149  0
                 super.refresh();
 150  0
                 if (this.getDelegationRuleBaseValues() == null) {
 151  0
                         this.refreshReferenceObject("delegationRuleBaseValues");
 152  0
                         if (this.getDelegationRuleBaseValues() == null) {
 153  0
                                 this.setDelegationRuleBaseValues(oldRuleBaseValues);
 154  
                         }
 155  
                 }
 156  0
         }
 157  
 }
 158