1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.rule;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.hibernate.annotations.GenericGenerator;
20 import org.hibernate.annotations.Parameter;
21 import org.kuali.rice.core.api.delegation.DelegationType;
22 import org.kuali.rice.kew.api.rule.RuleDelegationContract;
23 import org.kuali.rice.kew.doctype.bo.DocumentType;
24 import org.kuali.rice.kew.service.KEWServiceLocator;
25 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
26 import org.kuali.rice.kim.impl.group.GroupBo;
27 import org.kuali.rice.kim.impl.identity.PersonImpl;
28 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
29
30 import javax.persistence.CascadeType;
31 import javax.persistence.Column;
32 import javax.persistence.Entity;
33 import javax.persistence.FetchType;
34 import javax.persistence.GeneratedValue;
35 import javax.persistence.Id;
36 import javax.persistence.JoinColumn;
37 import javax.persistence.OneToOne;
38 import javax.persistence.Table;
39 import javax.persistence.Transient;
40
41
42
43
44
45
46
47
48
49 @Entity
50 @Table(name="KREW_DLGN_RSP_T")
51
52 public class RuleDelegationBo extends PersistableBusinessObjectBase implements RuleDelegationContract {
53
54 private static final long serialVersionUID = 7989203310473741293L;
55 @Id
56 @GeneratedValue(generator="KREW_RTE_TMPL_S")
57 @GenericGenerator(name="KREW_RTE_TMPL_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
58 @Parameter(name="sequence_name",value="KREW_RTE_TMPL_S"),
59 @Parameter(name="value_column",value="id")
60 })
61 @Column(name="DLGN_RULE_ID")
62 private String ruleDelegationId;
63 @Column(name="RSP_ID")
64 private String responsibilityId;
65 @Column(name="DLGN_RULE_BASE_VAL_ID", insertable=false, updatable=false)
66 private String delegateRuleId;
67 @Column(name="DLGN_TYP")
68 private String delegationTypeCode = DelegationType.PRIMARY.getCode();
69
70 @OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
71 @JoinColumn(name="DLGN_RULE_BASE_VAL_ID")
72 private RuleBaseValues delegationRule;
73
74
75
76
77 @Transient
78 private String groupReviewerName;
79 @Transient
80 private String groupReviewerNamespace;
81 @Transient
82 private String personReviewer;
83 @Transient
84 private String personReviewerType;
85
86 public RuleDelegationBo() {
87 }
88
89 public Object copy(boolean preserveKeys) {
90 RuleDelegationBo clone = new RuleDelegationBo();
91 if (ruleDelegationId != null && preserveKeys) {
92 clone.setRuleDelegationId(ruleDelegationId);
93 }
94 clone.setDelegationRule(delegationRule);
95 clone.setDelegateRuleId(delegationRule.getId());
96 if (delegationTypeCode != null) {
97 clone.setDelegationType(DelegationType.fromCode(delegationTypeCode));
98 }
99 return clone;
100 }
101
102 public String getDelegateRuleId() {
103 return delegateRuleId;
104 }
105 public void setDelegateRuleId(String delegateRuleId) {
106 this.delegateRuleId = delegateRuleId;
107 }
108
109 @Override
110 public RuleBaseValues getDelegationRule() {
111 return delegationRule;
112 }
113
114 public RuleBaseValues getDelegationRuleBaseValues() {
115 return delegationRule;
116 }
117
118 public void setDelegationRuleBaseValues(RuleBaseValues delegationRuleBaseValues) {
119 this.delegationRule = delegationRuleBaseValues;
120 }
121
122 public void setDelegationRule(RuleBaseValues delegationRule) {
123 this.delegationRule = delegationRule;
124 }
125
126
127
128
129
130 public void setDelegationTypeCode(String delegationTypeCode) {
131 DelegationType.fromCode(delegationTypeCode);
132 this.delegationTypeCode = delegationTypeCode;
133 }
134
135
136
137
138
139 public String getDelegationTypeCode() {
140 return delegationTypeCode;
141 }
142
143 @Override
144 public DelegationType getDelegationType() {
145 return DelegationType.fromCode(delegationTypeCode);
146 }
147 public void setDelegationType(DelegationType delegationType) {
148 this.delegationTypeCode = delegationType.getCode();
149 }
150 public String getRuleDelegationId() {
151 return ruleDelegationId;
152 }
153 public void setRuleDelegationId(String ruleDelegationId) {
154 this.ruleDelegationId = ruleDelegationId;
155 }
156
157
158
159
160
161 public RuleResponsibilityBo getRuleResponsibility() {
162 if ( getResponsibilityId() == null ) {
163 return null;
164 }
165 return KEWServiceLocator.getRuleService().findRuleResponsibility(getResponsibilityId());
166 }
167
168 public DocumentType getDocumentType() {
169 return this.getDelegationRule().getDocumentType();
170 }
171
172 public String getResponsibilityId() {
173 return responsibilityId;
174 }
175 public void setResponsibilityId(String ruleResponsibilityId) {
176 this.responsibilityId = ruleResponsibilityId;
177 }
178
179 public String getGroupReviewerName() {
180 return this.groupReviewerName;
181 }
182
183 public String getGroupReviewerNamespace() {
184 return this.groupReviewerNamespace;
185 }
186
187 public String getPersonReviewer() {
188 return this.personReviewer;
189 }
190
191 public void setGroupReviewerName(String groupReviewerName) {
192 this.groupReviewerName = groupReviewerName;
193 }
194
195 public void setGroupReviewerNamespace(String groupReviewerNamespace) {
196 this.groupReviewerNamespace = groupReviewerNamespace;
197 }
198
199 public void setPersonReviewer(String personReviewer) {
200 this.personReviewer = personReviewer;
201 }
202
203 public String getPersonReviewerType() {
204 return this.personReviewerType;
205 }
206
207 public void setPersonReviewerType(String personReviewerType) {
208 this.personReviewerType = personReviewerType;
209 }
210
211 public GroupBo getGroupBo() {
212 GroupBo groupBo = null;
213 if (StringUtils.isNotBlank(getGroupReviewerName())) {
214 if ( groupBo == null ) {
215 groupBo = GroupBo.from(KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(
216 getGroupReviewerNamespace(), getGroupReviewerName()));
217 }
218 }
219 return groupBo;
220 }
221
222 public PersonImpl getPersonImpl() {
223 return new PersonImpl();
224 }
225
226
227
228
229
230
231
232
233
234
235
236 @Override
237 public void refresh() {
238 RuleBaseValues oldRuleBaseValues = this.getDelegationRule();
239 super.refresh();
240 if (this.getDelegationRule() == null) {
241 this.refreshReferenceObject("delegationRuleBaseValues");
242 if (this.getDelegationRule() == null) {
243 this.setDelegationRule(oldRuleBaseValues);
244 }
245 }
246 }
247
248 public static org.kuali.rice.kew.api.rule.RuleDelegation to(RuleDelegationBo bo) {
249 if (bo == null) {
250 return null;
251 }
252 return org.kuali.rice.kew.api.rule.RuleDelegation.Builder.create(bo).build();
253
254
255
256
257
258 }
259 }
260