View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.actionrequest;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.Iterator;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.kuali.rice.kew.api.identity.PrincipalName;
25  import org.kuali.rice.kew.api.rule.RoleName;
26  import org.kuali.rice.kew.engine.RouteContext;
27  import org.kuali.rice.kew.routeheader.DocumentContent;
28  import org.kuali.rice.kew.rule.AbstractRoleAttribute;
29  import org.kuali.rice.kew.rule.ResolvedQualifiedRole;
30  
31  public class RoleToRoleDelegationRole extends AbstractRoleAttribute {
32  
33  
34  	private static final long serialVersionUID = 3881730393316239780L;
35  	public static final String MAIN_ROLE = "MAIN";
36  	public static final String PRIMARY_DELEGATE_ROLE = "PRIMARY_DELEGATE";
37  	public static final String SECONDARY_DELEGATE_ROLE = "SECONDARY_DELEGATE";
38  	
39  	private static final List ROLE_NAMES = new ArrayList();
40  	static {
41  		ROLE_NAMES.add(new RoleName(RoleToRoleDelegationRole.class.getName(), MAIN_ROLE, MAIN_ROLE));
42  		ROLE_NAMES.add(new RoleName(RoleToRoleDelegationRole.class.getName(), PRIMARY_DELEGATE_ROLE, PRIMARY_DELEGATE_ROLE));
43  		ROLE_NAMES.add(new RoleName(RoleToRoleDelegationRole.class.getName(), SECONDARY_DELEGATE_ROLE, SECONDARY_DELEGATE_ROLE));
44  	}
45  	
46  	public static List MAIN_USERS = new ArrayList();
47  	static {
48  		MAIN_USERS.add("ewestfal");
49  	}
50  	
51  	public static Map PRIMARY_DELEGATES = new HashMap();
52  	static {
53  		List primDelegates1 = new ArrayList();
54  		primDelegates1.add("jhopf");
55  		PRIMARY_DELEGATES.put("ewestfal", primDelegates1);
56  		PRIMARY_DELEGATES.put("rkirkend", new ArrayList());
57  	}
58  	
59  	public static Map SECONDARY_DELEGATES = new HashMap();
60  	static {
61  		List secondaryDelegates1 = new ArrayList();
62  		secondaryDelegates1.add("jitrue");
63  		secondaryDelegates1.add("xqi");
64  		List secondaryDelegates2 = new ArrayList();
65  		secondaryDelegates2.add("jhopf");
66  		secondaryDelegates2.add("bmcgough");
67  		secondaryDelegates2.add("natjohns");
68  		SECONDARY_DELEGATES.put("ewestfal", secondaryDelegates1);
69  		SECONDARY_DELEGATES.put("rkirkend", secondaryDelegates2);
70  	}
71  	
72  	public List getRoleNames() {
73  		return ROLE_NAMES;
74  	}
75  
76  	public List getQualifiedRoleNames(String roleName,
77  			DocumentContent documentContent) {
78  		List names = new ArrayList();
79  		if (MAIN_ROLE.equals(roleName)) {
80  			names = new ArrayList(MAIN_USERS);
81  		} else {
82  			throw new IllegalArgumentException("Can't get qualified role names for role '" + roleName +"'");
83  		}
84  		return names;
85  	}
86  
87  	public ResolvedQualifiedRole resolveQualifiedRole(RouteContext routeContext, String roleName, String qualifiedRole) {
88  		List userIds = new ArrayList();
89  		if (MAIN_ROLE.equals(roleName)) {
90  			userIds = MAIN_USERS;
91  		} else if (PRIMARY_DELEGATE_ROLE.equals(roleName)) {
92  			userIds = new ArrayList((List)PRIMARY_DELEGATES.get(qualifiedRole));
93  		} else if (SECONDARY_DELEGATE_ROLE.equals(roleName)) {
94  			userIds = new ArrayList((List)SECONDARY_DELEGATES.get(qualifiedRole));
95  		} else {
96  			throw new IllegalArgumentException("Can't resolve qualified role for role '" + roleName +"'");
97  		}
98  		List recipients = new ArrayList();
99  		for (Iterator iterator = userIds.iterator(); iterator.hasNext();) {
100 			String networkId = (String) iterator.next();
101 			recipients.add(new PrincipalName(networkId));
102 		}
103 		return new ResolvedQualifiedRole(roleName, recipients);
104 	}
105 
106 }