001/**
002 * Copyright 2005-2016 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 */
016package org.kuali.rice.kew.routeheader;
017
018import org.kuali.rice.kew.api.KewApiConstants;
019import org.kuali.rice.kew.api.preferences.Preferences;
020import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
021import org.kuali.rice.kim.api.services.KimApiServiceLocator;
022
023import javax.persistence.MappedSuperclass;
024import javax.persistence.Transient;
025
026
027/**
028 * An extension of {@link DocumentRouteHeaderValue} which is mapped to OJB to help
029 * with optimization of the loading of a user's Action List.
030 *
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 */
033//@Entity
034//@Table(name="KREW_DOC_HDR_T")
035@MappedSuperclass
036public class DocumentRouteHeaderValueActionListExtension extends DocumentRouteHeaderValue {
037
038        private static final long serialVersionUID = 8458532812557846684L;
039
040    @Transient
041        private String initiatorName = "";
042    @Transient
043    private boolean isInitiatorNameInitialized = false;
044
045    public void initialize(Preferences preferences) {
046        if (KewApiConstants.PREFERENCES_YES_VAL.equals(preferences.getShowInitiator())) {
047            initializeInitiatorName();
048        }
049    }
050
051    public String getInitiatorName() {
052        initializeInitiatorName();
053        return initiatorName;
054    }
055
056    /**
057     * Fetches the initiator name, masked appropriately if restricted.
058     */
059    private void initializeInitiatorName() {
060        if (!isInitiatorNameInitialized) {
061            EntityNamePrincipalName name = KimApiServiceLocator.getIdentityService().getDefaultNamesForPrincipalId(getInitiatorPrincipalId());
062            if (name != null) {
063                this.initiatorName = name.getDefaultName().getCompositeName();
064            }
065            isInitiatorNameInitialized = true;
066        }
067    }
068
069}
070