| 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.apache.commons.lang.builder.ToStringBuilder; |
| 21 | |
import org.hibernate.annotations.Fetch; |
| 22 | |
import org.hibernate.annotations.FetchMode; |
| 23 | |
import org.kuali.rice.core.jpa.annotations.Sequence; |
| 24 | |
import org.kuali.rice.kew.bo.KewPersistableBusinessObjectBase; |
| 25 | |
import org.kuali.rice.kew.bo.WorkflowPersistable; |
| 26 | |
import org.kuali.rice.kew.rule.Role; |
| 27 | |
import org.kuali.rice.kew.rule.RoleAttribute; |
| 28 | |
import org.kuali.rice.kew.rule.RuleTemplateOption; |
| 29 | |
import org.kuali.rice.kew.rule.WorkflowAttribute; |
| 30 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 31 | |
|
| 32 | |
import javax.persistence.*; |
| 33 | |
import java.net.URLEncoder; |
| 34 | |
import java.util.*; |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
@Entity |
| 45 | |
@Table(name="KREW_RULE_TMPL_T") |
| 46 | |
@Sequence(name="KREW_RTE_TMPL_S", property="ruleTemplateId") |
| 47 | |
@NamedQueries({@NamedQuery(name="findAllOrderedByName", query="SELECT rt FROM RuleTemplate rt ORDER BY rt.name ASC")}) |
| 48 | |
public class RuleTemplate extends KewPersistableBusinessObjectBase implements WorkflowPersistable { |
| 49 | |
|
| 50 | |
private static final long serialVersionUID = -3387940485523951302L; |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | 0 | public static final String[] DEFAULT_OPTION_KEYS = { |
| 56 | |
|
| 57 | |
KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, |
| 58 | |
KEWConstants.ACTION_REQUEST_APPROVE_REQ, |
| 59 | |
KEWConstants.ACTION_REQUEST_COMPLETE_REQ, |
| 60 | |
KEWConstants.ACTION_REQUEST_FYI_REQ, |
| 61 | |
KEWConstants.ACTION_REQUEST_DEFAULT_CD |
| 62 | |
}; |
| 63 | |
|
| 64 | |
@Id |
| 65 | |
@Column(name="RULE_TMPL_ID") |
| 66 | |
private Long ruleTemplateId; |
| 67 | |
@Column(name="NM") |
| 68 | |
private String name; |
| 69 | |
@Column(name="RULE_TMPL_DESC") |
| 70 | |
private String description; |
| 71 | |
|
| 72 | |
@Column(name="DLGN_RULE_TMPL_ID", insertable=false, updatable=false) |
| 73 | |
private Long delegationTemplateId; |
| 74 | |
@OneToOne(fetch=FetchType.EAGER) |
| 75 | |
@JoinColumn(name="DLGN_RULE_TMPL_ID") |
| 76 | |
private RuleTemplate delegationTemplate; |
| 77 | |
@Fetch(value = FetchMode.SUBSELECT) |
| 78 | |
@OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE}, |
| 79 | |
mappedBy="ruleTemplate") |
| 80 | |
private List<RuleTemplateAttribute> ruleTemplateAttributes; |
| 81 | |
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE}, |
| 82 | |
mappedBy="ruleTemplate") |
| 83 | |
private List<RuleTemplateOption> ruleTemplateOptions; |
| 84 | |
|
| 85 | |
|
| 86 | |
@Transient |
| 87 | |
private String returnUrl; |
| 88 | |
|
| 89 | 0 | public RuleTemplate() { |
| 90 | 0 | ruleTemplateAttributes = new ArrayList<RuleTemplateAttribute>(); |
| 91 | 0 | ruleTemplateOptions = new ArrayList<RuleTemplateOption>(); |
| 92 | 0 | } |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
public void removeNonDefaultOptions() { |
| 99 | 0 | Iterator<RuleTemplateOption> it = ruleTemplateOptions.iterator(); |
| 100 | 0 | while (it.hasNext()) { |
| 101 | 0 | RuleTemplateOption option = it.next(); |
| 102 | |
|
| 103 | 0 | if (!ArrayUtils.contains(DEFAULT_OPTION_KEYS, option.getKey())) { |
| 104 | 0 | it.remove(); |
| 105 | |
} |
| 106 | 0 | } |
| 107 | 0 | } |
| 108 | |
|
| 109 | |
public String getDelegateTemplateName() { |
| 110 | 0 | if (delegationTemplate != null) { |
| 111 | 0 | return delegationTemplate.getName(); |
| 112 | |
} |
| 113 | 0 | return ""; |
| 114 | |
} |
| 115 | |
|
| 116 | |
public String getRuleTemplateActionsUrl() { |
| 117 | 0 | return "<a href=\"RuleTemplate.do?methodToCall=report¤tRuleTemplateId=" + ruleTemplateId + "\" >report</a>" ; |
| 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 | |
private RuleTemplateAttribute getRuleTemplateAttribute(RuleTemplateAttribute ruleTemplateAttribute, Boolean active) { |
| 151 | 0 | for (RuleTemplateAttribute currentRuleTemplateAttribute: getRuleTemplateAttributes()) { |
| 152 | 0 | if (currentRuleTemplateAttribute.getRuleAttribute().getName().equals(ruleTemplateAttribute.getRuleAttribute().getName())) { |
| 153 | 0 | if (active == null) { |
| 154 | 0 | return currentRuleTemplateAttribute; |
| 155 | |
} |
| 156 | 0 | else if (active.compareTo(currentRuleTemplateAttribute.getActive()) == 0) { |
| 157 | 0 | return currentRuleTemplateAttribute; |
| 158 | |
} |
| 159 | |
} |
| 160 | |
} |
| 161 | 0 | return null; |
| 162 | |
} |
| 163 | |
|
| 164 | |
public RuleTemplateAttribute getRuleTemplateAttribute(RuleTemplateAttribute ruleTemplateAttribute) { |
| 165 | 0 | return getRuleTemplateAttribute(ruleTemplateAttribute, null); |
| 166 | |
} |
| 167 | |
|
| 168 | |
public boolean containsActiveRuleTemplateAttribute(RuleTemplateAttribute templateAttribute) { |
| 169 | 0 | return (getRuleTemplateAttribute(templateAttribute, Boolean.TRUE) != null); |
| 170 | |
} |
| 171 | |
|
| 172 | |
public boolean containsRuleTemplateAttribute(RuleTemplateAttribute templateAttribute) { |
| 173 | 0 | return (getRuleTemplateAttribute(templateAttribute, null) != null); |
| 174 | |
} |
| 175 | |
|
| 176 | |
public RuleTemplateAttribute getRuleTemplateAttribute(int index) { |
| 177 | 0 | while (getRuleTemplateAttributes().size() <= index) { |
| 178 | 0 | getRuleTemplateAttributes().add(new RuleTemplateAttribute()); |
| 179 | |
} |
| 180 | 0 | return (RuleTemplateAttribute) getRuleTemplateAttributes().get(index); |
| 181 | |
} |
| 182 | |
|
| 183 | |
public List<RuleTemplateAttribute> getRuleTemplateAttributes() { |
| 184 | 0 | Collections.sort(ruleTemplateAttributes); |
| 185 | 0 | return ruleTemplateAttributes; |
| 186 | |
} |
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
public List<RuleTemplateAttribute> getActiveRuleTemplateAttributes() { |
| 194 | 0 | List<RuleTemplateAttribute> activeAttributes = new ArrayList<RuleTemplateAttribute>(); |
| 195 | 0 | for (RuleTemplateAttribute templateAttribute : getRuleTemplateAttributes()) |
| 196 | |
{ |
| 197 | 0 | if (templateAttribute.isActive()) |
| 198 | |
{ |
| 199 | 0 | activeAttributes.add(templateAttribute); |
| 200 | |
} |
| 201 | |
} |
| 202 | 0 | Collections.sort(activeAttributes); |
| 203 | 0 | return activeAttributes; |
| 204 | |
} |
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
public void setActiveRuleTemplateAttributes(List<RuleTemplateAttribute> ruleTemplateAttributes) { |
| 211 | 0 | throw new UnsupportedOperationException("setActiveRuleTemplateAttributes is not implemented"); |
| 212 | |
} |
| 213 | |
|
| 214 | |
public void setRuleTemplateAttributes(List<RuleTemplateAttribute> ruleTemplateAttributes) { |
| 215 | 0 | this.ruleTemplateAttributes = ruleTemplateAttributes; |
| 216 | 0 | } |
| 217 | |
|
| 218 | |
public String getDescription() { |
| 219 | 0 | return description; |
| 220 | |
} |
| 221 | |
|
| 222 | |
public void setDescription(String description) { |
| 223 | 0 | this.description = description; |
| 224 | 0 | } |
| 225 | |
|
| 226 | |
public String getName() { |
| 227 | 0 | return name; |
| 228 | |
} |
| 229 | |
|
| 230 | |
public void setName(String name) { |
| 231 | 0 | this.name = name; |
| 232 | 0 | } |
| 233 | |
|
| 234 | |
public Long getRuleTemplateId() { |
| 235 | 0 | return ruleTemplateId; |
| 236 | |
} |
| 237 | |
|
| 238 | |
public void setRuleTemplateId(Long ruleTemplateId) { |
| 239 | 0 | this.ruleTemplateId = ruleTemplateId; |
| 240 | 0 | } |
| 241 | |
|
| 242 | |
public Long getDelegationTemplateId() { |
| 243 | 0 | return delegationTemplateId; |
| 244 | |
} |
| 245 | |
|
| 246 | |
public void setDelegationTemplateId(Long delegationTemplateId) { |
| 247 | 0 | this.delegationTemplateId = delegationTemplateId; |
| 248 | 0 | } |
| 249 | |
|
| 250 | |
public RuleTemplate getDelegationTemplate() { |
| 251 | 0 | return delegationTemplate; |
| 252 | |
} |
| 253 | |
|
| 254 | |
public void setDelegationTemplate(RuleTemplate delegationTemplate) { |
| 255 | 0 | this.delegationTemplate = delegationTemplate; |
| 256 | 0 | } |
| 257 | |
|
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
public Object copy(boolean preserveKeys) { |
| 263 | 0 | RuleTemplate ruleTemplateClone = new RuleTemplate(); |
| 264 | |
|
| 265 | 0 | if (description != null) { |
| 266 | 0 | ruleTemplateClone.setDescription(new String(description)); |
| 267 | |
} |
| 268 | 0 | if (name != null) { |
| 269 | 0 | ruleTemplateClone.setName(new String(name)); |
| 270 | |
} |
| 271 | 0 | if (preserveKeys && ruleTemplateId != null) { |
| 272 | 0 | ruleTemplateClone.setRuleTemplateId(new Long(ruleTemplateId.longValue())); |
| 273 | |
} |
| 274 | 0 | if ((getRuleTemplateAttributes() != null) && !getRuleTemplateAttributes().isEmpty()) { |
| 275 | 0 | List<RuleTemplateAttribute> ruleTemplateAttributeList = new ArrayList<RuleTemplateAttribute>(); |
| 276 | |
|
| 277 | 0 | for (RuleTemplateAttribute ruleTemplateAttribute: getRuleTemplateAttributes()) { |
| 278 | 0 | RuleTemplateAttribute ruleTemplateAttributeCopy = (RuleTemplateAttribute) ruleTemplateAttribute.copy(preserveKeys); |
| 279 | 0 | ruleTemplateAttributeCopy.setRuleTemplate(ruleTemplateClone); |
| 280 | 0 | ruleTemplateAttributeList.add(ruleTemplateAttributeCopy); |
| 281 | 0 | } |
| 282 | 0 | ruleTemplateClone.setRuleTemplateAttributes(ruleTemplateAttributeList); |
| 283 | |
} |
| 284 | 0 | if ((ruleTemplateOptions != null) && !ruleTemplateOptions.isEmpty()) { |
| 285 | 0 | List<RuleTemplateOption> ruleTemplateOptionList = new ArrayList<RuleTemplateOption>(); |
| 286 | |
|
| 287 | 0 | for (RuleTemplateOption ruleTemplateOption: ruleTemplateOptions) { |
| 288 | 0 | RuleTemplateOption ruleTemplateOptionCopy = (RuleTemplateOption) ruleTemplateOption.copy(preserveKeys); |
| 289 | 0 | ruleTemplateOptionCopy.setRuleTemplate(ruleTemplateClone); |
| 290 | 0 | ruleTemplateOptionList.add(ruleTemplateOptionCopy); |
| 291 | 0 | } |
| 292 | 0 | ruleTemplateClone.setRuleTemplateOptions(ruleTemplateOptionList); |
| 293 | |
} |
| 294 | |
|
| 295 | 0 | return ruleTemplateClone; |
| 296 | |
} |
| 297 | |
|
| 298 | |
public String getReturnUrl() { |
| 299 | 0 | return returnUrl; |
| 300 | |
} |
| 301 | |
|
| 302 | |
public void setReturnUrl(String returnUrl) { |
| 303 | 0 | this.returnUrl = returnUrl; |
| 304 | 0 | } |
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
public String getEncodedName() { |
| 310 | 0 | return URLEncoder.encode(getName()); |
| 311 | |
} |
| 312 | |
|
| 313 | |
public List<RuleTemplateOption> getRuleTemplateOptions() { |
| 314 | 0 | return ruleTemplateOptions; |
| 315 | |
} |
| 316 | |
|
| 317 | |
public void setRuleTemplateOptions(List<RuleTemplateOption> ruleTemplateOptions) { |
| 318 | 0 | this.ruleTemplateOptions = ruleTemplateOptions; |
| 319 | 0 | } |
| 320 | |
|
| 321 | |
public RuleTemplateOption getRuleTemplateOption(String key) { |
| 322 | 0 | for (RuleTemplateOption option: ruleTemplateOptions) { |
| 323 | 0 | if (option.getKey().equals(key)) { |
| 324 | 0 | return option; |
| 325 | |
} |
| 326 | |
} |
| 327 | 0 | return null; |
| 328 | |
} |
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
public void setAcknowledge(RuleTemplateOption acknowledge) { |
| 338 | 0 | RuleTemplateOption option = getRuleTemplateOption(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ); |
| 339 | 0 | option.setValue(acknowledge.getValue()); |
| 340 | 0 | option.setRuleTemplateOptionId(acknowledge.getRuleTemplateOptionId()); |
| 341 | 0 | option.setLockVerNbr(acknowledge.getLockVerNbr()); |
| 342 | 0 | } |
| 343 | |
|
| 344 | |
public void setComplete(RuleTemplateOption complete) { |
| 345 | 0 | RuleTemplateOption option = getRuleTemplateOption(KEWConstants.ACTION_REQUEST_COMPLETE_REQ); |
| 346 | 0 | option.setValue(complete.getValue()); |
| 347 | 0 | option.setRuleTemplateOptionId(complete.getRuleTemplateOptionId()); |
| 348 | 0 | option.setLockVerNbr(complete.getLockVerNbr()); |
| 349 | 0 | } |
| 350 | |
|
| 351 | |
public void setApprove(RuleTemplateOption approve) { |
| 352 | 0 | RuleTemplateOption option = getRuleTemplateOption(KEWConstants.ACTION_REQUEST_APPROVE_REQ); |
| 353 | 0 | option.setValue(approve.getValue()); |
| 354 | 0 | option.setRuleTemplateOptionId(approve.getRuleTemplateOptionId()); |
| 355 | 0 | option.setLockVerNbr(approve.getLockVerNbr()); |
| 356 | 0 | } |
| 357 | |
|
| 358 | |
public void setFyi(RuleTemplateOption fyi) { |
| 359 | 0 | RuleTemplateOption option = getRuleTemplateOption(KEWConstants.ACTION_REQUEST_FYI_REQ); |
| 360 | 0 | option.setValue(fyi.getValue()); |
| 361 | 0 | option.setRuleTemplateOptionId(fyi.getRuleTemplateOptionId()); |
| 362 | 0 | option.setLockVerNbr(fyi.getLockVerNbr()); |
| 363 | 0 | } |
| 364 | |
|
| 365 | |
public void setDefaultActionRequestValue(RuleTemplateOption defaultActionRequestValue) { |
| 366 | 0 | RuleTemplateOption option = getRuleTemplateOption(KEWConstants.ACTION_REQUEST_DEFAULT_CD); |
| 367 | 0 | option.setValue(defaultActionRequestValue.getValue()); |
| 368 | 0 | option.setRuleTemplateOptionId(defaultActionRequestValue.getRuleTemplateOptionId()); |
| 369 | 0 | option.setLockVerNbr(defaultActionRequestValue.getLockVerNbr()); |
| 370 | 0 | } |
| 371 | |
|
| 372 | |
|
| 373 | |
|
| 374 | |
|
| 375 | |
|
| 376 | |
public RuleTemplateOption getAcknowledge() { |
| 377 | 0 | return getRuleTemplateOption(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ); |
| 378 | |
} |
| 379 | |
|
| 380 | |
public RuleTemplateOption getComplete() { |
| 381 | 0 | return getRuleTemplateOption(KEWConstants.ACTION_REQUEST_COMPLETE_REQ); |
| 382 | |
} |
| 383 | |
|
| 384 | |
public RuleTemplateOption getApprove() { |
| 385 | 0 | return getRuleTemplateOption(KEWConstants.ACTION_REQUEST_APPROVE_REQ); |
| 386 | |
} |
| 387 | |
|
| 388 | |
public RuleTemplateOption getFyi() { |
| 389 | 0 | return getRuleTemplateOption(KEWConstants.ACTION_REQUEST_FYI_REQ); |
| 390 | |
} |
| 391 | |
|
| 392 | |
public RuleTemplateOption getDefaultActionRequestValue() { |
| 393 | 0 | return getRuleTemplateOption(KEWConstants.ACTION_REQUEST_DEFAULT_CD); |
| 394 | |
} |
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
public List<Role> getRoles() { |
| 401 | 0 | List<Role> roles = new ArrayList<Role>(); |
| 402 | 0 | List<RuleTemplateAttribute> ruleTemplateAttributes = getActiveRuleTemplateAttributes(); |
| 403 | 0 | Collections.sort(ruleTemplateAttributes); |
| 404 | 0 | for (RuleTemplateAttribute ruleTemplateAttribute : ruleTemplateAttributes) |
| 405 | |
{ |
| 406 | 0 | if (!ruleTemplateAttribute.isWorkflowAttribute()) |
| 407 | |
{ |
| 408 | 0 | continue; |
| 409 | |
} |
| 410 | 0 | WorkflowAttribute workflowAttribute = ruleTemplateAttribute.getWorkflowAttribute(); |
| 411 | 0 | if (workflowAttribute instanceof RoleAttribute) |
| 412 | |
{ |
| 413 | 0 | RoleAttribute roleAttribute = (RoleAttribute) workflowAttribute; |
| 414 | 0 | roles.addAll(roleAttribute.getRoleNames()); |
| 415 | |
} |
| 416 | 0 | } |
| 417 | 0 | return roles; |
| 418 | |
} |
| 419 | |
|
| 420 | |
public String toString() { |
| 421 | 0 | return new ToStringBuilder(this).append("ruleTemplateId", ruleTemplateId) |
| 422 | |
.append("name", name) |
| 423 | |
.append("description", description) |
| 424 | |
.append("delegationTemplateId", delegationTemplateId) |
| 425 | |
.append("totalRuleTemplateAttributes", getRuleTemplateAttributes() == null ? "null" : "size: " + getRuleTemplateAttributes().size()) |
| 426 | |
.append("activeRuleTemplateAttributes", getActiveRuleTemplateAttributes() == null ? "null" : "size: " + getActiveRuleTemplateAttributes().size()) |
| 427 | |
.append("returnUrl", returnUrl) |
| 428 | |
.append("versionNumber", versionNumber) |
| 429 | |
.append("ruleTemplateOptions", ruleTemplateOptions).toString(); |
| 430 | |
|
| 431 | |
} |
| 432 | |
|
| 433 | |
|
| 434 | |
|
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
@Override |
| 439 | |
protected LinkedHashMap<String, Object> toStringMapper() { |
| 440 | 0 | LinkedHashMap<String, Object> propMap = new LinkedHashMap<String, Object>(); |
| 441 | 0 | propMap.put("ruleTemplateId", getRuleTemplateId()); |
| 442 | 0 | propMap.put("name", getName()); |
| 443 | 0 | propMap.put("description", getDescription()); |
| 444 | 0 | propMap.put("delegationTemplateId", getDelegationTemplateId()); |
| 445 | 0 | propMap.put("totalRuleTemplateAttributes", getRuleTemplateAttributes() == null ? "null" : "size: " + getRuleTemplateAttributes().size()); |
| 446 | 0 | propMap.put("activeRuleTemplateAttributes", getActiveRuleTemplateAttributes() == null ? "null" : "size: " + getActiveRuleTemplateAttributes().size()); |
| 447 | 0 | propMap.put("returnUrl", getReturnUrl()); |
| 448 | 0 | propMap.put("versionNumber", getVersionNumber()); |
| 449 | 0 | propMap.put("ruleTemplateOptions", getRuleTemplateOptions()); |
| 450 | |
|
| 451 | 0 | return propMap; |
| 452 | |
|
| 453 | |
} |
| 454 | |
} |