1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.rule.bo; |
17 | |
|
18 | |
import org.apache.commons.lang.ArrayUtils; |
19 | |
import org.hibernate.annotations.Fetch; |
20 | |
import org.hibernate.annotations.FetchMode; |
21 | |
import org.hibernate.annotations.GenericGenerator; |
22 | |
import org.hibernate.annotations.Parameter; |
23 | |
import org.kuali.rice.kew.api.rule.RoleName; |
24 | |
import org.kuali.rice.kew.api.rule.RuleTemplate; |
25 | |
import org.kuali.rice.kew.api.rule.RuleTemplateContract; |
26 | |
import org.kuali.rice.kew.rule.RoleAttribute; |
27 | |
import org.kuali.rice.kew.rule.RuleTemplateOptionBo; |
28 | |
import org.kuali.rice.kew.rule.WorkflowRuleAttribute; |
29 | |
import org.kuali.rice.kew.api.KewApiConstants; |
30 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; |
31 | |
|
32 | |
import javax.persistence.CascadeType; |
33 | |
import javax.persistence.Column; |
34 | |
import javax.persistence.Entity; |
35 | |
import javax.persistence.FetchType; |
36 | |
import javax.persistence.GeneratedValue; |
37 | |
import javax.persistence.Id; |
38 | |
import javax.persistence.JoinColumn; |
39 | |
import javax.persistence.NamedQueries; |
40 | |
import javax.persistence.NamedQuery; |
41 | |
import javax.persistence.OneToMany; |
42 | |
import javax.persistence.OneToOne; |
43 | |
import javax.persistence.Table; |
44 | |
import javax.persistence.Transient; |
45 | |
import java.net.URLEncoder; |
46 | |
import java.util.ArrayList; |
47 | |
import java.util.Collections; |
48 | |
import java.util.Iterator; |
49 | |
import java.util.List; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | 0 | @Entity |
60 | |
@Table(name="KREW_RULE_TMPL_T") |
61 | |
|
62 | |
@NamedQueries({@NamedQuery(name="findAllOrderedByName", query="SELECT rt FROM RuleTemplate rt ORDER BY rt.name ASC")}) |
63 | |
public class RuleTemplateBo extends PersistableBusinessObjectBase implements RuleTemplateContract { |
64 | |
|
65 | |
private static final long serialVersionUID = -3387940485523951302L; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | 0 | public static final String[] DEFAULT_OPTION_KEYS = { |
71 | |
|
72 | |
KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, |
73 | |
KewApiConstants.ACTION_REQUEST_APPROVE_REQ, |
74 | |
KewApiConstants.ACTION_REQUEST_COMPLETE_REQ, |
75 | |
KewApiConstants.ACTION_REQUEST_FYI_REQ, |
76 | |
KewApiConstants.ACTION_REQUEST_DEFAULT_CD |
77 | |
}; |
78 | |
|
79 | |
@Id |
80 | |
@GeneratedValue(generator="KREW_RTE_TMPL_S") |
81 | |
@GenericGenerator(name="KREW_RTE_TMPL_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ |
82 | |
@Parameter(name="sequence_name",value="KREW_RTE_TMPL_S"), |
83 | |
@Parameter(name="value_column",value="id") |
84 | |
}) |
85 | |
@Column(name="RULE_TMPL_ID") |
86 | |
private String id; |
87 | |
@Column(name="NM") |
88 | |
private String name; |
89 | |
@Column(name="RULE_TMPL_DESC") |
90 | |
private String description; |
91 | |
|
92 | |
@Column(name="DLGN_RULE_TMPL_ID", insertable=false, updatable=false) |
93 | |
private String delegationTemplateId; |
94 | |
@OneToOne(fetch=FetchType.EAGER) |
95 | |
@JoinColumn(name="DLGN_RULE_TMPL_ID") |
96 | |
private RuleTemplateBo delegationTemplate; |
97 | |
@Fetch(value = FetchMode.SELECT) |
98 | |
@OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE}, |
99 | |
mappedBy="ruleTemplate") |
100 | |
private List<RuleTemplateAttributeBo> ruleTemplateAttributes; |
101 | |
@Fetch(value = FetchMode.SELECT) |
102 | |
@OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE}, |
103 | |
mappedBy="ruleTemplate", orphanRemoval=true) |
104 | |
private List<RuleTemplateOptionBo> ruleTemplateOptions; |
105 | |
|
106 | |
|
107 | |
@Transient |
108 | |
private String returnUrl; |
109 | |
|
110 | 0 | public RuleTemplateBo() { |
111 | 0 | ruleTemplateAttributes = new ArrayList<RuleTemplateAttributeBo>(); |
112 | 0 | ruleTemplateOptions = new ArrayList<RuleTemplateOptionBo>(); |
113 | 0 | } |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public void removeNonDefaultOptions() { |
120 | 0 | Iterator<RuleTemplateOptionBo> it = ruleTemplateOptions.iterator(); |
121 | 0 | while (it.hasNext()) { |
122 | 0 | RuleTemplateOptionBo option = it.next(); |
123 | |
|
124 | 0 | if (!ArrayUtils.contains(DEFAULT_OPTION_KEYS, option.getCode())) { |
125 | 0 | it.remove(); |
126 | |
} |
127 | 0 | } |
128 | 0 | } |
129 | |
|
130 | |
public String getDelegateTemplateName() { |
131 | 0 | if (delegationTemplate != null) { |
132 | 0 | return delegationTemplate.getName(); |
133 | |
} |
134 | 0 | return ""; |
135 | |
} |
136 | |
|
137 | |
public String getRuleTemplateActionsUrl() { |
138 | 0 | return "<a href=\"RuleTemplate.do?methodToCall=report¤tRuleTemplateId=" + id + "\" >report</a>" ; |
139 | |
|
140 | |
} |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
private RuleTemplateAttributeBo getRuleTemplateAttribute(RuleTemplateAttributeBo ruleTemplateAttribute, Boolean active) { |
172 | 0 | for (RuleTemplateAttributeBo currentRuleTemplateAttribute: getRuleTemplateAttributes()) { |
173 | 0 | if (currentRuleTemplateAttribute.getRuleAttribute().getName().equals(ruleTemplateAttribute.getRuleAttribute().getName())) { |
174 | 0 | if (active == null) { |
175 | 0 | return currentRuleTemplateAttribute; |
176 | |
} |
177 | 0 | else if (active.compareTo(currentRuleTemplateAttribute.getActive()) == 0) { |
178 | 0 | return currentRuleTemplateAttribute; |
179 | |
} |
180 | |
} |
181 | |
} |
182 | 0 | return null; |
183 | |
} |
184 | |
|
185 | |
public RuleTemplateAttributeBo getRuleTemplateAttribute(RuleTemplateAttributeBo ruleTemplateAttribute) { |
186 | 0 | return getRuleTemplateAttribute(ruleTemplateAttribute, null); |
187 | |
} |
188 | |
|
189 | |
public boolean containsActiveRuleTemplateAttribute(RuleTemplateAttributeBo templateAttribute) { |
190 | 0 | return (getRuleTemplateAttribute(templateAttribute, Boolean.TRUE) != null); |
191 | |
} |
192 | |
|
193 | |
public boolean containsRuleTemplateAttribute(RuleTemplateAttributeBo templateAttribute) { |
194 | 0 | return (getRuleTemplateAttribute(templateAttribute, null) != null); |
195 | |
} |
196 | |
|
197 | |
public RuleTemplateAttributeBo getRuleTemplateAttribute(int index) { |
198 | 0 | while (getRuleTemplateAttributes().size() <= index) { |
199 | 0 | getRuleTemplateAttributes().add(new RuleTemplateAttributeBo()); |
200 | |
} |
201 | 0 | return (RuleTemplateAttributeBo) getRuleTemplateAttributes().get(index); |
202 | |
} |
203 | |
|
204 | |
public List<RuleTemplateAttributeBo> getRuleTemplateAttributes() { |
205 | 0 | Collections.sort(ruleTemplateAttributes); |
206 | 0 | return ruleTemplateAttributes; |
207 | |
} |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
public List<RuleTemplateAttributeBo> getActiveRuleTemplateAttributes() { |
215 | 0 | List<RuleTemplateAttributeBo> activeAttributes = new ArrayList<RuleTemplateAttributeBo>(); |
216 | 0 | for (RuleTemplateAttributeBo templateAttribute : getRuleTemplateAttributes()) |
217 | |
{ |
218 | 0 | if (templateAttribute.isActive()) |
219 | |
{ |
220 | 0 | activeAttributes.add(templateAttribute); |
221 | |
} |
222 | |
} |
223 | 0 | Collections.sort(activeAttributes); |
224 | 0 | return activeAttributes; |
225 | |
} |
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
public void setActiveRuleTemplateAttributes(List<RuleTemplateAttributeBo> ruleTemplateAttributes) { |
232 | 0 | throw new UnsupportedOperationException("setActiveRuleTemplateAttributes is not implemented"); |
233 | |
} |
234 | |
|
235 | |
public void setRuleTemplateAttributes(List<RuleTemplateAttributeBo> ruleTemplateAttributes) { |
236 | 0 | this.ruleTemplateAttributes = ruleTemplateAttributes; |
237 | 0 | } |
238 | |
|
239 | |
public String getDescription() { |
240 | 0 | return description; |
241 | |
} |
242 | |
|
243 | |
public void setDescription(String description) { |
244 | 0 | this.description = description; |
245 | 0 | } |
246 | |
|
247 | |
public String getName() { |
248 | 0 | return name; |
249 | |
} |
250 | |
|
251 | |
public void setName(String name) { |
252 | 0 | this.name = name; |
253 | 0 | } |
254 | |
|
255 | |
public String getId() { |
256 | 0 | return id; |
257 | |
} |
258 | |
|
259 | |
public void setId(String id) { |
260 | 0 | this.id = id; |
261 | 0 | } |
262 | |
|
263 | |
public String getDelegationTemplateId() { |
264 | 0 | return delegationTemplateId; |
265 | |
} |
266 | |
|
267 | |
public void setDelegationTemplateId(String delegationTemplateId) { |
268 | 0 | this.delegationTemplateId = delegationTemplateId; |
269 | 0 | } |
270 | |
|
271 | |
public RuleTemplateBo getDelegationTemplate() { |
272 | 0 | return delegationTemplate; |
273 | |
} |
274 | |
|
275 | |
public void setDelegationTemplate(RuleTemplateBo delegationTemplate) { |
276 | 0 | this.delegationTemplate = delegationTemplate; |
277 | 0 | } |
278 | |
|
279 | |
public String getReturnUrl() { |
280 | 0 | return returnUrl; |
281 | |
} |
282 | |
|
283 | |
public void setReturnUrl(String returnUrl) { |
284 | 0 | this.returnUrl = returnUrl; |
285 | 0 | } |
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
public String getEncodedName() { |
291 | 0 | return URLEncoder.encode(getName()); |
292 | |
} |
293 | |
|
294 | |
public List<RuleTemplateOptionBo> getRuleTemplateOptions() { |
295 | 0 | return ruleTemplateOptions; |
296 | |
} |
297 | |
|
298 | |
public void setRuleTemplateOptions(List<RuleTemplateOptionBo> ruleTemplateOptions) { |
299 | 0 | this.ruleTemplateOptions = ruleTemplateOptions; |
300 | 0 | } |
301 | |
|
302 | |
public RuleTemplateOptionBo getRuleTemplateOption(String key) { |
303 | 0 | for (RuleTemplateOptionBo option: ruleTemplateOptions) { |
304 | 0 | if (option.getCode().equals(key)) { |
305 | 0 | return option; |
306 | |
} |
307 | |
} |
308 | 0 | return null; |
309 | |
} |
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
public void setAcknowledge(RuleTemplateOptionBo acknowledge) { |
319 | 0 | RuleTemplateOptionBo option = getRuleTemplateOption(KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ); |
320 | 0 | option.setValue(acknowledge.getValue()); |
321 | 0 | option.setId(acknowledge.getId()); |
322 | 0 | option.setVersionNumber(acknowledge.getVersionNumber()); |
323 | 0 | } |
324 | |
|
325 | |
public void setComplete(RuleTemplateOptionBo complete) { |
326 | 0 | RuleTemplateOptionBo option = getRuleTemplateOption(KewApiConstants.ACTION_REQUEST_COMPLETE_REQ); |
327 | 0 | option.setValue(complete.getValue()); |
328 | 0 | option.setId(complete.getId()); |
329 | 0 | option.setVersionNumber(complete.getVersionNumber()); |
330 | 0 | } |
331 | |
|
332 | |
public void setApprove(RuleTemplateOptionBo approve) { |
333 | 0 | RuleTemplateOptionBo option = getRuleTemplateOption(KewApiConstants.ACTION_REQUEST_APPROVE_REQ); |
334 | 0 | option.setValue(approve.getValue()); |
335 | 0 | option.setId(approve.getId()); |
336 | 0 | option.setVersionNumber(approve.getVersionNumber()); |
337 | 0 | } |
338 | |
|
339 | |
public void setFyi(RuleTemplateOptionBo fyi) { |
340 | 0 | RuleTemplateOptionBo option = getRuleTemplateOption(KewApiConstants.ACTION_REQUEST_FYI_REQ); |
341 | 0 | option.setValue(fyi.getValue()); |
342 | 0 | option.setId(fyi.getId()); |
343 | 0 | option.setVersionNumber(fyi.getVersionNumber()); |
344 | 0 | } |
345 | |
|
346 | |
public void setDefaultActionRequestValue(RuleTemplateOptionBo defaultActionRequestValue) { |
347 | 0 | RuleTemplateOptionBo option = getRuleTemplateOption(KewApiConstants.ACTION_REQUEST_DEFAULT_CD); |
348 | 0 | option.setValue(defaultActionRequestValue.getValue()); |
349 | 0 | option.setId(defaultActionRequestValue.getId()); |
350 | 0 | option.setVersionNumber(defaultActionRequestValue.getVersionNumber()); |
351 | 0 | } |
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
public RuleTemplateOptionBo getAcknowledge() { |
358 | 0 | return getRuleTemplateOption(KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ); |
359 | |
} |
360 | |
|
361 | |
public RuleTemplateOptionBo getComplete() { |
362 | 0 | return getRuleTemplateOption(KewApiConstants.ACTION_REQUEST_COMPLETE_REQ); |
363 | |
} |
364 | |
|
365 | |
public RuleTemplateOptionBo getApprove() { |
366 | 0 | return getRuleTemplateOption(KewApiConstants.ACTION_REQUEST_APPROVE_REQ); |
367 | |
} |
368 | |
|
369 | |
public RuleTemplateOptionBo getFyi() { |
370 | 0 | return getRuleTemplateOption(KewApiConstants.ACTION_REQUEST_FYI_REQ); |
371 | |
} |
372 | |
|
373 | |
public RuleTemplateOptionBo getDefaultActionRequestValue() { |
374 | 0 | return getRuleTemplateOption(KewApiConstants.ACTION_REQUEST_DEFAULT_CD); |
375 | |
} |
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | |
public List<RoleName> getRoles() { |
382 | 0 | List<RoleName> roles = new ArrayList<RoleName>(); |
383 | 0 | List<RuleTemplateAttributeBo> ruleTemplateAttributes = getActiveRuleTemplateAttributes(); |
384 | 0 | Collections.sort(ruleTemplateAttributes); |
385 | 0 | for (RuleTemplateAttributeBo ruleTemplateAttribute : ruleTemplateAttributes) |
386 | |
{ |
387 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) |
388 | |
{ |
389 | 0 | continue; |
390 | |
} |
391 | 0 | WorkflowRuleAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute(); |
392 | 0 | if (workflowAttribute instanceof RoleAttribute) |
393 | |
{ |
394 | 0 | RoleAttribute roleAttribute = (RoleAttribute) workflowAttribute; |
395 | 0 | roles.addAll(roleAttribute.getRoleNames()); |
396 | |
} |
397 | 0 | } |
398 | 0 | return roles; |
399 | |
} |
400 | |
|
401 | |
public static RuleTemplate to(RuleTemplateBo bo) { |
402 | 0 | if (bo == null) { |
403 | 0 | return null; |
404 | |
} |
405 | 0 | return RuleTemplate.Builder.create(bo).build(); |
406 | |
} |
407 | |
} |