View Javadoc

1   /**
2    * Copyright 2004-2013 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.hr.time.principal.service;
17  
18  import java.util.Map;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.hr.core.cache.CacheUtils;
22  import org.kuali.hr.time.HrBusinessObject;
23  import org.kuali.hr.time.principal.PrincipalHRAttributes;
24  import org.kuali.hr.time.service.base.TkServiceLocator;
25  import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl;
26  import org.kuali.rice.kim.api.identity.Person;
27  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
28  import org.kuali.rice.kns.document.MaintenanceDocument;
29  
30  public class PrincipalHRAttributesMaintainableImpl extends HrBusinessObjectMaintainableImpl {
31  	private static final long serialVersionUID = 1L;
32  
33  	@SuppressWarnings("rawtypes")
34  	@Override
35  	public Map populateBusinessObject(Map<String, String> fieldValues,
36  			MaintenanceDocument maintenanceDocument, String methodToCall) {
37  		if (fieldValues.containsKey("principalId")
38  				&& StringUtils.isNotEmpty(fieldValues.get("principalId"))) {
39  			Person p = KimApiServiceLocator.getPersonService().getPerson(
40  					fieldValues.get("principalId"));
41  			if (p != null) {
42  				fieldValues.put("name", p.getName());
43  			}else{
44  				fieldValues.put("name", "");
45  			}
46  		}
47  		return super.populateBusinessObject(fieldValues, maintenanceDocument,
48  				methodToCall);
49  	}
50  
51  	@Override
52  	public void saveBusinessObject() {
53  		super.saveBusinessObject();
54  		CacheUtils.flushCache(PrincipalHRAttributes.CACHE_NAME);
55  	}
56  
57  	@Override
58  	public HrBusinessObject getObjectById(String id) {
59  		return TkServiceLocator.getPrincipalHRAttributeService().getPrincipalHRAttributes(id);
60  	}
61  	
62  	
63  }