View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.RemotableAttributeErrorContract;
25  import org.kuali.rice.core.api.uif.RemotableAttributeError;
26  import org.kuali.rice.kew.api.rule.RoleName;
27  import org.kuali.rice.kew.engine.RouteContext;
28  import org.kuali.rice.kew.routeheader.DocumentContent;
29  
30  
31  /**
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class TestRuleAttributeThree implements WorkflowRuleAttribute, RoleAttribute, WorkflowAttributeXmlValidator {
35  
36  	private static final long serialVersionUID = -3502848534548531114L;
37  
38  	public static boolean VALID_CLIENT_ROUTING_DATA_CALLED = false;
39  	
40  	private static Map roles = new HashMap();
41  	private boolean required;
42  		
43      public boolean isMatch(DocumentContent documentContent, List ruleExtensions) {
44          return true;
45      }
46      
47      public List getRoleNames() {
48          List roleNames = new ArrayList();
49          for (Iterator iterator = roles.keySet().iterator(); iterator.hasNext();) {
50              String roleName = (String) iterator.next();
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 validateRuleData(Map paramMap) {
81      	return new ArrayList();
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 getQualifiedRoleNames(String roleName, DocumentContent documentContent) {
93  		ArrayList qualifiedRoleNames = new ArrayList();
94  		Map qualifiedRoles = (Map)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 qualifiedRoles = (Map)roles.get(roleName);
106 		if (qualifiedRoles != null) {
107 			List recipients = (List)qualifiedRoles.get(qualifiedRole);
108 			if (recipients != null) {
109 				resolved.setQualifiedRoleLabel(qualifiedRole);
110 				resolved.setRecipients(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 	public static void addRole(String roleName) {
121 		roles.put(roleName, new HashMap());
122 	}
123 	
124 	public static void removeRole(String roleName) {
125 		roles.remove(roleName);
126 	}
127 	
128 	public static Map getRole(String roleName) {
129 		return (Map)roles.get(roleName);
130 	}
131 	
132 	public static void addQualifiedRole(String roleName, String qualifiedRoleName) {
133 		getRole(roleName).put(qualifiedRoleName, new ArrayList());
134 	}
135 	
136 	public static void removeQualifiedRole(String roleName, String qualifiedRoleName) {
137 		getRole(roleName).remove(qualifiedRoleName);
138 	}
139 	
140 	public static void setRecipients(String roleName, String qualifiedRoleName, List recipients) {
141 		Map qualifiedRoles = getRole(roleName);
142 		qualifiedRoles.put(qualifiedRoleName, recipients);
143 	}
144 	
145 	public static List getRecipients(String roleName, String qualifiedRoleName) {
146 		Map qualifiedRoles = getRole(roleName);
147 		return (List)qualifiedRoles.get(qualifiedRoleName);
148 	}
149 
150 	public List<? extends RemotableAttributeErrorContract> validateClientRoutingData() {
151 		VALID_CLIENT_ROUTING_DATA_CALLED = true;
152 		List<RemotableAttributeError> errors = new ArrayList<RemotableAttributeError>();
153 		errors.add(RemotableAttributeError.Builder.create("key1", "value1").build());
154 		errors.add(RemotableAttributeError.Builder.create("key2", "value2").build());
155 		return errors;
156 	}
157 
158 }