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