| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kew.rule.web; |
| 17 | |
|
| 18 | |
import org.apache.commons.beanutils.PropertyUtils; |
| 19 | |
import org.apache.commons.lang.StringUtils; |
| 20 | |
import org.apache.struts.action.ActionErrors; |
| 21 | |
import org.apache.struts.action.ActionMessage; |
| 22 | |
import org.kuali.rice.core.api.util.RiceConstants; |
| 23 | |
import org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils; |
| 24 | |
import org.kuali.rice.kew.api.rule.RoleName; |
| 25 | |
import org.kuali.rice.kew.api.util.CodeTranslator; |
| 26 | |
import org.kuali.rice.kew.exception.WorkflowServiceError; |
| 27 | |
import org.kuali.rice.kew.rule.KeyValueId; |
| 28 | |
import org.kuali.rice.kew.rule.RoleAttribute; |
| 29 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
| 30 | |
import org.kuali.rice.kew.rule.RuleDelegationBo; |
| 31 | |
import org.kuali.rice.kew.rule.RuleExtensionBo; |
| 32 | |
import org.kuali.rice.kew.rule.RuleExtensionValue; |
| 33 | |
import org.kuali.rice.kew.rule.RuleResponsibilityBo; |
| 34 | |
import org.kuali.rice.kew.rule.WorkflowRuleAttribute; |
| 35 | |
import org.kuali.rice.kew.rule.bo.RuleAttribute; |
| 36 | |
import org.kuali.rice.kew.rule.bo.RuleTemplateAttributeBo; |
| 37 | |
import org.kuali.rice.kew.rule.bo.RuleTemplateBo; |
| 38 | |
import org.kuali.rice.kew.rule.service.RuleDelegationService; |
| 39 | |
import org.kuali.rice.kew.rule.service.RuleTemplateService; |
| 40 | |
import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute; |
| 41 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 42 | |
import org.kuali.rice.kew.api.KewApiConstants; |
| 43 | |
import org.kuali.rice.kns.web.ui.Field; |
| 44 | |
import org.kuali.rice.kns.web.ui.Row; |
| 45 | |
|
| 46 | |
import java.sql.Timestamp; |
| 47 | |
import java.text.ParseException; |
| 48 | |
import java.text.SimpleDateFormat; |
| 49 | |
import java.util.ArrayList; |
| 50 | |
import java.util.Calendar; |
| 51 | |
import java.util.Collection; |
| 52 | |
import java.util.Collections; |
| 53 | |
import java.util.Date; |
| 54 | |
import java.util.HashMap; |
| 55 | |
import java.util.Iterator; |
| 56 | |
import java.util.List; |
| 57 | |
import java.util.Map; |
| 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 fromDateString; |
| 75 | |
private String toDateString; |
| 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 | RuleTemplateBo 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 | RuleTemplateAttributeBo ruleTemplateAttribute = (RuleTemplateAttributeBo) iter.next(); |
| 95 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) { |
| 96 | 0 | continue; |
| 97 | |
} |
| 98 | 0 | WorkflowRuleAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute(); |
| 99 | 0 | RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute(); |
| 100 | 0 | if (ruleAttribute.getType().equals(KewApiConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
| 101 | 0 | ((GenericXMLRuleAttribute) workflowAttribute).setExtensionDefinition(RuleAttribute.to(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 | String fieldValue = ""; |
| 108 | 0 | RuleExtensionValue extensionValue = getRuleExtensionValue(ruleTemplateAttribute.getId(), field.getPropertyName()); |
| 109 | |
|
| 110 | 0 | fieldValue = (extensionValue != null) ? extensionValue.getValue() : field.getPropertyValue(); |
| 111 | 0 | fields.add(new KeyValueId(field.getPropertyName(), fieldValue, ruleTemplateAttribute.getId())); |
| 112 | 0 | } |
| 113 | 0 | } |
| 114 | 0 | } |
| 115 | |
} |
| 116 | |
} |
| 117 | 0 | } |
| 118 | |
|
| 119 | |
public void loadFieldsWithDefaultValues() { |
| 120 | 0 | fields.clear(); |
| 121 | 0 | if (getRuleTemplateId() != null) { |
| 122 | 0 | RuleTemplateBo ruleTemplate = getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId()); |
| 123 | 0 | if (ruleTemplate != null) { |
| 124 | 0 | List ruleTemplateAttributes = ruleTemplate.getActiveRuleTemplateAttributes(); |
| 125 | 0 | Collections.sort(ruleTemplateAttributes); |
| 126 | 0 | for (Iterator iter = ruleTemplateAttributes.iterator(); iter.hasNext();) { |
| 127 | 0 | RuleTemplateAttributeBo ruleTemplateAttribute = (RuleTemplateAttributeBo) iter.next(); |
| 128 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) { |
| 129 | 0 | continue; |
| 130 | |
} |
| 131 | 0 | WorkflowRuleAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute(); |
| 132 | 0 | RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute(); |
| 133 | 0 | if (ruleAttribute.getType().equals(KewApiConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
| 134 | 0 | ((GenericXMLRuleAttribute) workflowAttribute).setExtensionDefinition(RuleAttribute.to(ruleAttribute)); |
| 135 | |
} |
| 136 | 0 | for (Object element : workflowAttribute.getRuleRows()) { |
| 137 | 0 | Row row = (Row) element; |
| 138 | 0 | for (Object element2 : row.getFields()) { |
| 139 | 0 | Field field = (Field) element2; |
| 140 | 0 | fields.add(new KeyValueId(field.getPropertyName(), field.getPropertyValue(), ruleTemplateAttribute.getId() + "")); |
| 141 | 0 | } |
| 142 | 0 | } |
| 143 | 0 | } |
| 144 | |
} |
| 145 | |
} |
| 146 | 0 | } |
| 147 | |
|
| 148 | |
private void loadWebValues() { |
| 149 | 0 | loadRows(); |
| 150 | 0 | loadDates(); |
| 151 | 0 | loadRuleTemplateName(); |
| 152 | 0 | } |
| 153 | |
|
| 154 | |
private void loadRows() { |
| 155 | 0 | getRoles().clear(); |
| 156 | 0 | if (getRuleTemplateId() != null) { |
| 157 | 0 | RuleTemplateBo ruleTemplate = getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId()); |
| 158 | 0 | if (ruleTemplate != null) { |
| 159 | 0 | setRuleTemplateName(ruleTemplate.getName()); |
| 160 | 0 | List<RuleTemplateAttributeBo> ruleTemplateAttributes = ruleTemplate.getActiveRuleTemplateAttributes(); |
| 161 | 0 | Collections.sort(ruleTemplateAttributes); |
| 162 | 0 | List<Row> rows = new ArrayList<Row>(); |
| 163 | 0 | for (RuleTemplateAttributeBo ruleTemplateAttribute : ruleTemplateAttributes) { |
| 164 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) { |
| 165 | 0 | continue; |
| 166 | |
} |
| 167 | 0 | WorkflowRuleAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute(); |
| 168 | |
|
| 169 | 0 | RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute(); |
| 170 | 0 | if (ruleAttribute.getType().equals(KewApiConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
| 171 | 0 | ((GenericXMLRuleAttribute) workflowAttribute).setExtensionDefinition(RuleAttribute.to(ruleAttribute)); |
| 172 | |
} |
| 173 | 0 | workflowAttribute.validateRuleData(getFieldMap(ruleTemplateAttribute.getId()+"")); |
| 174 | 0 | rows.addAll(workflowAttribute.getRuleRows()); |
| 175 | 0 | if (workflowAttribute instanceof RoleAttribute) { |
| 176 | 0 | RoleAttribute roleAttribute = (RoleAttribute) workflowAttribute; |
| 177 | 0 | getRoles().addAll(roleAttribute.getRoleNames()); |
| 178 | |
} |
| 179 | 0 | } |
| 180 | 0 | setRows(rows); |
| 181 | |
} |
| 182 | |
} |
| 183 | 0 | } |
| 184 | |
|
| 185 | |
private void loadDates() { |
| 186 | 0 | if (getFromDateString() != null) { |
| 187 | 0 | setFromDateString(RiceConstants.getDefaultDateFormat().format(getFromDateValue())); |
| 188 | |
} |
| 189 | 0 | if (getToDateString() != null) { |
| 190 | 0 | setToDateString(RiceConstants.getDefaultDateFormat().format(getToDateValue())); |
| 191 | |
} |
| 192 | 0 | } |
| 193 | |
|
| 194 | |
private void loadRuleTemplateName() { |
| 195 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(getRuleTemplateName()) && getRuleTemplateId() != null) { |
| 196 | 0 | RuleTemplateBo ruleTemplate = getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId()); |
| 197 | 0 | if (ruleTemplate != null) { |
| 198 | 0 | setRuleTemplateName(ruleTemplate.getName()); |
| 199 | |
} |
| 200 | |
} |
| 201 | 0 | } |
| 202 | |
|
| 203 | |
public List getFields() { |
| 204 | 0 | return fields; |
| 205 | |
} |
| 206 | |
|
| 207 | |
public void setFields(List fields) { |
| 208 | 0 | this.fields = fields; |
| 209 | 0 | } |
| 210 | |
|
| 211 | |
public KeyValueId getField(int index) { |
| 212 | 0 | while (getFields().size() <= index) { |
| 213 | 0 | KeyValueId field = new KeyValueId(); |
| 214 | 0 | getFields().add(field); |
| 215 | 0 | } |
| 216 | 0 | return (KeyValueId) getFields().get(index); |
| 217 | |
} |
| 218 | |
|
| 219 | |
public String getFromDateString() { |
| 220 | 0 | return fromDateString; |
| 221 | |
} |
| 222 | |
|
| 223 | |
public void setFromDateString(String fromDateString) { |
| 224 | 0 | this.fromDateString = fromDateString; |
| 225 | 0 | } |
| 226 | |
|
| 227 | |
public List<RoleName> getRoles() { |
| 228 | 0 | return roles; |
| 229 | |
} |
| 230 | |
|
| 231 | |
public void setRoles(List<RoleName> roles) { |
| 232 | 0 | this.roles = roles; |
| 233 | 0 | } |
| 234 | |
|
| 235 | |
public List<RoleName> getRows() { |
| 236 | 0 | return rows; |
| 237 | |
} |
| 238 | |
|
| 239 | |
public void setRows(List ruleTemplateAttributes) { |
| 240 | 0 | this.rows = ruleTemplateAttributes; |
| 241 | 0 | } |
| 242 | |
|
| 243 | |
@Override |
| 244 | |
public String getToDateString() { |
| 245 | 0 | return this.toDateString; |
| 246 | |
} |
| 247 | |
|
| 248 | |
public void setToDateString(String toDateString) { |
| 249 | 0 | this.toDateString = toDateString; |
| 250 | 0 | } |
| 251 | |
|
| 252 | |
@Override |
| 253 | |
public String getRuleTemplateName() { |
| 254 | 0 | return ruleTemplateName; |
| 255 | |
} |
| 256 | |
|
| 257 | |
public void setRuleTemplateName(String ruleTemplateName) { |
| 258 | 0 | this.ruleTemplateName = ruleTemplateName; |
| 259 | 0 | } |
| 260 | |
|
| 261 | |
public boolean isHasExtensionValueErrors() { |
| 262 | 0 | return hasExtensionValueErrors; |
| 263 | |
} |
| 264 | |
|
| 265 | |
public void setHasExtensionValueErrors(boolean hasRuleExtensionValueErrors) { |
| 266 | 0 | this.hasExtensionValueErrors = hasRuleExtensionValueErrors; |
| 267 | 0 | } |
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
public void edit(RuleBaseValues rule) throws Exception { |
| 275 | 0 | load(rule); |
| 276 | 0 | initialize(); |
| 277 | 0 | } |
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
public void load(RuleBaseValues rule) throws Exception { |
| 283 | 0 | PropertyUtils.copyProperties(this, rule); |
| 284 | 0 | injectWebMembers(); |
| 285 | 0 | } |
| 286 | |
|
| 287 | |
public void initialize() throws Exception { |
| 288 | 0 | loadFields(); |
| 289 | |
|
| 290 | 0 | for (Object element : getRuleResponsibilities()) { |
| 291 | 0 | WebRuleResponsibility responsibility = (WebRuleResponsibility) element; |
| 292 | 0 | responsibility.initialize(); |
| 293 | 0 | } |
| 294 | 0 | establishRequiredState(); |
| 295 | 0 | } |
| 296 | |
|
| 297 | |
private void injectWebMembers() throws Exception { |
| 298 | 0 | List currentResponsibilities = getRuleResponsibilities(); |
| 299 | 0 | setRuleResponsibilities(new ArrayList()); |
| 300 | 0 | for (Iterator iterator = currentResponsibilities.iterator(); iterator.hasNext();) { |
| 301 | 0 | RuleResponsibilityBo responsibility = (RuleResponsibilityBo) iterator.next(); |
| 302 | 0 | WebRuleResponsibility webResponsibility = createNewRuleResponsibility(); |
| 303 | 0 | webResponsibility.load(responsibility); |
| 304 | 0 | } |
| 305 | 0 | } |
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
public void establishRequiredState() throws Exception { |
| 311 | 0 | loadWebValues(); |
| 312 | 0 | if (getRuleResponsibilities().isEmpty()) { |
| 313 | 0 | createNewRuleResponsibility(); |
| 314 | |
} |
| 315 | 0 | for (Object element : getRuleResponsibilities()) { |
| 316 | 0 | WebRuleResponsibility responsibility = (WebRuleResponsibility) element; |
| 317 | 0 | responsibility.establishRequiredState(); |
| 318 | 0 | } |
| 319 | 0 | } |
| 320 | |
|
| 321 | |
@Override |
| 322 | |
public RuleResponsibilityBo getResponsibility(int index) { |
| 323 | 0 | while (getRuleResponsibilities().size() <= index) { |
| 324 | 0 | createNewRuleResponsibility(); |
| 325 | |
} |
| 326 | 0 | return getRuleResponsibilities().get(index); |
| 327 | |
} |
| 328 | |
|
| 329 | |
public int getResponsibilitiesSize() { |
| 330 | 0 | return getRuleResponsibilities().size(); |
| 331 | |
} |
| 332 | |
|
| 333 | |
public WebRuleResponsibility createNewRuleResponsibility() { |
| 334 | 0 | WebRuleResponsibility responsibility = new WebRuleResponsibility(); |
| 335 | 0 | responsibility.setRuleBaseValues(this); |
| 336 | 0 | addRuleResponsibility(responsibility); |
| 337 | 0 | return responsibility; |
| 338 | |
} |
| 339 | |
|
| 340 | |
public Map getFieldMap(String ruleTemplateAttributeId) { |
| 341 | 0 | Map fieldMap = new HashMap(); |
| 342 | 0 | for (Iterator iterator = getFields().iterator(); iterator.hasNext();) { |
| 343 | 0 | KeyValueId field = (KeyValueId) iterator.next(); |
| 344 | 0 | if (ruleTemplateAttributeId.equals(field.getId())) { |
| 345 | 0 | fieldMap.put(field.getKey(), field.getValue()); |
| 346 | |
} |
| 347 | 0 | } |
| 348 | 0 | return fieldMap; |
| 349 | |
} |
| 350 | |
|
| 351 | |
public void populatePreviousRuleIds() { |
| 352 | 0 | if (getPreviousRuleId() == null) { |
| 353 | 0 | setPreviousRuleId(getId()); |
| 354 | |
} |
| 355 | 0 | for (Object element : getRuleResponsibilities()) { |
| 356 | 0 | WebRuleResponsibility responsibility = (WebRuleResponsibility) element; |
| 357 | 0 | responsibility.populatePreviousRuleIds(); |
| 358 | 0 | } |
| 359 | 0 | } |
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
public void materialize() { |
| 365 | 0 | if (getRuleTemplate() == null && getRuleTemplateId() != null) { |
| 366 | 0 | setRuleTemplate(getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId())); |
| 367 | |
} |
| 368 | 0 | } |
| 369 | |
|
| 370 | |
public void validateRule(String keyPrefix, ActionErrors errors) { |
| 371 | |
|
| 372 | 0 | if (getRuleTemplateId() == null) { |
| 373 | 0 | errors.add(keyPrefix + "ruleTemplateId", new ActionMessage("routetemplate.required.html", "rule template")); |
| 374 | |
} else { |
| 375 | 0 | List errorList = new ArrayList(); |
| 376 | 0 | populateRuleExtensionValues(errorList); |
| 377 | 0 | saveServiceErrors(keyPrefix + "ruleExtensionValues", errorList, errors); |
| 378 | 0 | if (!errorList.isEmpty()) { |
| 379 | 0 | setHasExtensionValueErrors(true); |
| 380 | |
} |
| 381 | |
} |
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | 0 | boolean dateParseProblem = false; |
| 386 | |
try { |
| 387 | 0 | setToDateValue(decodeTimestamp(getToDateString())); |
| 388 | 0 | } catch (ParseException e) { |
| 389 | 0 | errors.add(keyPrefix + "toDateValue", new ActionMessage("routetemplate.required.html", "to date (MM/DD/YYYY)")); |
| 390 | 0 | dateParseProblem = true; |
| 391 | 0 | } |
| 392 | |
try { |
| 393 | 0 | setFromDateValue(decodeTimestamp(getFromDateString())); |
| 394 | 0 | } catch (ParseException e) { |
| 395 | 0 | errors.add(keyPrefix + "fromDateValue", new ActionMessage("routetemplate.required.html", "from date (MM/DD/YYYY)")); |
| 396 | 0 | dateParseProblem = true; |
| 397 | 0 | } |
| 398 | 0 | throttleDates(); |
| 399 | 0 | if (getFromDateValue() == null) { |
| 400 | 0 | setFromDateValue(new Timestamp(new Date().getTime())); |
| 401 | |
} |
| 402 | 0 | if (getToDateValue() == null) { |
| 403 | |
try { |
| 404 | 0 | setToDateValue(new Timestamp(new SimpleDateFormat("MM/dd/yyyy").parse("01/01/2100").getTime())); |
| 405 | 0 | } catch (ParseException e) { |
| 406 | 0 | errors.add(keyPrefix + "toDateValue", new ActionMessage("routetemplate.required.html", "to date")); |
| 407 | 0 | dateParseProblem = true; |
| 408 | 0 | } |
| 409 | |
} |
| 410 | 0 | if (!dateParseProblem && getToDateValue().before(getFromDateValue())) { |
| 411 | 0 | errors.add(keyPrefix + "toDateValue", new ActionMessage("routetemplate.ruleservice.daterange.fromafterto")); |
| 412 | |
} |
| 413 | |
|
| 414 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(getDescription())) { |
| 415 | 0 | errors.add(keyPrefix + "description", new ActionMessage("routetemplate.ruleservice.description.required")); |
| 416 | |
} |
| 417 | |
|
| 418 | 0 | if (getRuleResponsibilities().isEmpty()) { |
| 419 | 0 | errors.add(keyPrefix + "responsibilities", new ActionMessage("routetemplate.ruleservice.responsibility.required")); |
| 420 | |
} |
| 421 | |
|
| 422 | 0 | int respIndex = 0; |
| 423 | 0 | for (Object element : getRuleResponsibilities()) { |
| 424 | 0 | WebRuleResponsibility responsibility = (WebRuleResponsibility) element; |
| 425 | 0 | String respPrefix = keyPrefix + "responsibility[" + respIndex + "]."; |
| 426 | 0 | responsibility.validateResponsibility(respPrefix, errors); |
| 427 | 0 | respIndex++; |
| 428 | 0 | } |
| 429 | 0 | } |
| 430 | |
|
| 431 | |
|
| 432 | |
|
| 433 | |
|
| 434 | |
|
| 435 | |
private void throttleDates() { |
| 436 | 0 | if (getToDateValue() != null) { |
| 437 | 0 | Calendar calendar = Calendar.getInstance(); |
| 438 | 0 | calendar.setTime(getToDateValue()); |
| 439 | 0 | if (calendar.get(Calendar.YEAR) > TO_DATE_UPPER_LIMIT) { |
| 440 | 0 | calendar.set(Calendar.YEAR, TO_DATE_UPPER_LIMIT); |
| 441 | 0 | setToDateValue(new Timestamp(calendar.getTimeInMillis())); |
| 442 | 0 | setToDateString(new SimpleDateFormat("MM/dd/yyyy").format(getToDateValue())); |
| 443 | |
} |
| 444 | |
} |
| 445 | 0 | } |
| 446 | |
|
| 447 | |
private void saveServiceErrors(String errorKey, Collection srvErrors, ActionErrors errors) { |
| 448 | 0 | for (Iterator iterator = srvErrors.iterator(); iterator.hasNext();) { |
| 449 | 0 | WorkflowServiceError error = (WorkflowServiceError) iterator.next(); |
| 450 | 0 | if (error.getArg1() == null && error.getArg2() == null) { |
| 451 | 0 | errors.add(errorKey, new ActionMessage(error.getKey())); |
| 452 | 0 | } else if (error.getArg1() != null && error.getArg2() == null) { |
| 453 | 0 | errors.add(errorKey, new ActionMessage(error.getKey(), error.getArg1())); |
| 454 | |
} else { |
| 455 | 0 | errors.add(errorKey, new ActionMessage(error.getKey(), error.getArg1(), error.getArg2())); |
| 456 | |
} |
| 457 | 0 | } |
| 458 | 0 | } |
| 459 | |
|
| 460 | |
private Timestamp decodeTimestamp(String dateValue) throws ParseException { |
| 461 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(dateValue)) { |
| 462 | 0 | return null; |
| 463 | |
} |
| 464 | |
|
| 465 | |
|
| 466 | |
|
| 467 | 0 | String convertedDate = SQLUtils.getEntryFormattedDate(dateValue); |
| 468 | 0 | if (convertedDate == null) { |
| 469 | 0 | throw new ParseException("Date entered as '" + dateValue + "' is in invalid format", 0); |
| 470 | |
} |
| 471 | 0 | Date date = RiceConstants.getDefaultDateFormat().parse(convertedDate); |
| 472 | 0 | return new Timestamp(date.getTime()); |
| 473 | |
} |
| 474 | |
|
| 475 | |
private void populateRuleExtensionValues(List errorList) { |
| 476 | 0 | RuleTemplateBo ruleTemplate = getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId()); |
| 477 | 0 | setRuleTemplate(ruleTemplate); |
| 478 | |
|
| 479 | |
|
| 480 | 0 | List extensions = new ArrayList(); |
| 481 | 0 | for (Object element : ruleTemplate.getActiveRuleTemplateAttributes()) { |
| 482 | 0 | RuleTemplateAttributeBo ruleTemplateAttribute = (RuleTemplateAttributeBo) element; |
| 483 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) { |
| 484 | 0 | continue; |
| 485 | |
} |
| 486 | 0 | WorkflowRuleAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute(); |
| 487 | |
|
| 488 | 0 | RuleAttribute ruleAttribute = ruleTemplateAttribute.getRuleAttribute(); |
| 489 | 0 | if (ruleAttribute.getType().equals(KewApiConstants.RULE_XML_ATTRIBUTE_TYPE)) { |
| 490 | 0 | ((GenericXMLRuleAttribute) workflowAttribute).setExtensionDefinition(RuleAttribute.to(ruleAttribute)); |
| 491 | |
} |
| 492 | |
|
| 493 | 0 | List attValidationErrors = workflowAttribute.validateRuleData(getFieldMap(ruleTemplateAttribute.getId()+"")); |
| 494 | 0 | if (attValidationErrors != null && !attValidationErrors.isEmpty()) { |
| 495 | 0 | errorList.addAll(attValidationErrors); |
| 496 | |
} else { |
| 497 | 0 | List ruleExtensionValues = workflowAttribute.getRuleExtensionValues(); |
| 498 | 0 | if (ruleExtensionValues != null && !ruleExtensionValues.isEmpty()) { |
| 499 | 0 | RuleExtensionBo ruleExtension = new RuleExtensionBo(); |
| 500 | 0 | ruleExtension.setRuleTemplateAttributeId(ruleTemplateAttribute.getId()); |
| 501 | |
|
| 502 | 0 | ruleExtension.setExtensionValues(ruleExtensionValues); |
| 503 | 0 | extensions.add(ruleExtension); |
| 504 | |
} |
| 505 | |
} |
| 506 | 0 | } |
| 507 | 0 | setRuleExtensions(extensions); |
| 508 | 0 | setRuleTemplate(ruleTemplate); |
| 509 | |
|
| 510 | 0 | for (Object element : getRuleExtensions()) { |
| 511 | 0 | RuleExtensionBo ruleExtension = (RuleExtensionBo) element; |
| 512 | 0 | ruleExtension.setRuleBaseValues(this); |
| 513 | |
|
| 514 | 0 | for (Object element2 : ruleTemplate.getActiveRuleTemplateAttributes()) { |
| 515 | 0 | RuleTemplateAttributeBo ruleTemplateAttribute = (RuleTemplateAttributeBo) element2; |
| 516 | 0 | if (StringUtils.equals(ruleTemplateAttribute.getId(), ruleExtension.getRuleTemplateAttributeId())) { |
| 517 | 0 | ruleExtension.setRuleTemplateAttribute(ruleTemplateAttribute); |
| 518 | 0 | break; |
| 519 | |
} |
| 520 | 0 | } |
| 521 | |
|
| 522 | 0 | for (Object element2 : ruleExtension.getExtensionValues()) { |
| 523 | 0 | RuleExtensionValue ruleExtensionValue = (RuleExtensionValue) element2; |
| 524 | 0 | ruleExtensionValue.setExtension(ruleExtension); |
| 525 | 0 | } |
| 526 | 0 | } |
| 527 | |
|
| 528 | 0 | } |
| 529 | |
|
| 530 | |
private RuleTemplateService getRuleTemplateService() { |
| 531 | 0 | return (RuleTemplateService) KEWServiceLocator.getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE); |
| 532 | |
} |
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
public Map getActionRequestCodes() { |
| 538 | 0 | Map actionRequestCodes = new HashMap(); |
| 539 | 0 | actionRequestCodes.putAll(CodeTranslator.arLabels); |
| 540 | 0 | if (getRuleTemplateId() != null) { |
| 541 | 0 | RuleTemplateBo ruleTemplate = getRuleTemplateService().findByRuleTemplateId(getRuleTemplateId()); |
| 542 | 0 | if (ruleTemplate != null) { |
| 543 | 0 | if (ruleTemplate.getAcknowledge() != null && "false".equals(ruleTemplate.getAcknowledge().getValue())) { |
| 544 | 0 | actionRequestCodes.remove(KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ); |
| 545 | |
} |
| 546 | 0 | if (ruleTemplate.getComplete() != null && "false".equals(ruleTemplate.getComplete().getValue())) { |
| 547 | 0 | actionRequestCodes.remove(KewApiConstants.ACTION_REQUEST_COMPLETE_REQ); |
| 548 | |
} |
| 549 | 0 | if (ruleTemplate.getApprove() != null && "false".equals(ruleTemplate.getApprove().getValue())) { |
| 550 | 0 | actionRequestCodes.remove(KewApiConstants.ACTION_REQUEST_APPROVE_REQ); |
| 551 | |
} |
| 552 | 0 | if (ruleTemplate.getFyi() != null && "false".equals(ruleTemplate.getFyi().getValue())) { |
| 553 | 0 | actionRequestCodes.remove(KewApiConstants.ACTION_REQUEST_FYI_REQ); |
| 554 | |
} |
| 555 | |
} |
| 556 | |
} |
| 557 | 0 | return actionRequestCodes; |
| 558 | |
} |
| 559 | |
|
| 560 | |
public RuleDelegationBo getRuleDelegation() { |
| 561 | 0 | if (getDelegateRule().booleanValue()) { |
| 562 | 0 | List ruleDelegations = getRuleDelegationService().findByDelegateRuleId(getId()); |
| 563 | 0 | RuleDelegationBo currentRuleDelegation = (RuleDelegationBo) ruleDelegations.get(0); |
| 564 | 0 | RuleBaseValues mostRecentRule = currentRuleDelegation.getRuleResponsibility().getRuleBaseValues(); |
| 565 | |
|
| 566 | 0 | for (Iterator iter = ruleDelegations.iterator(); iter.hasNext();) { |
| 567 | 0 | RuleDelegationBo ruleDelegation = (RuleDelegationBo) iter.next(); |
| 568 | 0 | RuleBaseValues parentRule = ruleDelegation.getRuleResponsibility().getRuleBaseValues(); |
| 569 | |
|
| 570 | 0 | if (parentRule.getActivationDate().after(mostRecentRule.getActivationDate())) { |
| 571 | 0 | mostRecentRule = ruleDelegation.getRuleResponsibility().getRuleBaseValues(); |
| 572 | 0 | currentRuleDelegation = ruleDelegation; |
| 573 | |
} |
| 574 | 0 | } |
| 575 | 0 | return currentRuleDelegation; |
| 576 | |
} |
| 577 | 0 | return null; |
| 578 | |
} |
| 579 | |
|
| 580 | |
public String getParentRuleId() { |
| 581 | 0 | if (getDelegateRule().booleanValue()) { |
| 582 | 0 | List ruleDelegations = getRuleDelegationService().findByDelegateRuleId(getId()); |
| 583 | 0 | RuleDelegationBo currentRuleDelegation = (RuleDelegationBo) ruleDelegations.get(0); |
| 584 | 0 | RuleBaseValues mostRecentRule = currentRuleDelegation.getRuleResponsibility().getRuleBaseValues(); |
| 585 | |
|
| 586 | 0 | for (Iterator iter = ruleDelegations.iterator(); iter.hasNext();) { |
| 587 | 0 | RuleDelegationBo ruleDelegation = (RuleDelegationBo) iter.next(); |
| 588 | 0 | RuleBaseValues parentRule = ruleDelegation.getRuleResponsibility().getRuleBaseValues(); |
| 589 | |
|
| 590 | 0 | if (parentRule.getActivationDate().after(mostRecentRule.getActivationDate())) { |
| 591 | 0 | mostRecentRule = ruleDelegation.getRuleResponsibility().getRuleBaseValues(); |
| 592 | |
} |
| 593 | 0 | } |
| 594 | 0 | return mostRecentRule.getId(); |
| 595 | |
} |
| 596 | 0 | return null; |
| 597 | |
} |
| 598 | |
|
| 599 | |
private RuleDelegationService getRuleDelegationService() { |
| 600 | 0 | return (RuleDelegationService) KEWServiceLocator.getService(KEWServiceLocator.RULE_DELEGATION_SERVICE); |
| 601 | |
} |
| 602 | |
} |