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.RemotableAttributeError;
025 import org.kuali.rice.kew.api.rule.RoleName;
026 import org.kuali.rice.kew.engine.RouteContext;
027 import org.kuali.rice.kew.routeheader.DocumentContent;
028
029
030 /**
031 * Another test attribute, this one doesn't implement {@link WorkflowAttributeXmlValidator}
032 *
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 */
035 public class TestRuleAttributeDuex implements WorkflowRuleAttribute, RoleAttribute {
036
037 private static final long serialVersionUID = 1L;
038 private static Map roles = new HashMap();
039 private boolean required;
040
041 public boolean isMatch(DocumentContent documentContent, List ruleExtensions) {
042 return true;
043 }
044
045 public List getRoleNames() {
046 List roleNames = new ArrayList();
047 for (Iterator iterator = roles.keySet().iterator(); iterator.hasNext();) {
048 String roleName = (String) iterator.next();
049 roleNames.add(new RoleName(getClass().getName(), roleName, roleName));
050 }
051 return roleNames;
052 }
053
054 public List getRuleRows() {
055 return new ArrayList();
056 }
057
058 public List getRoutingDataRows() {
059 return new ArrayList();
060 }
061
062 public String getDocContent() {
063 return "<testRuleAttributeContent/>";
064 }
065
066 public List getRuleExtensionValues() {
067 return new ArrayList();
068 }
069
070 public List validateRoutingData(Map paramMap) {
071 return new ArrayList();
072 }
073
074 public String getAttributeLabel(){
075 return "";
076 }
077
078 public List<RemotableAttributeError> validateRuleData(Map paramMap) {
079 return new ArrayList<RemotableAttributeError>();
080 }
081
082 public void setRequired(boolean required) {
083 this.required = required;
084 }
085
086 public boolean isRequired() {
087 return required;
088 }
089
090 public List getQualifiedRoleNames(String roleName, DocumentContent documentContent) {
091 ArrayList qualifiedRoleNames = new ArrayList();
092 Map qualifiedRoles = (Map)roles.get(roleName);
093 if (qualifiedRoles != null) {
094 qualifiedRoleNames.addAll(qualifiedRoles.keySet());
095 } else {
096 throw new IllegalArgumentException("TestRuleAttribute does not support the given role " + roleName);
097 }
098 return qualifiedRoleNames;
099 }
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 }