View Javadoc
1   /**
2    * Copyright 2005-2015 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.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.delegation.DelegationType;
20  import org.kuali.rice.kew.api.rule.RuleDelegationContract;
21  import org.kuali.rice.kew.doctype.bo.DocumentType;
22  import org.kuali.rice.kew.service.KEWServiceLocator;
23  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
24  import org.kuali.rice.kim.impl.group.GroupBo;
25  import org.kuali.rice.kim.impl.identity.PersonImpl;
26  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
27  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
28  
29  import javax.persistence.CascadeType;
30  import javax.persistence.Column;
31  import javax.persistence.Entity;
32  import javax.persistence.FetchType;
33  import javax.persistence.GeneratedValue;
34  import javax.persistence.Id;
35  import javax.persistence.JoinColumn;
36  import javax.persistence.OneToOne;
37  import javax.persistence.Table;
38  import javax.persistence.Transient;
39  
40  
41  /**
42   * A model bean representing the delegation of a rule from a responsibility to
43   * another rule.  Specifies the delegation type which can be either
44   * {@link {@link DelegationType#PRIMARY} or {@link DelegationType#SECONDARY}.
45   *
46   * @author Kuali Rice Team (rice.collab@kuali.org)
47   */
48  @Entity
49  @Table(name="KREW_DLGN_RSP_T")
50  //@Sequence(name="KREW_RTE_TMPL_S", property="ruleDelegationId")
51  public class RuleDelegationBo extends PersistableBusinessObjectBase implements RuleDelegationContract {
52  
53  	private static final long serialVersionUID = 7989203310473741293L;
54  	@Id
55      @PortableSequenceGenerator(name="KREW_RTE_TMPL_S")
56  	@GeneratedValue(generator="KREW_RTE_TMPL_S")
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",nullable = false)
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     public GroupBo getGroupBo() {
208         GroupBo groupBo = null;
209         if (StringUtils.isNotBlank(getGroupReviewerName()) && StringUtils.isNotBlank(getGroupReviewerNamespace()) ) {
210             if ( groupBo == null ) {
211                 groupBo = GroupBo.from(KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(
212                         getGroupReviewerNamespace(), getGroupReviewerName()));
213             }
214         }
215         return groupBo;
216     }
217 
218     public PersonImpl getPersonImpl() {
219         return new PersonImpl();
220     }
221 
222 //        /**
223 //       * An override of the refresh() method that properly preserves the RuleBaseValues instance. If the delegationRuleBaseValues property
224 //       * becomes null as a result of the refresh() method on the PersistableBusinessObjectBase superclass, an attempt is made to retrieve
225 //       * it by calling refreshReferenceObject() for the property. If that also fails, then the RuleBaseValues instance that was in-place
226 //       * prior to the refresh() superclass call will be used as the delegationRuleBaseValues property's value. This override is necessary
227 //       * in order to prevent certain exceptions during the cancellation of a rule delegation maintenance document.
228 //       *
229 //       * @see org.kuali.rice.krad.bo.PersistableBusinessObjectBase#refresh()
230 //       * @see org.kuali.rice.krad.bo.PersistableBusinessObjectBase#refreshReferenceObject(java.lang.String)
231 //       */
232 //	@Override
233 //	public void refresh() {
234 //		RuleBaseValues oldRuleBaseValues = this.getDelegationRule();
235 //		super.refresh();
236 //		if (this.getDelegationRule() == null) {
237 //			this.refreshReferenceObject("delegationRuleBaseValues");
238 //			if (this.getDelegationRule() == null) {
239 //				this.setDelegationRule(oldRuleBaseValues);
240 //			}
241 //		}
242 //	}
243 
244     public static org.kuali.rice.kew.api.rule.RuleDelegation to(RuleDelegationBo bo) {
245         if (bo == null) {
246             return null;
247         }
248         return org.kuali.rice.kew.api.rule.RuleDelegation.Builder.create(bo).build();
249         /*org.kuali.rice.kew.api.rule.RuleDelegation.Builder builder = org.kuali.rice.kew.api.rule.RuleDelegation.Builder.create();
250         builder.setDelegationType(bo.getDelegationType());
251         builder.setDelegationRule(org.kuali.rice.kew.api.rule.Rule.Builder.create(RuleBaseValues.to(
252                 bo.getDelegationRule())));
253         return builder.build();*/
254     }
255 }
256