<commit_before>package org.kuali.rice.kew.user;

import org.kuali.rice.kew.service.KEWServiceLocator;
import org.kuali.rice.kew.web.session.UserSession;
import org.kuali.rice.kim.bo.Person;
import org.kuali.rice.kim.bo.entity.EntityPrivacyPreferences;
import org.kuali.rice.kim.bo.entity.KimEntity;
import org.kuali.rice.kim.bo.entity.KimPrincipal;
import org.kuali.rice.kim.service.KIMServiceLocator;

/**
 * Provides some utility methods for translating user ID types.
 *
 * @author K<NAME> (<EMAIL>)
 */
public class UserUtils {

	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UserUtils.class);

	private static final String RESTRICTED_DATA_MASK = "xxxxxx";
	
	public static String getIdValue(String idType, Person user) {
	    if ("workflowId".equalsIgnoreCase(idType) || "w".equalsIgnoreCase(idType) || "principalId".equalsIgnoreCase(idType)) {
	      return user.getPrincipalId();
	    } else if ("authenticationId".equalsIgnoreCase(idType) || "a".equalsIgnoreCase(idType) || "principalName".equalsIgnoreCase(idType)) {
	      return user.getPrincipalName();
	    } else if ("emplId".equalsIgnoreCase(idType) || "e".equalsIgnoreCase(idType)) {
	      return user.getEmployeeId();
	    } else {
	      LOG.error("Could not determine ID Value for given id type!" + idType);
	    }
	    return null;
	  }

	public static String getDisplayableName(UserSession userSession, String principalId) {
		return getDisplayableName(userSession, KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId));
	}
	
	public static String getDisplayableName(UserSession userSession, KimPrincipal principal) {
		if (userSession != null && userSession.getPrincipalId().equals(principal.getPrincipalId()) && isEntityNameRestricted(principal.getEntityId())) {
			return RESTRICTED_DATA_MASK;
		}
		Person person = KIMServiceLocator.getPersonService().getPerson(principal.getPrincipalId());
		return person.getName();
	}
	
	public static String getTransposedName(UserSession userSession, KimPrincipal principal) {
		if (userSession != null && userSession.getPrincipalId().equals(principal.getPrincipalId()) && isEntityNameRestricted(principal.getEntityId())) {
			return RESTRICTED_DATA_MASK;
		}
		Person person = KIMServiceLocator.getPersonService().getPerson(principal.getPrincipalId());
		return contructTransposedName(person);
	}
	
	private static String contructTransposedName(Person person) {
		return person.getLastName() + ", " + person.getFirstName();
	}

	public static String getDisplayableEmailAddress(UserSession userSession, KimPrincipal principal) {
		if (userSession != null && userSession.getPrincipalId().equals(principal.getPrincipalId()) && isEntityEmailRestricted(principal.getEntityId())) {
			return RESTRICTED_DATA_MASK;
		}
		Person person = KIMServiceLocator.getPersonService().getPerson(principal.getPrincipalId());
		return person.getEmailAddress();
	}
	
	public static boolean isEntityNameRestricted(String entityId) {
		KimEntity entity = KIMServiceLocator.getIdentityManagementService().getEntity(entityId);
		EntityPrivacyPreferences privacy = entity.getPrivacyPreferences();
		if (privacy != null) {
			return entity.getPrivacyPreferences().isSuppressName();
		}
		return false;
	}

	public static boolean isEntityEmailRestricted(String entityId) {
		KimEntity entity = KIMServiceLocator.getIdentityManagementService().getEntity(entityId);
		EntityPrivacyPreferences privacy = entity.getPrivacyPreferences();
		if (privacy != null) {
			return entity.getPrivacyPreferences().isSuppressEmail();
		}
		return false;
	}

}
<commit_msg>KULRICE-2572 : fixed isSuppressName error caused by OJB proxy change<commit_after>package org.kuali.rice.kew.user;

import org.kuali.rice.kew.service.KEWServiceLocator;
import org.kuali.rice.kew.web.session.UserSession;
import org.kuali.rice.kim.bo.Person;
import org.kuali.rice.kim.bo.entity.EntityPrivacyPreferences;
import org.kuali.rice.kim.bo.entity.KimEntity;
import org.kuali.rice.kim.bo.entity.KimPrincipal;
import org.kuali.rice.kim.service.IdentityManagementService;
import org.kuali.rice.kim.service.KIMServiceLocator;
import org.kuali.rice.kim.service.PersonService;
import org.kuali.rice.kns.util.ObjectUtils;

/**
 * Provides some utility methods for translating user ID types.
 *
 * @author <NAME> (<EMAIL>)
 */
public class UserUtils {

	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UserUtils.class);

	private static PersonService personService;
	private static IdentityManagementService identityManagementService;
	
	private static final String RESTRICTED_DATA_MASK = "xxxxxx";
	
	public static String getIdValue(String idType, Person user) {
	    if ("workflowId".equalsIgnoreCase(idType) || "w".equalsIgnoreCase(idType) || "principalId".equalsIgnoreCase(idType)) {
	      return user.getPrincipalId();
	    } else if ("authenticationId".equalsIgnoreCase(idType) || "a".equalsIgnoreCase(idType) || "principalName".equalsIgnoreCase(idType)) {
	      return user.getPrincipalName();
	    } else if ("emplId".equalsIgnoreCase(idType) || "e".equalsIgnoreCase(idType)) {
	      return user.getEmployeeId();
	    } else {
	      LOG.error("Could not determine ID Value for given id type!" + idType);
	    }
	    return null;
	  }

	public static String getDisplayableName(UserSession userSession, String principalId) {
		return getDisplayableName(userSession, KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId));
	}
	
	public static String getDisplayableName(UserSession userSession, KimPrincipal principal) {
		if (userSession != null && userSession.getPrincipalId().equals(principal.getPrincipalId()) && isEntityNameRestricted(principal.getEntityId())) {
			return RESTRICTED_DATA_MASK;
		}
		Person person = getPersonService().getPerson(principal.getPrincipalId());
		return person.getName();
	}
	
	public static String getTransposedName(UserSession userSession, KimPrincipal principal) {
		if (userSession != null && userSession.getPrincipalId().equals(principal.getPrincipalId()) && isEntityNameRestricted(principal.getEntityId())) {
			return RESTRICTED_DATA_MASK;
		}
		Person person = getPersonService().getPerson(principal.getPrincipalId());
		return contructTransposedName(person);
	}
	
	private static String contructTransposedName(Person person) {
		return person.getLastName() + ", " + person.getFirstName();
	}

	public static String getDisplayableEmailAddress(UserSession userSession, KimPrincipal principal) {
		if (userSession != null && userSession.getPrincipalId().equals(principal.getPrincipalId()) && isEntityEmailRestricted(principal.getEntityId())) {
			return RESTRICTED_DATA_MASK;
		}
		Person person = getPersonService().getPerson(principal.getPrincipalId());
		return person.getEmailAddress();
	}
	
	public static boolean isEntityNameRestricted(String entityId) {
		KimEntity entity = getIdentityManagementService().getEntity(entityId);
		EntityPrivacyPreferences privacy = entity.getPrivacyPreferences();
		if ( ObjectUtils.isNotNull(privacy) ) {
			return privacy.isSuppressName();
		}
		return false;
	}

	public static boolean isEntityEmailRestricted(String entityId) {
		KimEntity entity = getIdentityManagementService().getEntity(entityId);
		EntityPrivacyPreferences privacy = entity.getPrivacyPreferences();
		if (ObjectUtils.isNotNull(privacy) ) {
			return privacy.isSuppressEmail();
		}
		return false;
	}

	/**
	 * @return the personService
	 */
	public static PersonService getPersonService() {
		if ( personService == null ) {
			personService = KIMServiceLocator.getPersonService();
		}
		return personService;
	}

	/**
	 * @return the identityManagementService
	 */
	public static IdentityManagementService getIdentityManagementService() {
		if ( identityManagementService == null ) {
			identityManagementService = KIMServiceLocator.getIdentityManagementService();
		}
		return identityManagementService;
	}

}

{'fraction_non_alphanumeric': 0.10962533114671376, 'fraction_numerical': 0.0010092090324208402, 'mean_word_length': 5.673400673400673, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7317931', 'n_tokens_mistral': 2485, 'n_tokens_neox': 2280, 'n_words': 434}