001 /* 002 * Copyright 2005-2007 The Kuali Foundation 003 * 004 * 005 * Licensed under the Educational Community License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.opensource.org/licenses/ecl2.php 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.kuali.rice.kew.rule; 018 019 import java.util.ArrayList; 020 import java.util.HashMap; 021 import java.util.Iterator; 022 import java.util.List; 023 import java.util.Map; 024 025 import org.kuali.rice.kew.engine.RouteContext; 026 import org.kuali.rice.kew.routeheader.DocumentContent; 027 028 029 /** 030 * Another test attribute, this one doesn't implement {@link WorkflowAttributeXmlValidator} 031 * 032 * @author Kuali Rice Team (rice.collab@kuali.org) 033 */ 034 public class TestRuleAttributeDuex implements WorkflowAttribute, RoleAttribute { 035 036 private static final long serialVersionUID = 1L; 037 private static Map roles = new HashMap(); 038 private boolean required; 039 040 public boolean isMatch(DocumentContent documentContent, List ruleExtensions) { 041 return true; 042 } 043 044 public List getRoleNames() { 045 List roleNames = new ArrayList(); 046 for (Iterator iterator = roles.keySet().iterator(); iterator.hasNext();) { 047 String roleName = (String) iterator.next(); 048 roleNames.add(new Role(getClass(), roleName, roleName)); 049 } 050 return roleNames; 051 } 052 053 public List getRuleRows() { 054 return new ArrayList(); 055 } 056 057 public List getRoutingDataRows() { 058 return new ArrayList(); 059 } 060 061 public String getDocContent() { 062 return "<testRuleAttributeContent/>"; 063 } 064 065 public List getRuleExtensionValues() { 066 return new ArrayList(); 067 } 068 069 public List validateRoutingData(Map paramMap) { 070 return new ArrayList(); 071 } 072 073 public String getAttributeLabel(){ 074 return ""; 075 } 076 077 public List validateRuleData(Map paramMap) { 078 return new ArrayList(); 079 } 080 081 public void setRequired(boolean required) { 082 this.required = required; 083 } 084 085 public boolean isRequired() { 086 return required; 087 } 088 089 public List getQualifiedRoleNames(String roleName, DocumentContent documentContent) { 090 ArrayList qualifiedRoleNames = new ArrayList(); 091 Map qualifiedRoles = (Map)roles.get(roleName); 092 if (qualifiedRoles != null) { 093 qualifiedRoleNames.addAll(qualifiedRoles.keySet()); 094 } else { 095 throw new IllegalArgumentException("TestRuleAttribute does not support the given role " + roleName); 096 } 097 return qualifiedRoleNames; 098 } 099 100 public ResolvedQualifiedRole resolveQualifiedRole(RouteContext routeContext, String roleName, String qualifiedRole) { 101 ResolvedQualifiedRole resolved = new ResolvedQualifiedRole(); 102 Map qualifiedRoles = (Map)roles.get(roleName); 103 if (qualifiedRoles != null) { 104 List recipients = (List)qualifiedRoles.get(qualifiedRole); 105 if (recipients != null) { 106 resolved.setQualifiedRoleLabel(qualifiedRole); 107 resolved.setRecipients(recipients); 108 } else { 109 throw new IllegalArgumentException("TestRuleAttribute does not support the qualified role " + qualifiedRole); 110 } 111 } else { 112 throw new IllegalArgumentException("TestRuleAttribute does not support the given role " + roleName); 113 } 114 return resolved; 115 } 116 117 public static void addRole(String roleName) { 118 roles.put(roleName, new HashMap()); 119 } 120 121 public static void removeRole(String roleName) { 122 roles.remove(roleName); 123 } 124 125 public static Map getRole(String roleName) { 126 return (Map)roles.get(roleName); 127 } 128 129 public static void addQualifiedRole(String roleName, String qualifiedRoleName) { 130 getRole(roleName).put(qualifiedRoleName, new ArrayList()); 131 } 132 133 public static void removeQualifiedRole(String roleName, String qualifiedRoleName) { 134 getRole(roleName).remove(qualifiedRoleName); 135 } 136 137 public static void setRecipients(String roleName, String qualifiedRoleName, List recipients) { 138 Map qualifiedRoles = getRole(roleName); 139 qualifiedRoles.put(qualifiedRoleName, recipients); 140 } 141 142 public static List getRecipients(String roleName, String qualifiedRoleName) { 143 Map qualifiedRoles = getRole(roleName); 144 return (List)qualifiedRoles.get(qualifiedRoleName); 145 } 146 }