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