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: * @author ewestfal
034: */
035: public class TestRuleAttributeThree implements WorkflowAttribute,
036: RoleAttribute, WorkflowAttributeXmlValidator {
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,
044: List ruleExtensions) {
045: return true;
046: }
047:
048: public List getRoleNames() {
049: List roleNames = new ArrayList();
050: for (Iterator iterator = roles.keySet().iterator(); iterator
051: .hasNext();) {
052: String roleName = (String) iterator.next();
053: roleNames.add(new Role(getClass(), roleName, roleName));
054: }
055: return roleNames;
056: }
057:
058: public List getRuleRows() {
059: return new ArrayList();
060: }
061:
062: public List getRoutingDataRows() {
063: return new ArrayList();
064: }
065:
066: public String getDocContent() {
067: return "<testRuleAttributeContent/>";
068: }
069:
070: public List getRuleExtensionValues() {
071: return new ArrayList();
072: }
073:
074: public List validateRoutingData(Map paramMap) {
075: return new ArrayList();
076: }
077:
078: public String getAttributeLabel() {
079: return "";
080: }
081:
082: public List validateRuleData(Map paramMap) {
083: return new ArrayList();
084: }
085:
086: public void setRequired(boolean required) {
087: this .required = required;
088: }
089:
090: public boolean isRequired() {
091: return required;
092: }
093:
094: public List getQualifiedRoleNames(String roleName,
095: DocumentContent documentContent)
096: throws EdenUserNotFoundException {
097: ArrayList qualifiedRoleNames = new ArrayList();
098: Map qualifiedRoles = (Map) roles.get(roleName);
099: if (qualifiedRoles != null) {
100: qualifiedRoleNames.addAll(qualifiedRoles.keySet());
101: } else {
102: throw new IllegalArgumentException(
103: "TestRuleAttribute does not support the given role "
104: + roleName);
105: }
106: return qualifiedRoleNames;
107: }
108:
109: public ResolvedQualifiedRole resolveQualifiedRole(
110: RouteContext routeContext, String roleName,
111: String qualifiedRole) throws EdenUserNotFoundException {
112: ResolvedQualifiedRole resolved = new ResolvedQualifiedRole();
113: Map qualifiedRoles = (Map) roles.get(roleName);
114: if (qualifiedRoles != null) {
115: List recipients = (List) qualifiedRoles.get(qualifiedRole);
116: if (recipients != null) {
117: resolved.setQualifiedRoleLabel(qualifiedRole);
118: resolved.setRecipients(recipients);
119: } else {
120: throw new IllegalArgumentException(
121: "TestRuleAttribute does not support the qualified role "
122: + qualifiedRole);
123: }
124: } else {
125: throw new IllegalArgumentException(
126: "TestRuleAttribute does not support the given role "
127: + roleName);
128: }
129: return resolved;
130: }
131:
132: public static void addRole(String roleName) {
133: roles.put(roleName, new HashMap());
134: }
135:
136: public static void removeRole(String roleName) {
137: roles.remove(roleName);
138: }
139:
140: public static Map getRole(String roleName) {
141: return (Map) roles.get(roleName);
142: }
143:
144: public static void addQualifiedRole(String roleName,
145: String qualifiedRoleName) {
146: getRole(roleName).put(qualifiedRoleName, new ArrayList());
147: }
148:
149: public static void removeQualifiedRole(String roleName,
150: String qualifiedRoleName) {
151: getRole(roleName).remove(qualifiedRoleName);
152: }
153:
154: public static void setRecipients(String roleName,
155: String qualifiedRoleName, List recipients) {
156: Map qualifiedRoles = getRole(roleName);
157: qualifiedRoles.put(qualifiedRoleName, recipients);
158: }
159:
160: public static List getRecipients(String roleName,
161: String qualifiedRoleName) {
162: Map qualifiedRoles = getRole(roleName);
163: return (List) qualifiedRoles.get(qualifiedRoleName);
164: }
165:
166: public List<WorkflowAttributeValidationError> validateClientRoutingData() {
167: VALID_CLIENT_ROUTING_DATA_CALLED = true;
168: List<WorkflowAttributeValidationError> errors = new ArrayList<WorkflowAttributeValidationError>();
169: errors.add(new WorkflowAttributeValidationError("key1",
170: "value1"));
171: errors.add(new WorkflowAttributeValidationError("key2",
172: "value2"));
173: return errors;
174: }
175:
176: }
|