1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.rule.web; |
18 | |
|
19 | |
import java.sql.Timestamp; |
20 | |
import java.text.ParseException; |
21 | |
import java.text.SimpleDateFormat; |
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Calendar; |
24 | |
import java.util.Collection; |
25 | |
import java.util.Collections; |
26 | |
import java.util.Date; |
27 | |
import java.util.HashMap; |
28 | |
import java.util.Iterator; |
29 | |
import java.util.List; |
30 | |
import java.util.Map; |
31 | |
|
32 | |
import org.apache.commons.beanutils.PropertyUtils; |
33 | |
import org.apache.commons.lang.StringUtils; |
34 | |
import org.apache.struts.action.ActionErrors; |
35 | |
import org.apache.struts.action.ActionMessage; |
36 | |
import org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils; |
37 | |
import org.kuali.rice.core.util.RiceConstants; |
38 | |
import org.kuali.rice.kew.exception.WorkflowServiceError; |
39 | |
import org.kuali.rice.kew.rule.KeyValueId; |
40 | |
import org.kuali.rice.kew.rule.RoleAttribute; |
41 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
42 | |
import org.kuali.rice.kew.rule.RuleDelegation; |
43 | |
import org.kuali.rice.kew.rule.RuleExtension; |
44 | |
import org.kuali.rice.kew.rule.RuleExtensionValue; |
45 | |
import org.kuali.rice.kew.rule.RuleResponsibility; |
46 | |
import org.kuali.rice.kew.rule.WorkflowAttribute; |
47 | |
import org.kuali.rice.kew.rule.bo.RuleAttribute; |
48 | |
import org.kuali.rice.kew.rule.bo.RuleTemplate; |
49 | |
import org.kuali.rice.kew.rule.bo.RuleTemplateAttribute; |
50 | |
import org.kuali.rice.kew.rule.service.RuleDelegationService; |
51 | |
import org.kuali.rice.kew.rule.service.RuleTemplateService; |
52 | |
import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute; |
53 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
54 | |
import org.kuali.rice.kew.util.CodeTranslator; |
55 | |
import org.kuali.rice.kew.util.KEWConstants; |
56 | |
import org.kuali.rice.kns.web.ui.Field; |
57 | |
import org.kuali.rice.kns.web.ui.Row; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public class WebRuleBaseValues extends RuleBaseValues { |
68 | |
|
69 | |
private static final long serialVersionUID = 5938997470219200474L; |
70 | |
private static final int TO_DATE_UPPER_LIMIT = 2100; |
71 | 0 | private List rows = new ArrayList(); |
72 | 0 | private List fields = new ArrayList(); |
73 | 0 | private List roles = new ArrayList(); |
74 | |
private String fromDateValue; |
75 | |
private String toDateValue; |
76 | |
private String ruleTemplateName; |
77 | 0 | private boolean hasExtensionValueErrors = false; |
78 | |
|
79 | 0 | public WebRuleBaseValues() { |
80 | 0 | } |
81 | |
|
82 | 0 | public WebRuleBaseValues(RuleBaseValues rule) throws Exception { |
83 | 0 | edit(rule); |
84 | 0 | } |
85 | |
|
86 | |
private void loadFields() { |
87 | 0 | fields.clear(); |
88 | 0 | if (getRuleTemplateId() != null) { |
89 | 0 | RuleTemplate ruleTemplate = getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId()); |
90 | 0 | if (ruleTemplate != null) { |
91 | 0 | List ruleTemplateAttributes = ruleTemplate.getActiveRuleTemplateAttributes(); |
92 | 0 | Collections.sort(ruleTemplateAttributes); |
93 | 0 | for (Iterator iter = ruleTemplateAttributes.iterator(); iter.hasNext();) { |
94 | 0 | RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter.next(); |
95 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) { |
96 | 0 | continue; |
97 | |
} |
98 | 0 | WorkflowAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute(); |
99 | 0 | RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute(); |
100 | 0 | if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
101 | 0 | ((GenericXMLRuleAttribute) workflowAttribute).setRuleAttribute(ruleAttribute); |
102 | |
} |
103 | 0 | for (Object element : workflowAttribute.getRuleRows()) { |
104 | 0 | Row row = (Row) element; |
105 | 0 | for (Object element2 : row.getFields()) { |
106 | 0 | Field field = (Field) element2; |
107 | 0 | if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
108 | 0 | String fieldValue = ""; |
109 | 0 | RuleExtensionValue extensionValue = getRuleExtensionValue(ruleTemplateAttribute.getRuleTemplateAttributeId(), field.getPropertyName()); |
110 | 0 | if (extensionValue != null) { |
111 | 0 | fieldValue = extensionValue.getValue(); |
112 | |
} else { |
113 | 0 | fieldValue = field.getPropertyValue(); |
114 | |
} |
115 | 0 | fields.add(new KeyValueId(field.getPropertyName(), fieldValue, ruleTemplateAttribute.getRuleTemplateAttributeId()+"")); |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | 0 | } else { |
126 | 0 | String fieldValue = ""; |
127 | 0 | RuleExtensionValue extensionValue = getRuleExtensionValue(ruleTemplateAttribute.getRuleTemplateAttributeId(), field.getPropertyName()); |
128 | 0 | if (extensionValue != null) { |
129 | 0 | fieldValue = extensionValue.getValue(); |
130 | |
} else { |
131 | 0 | fieldValue = field.getPropertyValue(); |
132 | |
} |
133 | 0 | fields.add(new KeyValueId(field.getPropertyName(), fieldValue, ruleTemplateAttribute.getRuleTemplateAttributeId()+"")); |
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 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | 0 | } |
186 | 0 | } |
187 | 0 | } |
188 | |
} |
189 | |
} |
190 | 0 | } |
191 | |
|
192 | |
public void loadFieldsWithDefaultValues() { |
193 | 0 | fields.clear(); |
194 | 0 | if (getRuleTemplateId() != null) { |
195 | 0 | RuleTemplate ruleTemplate = getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId()); |
196 | 0 | if (ruleTemplate != null) { |
197 | 0 | List ruleTemplateAttributes = ruleTemplate.getActiveRuleTemplateAttributes(); |
198 | 0 | Collections.sort(ruleTemplateAttributes); |
199 | 0 | for (Iterator iter = ruleTemplateAttributes.iterator(); iter.hasNext();) { |
200 | 0 | RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter.next(); |
201 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) { |
202 | 0 | continue; |
203 | |
} |
204 | 0 | WorkflowAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute(); |
205 | 0 | RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute(); |
206 | 0 | if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
207 | 0 | ((GenericXMLRuleAttribute) workflowAttribute).setRuleAttribute(ruleAttribute); |
208 | |
} |
209 | 0 | for (Object element : workflowAttribute.getRuleRows()) { |
210 | 0 | Row row = (Row) element; |
211 | 0 | for (Object element2 : row.getFields()) { |
212 | 0 | Field field = (Field) element2; |
213 | 0 | if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
214 | 0 | fields.add(new KeyValueId(field.getPropertyName(), field.getPropertyValue(), ruleTemplateAttribute.getRuleTemplateAttributeId() + "")); |
215 | |
|
216 | |
|
217 | |
} else { |
218 | 0 | fields.add(new KeyValueId(field.getPropertyName(), field.getPropertyValue(), ruleTemplateAttribute.getRuleTemplateAttributeId() + "")); |
219 | |
} |
220 | 0 | } |
221 | 0 | } |
222 | 0 | } |
223 | |
} |
224 | |
} |
225 | 0 | } |
226 | |
|
227 | |
private void loadWebValues() { |
228 | 0 | loadRows(); |
229 | 0 | loadDates(); |
230 | 0 | loadRuleTemplateName(); |
231 | 0 | } |
232 | |
|
233 | |
private void loadRows() { |
234 | 0 | getRoles().clear(); |
235 | 0 | if (getRuleTemplateId() != null) { |
236 | 0 | RuleTemplate ruleTemplate = getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId()); |
237 | 0 | if (ruleTemplate != null) { |
238 | 0 | setRuleTemplateName(ruleTemplate.getName()); |
239 | 0 | List ruleTemplateAttributes = ruleTemplate.getActiveRuleTemplateAttributes(); |
240 | 0 | Collections.sort(ruleTemplateAttributes); |
241 | 0 | List rows = new ArrayList(); |
242 | 0 | for (Iterator iter = ruleTemplateAttributes.iterator(); iter.hasNext();) { |
243 | 0 | RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) iter.next(); |
244 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) { |
245 | 0 | continue; |
246 | |
} |
247 | 0 | WorkflowAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute(); |
248 | |
|
249 | 0 | RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute(); |
250 | 0 | if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
251 | 0 | ((GenericXMLRuleAttribute) workflowAttribute).setRuleAttribute(ruleAttribute); |
252 | |
} |
253 | 0 | workflowAttribute.validateRuleData(getFieldMap(ruleTemplateAttribute.getRuleTemplateAttributeId()+"")); |
254 | 0 | rows.addAll(workflowAttribute.getRuleRows()); |
255 | 0 | if (workflowAttribute instanceof RoleAttribute) { |
256 | 0 | RoleAttribute roleAttribute = (RoleAttribute) workflowAttribute; |
257 | 0 | getRoles().addAll(roleAttribute.getRoleNames()); |
258 | |
} |
259 | 0 | } |
260 | 0 | setRows(rows); |
261 | |
} |
262 | |
} |
263 | 0 | } |
264 | |
|
265 | |
private void loadDates() { |
266 | 0 | if (getFromDate() != null) { |
267 | 0 | setFromDateValue(RiceConstants.getDefaultDateFormat().format(getFromDate())); |
268 | |
} |
269 | 0 | if (getToDate() != null) { |
270 | 0 | setToDateValue(RiceConstants.getDefaultDateFormat().format(getToDate())); |
271 | |
} |
272 | 0 | } |
273 | |
|
274 | |
private void loadRuleTemplateName() { |
275 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(getRuleTemplateName()) && getRuleTemplateId() != null) { |
276 | 0 | RuleTemplate ruleTemplate = getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId()); |
277 | 0 | if (ruleTemplate != null) { |
278 | 0 | setRuleTemplateName(ruleTemplate.getName()); |
279 | |
} |
280 | |
} |
281 | 0 | } |
282 | |
|
283 | |
public List getFields() { |
284 | 0 | return fields; |
285 | |
} |
286 | |
|
287 | |
public void setFields(List fields) { |
288 | 0 | this.fields = fields; |
289 | 0 | } |
290 | |
|
291 | |
public KeyValueId getField(int index) { |
292 | 0 | while (getFields().size() <= index) { |
293 | 0 | KeyValueId field = new KeyValueId(); |
294 | 0 | getFields().add(field); |
295 | 0 | } |
296 | 0 | return (KeyValueId) getFields().get(index); |
297 | |
} |
298 | |
|
299 | |
public String getFromDateValue() { |
300 | 0 | return fromDateValue; |
301 | |
} |
302 | |
|
303 | |
public void setFromDateValue(String fromDateValue) { |
304 | 0 | this.fromDateValue = fromDateValue; |
305 | 0 | } |
306 | |
|
307 | |
public List getRoles() { |
308 | 0 | return roles; |
309 | |
} |
310 | |
|
311 | |
public void setRoles(List roles) { |
312 | 0 | this.roles = roles; |
313 | 0 | } |
314 | |
|
315 | |
public List getRows() { |
316 | 0 | return rows; |
317 | |
} |
318 | |
|
319 | |
public void setRows(List ruleTemplateAttributes) { |
320 | 0 | this.rows = ruleTemplateAttributes; |
321 | 0 | } |
322 | |
|
323 | |
public String getToDateValue() { |
324 | 0 | return toDateValue; |
325 | |
} |
326 | |
|
327 | |
public void setToDateValue(String toDateValue) { |
328 | 0 | this.toDateValue = toDateValue; |
329 | 0 | } |
330 | |
|
331 | |
@Override |
332 | |
public String getRuleTemplateName() { |
333 | 0 | return ruleTemplateName; |
334 | |
} |
335 | |
|
336 | |
public void setRuleTemplateName(String ruleTemplateName) { |
337 | 0 | this.ruleTemplateName = ruleTemplateName; |
338 | 0 | } |
339 | |
|
340 | |
public boolean isHasExtensionValueErrors() { |
341 | 0 | return hasExtensionValueErrors; |
342 | |
} |
343 | |
|
344 | |
public void setHasExtensionValueErrors(boolean hasRuleExtensionValueErrors) { |
345 | 0 | this.hasExtensionValueErrors = hasRuleExtensionValueErrors; |
346 | 0 | } |
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
public void edit(RuleBaseValues rule) throws Exception { |
354 | 0 | load(rule); |
355 | 0 | initialize(); |
356 | 0 | } |
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
public void load(RuleBaseValues rule) throws Exception { |
362 | 0 | PropertyUtils.copyProperties(this, rule); |
363 | 0 | injectWebMembers(); |
364 | 0 | } |
365 | |
|
366 | |
public void initialize() throws Exception { |
367 | 0 | loadFields(); |
368 | |
|
369 | 0 | for (Object element : getResponsibilities()) { |
370 | 0 | WebRuleResponsibility responsibility = (WebRuleResponsibility) element; |
371 | 0 | responsibility.initialize(); |
372 | 0 | } |
373 | 0 | establishRequiredState(); |
374 | 0 | } |
375 | |
|
376 | |
private void injectWebMembers() throws Exception { |
377 | 0 | List currentResponsibilities = getResponsibilities(); |
378 | 0 | setResponsibilities(new ArrayList()); |
379 | 0 | for (Iterator iterator = currentResponsibilities.iterator(); iterator.hasNext();) { |
380 | 0 | RuleResponsibility responsibility = (RuleResponsibility) iterator.next(); |
381 | 0 | WebRuleResponsibility webResponsibility = createNewRuleResponsibility(); |
382 | 0 | webResponsibility.load(responsibility); |
383 | 0 | } |
384 | 0 | } |
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
public void establishRequiredState() throws Exception { |
390 | 0 | if (getActiveInd() == null) { |
391 | 0 | setActiveInd(Boolean.TRUE); |
392 | |
} |
393 | 0 | if (getForceAction() == null) { |
394 | 0 | setForceAction(Boolean.FALSE); |
395 | |
} |
396 | 0 | loadWebValues(); |
397 | 0 | if (getResponsibilities().isEmpty()) { |
398 | 0 | createNewRuleResponsibility(); |
399 | |
} |
400 | 0 | for (Object element : getResponsibilities()) { |
401 | 0 | WebRuleResponsibility responsibility = (WebRuleResponsibility) element; |
402 | 0 | responsibility.establishRequiredState(); |
403 | 0 | } |
404 | 0 | } |
405 | |
|
406 | |
@Override |
407 | |
public RuleResponsibility getResponsibility(int index) { |
408 | 0 | while (getResponsibilities().size() <= index) { |
409 | 0 | createNewRuleResponsibility(); |
410 | |
} |
411 | 0 | return getResponsibilities().get(index); |
412 | |
} |
413 | |
|
414 | |
public int getResponsibilitiesSize() { |
415 | 0 | return getResponsibilities().size(); |
416 | |
} |
417 | |
|
418 | |
public WebRuleResponsibility createNewRuleResponsibility() { |
419 | 0 | WebRuleResponsibility responsibility = new WebRuleResponsibility(); |
420 | 0 | responsibility.setRuleBaseValues(this); |
421 | 0 | addRuleResponsibility(responsibility); |
422 | 0 | return responsibility; |
423 | |
} |
424 | |
|
425 | |
public Map getFieldMap(String ruleTemplateAttributeId) { |
426 | 0 | Map fieldMap = new HashMap(); |
427 | 0 | for (Iterator iterator = getFields().iterator(); iterator.hasNext();) { |
428 | 0 | KeyValueId field = (KeyValueId) iterator.next(); |
429 | 0 | if (ruleTemplateAttributeId.equals(field.getId())) { |
430 | 0 | fieldMap.put(field.getKey(), field.getValue()); |
431 | |
} |
432 | 0 | } |
433 | 0 | return fieldMap; |
434 | |
} |
435 | |
|
436 | |
public void populatePreviousVersionIds() { |
437 | 0 | if (getPreviousVersionId() == null) { |
438 | 0 | setPreviousVersionId(getRuleBaseValuesId()); |
439 | |
} |
440 | 0 | for (Object element : getResponsibilities()) { |
441 | 0 | WebRuleResponsibility responsibility = (WebRuleResponsibility) element; |
442 | 0 | responsibility.populatePreviousVersionIds(); |
443 | 0 | } |
444 | 0 | } |
445 | |
|
446 | |
|
447 | |
|
448 | |
|
449 | |
public void materialize() { |
450 | 0 | if (getRuleTemplate() == null && getRuleTemplateId() != null) { |
451 | 0 | setRuleTemplate(getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId())); |
452 | |
} |
453 | 0 | } |
454 | |
|
455 | |
public void validateRule(String keyPrefix, ActionErrors errors) { |
456 | |
|
457 | 0 | if (getRuleTemplateId() == null) { |
458 | 0 | errors.add(keyPrefix + "ruleTemplateId", new ActionMessage("routetemplate.required.html", "rule template")); |
459 | |
} else { |
460 | 0 | List errorList = new ArrayList(); |
461 | 0 | populateRuleExtensionValues(errorList); |
462 | 0 | saveServiceErrors(keyPrefix + "ruleExtensionValues", errorList, errors); |
463 | 0 | if (!errorList.isEmpty()) { |
464 | 0 | setHasExtensionValueErrors(true); |
465 | |
} |
466 | |
} |
467 | |
|
468 | |
|
469 | |
|
470 | 0 | boolean dateParseProblem = false; |
471 | |
try { |
472 | 0 | setToDate(decodeTimestamp(getToDateValue())); |
473 | 0 | } catch (ParseException e) { |
474 | 0 | errors.add(keyPrefix + "toDateValue", new ActionMessage("routetemplate.required.html", "to date (MM/DD/YYYY)")); |
475 | 0 | dateParseProblem = true; |
476 | 0 | } |
477 | |
try { |
478 | 0 | setFromDate(decodeTimestamp(getFromDateValue())); |
479 | 0 | } catch (ParseException e) { |
480 | 0 | errors.add(keyPrefix + "fromDateValue", new ActionMessage("routetemplate.required.html", "from date (MM/DD/YYYY)")); |
481 | 0 | dateParseProblem = true; |
482 | 0 | } |
483 | 0 | throttleDates(); |
484 | 0 | if (getFromDate() == null) { |
485 | 0 | setFromDate(new Timestamp(new Date().getTime())); |
486 | |
} |
487 | 0 | if (getToDate() == null) { |
488 | |
try { |
489 | 0 | setToDate(new Timestamp(new SimpleDateFormat("MM/dd/yyyy").parse("01/01/2100").getTime())); |
490 | 0 | } catch (ParseException e) { |
491 | 0 | errors.add(keyPrefix + "toDateValue", new ActionMessage("routetemplate.required.html", "to date")); |
492 | 0 | dateParseProblem = true; |
493 | 0 | } |
494 | |
} |
495 | 0 | if (!dateParseProblem && getToDate().before(getFromDate())) { |
496 | 0 | errors.add(keyPrefix + "toDateValue", new ActionMessage("routetemplate.ruleservice.daterange.fromafterto")); |
497 | |
} |
498 | |
|
499 | 0 | if (getActiveInd() == null) { |
500 | 0 | errors.add(keyPrefix + "activeInd", new ActionMessage("routetemplate.ruleservice.activeind.required")); |
501 | |
} |
502 | |
|
503 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(getDescription())) { |
504 | 0 | errors.add(keyPrefix + "description", new ActionMessage("routetemplate.ruleservice.description.required")); |
505 | |
} |
506 | |
|
507 | 0 | if (getForceAction() == null) { |
508 | 0 | errors.add(keyPrefix + "forceAction", new ActionMessage("routetemplate.ruleservice.forceAction.required")); |
509 | |
} |
510 | |
|
511 | 0 | if (getResponsibilities().isEmpty()) { |
512 | 0 | errors.add(keyPrefix + "responsibilities", new ActionMessage("routetemplate.ruleservice.responsibility.required")); |
513 | |
} |
514 | |
|
515 | 0 | int respIndex = 0; |
516 | 0 | for (Object element : getResponsibilities()) { |
517 | 0 | WebRuleResponsibility responsibility = (WebRuleResponsibility) element; |
518 | 0 | String respPrefix = keyPrefix + "responsibility[" + respIndex + "]."; |
519 | 0 | responsibility.validateResponsibility(respPrefix, errors); |
520 | 0 | respIndex++; |
521 | 0 | } |
522 | 0 | } |
523 | |
|
524 | |
|
525 | |
|
526 | |
|
527 | |
|
528 | |
private void throttleDates() { |
529 | 0 | if (getToDate() != null) { |
530 | 0 | Calendar calendar = Calendar.getInstance(); |
531 | 0 | calendar.setTime(getToDate()); |
532 | 0 | if (calendar.get(Calendar.YEAR) > TO_DATE_UPPER_LIMIT) { |
533 | 0 | calendar.set(Calendar.YEAR, TO_DATE_UPPER_LIMIT); |
534 | 0 | setToDate(new Timestamp(calendar.getTimeInMillis())); |
535 | 0 | setToDateValue(new SimpleDateFormat("MM/dd/yyyy").format(getToDate())); |
536 | |
} |
537 | |
} |
538 | 0 | } |
539 | |
|
540 | |
private void saveServiceErrors(String errorKey, Collection srvErrors, ActionErrors errors) { |
541 | 0 | for (Iterator iterator = srvErrors.iterator(); iterator.hasNext();) { |
542 | 0 | WorkflowServiceError error = (WorkflowServiceError) iterator.next(); |
543 | 0 | if (error.getArg1() == null && error.getArg2() == null) { |
544 | 0 | errors.add(errorKey, new ActionMessage(error.getKey())); |
545 | 0 | } else if (error.getArg1() != null && error.getArg2() == null) { |
546 | 0 | errors.add(errorKey, new ActionMessage(error.getKey(), error.getArg1())); |
547 | |
} else { |
548 | 0 | errors.add(errorKey, new ActionMessage(error.getKey(), error.getArg1(), error.getArg2())); |
549 | |
} |
550 | 0 | } |
551 | 0 | } |
552 | |
|
553 | |
private Timestamp decodeTimestamp(String dateValue) throws ParseException { |
554 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(dateValue)) { |
555 | 0 | return null; |
556 | |
} |
557 | |
|
558 | |
|
559 | |
|
560 | 0 | String convertedDate = SQLUtils.getEntryFormattedDate(dateValue); |
561 | 0 | if (convertedDate == null) { |
562 | 0 | throw new ParseException("Date entered as '" + dateValue + "' is in invalid format", 0); |
563 | |
} |
564 | 0 | Date date = RiceConstants.getDefaultDateFormat().parse(convertedDate); |
565 | 0 | return new Timestamp(date.getTime()); |
566 | |
} |
567 | |
|
568 | |
private void populateRuleExtensionValues(List errorList) { |
569 | 0 | RuleTemplate ruleTemplate = getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId()); |
570 | 0 | setRuleTemplate(ruleTemplate); |
571 | |
|
572 | |
|
573 | 0 | List extensions = new ArrayList(); |
574 | 0 | for (Object element : ruleTemplate.getActiveRuleTemplateAttributes()) { |
575 | 0 | RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) element; |
576 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) { |
577 | 0 | continue; |
578 | |
} |
579 | 0 | WorkflowAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute(); |
580 | |
|
581 | 0 | RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute(); |
582 | 0 | if (ruleAttribute.getType().equals(KEWConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
583 | 0 | ((GenericXMLRuleAttribute) workflowAttribute).setRuleAttribute(ruleAttribute); |
584 | |
} |
585 | |
|
586 | 0 | List attValidationErrors = workflowAttribute.validateRuleData(getFieldMap(ruleTemplateAttribute.getRuleTemplateAttributeId()+"")); |
587 | 0 | if (attValidationErrors != null && !attValidationErrors.isEmpty()) { |
588 | 0 | errorList.addAll(attValidationErrors); |
589 | |
} else { |
590 | 0 | List ruleExtensionValues = workflowAttribute.getRuleExtensionValues(); |
591 | 0 | if (ruleExtensionValues != null && !ruleExtensionValues.isEmpty()) { |
592 | 0 | RuleExtension ruleExtension = new RuleExtension(); |
593 | 0 | ruleExtension.setRuleTemplateAttributeId(ruleTemplateAttribute.getRuleTemplateAttributeId()); |
594 | |
|
595 | 0 | ruleExtension.setExtensionValues(ruleExtensionValues); |
596 | 0 | extensions.add(ruleExtension); |
597 | |
} |
598 | |
} |
599 | 0 | } |
600 | 0 | setRuleExtensions(extensions); |
601 | 0 | setRuleTemplate(ruleTemplate); |
602 | |
|
603 | 0 | for (Object element : getRuleExtensions()) { |
604 | 0 | RuleExtension ruleExtension = (RuleExtension) element; |
605 | 0 | ruleExtension.setRuleBaseValues(this); |
606 | |
|
607 | 0 | for (Object element2 : ruleTemplate.getActiveRuleTemplateAttributes()) { |
608 | 0 | RuleTemplateAttribute ruleTemplateAttribute = (RuleTemplateAttribute) element2; |
609 | 0 | if (StringUtils.equals(ruleTemplateAttribute.getRuleTemplateAttributeId(), ruleExtension.getRuleTemplateAttributeId())) { |
610 | 0 | ruleExtension.setRuleTemplateAttribute(ruleTemplateAttribute); |
611 | 0 | break; |
612 | |
} |
613 | 0 | } |
614 | |
|
615 | 0 | for (Object element2 : ruleExtension.getExtensionValues()) { |
616 | 0 | RuleExtensionValue ruleExtensionValue = (RuleExtensionValue) element2; |
617 | 0 | ruleExtensionValue.setExtension(ruleExtension); |
618 | 0 | } |
619 | 0 | } |
620 | |
|
621 | 0 | } |
622 | |
|
623 | |
private RuleTemplateService getRuleTemplateService() { |
624 | 0 | return (RuleTemplateService) KEWServiceLocator.getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE); |
625 | |
} |
626 | |
|
627 | |
|
628 | |
|
629 | |
|
630 | |
public Map getActionRequestCodes() { |
631 | 0 | Map actionRequestCodes = new HashMap(); |
632 | 0 | actionRequestCodes.putAll(CodeTranslator.arLabels); |
633 | 0 | if (getRuleTemplateId() != null) { |
634 | 0 | RuleTemplate ruleTemplate = getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId()); |
635 | 0 | if (ruleTemplate != null) { |
636 | 0 | if (ruleTemplate.getAcknowledge() != null && "false".equals(ruleTemplate.getAcknowledge().getValue())) { |
637 | 0 | actionRequestCodes.remove(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ); |
638 | |
} |
639 | 0 | if (ruleTemplate.getComplete() != null && "false".equals(ruleTemplate.getComplete().getValue())) { |
640 | 0 | actionRequestCodes.remove(KEWConstants.ACTION_REQUEST_COMPLETE_REQ); |
641 | |
} |
642 | 0 | if (ruleTemplate.getApprove() != null && "false".equals(ruleTemplate.getApprove().getValue())) { |
643 | 0 | actionRequestCodes.remove(KEWConstants.ACTION_REQUEST_APPROVE_REQ); |
644 | |
} |
645 | 0 | if (ruleTemplate.getFyi() != null && "false".equals(ruleTemplate.getFyi().getValue())) { |
646 | 0 | actionRequestCodes.remove(KEWConstants.ACTION_REQUEST_FYI_REQ); |
647 | |
} |
648 | |
} |
649 | |
} |
650 | 0 | return actionRequestCodes; |
651 | |
} |
652 | |
|
653 | |
public RuleDelegation getRuleDelegation() { |
654 | 0 | if (getDelegateRule().booleanValue()) { |
655 | 0 | List ruleDelegations = getRuleDelegationService().findByDelegateRuleId(getRuleBaseValuesId()); |
656 | 0 | RuleDelegation currentRuleDelegation = (RuleDelegation) ruleDelegations.get(0); |
657 | 0 | RuleBaseValues mostRecentRule = currentRuleDelegation.getRuleResponsibility().getRuleBaseValues(); |
658 | |
|
659 | 0 | for (Iterator iter = ruleDelegations.iterator(); iter.hasNext();) { |
660 | 0 | RuleDelegation ruleDelegation = (RuleDelegation) iter.next(); |
661 | 0 | RuleBaseValues parentRule = ruleDelegation.getRuleResponsibility().getRuleBaseValues(); |
662 | |
|
663 | 0 | if (parentRule.getActivationDate().after(mostRecentRule.getActivationDate())) { |
664 | 0 | mostRecentRule = ruleDelegation.getRuleResponsibility().getRuleBaseValues(); |
665 | 0 | currentRuleDelegation = ruleDelegation; |
666 | |
} |
667 | 0 | } |
668 | 0 | return currentRuleDelegation; |
669 | |
} |
670 | 0 | return null; |
671 | |
} |
672 | |
|
673 | |
public String getParentRuleId() { |
674 | 0 | if (getDelegateRule().booleanValue()) { |
675 | 0 | List ruleDelegations = getRuleDelegationService().findByDelegateRuleId(getRuleBaseValuesId()); |
676 | 0 | RuleDelegation currentRuleDelegation = (RuleDelegation) ruleDelegations.get(0); |
677 | 0 | RuleBaseValues mostRecentRule = currentRuleDelegation.getRuleResponsibility().getRuleBaseValues(); |
678 | |
|
679 | 0 | for (Iterator iter = ruleDelegations.iterator(); iter.hasNext();) { |
680 | 0 | RuleDelegation ruleDelegation = (RuleDelegation) iter.next(); |
681 | 0 | RuleBaseValues parentRule = ruleDelegation.getRuleResponsibility().getRuleBaseValues(); |
682 | |
|
683 | 0 | if (parentRule.getActivationDate().after(mostRecentRule.getActivationDate())) { |
684 | 0 | mostRecentRule = ruleDelegation.getRuleResponsibility().getRuleBaseValues(); |
685 | |
} |
686 | 0 | } |
687 | 0 | return mostRecentRule.getRuleBaseValuesId(); |
688 | |
} |
689 | 0 | return null; |
690 | |
} |
691 | |
|
692 | |
private RuleDelegationService getRuleDelegationService() { |
693 | 0 | return (RuleDelegationService) KEWServiceLocator.getService(KEWServiceLocator.RULE_DELEGATION_SERVICE); |
694 | |
} |
695 | |
} |