View Javadoc

1   /*
2    * Copyright 2007-2009 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.apache.commons.lang.StringUtils;
19  import org.kuali.rice.kew.service.KEWServiceLocator;
20  import org.kuali.rice.kew.web.session.UserSession;
21  import org.kuali.rice.kim.bo.Person;
22  import org.kuali.rice.kim.bo.entity.KimEntityPrivacyPreferences;
23  import org.kuali.rice.kim.bo.entity.KimPrincipal;
24  import org.kuali.rice.kim.service.IdentityManagementService;
25  import org.kuali.rice.kim.service.KIMServiceLocator;
26  import org.kuali.rice.kim.service.PersonService;
27  import org.kuali.rice.kns.util.ObjectUtils;
28  
29  /**
30   * Provides some utility methods for translating user ID types.
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class UserUtils {
35  
36  	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UserUtils.class);
37  
38  	private static PersonService<Person> personService;
39  	private static IdentityManagementService identityManagementService;
40  	
41  	private static final String RESTRICTED_DATA_MASK = "xxxxxx";
42  	
43  	public static String getIdValue(String idType, Person user) {
44  	    if ("workflowId".equalsIgnoreCase(idType) || "w".equalsIgnoreCase(idType) || "principalId".equalsIgnoreCase(idType)) {
45  	      return user.getPrincipalId();
46  	    } else if ("authenticationId".equalsIgnoreCase(idType) || "a".equalsIgnoreCase(idType) || "principalName".equalsIgnoreCase(idType)) {
47  	      return user.getPrincipalName();
48  	    } else if ("emplId".equalsIgnoreCase(idType) || "e".equalsIgnoreCase(idType)) {
49  	      return user.getEmployeeId();
50  	    } else {
51  	      LOG.error("Could not determine ID Value for given id type!" + idType);
52  	    }
53  	    return null;
54  	  }
55  
56  	//public static String getDisplayableName(UserSession userSession, String principalId) {
57  	//	return getDisplayableName(userSession, KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId));
58  	//}
59  	
60  	/*
61       * @deprecated  Person getEmailName method accounts for privacy.
62       */
63      //@Deprecated
64  	//public static String getDisplayableName(UserSession userSession, KimPrincipal principal) {
65  	//	if (userSession != null && !userSession.getPrincipalId().equals(principal.getPrincipalId()) && isEntityNameRestricted(principal.getEntityId())) {
66  	//		return RESTRICTED_DATA_MASK;
67  	//	}
68  	//	Person person = getPersonService().getPerson(principal.getPrincipalId());
69  	//	return person.getName();
70  	//}
71  	
72  	public static String getTransposedName(UserSession userSession, KimPrincipal principal) {
73  		Person person = getPersonService().getPerson(principal.getPrincipalId());
74  		return person.getName(); //contructTransposedName(person);
75  	}
76  	
77  	//private static String contructTransposedName(Person person) {
78  	//	return person.getLastName() + (StringUtils.isNotBlank(person.getFirstName())?", " + person.getFirstName():"");
79  	//}
80  
81  	/*
82  	 * @deprecated  Person getEmailAddress method accounts for privacy.
83  	 */
84  	//@Deprecated
85  	//public static String getDisplayableEmailAddress(UserSession userSession, KimPrincipal principal) {
86  	//	if (userSession != null && !userSession.getPrincipalId().equals(principal.getPrincipalId()) && isEntityEmailRestricted(principal.getEntityId())) {
87  	//		return RESTRICTED_DATA_MASK;
88  	//	}
89  	//	Person person = getPersonService().getPerson(principal.getPrincipalId());
90  	//	return person.getEmailAddress();
91  	//}
92  	
93  	//public static boolean isEntityNameRestricted(String entityId) {
94  	//	KimEntityPrivacyPreferences privacy = getIdentityManagementService().getEntityPrivacyPreferences( entityId );
95  	//	if ( ObjectUtils.isNotNull(privacy) ) {
96  	//		return privacy.isSuppressName();
97  	//	}
98  	//	return false;
99  	//}
100 
101 	//public static boolean isEntityEmailRestricted(String entityId) {
102 	//	KimEntityPrivacyPreferences privacy = getIdentityManagementService().getEntityPrivacyPreferences( entityId );
103 	//	if (ObjectUtils.isNotNull(privacy) ) {
104 	//		return privacy.isSuppressEmail();
105 	//	}
106 	//	return false;
107 	//}
108 
109 	/**
110 	 * @return the personService
111 	 */
112 	public static PersonService<Person> getPersonService() {
113 		if ( personService == null ) {
114 			personService = KIMServiceLocator.getPersonService();
115 		}
116 		return personService;
117 	}
118 
119 	/**
120 	 * @return the identityManagementService
121 	 */
122 	public static IdentityManagementService getIdentityManagementService() {
123 		if ( identityManagementService == null ) {
124 			identityManagementService = KIMServiceLocator.getIdentityManagementService();
125 		}
126 		return identityManagementService;
127 	}
128 
129 }