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.user;
17  
18  import org.kuali.rice.kim.api.identity.Person;
19  import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
20  
21  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22  import org.kuali.rice.kim.api.identity.PersonService;
23  import org.kuali.rice.krad.UserSession;
24  
25  /**
26   * Provides some utility methods for translating user ID types.
27   *
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public final class UserUtils {
31  
32  	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UserUtils.class);
33  
34  	private static PersonService personService;
35  	
36  	private UserUtils() {
37  		throw new UnsupportedOperationException("do not call");
38  	}
39  	
40  	public static String getIdValue(String idType, Person user) {
41  	    if ("workflowId".equalsIgnoreCase(idType) || "w".equalsIgnoreCase(idType) || "principalId".equalsIgnoreCase(idType)) {
42  	      return user.getPrincipalId();
43  	    } else if ("authenticationId".equalsIgnoreCase(idType) || "a".equalsIgnoreCase(idType) || "principalName".equalsIgnoreCase(idType)) {
44  	      return user.getPrincipalName();
45  	    } else if ("emplId".equalsIgnoreCase(idType) || "e".equalsIgnoreCase(idType)) {
46  	      return user.getEmployeeId();
47  	    } else {
48  	      LOG.error("Could not determine ID Value for given id type!" + idType);
49  	    }
50  	    return null;
51  	  }
52  
53      public static String getIdValue(String idType, String principalId) {
54          if ("workflowId".equalsIgnoreCase(idType) || "w".equalsIgnoreCase(idType) || "principalId".equalsIgnoreCase(idType)) {
55              return principalId;
56          }
57          Person person = KimApiServiceLocator.getPersonService().getPerson(principalId);
58          return getIdValue(idType, person);
59      }
60  	
61  	public static String getTransposedName(UserSession userSession, PrincipalContract principal) {
62  		Person person = getPersonService().getPerson(principal.getPrincipalId());
63  		return person.getName(); //contructTransposedName(person);
64  	}
65  
66  	/**
67  	 * @return the personService
68  	 */
69  	public static PersonService getPersonService() {
70  		if ( personService == null ) {
71  			personService = KimApiServiceLocator.getPersonService();
72  		}
73  		return personService;
74  	}
75  }