| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kew.rule; |
| 18 | |
|
| 19 | |
import java.util.LinkedHashMap; |
| 20 | |
import java.util.List; |
| 21 | |
|
| 22 | |
import javax.persistence.Column; |
| 23 | |
import javax.persistence.Entity; |
| 24 | |
import javax.persistence.FetchType; |
| 25 | |
import javax.persistence.Id; |
| 26 | |
import javax.persistence.JoinColumn; |
| 27 | |
import javax.persistence.ManyToOne; |
| 28 | |
import javax.persistence.Table; |
| 29 | |
|
| 30 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
| 31 | |
import org.kuali.rice.core.jpa.annotations.Sequence; |
| 32 | |
import org.kuali.rice.core.reflect.ObjectDefinition; |
| 33 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
| 34 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
| 35 | |
import org.kuali.rice.kew.bo.KewPersistableBusinessObjectBase; |
| 36 | |
import org.kuali.rice.kew.exception.WorkflowException; |
| 37 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 38 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 39 | |
import org.kuali.rice.kew.util.Utilities; |
| 40 | |
import org.kuali.rice.kim.bo.Group; |
| 41 | |
import org.kuali.rice.kim.bo.entity.KimPrincipal; |
| 42 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
@Entity |
| 54 | |
@Table(name="KREW_RULE_RSP_T") |
| 55 | |
@Sequence(name="KREW_RSP_S", property="ruleResponsibilityKey") |
| 56 | 0 | public class RuleResponsibility extends KewPersistableBusinessObjectBase { |
| 57 | |
|
| 58 | |
private static final long serialVersionUID = -1565688857123316797L; |
| 59 | |
@Id |
| 60 | |
@Column(name="RULE_RSP_ID") |
| 61 | |
private Long ruleResponsibilityKey; |
| 62 | |
@Column(name="RSP_ID") |
| 63 | |
private Long responsibilityId; |
| 64 | |
@Column(name="RULE_ID", insertable=false, updatable=false) |
| 65 | |
private Long ruleBaseValuesId; |
| 66 | |
@Column(name="ACTN_RQST_CD") |
| 67 | |
private String actionRequestedCd; |
| 68 | |
@Column(name="NM") |
| 69 | |
private String ruleResponsibilityName; |
| 70 | |
@Column(name="TYP") |
| 71 | |
private String ruleResponsibilityType; |
| 72 | |
@Column(name="PRIO") |
| 73 | |
private Integer priority; |
| 74 | |
@Column(name="APPR_PLCY") |
| 75 | |
private String approvePolicy; |
| 76 | |
|
| 77 | |
@ManyToOne(fetch=FetchType.EAGER) |
| 78 | |
@JoinColumn(name="RULE_ID") |
| 79 | |
private RuleBaseValues ruleBaseValues; |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
public KimPrincipal getPrincipal() |
| 85 | |
{ |
| 86 | 0 | if (isUsingWorkflowUser()) { |
| 87 | 0 | return KEWServiceLocator.getIdentityHelperService().getPrincipal(ruleResponsibilityName); |
| 88 | |
} |
| 89 | 0 | return null; |
| 90 | |
} |
| 91 | |
|
| 92 | |
public Group getGroup() { |
| 93 | 0 | if (isUsingGroup()) { |
| 94 | 0 | return KIMServiceLocator.getIdentityManagementService().getGroup(ruleResponsibilityName); |
| 95 | |
} |
| 96 | 0 | return null; |
| 97 | |
} |
| 98 | |
|
| 99 | |
public String getRole() { |
| 100 | 0 | if (isUsingRole()) { |
| 101 | 0 | return ruleResponsibilityName; |
| 102 | |
} |
| 103 | 0 | return null; |
| 104 | |
} |
| 105 | |
|
| 106 | |
public String getResolvedRoleName() { |
| 107 | 0 | if (isUsingRole()) { |
| 108 | 0 | return getRole().substring(getRole().indexOf("!") + 1, getRole().length()); |
| 109 | |
} |
| 110 | 0 | return null; |
| 111 | |
} |
| 112 | |
|
| 113 | |
public String getRoleAttributeName() { |
| 114 | 0 | return getRole().substring(0, getRole().indexOf("!")); |
| 115 | |
} |
| 116 | |
|
| 117 | |
public RoleAttribute resolveRoleAttribute() throws WorkflowException { |
| 118 | 0 | if (isUsingRole()) { |
| 119 | 0 | String attributeName = getRoleAttributeName(); |
| 120 | 0 | return (RoleAttribute) GlobalResourceLoader.getResourceLoader().getObject(new ObjectDefinition(attributeName)); |
| 121 | |
} |
| 122 | 0 | return null; |
| 123 | |
} |
| 124 | |
|
| 125 | |
public boolean isUsingRole() { |
| 126 | 0 | return (ruleResponsibilityName != null && ruleResponsibilityType != null && ruleResponsibilityType.equals(KEWConstants.RULE_RESPONSIBILITY_ROLE_ID)); |
| 127 | |
} |
| 128 | |
|
| 129 | |
public boolean isUsingWorkflowUser() { |
| 130 | 0 | return (ruleResponsibilityName != null && !ruleResponsibilityName.trim().equals("") && ruleResponsibilityType != null && ruleResponsibilityType.equals(KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID)); |
| 131 | |
} |
| 132 | |
|
| 133 | |
public boolean isUsingGroup() { |
| 134 | 0 | return (ruleResponsibilityName != null && !ruleResponsibilityName.trim().equals("") && ruleResponsibilityType != null && ruleResponsibilityType.equals(KEWConstants.RULE_RESPONSIBILITY_GROUP_ID)); |
| 135 | |
} |
| 136 | |
|
| 137 | |
public Long getRuleBaseValuesId() { |
| 138 | 0 | return ruleBaseValuesId; |
| 139 | |
} |
| 140 | |
|
| 141 | |
public void setRuleBaseValuesId(Long ruleBaseValuesId) { |
| 142 | 0 | this.ruleBaseValuesId = ruleBaseValuesId; |
| 143 | 0 | } |
| 144 | |
|
| 145 | |
public RuleBaseValues getRuleBaseValues() { |
| 146 | 0 | return ruleBaseValues; |
| 147 | |
} |
| 148 | |
|
| 149 | |
public void setRuleBaseValues(RuleBaseValues ruleBaseValues) { |
| 150 | 0 | this.ruleBaseValues = ruleBaseValues; |
| 151 | 0 | } |
| 152 | |
|
| 153 | |
public String getActionRequestedCd() { |
| 154 | 0 | return actionRequestedCd; |
| 155 | |
} |
| 156 | |
|
| 157 | |
public void setActionRequestedCd(String actionRequestedCd) { |
| 158 | 0 | this.actionRequestedCd = actionRequestedCd; |
| 159 | 0 | } |
| 160 | |
|
| 161 | |
public Long getRuleResponsibilityKey() { |
| 162 | 0 | return ruleResponsibilityKey; |
| 163 | |
} |
| 164 | |
|
| 165 | |
public void setRuleResponsibilityKey(Long ruleResponsibilityId) { |
| 166 | 0 | this.ruleResponsibilityKey = ruleResponsibilityId; |
| 167 | 0 | } |
| 168 | |
public Integer getPriority() { |
| 169 | 0 | return priority; |
| 170 | |
} |
| 171 | |
|
| 172 | |
public void setPriority(Integer priority) { |
| 173 | 0 | this.priority = priority; |
| 174 | 0 | } |
| 175 | |
|
| 176 | |
public String getApprovePolicy() { |
| 177 | 0 | return approvePolicy; |
| 178 | |
} |
| 179 | |
|
| 180 | |
public void setApprovePolicy(String approvePolicy) { |
| 181 | 0 | this.approvePolicy = approvePolicy; |
| 182 | 0 | } |
| 183 | |
|
| 184 | |
public Object copy(boolean preserveKeys) { |
| 185 | 0 | RuleResponsibility ruleResponsibilityClone = new RuleResponsibility(); |
| 186 | 0 | ruleResponsibilityClone.setApprovePolicy(getApprovePolicy()); |
| 187 | 0 | if (actionRequestedCd != null) { |
| 188 | 0 | ruleResponsibilityClone.setActionRequestedCd(actionRequestedCd); |
| 189 | |
} |
| 190 | 0 | if (ruleResponsibilityKey != null && preserveKeys) { |
| 191 | 0 | ruleResponsibilityClone.setRuleResponsibilityKey(ruleResponsibilityKey); |
| 192 | |
} |
| 193 | |
|
| 194 | 0 | if (responsibilityId != null) { |
| 195 | 0 | ruleResponsibilityClone.setResponsibilityId(responsibilityId); |
| 196 | |
} |
| 197 | |
|
| 198 | 0 | if (ruleResponsibilityName != null) { |
| 199 | 0 | ruleResponsibilityClone.setRuleResponsibilityName(ruleResponsibilityName); |
| 200 | |
} |
| 201 | 0 | if (ruleResponsibilityType != null) { |
| 202 | 0 | ruleResponsibilityClone.setRuleResponsibilityType(ruleResponsibilityType); |
| 203 | |
} |
| 204 | 0 | if (priority != null) { |
| 205 | 0 | ruleResponsibilityClone.setPriority(priority); |
| 206 | |
} |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | 0 | return ruleResponsibilityClone; |
| 217 | |
} |
| 218 | |
|
| 219 | |
public String getRuleResponsibilityName() { |
| 220 | 0 | return ruleResponsibilityName; |
| 221 | |
} |
| 222 | |
|
| 223 | |
public void setRuleResponsibilityName(String ruleResponsibilityName) { |
| 224 | 0 | this.ruleResponsibilityName = ruleResponsibilityName; |
| 225 | 0 | } |
| 226 | |
|
| 227 | |
public String getRuleResponsibilityType() { |
| 228 | 0 | return ruleResponsibilityType; |
| 229 | |
} |
| 230 | |
|
| 231 | |
public void setRuleResponsibilityType(String ruleResponsibilityType) { |
| 232 | 0 | this.ruleResponsibilityType = ruleResponsibilityType; |
| 233 | 0 | } |
| 234 | |
|
| 235 | |
public Long getResponsibilityId() { |
| 236 | 0 | return responsibilityId; |
| 237 | |
} |
| 238 | |
public void setResponsibilityId(Long responsibilityId) { |
| 239 | 0 | this.responsibilityId = responsibilityId; |
| 240 | 0 | } |
| 241 | |
|
| 242 | |
public List<RuleDelegation> getDelegationRules() { |
| 243 | 0 | return KEWServiceLocator.getRuleDelegationService().findByResponsibilityId(getResponsibilityId()); |
| 244 | |
} |
| 245 | |
|
| 246 | |
public RuleDelegation getDelegationRule(int index) { |
| 247 | 0 | return getDelegationRules().get(index); |
| 248 | |
} |
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
public String getActionRequestedDisplayValue() { |
| 274 | 0 | return KEWConstants.ACTION_REQUEST_CODES.get(getActionRequestedCd()); |
| 275 | |
} |
| 276 | |
|
| 277 | |
public String getRuleResponsibilityTypeDisplayValue() { |
| 278 | 0 | return KEWConstants.RULE_RESPONSIBILITY_TYPES.get(getRuleResponsibilityType()); |
| 279 | |
} |
| 280 | |
|
| 281 | |
public boolean equals(Object o) { |
| 282 | 0 | if (o == null) return false; |
| 283 | 0 | if (!(o instanceof RuleResponsibility)) return false; |
| 284 | 0 | RuleResponsibility pred = (RuleResponsibility) o; |
| 285 | 0 | return Utilities.equals(ruleResponsibilityName, pred.getRuleResponsibilityName()) && |
| 286 | |
Utilities.equals(actionRequestedCd, pred.getActionRequestedCd()) && |
| 287 | |
Utilities.equals(priority, pred.getPriority()) && |
| 288 | |
Utilities.equals(approvePolicy, pred.getApprovePolicy()); |
| 289 | |
} |
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
@Override |
| 295 | |
public int hashCode() { |
| 296 | 0 | return new HashCodeBuilder() |
| 297 | |
.append(this.actionRequestedCd) |
| 298 | |
.append(this.approvePolicy) |
| 299 | |
.append(this.priority) |
| 300 | |
.append(this.ruleResponsibilityName).toHashCode(); |
| 301 | |
} |
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
@Override |
| 306 | |
protected LinkedHashMap toStringMapper() { |
| 307 | 0 | LinkedHashMap map = new LinkedHashMap(); |
| 308 | 0 | map.put("responsibilityId", responsibilityId); |
| 309 | 0 | map.put("ruleResponsibilityKey", ruleResponsibilityKey); |
| 310 | 0 | map.put("ruleResponsibilityName", ruleResponsibilityName); |
| 311 | 0 | map.put("ruleResponsibilityType", ruleResponsibilityType); |
| 312 | 0 | map.put("ruleBaseValuesId", ruleBaseValuesId); |
| 313 | 0 | map.put("actionRequestedCd", actionRequestedCd); |
| 314 | 0 | map.put("priority", priority); |
| 315 | 0 | return map; |
| 316 | |
} |
| 317 | |
|
| 318 | |
|
| 319 | |
} |