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