001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.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/ecl1.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 edu.iu.uis.eden.routetemplate;
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 edu.iu.uis.eden.engine.RouteContext;
026: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
027: import edu.iu.uis.eden.plugin.attributes.RoleAttribute;
028: import edu.iu.uis.eden.plugin.attributes.WorkflowAttribute;
029: import edu.iu.uis.eden.plugin.attributes.WorkflowAttributeXmlValidator;
030: import edu.iu.uis.eden.routeheader.DocumentContent;
031:
032: /**
033: * Another test attribute, this one doesn't implement {@link WorkflowAttributeXmlValidator}
034: *
035: * @author rkirkend
036: */
037: public class TestRuleAttributeDuex implements WorkflowAttribute,
038: RoleAttribute {
039:
040: private static final long serialVersionUID = 1L;
041: private static Map roles = new HashMap();
042: private boolean required;
043:
044: public boolean isMatch(DocumentContent documentContent,
045: List ruleExtensions) {
046: return true;
047: }
048:
049: public List getRoleNames() {
050: List roleNames = new ArrayList();
051: for (Iterator iterator = roles.keySet().iterator(); iterator
052: .hasNext();) {
053: String roleName = (String) iterator.next();
054: roleNames.add(new Role(getClass(), roleName, roleName));
055: }
056: return roleNames;
057: }
058:
059: public List getRuleRows() {
060: return new ArrayList();
061: }
062:
063: public List getRoutingDataRows() {
064: return new ArrayList();
065: }
066:
067: public String getDocContent() {
068: return "<testRuleAttributeContent/>";
069: }
070:
071: public List getRuleExtensionValues() {
072: return new ArrayList();
073: }
074:
075: public List validateRoutingData(Map paramMap) {
076: return new ArrayList();
077: }
078:
079: public String getAttributeLabel() {
080: return "";
081: }
082:
083: public List validateRuleData(Map paramMap) {
084: return new ArrayList();
085: }
086:
087: public void setRequired(boolean required) {
088: this .required = required;
089: }
090:
091: public boolean isRequired() {
092: return required;
093: }
094:
095: public List getQualifiedRoleNames(String roleName,
096: DocumentContent documentContent)
097: throws EdenUserNotFoundException {
098: ArrayList qualifiedRoleNames = new ArrayList();
099: Map qualifiedRoles = (Map) roles.get(roleName);
100: if (qualifiedRoles != null) {
101: qualifiedRoleNames.addAll(qualifiedRoles.keySet());
102: } else {
103: throw new IllegalArgumentException(
104: "TestRuleAttribute does not support the given role "
105: + roleName);
106: }
107: return qualifiedRoleNames;
108: }
109:
110: public ResolvedQualifiedRole resolveQualifiedRole(
111: RouteContext routeContext, String roleName,
112: String qualifiedRole) throws EdenUserNotFoundException {
113: ResolvedQualifiedRole resolved = new ResolvedQualifiedRole();
114: Map qualifiedRoles = (Map) roles.get(roleName);
115: if (qualifiedRoles != null) {
116: List recipients = (List) qualifiedRoles.get(qualifiedRole);
117: if (recipients != null) {
118: resolved.setQualifiedRoleLabel(qualifiedRole);
119: resolved.setRecipients(recipients);
120: } else {
121: throw new IllegalArgumentException(
122: "TestRuleAttribute does not support the qualified role "
123: + qualifiedRole);
124: }
125: } else {
126: throw new IllegalArgumentException(
127: "TestRuleAttribute does not support the given role "
128: + roleName);
129: }
130: return resolved;
131: }
132:
133: public static void addRole(String roleName) {
134: roles.put(roleName, new HashMap());
135: }
136:
137: public static void removeRole(String roleName) {
138: roles.remove(roleName);
139: }
140:
141: public static Map getRole(String roleName) {
142: return (Map) roles.get(roleName);
143: }
144:
145: public static void addQualifiedRole(String roleName,
146: String qualifiedRoleName) {
147: getRole(roleName).put(qualifiedRoleName, new ArrayList());
148: }
149:
150: public static void removeQualifiedRole(String roleName,
151: String qualifiedRoleName) {
152: getRole(roleName).remove(qualifiedRoleName);
153: }
154:
155: public static void setRecipients(String roleName,
156: String qualifiedRoleName, List recipients) {
157: Map qualifiedRoles = getRole(roleName);
158: qualifiedRoles.put(qualifiedRoleName, recipients);
159: }
160:
161: public static List getRecipients(String roleName,
162: String qualifiedRoleName) {
163: Map qualifiedRoles = getRole(roleName);
164: return (List) qualifiedRoles.get(qualifiedRoleName);
165: }
166: }
|