001 /** 002 * Copyright 2004-2013 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.hr.time.principal.service; 017 018 import java.util.Map; 019 020 import org.apache.commons.lang.StringUtils; 021 import org.kuali.hr.core.KPMEConstants; 022 import org.kuali.hr.core.cache.CacheUtils; 023 import org.kuali.hr.time.HrBusinessObject; 024 import org.kuali.hr.time.principal.PrincipalHRAttributes; 025 import org.kuali.hr.time.service.base.TkServiceLocator; 026 import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl; 027 import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName; 028 import org.kuali.rice.kim.api.services.KimApiServiceLocator; 029 import org.kuali.rice.kns.document.MaintenanceDocument; 030 031 public class PrincipalHRAttributesMaintainableImpl extends HrBusinessObjectMaintainableImpl { 032 private static final long serialVersionUID = 1L; 033 034 @SuppressWarnings("rawtypes") 035 @Override 036 public Map populateBusinessObject(Map<String, String> fieldValues, 037 MaintenanceDocument maintenanceDocument, String methodToCall) { 038 if (fieldValues.containsKey("principalId") 039 && StringUtils.isNotEmpty(fieldValues.get("principalId"))) { 040 EntityNamePrincipalName p = KimApiServiceLocator.getIdentityService().getDefaultNamesForPrincipalId(fieldValues.get("principalId")); 041 if (p != null 042 && p.getDefaultName() != null) { 043 fieldValues.put("name", p.getDefaultName().getCompositeName()); 044 }else{ 045 fieldValues.put("name", ""); 046 } 047 } 048 return super.populateBusinessObject(fieldValues, maintenanceDocument, 049 methodToCall); 050 } 051 052 @Override 053 public void saveBusinessObject() { 054 super.saveBusinessObject(); 055 CacheUtils.flushCache(PrincipalHRAttributes.CACHE_NAME); 056 CacheUtils.flushCache(KPMEConstants.KPME_GLOBAL_CACHE_NAME); 057 } 058 059 @Override 060 public HrBusinessObject getObjectById(String id) { 061 return TkServiceLocator.getPrincipalHRAttributeService().getPrincipalHRAttributes(id); 062 } 063 064 065 }