001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.rule;
017
018 import java.util.ArrayList;
019 import java.util.HashMap;
020 import java.util.Iterator;
021 import java.util.List;
022 import java.util.Map;
023
024 import org.kuali.rice.core.api.uif.RemotableAttributeErrorContract;
025 import org.kuali.rice.core.api.uif.RemotableAttributeError;
026 import org.kuali.rice.kew.api.rule.RoleName;
027 import org.kuali.rice.kew.engine.RouteContext;
028 import org.kuali.rice.kew.routeheader.DocumentContent;
029
030
031 /**
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034 public class TestRuleAttributeThree implements WorkflowRuleAttribute, RoleAttribute, WorkflowAttributeXmlValidator {
035
036 private static final long serialVersionUID = -3502848534548531114L;
037
038 public static boolean VALID_CLIENT_ROUTING_DATA_CALLED = false;
039
040 private static Map roles = new HashMap();
041 private boolean required;
042
043 public boolean isMatch(DocumentContent documentContent, List ruleExtensions) {
044 return true;
045 }
046
047 public List getRoleNames() {
048 List roleNames = new ArrayList();
049 for (Iterator iterator = roles.keySet().iterator(); iterator.hasNext();) {
050 String roleName = (String) iterator.next();
051 roleNames.add(new RoleName(getClass().getName(), roleName, roleName));
052 }
053 return roleNames;
054 }
055
056 public List getRuleRows() {
057 return new ArrayList();
058 }
059
060 public List getRoutingDataRows() {
061 return new ArrayList();
062 }
063
064 public String getDocContent() {
065 return "<testRuleAttributeContent/>";
066 }
067
068 public List getRuleExtensionValues() {
069 return new ArrayList();
070 }
071
072 public List validateRoutingData(Map paramMap) {
073 return new ArrayList();
074 }
075
076 public String getAttributeLabel(){
077 return "";
078 }
079
080 public List validateRuleData(Map paramMap) {
081 return new ArrayList();
082 }
083
084 public void setRequired(boolean required) {
085 this.required = required;
086 }
087
088 public boolean isRequired() {
089 return required;
090 }
091
092 public List getQualifiedRoleNames(String roleName, DocumentContent documentContent) {
093 ArrayList qualifiedRoleNames = new ArrayList();
094 Map qualifiedRoles = (Map)roles.get(roleName);
095 if (qualifiedRoles != null) {
096 qualifiedRoleNames.addAll(qualifiedRoles.keySet());
097 } else {
098 throw new IllegalArgumentException("TestRuleAttribute does not support the given role " + roleName);
099 }
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 }