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.ArrayList;
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.kuali.rice.kew.engine.RouteContext;
26 import org.kuali.rice.kew.routeheader.DocumentContent;
27 import org.kuali.rice.kew.rule.ResolvedQualifiedRole;
28 import org.kuali.rice.kew.rule.Role;
29 import org.kuali.rice.kew.rule.RoleAttribute;
30 import org.kuali.rice.kew.rule.WorkflowAttribute;
31 import org.kuali.rice.kew.rule.WorkflowAttributeValidationError;
32 import org.kuali.rice.kew.rule.WorkflowAttributeXmlValidator;
33
34
35
36
37
38 public class TestRuleAttributeThree implements WorkflowAttribute, RoleAttribute, WorkflowAttributeXmlValidator {
39
40 private static final long serialVersionUID = -3502848534548531114L;
41
42 public static boolean VALID_CLIENT_ROUTING_DATA_CALLED = false;
43
44 private static Map roles = new HashMap();
45 private boolean required;
46
47 public boolean isMatch(DocumentContent documentContent, List ruleExtensions) {
48 return true;
49 }
50
51 public List getRoleNames() {
52 List roleNames = new ArrayList();
53 for (Iterator iterator = roles.keySet().iterator(); iterator.hasNext();) {
54 String roleName = (String) iterator.next();
55 roleNames.add(new Role(getClass(), roleName, roleName));
56 }
57 return roleNames;
58 }
59
60 public List getRuleRows() {
61 return new ArrayList();
62 }
63
64 public List getRoutingDataRows() {
65 return new ArrayList();
66 }
67
68 public String getDocContent() {
69 return "<testRuleAttributeContent/>";
70 }
71
72 public List getRuleExtensionValues() {
73 return new ArrayList();
74 }
75
76 public List validateRoutingData(Map paramMap) {
77 return new ArrayList();
78 }
79
80 public String getAttributeLabel(){
81 return "";
82 }
83
84 public List validateRuleData(Map paramMap) {
85 return new ArrayList();
86 }
87
88 public void setRequired(boolean required) {
89 this.required = required;
90 }
91
92 public boolean isRequired() {
93 return required;
94 }
95
96 public List getQualifiedRoleNames(String roleName, DocumentContent documentContent) {
97 ArrayList qualifiedRoleNames = new ArrayList();
98 Map qualifiedRoles = (Map)roles.get(roleName);
99 if (qualifiedRoles != null) {
100 qualifiedRoleNames.addAll(qualifiedRoles.keySet());
101 } else {
102 throw new IllegalArgumentException("TestRuleAttribute does not support the given role " + roleName);
103 }
104 return qualifiedRoleNames;
105 }
106
107 public ResolvedQualifiedRole resolveQualifiedRole(RouteContext routeContext, String roleName, String qualifiedRole) {
108 ResolvedQualifiedRole resolved = new ResolvedQualifiedRole();
109 Map qualifiedRoles = (Map)roles.get(roleName);
110 if (qualifiedRoles != null) {
111 List recipients = (List)qualifiedRoles.get(qualifiedRole);
112 if (recipients != null) {
113 resolved.setQualifiedRoleLabel(qualifiedRole);
114 resolved.setRecipients(recipients);
115 } else {
116 throw new IllegalArgumentException("TestRuleAttribute does not support the qualified role " + qualifiedRole);
117 }
118 } else {
119 throw new IllegalArgumentException("TestRuleAttribute does not support the given role " + roleName);
120 }
121 return resolved;
122 }
123
124 public static void addRole(String roleName) {
125 roles.put(roleName, new HashMap());
126 }
127
128 public static void removeRole(String roleName) {
129 roles.remove(roleName);
130 }
131
132 public static Map getRole(String roleName) {
133 return (Map)roles.get(roleName);
134 }
135
136 public static void addQualifiedRole(String roleName, String qualifiedRoleName) {
137 getRole(roleName).put(qualifiedRoleName, new ArrayList());
138 }
139
140 public static void removeQualifiedRole(String roleName, String qualifiedRoleName) {
141 getRole(roleName).remove(qualifiedRoleName);
142 }
143
144 public static void setRecipients(String roleName, String qualifiedRoleName, List recipients) {
145 Map qualifiedRoles = getRole(roleName);
146 qualifiedRoles.put(qualifiedRoleName, recipients);
147 }
148
149 public static List getRecipients(String roleName, String qualifiedRoleName) {
150 Map qualifiedRoles = getRole(roleName);
151 return (List)qualifiedRoles.get(qualifiedRoleName);
152 }
153
154 public List<WorkflowAttributeValidationError> validateClientRoutingData() {
155 VALID_CLIENT_ROUTING_DATA_CALLED = true;
156 List<WorkflowAttributeValidationError> errors = new ArrayList<WorkflowAttributeValidationError>();
157 errors.add(new WorkflowAttributeValidationError("key1", "value1"));
158 errors.add(new WorkflowAttributeValidationError("key2", "value2"));
159 return errors;
160 }
161
162 }