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