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