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.util.ArrayList;
20 import java.util.List;
21
22 import javax.servlet.http.HttpServletRequest;
23
24 import org.kuali.rice.core.exception.RiceRuntimeException;
25 import org.kuali.rice.kew.rule.RuleBaseValues;
26 import org.kuali.rice.kew.rule.RuleResponsibility;
27 import org.kuali.rice.kew.service.KEWServiceLocator;
28 import org.kuali.rice.kew.util.KEWConstants;
29 import org.kuali.rice.kim.bo.Group;
30 import org.kuali.rice.kim.bo.entity.KimPrincipal;
31 import org.kuali.rice.kim.service.KIMServiceLocator;
32 import org.kuali.rice.kns.web.struts.form.KualiForm;
33
34
35
36
37
38
39
40 public class DelegateRuleForm extends KualiForm {
41
42 private static final long serialVersionUID = 5412969516727713859L;
43
44 private Long parentRuleId;
45 private Long parentResponsibilityId;
46
47 private RuleBaseValues parentRule;
48 private RuleResponsibility parentResponsibility;
49
50 private List<String> reviewers = new ArrayList<String>();
51 private List<String> responsibilityTypes = new ArrayList<String>();
52 private List<String> actionRequestCodes = new ArrayList<String>();
53
54 public Long getParentRuleId() {
55 return this.parentRuleId;
56 }
57
58 public void setParentRuleId(Long parentRuleId) {
59 this.parentRuleId = parentRuleId;
60 }
61
62 public Long getParentResponsibilityId() {
63 return this.parentResponsibilityId;
64 }
65
66 public void setParentResponsibilityId(Long parentResponsibilityId) {
67 this.parentResponsibilityId = parentResponsibilityId;
68 }
69
70 public RuleBaseValues getParentRule() {
71 return this.parentRule;
72 }
73
74 public void setParentRule(RuleBaseValues parentRule) {
75 if (this.parentRule != null
76 && parentRule != null
77 && this.parentResponsibility != null) {
78 if (this.parentRule.getRuleBaseValuesId().longValue() != parentRule.getRuleBaseValuesId().longValue()) {
79 this.parentResponsibility = null;
80 this.parentResponsibilityId = null;
81 }
82 }
83 this.parentRule = parentRule;
84 }
85
86 public RuleResponsibility getParentResponsibility() {
87 return this.parentResponsibility;
88 }
89
90 public void setParentResponsibility(RuleResponsibility parentResponsibility) {
91 this.parentResponsibility = parentResponsibility;
92 }
93
94 public List<String> getReviewers() {
95 return this.reviewers;
96 }
97
98 public void setReviewers(List<String> reviewers) {
99 this.reviewers = reviewers;
100 }
101
102 public List<String> getResponsibilityTypes() {
103 return this.responsibilityTypes;
104 }
105
106 public void setResponsibilityTypes(List<String> responsibilityTypes) {
107 this.responsibilityTypes = responsibilityTypes;
108 }
109
110 public List<String> getActionRequestCodes() {
111 return this.actionRequestCodes;
112 }
113
114 public void setActionRequestCodes(List<String> actionRequestCodes) {
115 this.actionRequestCodes = actionRequestCodes;
116 }
117
118 public String getRuleDescription() {
119 if (getParentRule() == null) {
120 return "";
121 }
122 return getParentRule().getDescription();
123 }
124
125 @Override
126 public void populate(HttpServletRequest request) {
127
128 super.populate(request);
129
130 reviewers.clear();
131 responsibilityTypes.clear();
132 actionRequestCodes.clear();
133
134 if (getParentRuleId() != null) {
135 setParentRule(KEWServiceLocator.getRuleService().findRuleBaseValuesById(getParentRuleId()));
136 }
137 if (getParentResponsibilityId() != null && getParentRule() != null) {
138 for (RuleResponsibility responsibility : getParentRule().getResponsibilities()) {
139 if (responsibility.getResponsibilityId().equals(getParentResponsibilityId())) {
140 setParentResponsibility(responsibility);
141 break;
142 }
143 }
144 }
145
146 if (getParentRule() != null) {
147 for (RuleResponsibility responsibility : getParentRule().getResponsibilities()) {
148 if (KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID.equals(responsibility.getRuleResponsibilityType())) {
149 KimPrincipal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(responsibility.getRuleResponsibilityName());
150 if (principal != null) {
151 reviewers.add(principal.getPrincipalName());
152 }
153 responsibilityTypes.add(KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID_LABEL);
154 } else if (KEWConstants.RULE_RESPONSIBILITY_GROUP_ID.equals(responsibility.getRuleResponsibilityType())) {
155 Group group = KIMServiceLocator.getIdentityManagementService().getGroup(responsibility.getRuleResponsibilityName());
156 if (group != null) {
157 reviewers.add(group.getNamespaceCode() + " " + group.getGroupName());
158 }
159 responsibilityTypes.add(KEWConstants.RULE_RESPONSIBILITY_GROUP_ID_LABEL);
160 } else if (KEWConstants.RULE_RESPONSIBILITY_ROLE_ID.equals(responsibility.getRuleResponsibilityType())) {
161 reviewers.add(responsibility.getResolvedRoleName());
162 responsibilityTypes.add(KEWConstants.RULE_RESPONSIBILITY_ROLE_ID_LABEL);
163 } else {
164 throw new RiceRuntimeException("Encountered a responsibility with an invalid type, type value was " + responsibility.getRuleResponsibilityType());
165 }
166 actionRequestCodes.add(KEWConstants.ACTION_REQUEST_CODES.get(responsibility.getActionRequestedCd()));
167 }
168 }
169
170 }
171
172
173
174 }