View Javadoc

1   /**
2    * Copyright 2004-2012 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.principal.PrincipalHRAttributes;
23  import org.kuali.rice.kim.api.identity.Person;
24  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
25  import org.kuali.rice.kns.document.MaintenanceDocument;
26  import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
27  import org.kuali.rice.krad.service.KRADServiceLocator;
28  
29  public class PrincipalHRAttributesMaintainableImpl extends KualiMaintainableImpl {
30  	private static final long serialVersionUID = 1L;
31  
32  	@SuppressWarnings("rawtypes")
33  	@Override
34  	public Map populateBusinessObject(Map<String, String> fieldValues,
35  			MaintenanceDocument maintenanceDocument, String methodToCall) {
36  		if (fieldValues.containsKey("principalId")
37  				&& StringUtils.isNotEmpty(fieldValues.get("principalId"))) {
38  			Person p = KimApiServiceLocator.getPersonService().getPerson(
39  					fieldValues.get("principalId"));
40  			if (p != null) {
41  				fieldValues.put("name", p.getName());
42  			}else{
43  				fieldValues.put("name", "");
44  			}
45  		}
46  		return super.populateBusinessObject(fieldValues, maintenanceDocument,
47  				methodToCall);
48  	}
49  
50  	@Override
51  	public void saveBusinessObject() {
52  		PrincipalHRAttributes principalHRAttr = (PrincipalHRAttributes) this.getBusinessObject();
53  		principalHRAttr.setTimestamp(null);
54  		KRADServiceLocator.getBusinessObjectService().save(principalHRAttr);
55          CacheUtils.flushCache(PrincipalHRAttributes.CACHE_NAME);
56  	}
57  	
58  	
59  }