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