001 /**
002 * Copyright 2005-2012 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.user;
017
018 import org.kuali.rice.kim.api.identity.Person;
019 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
020
021 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
022 import org.kuali.rice.kim.api.identity.PersonService;
023 import org.kuali.rice.krad.UserSession;
024
025 /**
026 * Provides some utility methods for translating user ID types.
027 *
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 */
030 public final class UserUtils {
031
032 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UserUtils.class);
033
034 private static PersonService personService;
035
036 private UserUtils() {
037 throw new UnsupportedOperationException("do not call");
038 }
039
040 public static String getIdValue(String idType, Person user) {
041 if ("workflowId".equalsIgnoreCase(idType) || "w".equalsIgnoreCase(idType) || "principalId".equalsIgnoreCase(idType)) {
042 return user.getPrincipalId();
043 } else if ("authenticationId".equalsIgnoreCase(idType) || "a".equalsIgnoreCase(idType) || "principalName".equalsIgnoreCase(idType)) {
044 return user.getPrincipalName();
045 } else if ("emplId".equalsIgnoreCase(idType) || "e".equalsIgnoreCase(idType)) {
046 return user.getEmployeeId();
047 } else {
048 LOG.error("Could not determine ID Value for given id type!" + idType);
049 }
050 return null;
051 }
052
053 public static String getIdValue(String idType, String principalId) {
054 if ("workflowId".equalsIgnoreCase(idType) || "w".equalsIgnoreCase(idType) || "principalId".equalsIgnoreCase(idType)) {
055 return principalId;
056 }
057 Person person = KimApiServiceLocator.getPersonService().getPerson(principalId);
058 return getIdValue(idType, person);
059 }
060
061 public static String getTransposedName(UserSession userSession, PrincipalContract principal) {
062 Person person = getPersonService().getPerson(principal.getPrincipalId());
063 return person.getName(); //contructTransposedName(person);
064 }
065
066 /**
067 * @return the personService
068 */
069 public static PersonService getPersonService() {
070 if ( personService == null ) {
071 personService = KimApiServiceLocator.getPersonService();
072 }
073 return personService;
074 }
075 }