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