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