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