1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.rule;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.kuali.rice.core.api.uif.RemotableAttributeError;
24 import org.kuali.rice.core.api.uif.RemotableAttributeErrorContract;
25 import org.kuali.rice.kew.api.identity.Id;
26 import org.kuali.rice.kew.api.identity.PrincipalId;
27 import org.kuali.rice.kew.api.rule.RoleName;
28 import org.kuali.rice.kew.engine.RouteContext;
29 import org.kuali.rice.kew.routeheader.DocumentContent;
30
31
32
33
34
35 public class TestRuleAttribute implements WorkflowRuleAttribute, RoleAttribute, WorkflowAttributeXmlValidator {
36
37 private static final long serialVersionUID = -220808609566348066L;
38
39 public static boolean VALID_CLIENT_ROUTING_DATA_CALLED = false;
40
41 private static Map<String, Map<String, List<String>>> roles = new HashMap<String, Map<String, List<String>>>();
42 private boolean required;
43
44 public boolean isMatch(DocumentContent documentContent, List ruleExtensions) {
45 return true;
46 }
47
48 public List getRoleNames() {
49 List roleNames = new ArrayList();
50 for (String roleName : roles.keySet()) {
51 roleNames.add(new RoleName(getClass().getName(), roleName, roleName));
52 }
53 return roleNames;
54 }
55
56 public List getRuleRows() {
57 return new ArrayList();
58 }
59
60 public List getRoutingDataRows() {
61 return new ArrayList();
62 }
63
64 public String getDocContent() {
65 return "<testRuleAttributeContent/>";
66 }
67
68 public List getRuleExtensionValues() {
69 return new ArrayList();
70 }
71
72 public List validateRoutingData(Map paramMap) {
73 return new ArrayList();
74 }
75
76 public String getAttributeLabel(){
77 return "";
78 }
79
80 public List<RemotableAttributeError> validateRuleData(Map paramMap) {
81 return new ArrayList<RemotableAttributeError>();
82 }
83
84 public void setRequired(boolean required) {
85 this.required = required;
86 }
87
88 public boolean isRequired() {
89 return required;
90 }
91
92 public List<String> getQualifiedRoleNames(String roleName, DocumentContent documentContent) {
93 List<String> qualifiedRoleNames = new ArrayList<String>();
94 Map<String, List<String>> qualifiedRoles = roles.get(roleName);
95 if (qualifiedRoles != null) {
96 qualifiedRoleNames.addAll(qualifiedRoles.keySet());
97 } else {
98 throw new IllegalArgumentException("TestRuleAttribute does not support the given role " + roleName);
99 }
100 return qualifiedRoleNames;
101 }
102
103 public ResolvedQualifiedRole resolveQualifiedRole(RouteContext routeContext, String roleName, String qualifiedRole) {
104 ResolvedQualifiedRole resolved = new ResolvedQualifiedRole();
105 Map<String, List<String>> qualifiedRoles = (Map<String, List<String>>)roles.get(roleName);
106 if (qualifiedRoles != null) {
107 List<String> recipients = (List<String>)qualifiedRoles.get(qualifiedRole);
108 if (recipients != null) {
109 resolved.setQualifiedRoleLabel(qualifiedRole);
110 resolved.setRecipients(convertPrincipalIdList(recipients));
111 } else {
112 throw new IllegalArgumentException("TestRuleAttribute does not support the qualified role " + qualifiedRole);
113 }
114 } else {
115 throw new IllegalArgumentException("TestRuleAttribute does not support the given role " + roleName);
116 }
117 return resolved;
118 }
119
120 private static List<Id> convertPrincipalIdList(List<String> principalIds) {
121 List<Id> idList = new ArrayList<Id>();
122 for (String principalId : principalIds) {
123 idList.add(new PrincipalId(principalId));
124 }
125 return idList;
126 }
127
128 public static void addRole(String roleName) {
129 roles.put(roleName, new HashMap<String, List<String>>());
130 }
131
132 public static void removeRole(String roleName) {
133 roles.remove(roleName);
134 }
135
136 public static Map<String, List<String>> getRole(String roleName) {
137 return (Map<String, List<String>>)roles.get(roleName);
138 }
139
140 public static void addQualifiedRole(String roleName, String qualifiedRoleName) {
141 getRole(roleName).put(qualifiedRoleName, new ArrayList<String>());
142 }
143
144 public static void removeQualifiedRole(String roleName, String qualifiedRoleName) {
145 getRole(roleName).remove(qualifiedRoleName);
146 }
147
148
149
150
151
152
153
154
155 public static void setRecipientPrincipalIds(String roleName, String qualifiedRoleName, List<String> principalIds) {
156 Map<String, List<String>> qualifiedRoles = getRole(roleName);
157 if (qualifiedRoles == null) {
158 addRole(roleName);
159 }
160 if (qualifiedRoles == null) {
161 addRole(roleName);
162 addQualifiedRole(roleName, qualifiedRoleName);
163 qualifiedRoles = getRole(roleName);
164 }
165 qualifiedRoles.put(qualifiedRoleName, principalIds);
166 }
167
168 public static List<String> getRecipientPrincipalIds(String roleName, String qualifiedRoleName) {
169 Map<String, List<String>> qualifiedRoles = getRole(roleName);
170 return (List<String>)qualifiedRoles.get(qualifiedRoleName);
171 }
172
173 public List<RemotableAttributeError> validateClientRoutingData() {
174 return new ArrayList<RemotableAttributeError>();
175 }
176
177 }