View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.rule;
17  
18  import org.hibernate.annotations.GenericGenerator;
19  import org.hibernate.annotations.Parameter;
20  import org.kuali.rice.core.api.delegation.DelegationType;
21  import org.kuali.rice.kew.api.rule.RuleDelegationContract;
22  import org.kuali.rice.kew.doctype.bo.DocumentType;
23  import org.kuali.rice.kew.service.KEWServiceLocator;
24  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
25  
26  import javax.persistence.CascadeType;
27  import javax.persistence.Column;
28  import javax.persistence.Entity;
29  import javax.persistence.FetchType;
30  import javax.persistence.GeneratedValue;
31  import javax.persistence.Id;
32  import javax.persistence.JoinColumn;
33  import javax.persistence.OneToOne;
34  import javax.persistence.Table;
35  import javax.persistence.Transient;
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 {@link DelegationType#PRIMARY} or {@link DelegationType#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 RuleDelegationBo extends PersistableBusinessObjectBase implements RuleDelegationContract {
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      @Column(name="DLGN_TYP")
64      private String delegationTypeCode = DelegationType.PRIMARY.getCode();
65  
66      @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
67  	@JoinColumn(name="DLGN_RULE_BASE_VAL_ID")
68  	private RuleBaseValues delegationRule;
69  //    @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
70  //	@JoinColumn(name="RULE_RSP_ID")
71  //	private RuleResponsibility ruleResponsibility;
72  
73      @Transient
74      private String groupReviewerName;
75      @Transient
76      private String groupReviewerNamespace;
77      @Transient
78      private String personReviewer;
79      @Transient
80      private String personReviewerType;
81  
82      public RuleDelegationBo() {
83      }
84  
85      public Object copy(boolean preserveKeys) {
86          RuleDelegationBo clone = new RuleDelegationBo();
87          if (ruleDelegationId != null && preserveKeys) {
88              clone.setRuleDelegationId(ruleDelegationId);
89          }
90          clone.setDelegationRule(delegationRule);
91          clone.setDelegateRuleId(delegationRule.getId());
92          if (delegationTypeCode != null) {
93              clone.setDelegationType(DelegationType.fromCode(delegationTypeCode));
94          }
95          return clone;
96      }
97  
98      public String getDelegateRuleId() {
99          return delegateRuleId;
100     }
101     public void setDelegateRuleId(String delegateRuleId) {
102         this.delegateRuleId = delegateRuleId;
103     }
104 
105     @Override
106     public RuleBaseValues getDelegationRule() {
107         return delegationRule;
108     }
109 
110     public RuleBaseValues getDelegationRuleBaseValues() {
111         return delegationRule;
112     }
113 
114     public void setDelegationRuleBaseValues(RuleBaseValues delegationRuleBaseValues) {
115         this.delegationRule = delegationRuleBaseValues;
116     }
117 
118     public void setDelegationRule(RuleBaseValues delegationRule) {
119         this.delegationRule = delegationRule;
120     }
121 
122     /**
123      * Setter for type code preserved for DD
124      * @param delegationTypeCode the DelegationType code
125      */
126     public void setDelegationTypeCode(String delegationTypeCode) {
127         DelegationType.fromCode(delegationTypeCode);
128         this.delegationTypeCode = delegationTypeCode;
129     }
130 
131     /**
132      * Getter for type code preserved for DD
133      * @return the DelegationType code
134      */
135     public String getDelegationTypeCode() {
136         return delegationTypeCode;
137     }
138 
139     @Override
140     public DelegationType getDelegationType() {
141         return DelegationType.fromCode(delegationTypeCode);
142     }
143     public void setDelegationType(DelegationType delegationType) {
144         this.delegationTypeCode = delegationType.getCode();
145     }
146     public String getRuleDelegationId() {
147         return ruleDelegationId;
148     }
149     public void setRuleDelegationId(String ruleDelegationId) {
150         this.ruleDelegationId = ruleDelegationId;
151     }
152 
153     /**
154      * Returns the most recent RuleResponsibility for the responsibility
155      * id on this RuleDelegation.
156      */
157     public RuleResponsibilityBo getRuleResponsibility() {
158     	if ( getResponsibilityId() == null ) {
159     		return null;
160     	}
161     	return KEWServiceLocator.getRuleService().findRuleResponsibility(getResponsibilityId());
162     }
163 
164     public DocumentType getDocumentType() {
165         return this.getDelegationRule().getDocumentType();
166     }
167 
168     public String getResponsibilityId() {
169         return responsibilityId;
170     }
171     public void setResponsibilityId(String ruleResponsibilityId) {
172         this.responsibilityId = ruleResponsibilityId;
173     }
174 
175     public String getGroupReviewerName() {
176         return this.groupReviewerName;
177     }
178 
179     public String getGroupReviewerNamespace() {
180         return this.groupReviewerNamespace;
181     }
182 
183     public String getPersonReviewer() {
184         return this.personReviewer;
185     }
186 
187     public void setGroupReviewerName(String groupReviewerName) {
188         this.groupReviewerName = groupReviewerName;
189     }
190 
191     public void setGroupReviewerNamespace(String groupReviewerNamespace) {
192         this.groupReviewerNamespace = groupReviewerNamespace;
193     }
194 
195     public void setPersonReviewer(String personReviewer) {
196         this.personReviewer = personReviewer;
197     }
198 
199     public String getPersonReviewerType() {
200         return this.personReviewerType;
201     }
202 
203     public void setPersonReviewerType(String personReviewerType) {
204         this.personReviewerType = personReviewerType;
205     }
206 
207 
208 
209         /**
210        * An override of the refresh() method that properly preserves the RuleBaseValues instance. If the delegationRuleBaseValues property
211        * becomes null as a result of the refresh() method on the PersistableBusinessObjectBase superclass, an attempt is made to retrieve
212        * it by calling refreshReferenceObject() for the property. If that also fails, then the RuleBaseValues instance that was in-place
213        * prior to the refresh() superclass call will be used as the delegationRuleBaseValues property's value. This override is necessary
214        * in order to prevent certain exceptions during the cancellation of a rule delegation maintenance document.
215        *
216        * @see org.kuali.rice.krad.bo.PersistableBusinessObjectBase#refresh()
217        * @see org.kuali.rice.krad.bo.PersistableBusinessObjectBase#refreshReferenceObject(java.lang.String)
218        */
219 	@Override
220 	public void refresh() {
221 		RuleBaseValues oldRuleBaseValues = this.getDelegationRule();
222 		super.refresh();
223 		if (this.getDelegationRule() == null) {
224 			this.refreshReferenceObject("delegationRuleBaseValues");
225 			if (this.getDelegationRule() == null) {
226 				this.setDelegationRule(oldRuleBaseValues);
227 			}
228 		}
229 	}
230 
231     public static org.kuali.rice.kew.api.rule.RuleDelegation to(RuleDelegationBo bo) {
232         if (bo == null) {
233             return null;
234         }
235         return org.kuali.rice.kew.api.rule.RuleDelegation.Builder.create(bo).build();
236         /*org.kuali.rice.kew.api.rule.RuleDelegation.Builder builder = org.kuali.rice.kew.api.rule.RuleDelegation.Builder.create();
237         builder.setDelegationType(bo.getDelegationType());
238         builder.setDelegationRule(org.kuali.rice.kew.api.rule.Rule.Builder.create(RuleBaseValues.to(
239                 bo.getDelegationRule())));
240         return builder.build();*/
241     }
242 }
243