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.actionrequest; 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.kew.api.identity.PrincipalName; 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 import org.kuali.rice.kew.rule.AbstractRoleAttribute; 029 import org.kuali.rice.kew.rule.ResolvedQualifiedRole; 030 031 public class RoleToRoleDelegationRole extends AbstractRoleAttribute { 032 033 034 private static final long serialVersionUID = 3881730393316239780L; 035 public static final String MAIN_ROLE = "MAIN"; 036 public static final String PRIMARY_DELEGATE_ROLE = "PRIMARY_DELEGATE"; 037 public static final String SECONDARY_DELEGATE_ROLE = "SECONDARY_DELEGATE"; 038 039 private static final List ROLE_NAMES = new ArrayList(); 040 static { 041 ROLE_NAMES.add(new RoleName(RoleToRoleDelegationRole.class.getName(), MAIN_ROLE, MAIN_ROLE)); 042 ROLE_NAMES.add(new RoleName(RoleToRoleDelegationRole.class.getName(), PRIMARY_DELEGATE_ROLE, PRIMARY_DELEGATE_ROLE)); 043 ROLE_NAMES.add(new RoleName(RoleToRoleDelegationRole.class.getName(), SECONDARY_DELEGATE_ROLE, SECONDARY_DELEGATE_ROLE)); 044 } 045 046 public static List MAIN_USERS = new ArrayList(); 047 static { 048 MAIN_USERS.add("ewestfal"); 049 } 050 051 public static Map PRIMARY_DELEGATES = new HashMap(); 052 static { 053 List primDelegates1 = new ArrayList(); 054 primDelegates1.add("jhopf"); 055 PRIMARY_DELEGATES.put("ewestfal", primDelegates1); 056 PRIMARY_DELEGATES.put("rkirkend", new ArrayList()); 057 } 058 059 public static Map SECONDARY_DELEGATES = new HashMap(); 060 static { 061 List secondaryDelegates1 = new ArrayList(); 062 secondaryDelegates1.add("jitrue"); 063 secondaryDelegates1.add("xqi"); 064 List secondaryDelegates2 = new ArrayList(); 065 secondaryDelegates2.add("jhopf"); 066 secondaryDelegates2.add("bmcgough"); 067 secondaryDelegates2.add("natjohns"); 068 SECONDARY_DELEGATES.put("ewestfal", secondaryDelegates1); 069 SECONDARY_DELEGATES.put("rkirkend", secondaryDelegates2); 070 } 071 072 public List getRoleNames() { 073 return ROLE_NAMES; 074 } 075 076 public List getQualifiedRoleNames(String roleName, 077 DocumentContent documentContent) { 078 List names = new ArrayList(); 079 if (MAIN_ROLE.equals(roleName)) { 080 names = new ArrayList(MAIN_USERS); 081 } else { 082 throw new IllegalArgumentException("Can't get qualified role names for role '" + roleName +"'"); 083 } 084 return names; 085 } 086 087 public ResolvedQualifiedRole resolveQualifiedRole(RouteContext routeContext, String roleName, String qualifiedRole) { 088 List userIds = new ArrayList(); 089 if (MAIN_ROLE.equals(roleName)) { 090 userIds = MAIN_USERS; 091 } else if (PRIMARY_DELEGATE_ROLE.equals(roleName)) { 092 userIds = new ArrayList((List)PRIMARY_DELEGATES.get(qualifiedRole)); 093 } else if (SECONDARY_DELEGATE_ROLE.equals(roleName)) { 094 userIds = new ArrayList((List)SECONDARY_DELEGATES.get(qualifiedRole)); 095 } else { 096 throw new IllegalArgumentException("Can't resolve qualified role for role '" + roleName +"'"); 097 } 098 List recipients = new ArrayList(); 099 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 }