1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.hr.time.util;
17  
18  import java.lang.reflect.Field;
19  import java.sql.Timestamp;
20  
21  import org.kuali.hr.core.cache.CacheUtils;
22  import org.kuali.hr.time.HrBusinessObject;
23  import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
24  import org.kuali.rice.krad.service.KRADServiceLocator;
25  import sun.util.LocaleServiceProviderPool;
26  
27  public abstract class HrBusinessObjectMaintainableImpl extends KualiMaintainableImpl {
28      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HrBusinessObjectMaintainableImpl.class);
29  	
30  
31  
32  	private static final long serialVersionUID = 1L;
33  
34  	@Override
35  	public void saveBusinessObject() {
36  		HrBusinessObject hrObj = (HrBusinessObject) this.getBusinessObject();
37  		if(hrObj.getId()!=null){
38  			HrBusinessObject oldHrObj = this.getObjectById(hrObj.getId());
39  			if(oldHrObj!= null){
40  				
41  				if(hrObj.getEffectiveDate().equals(oldHrObj.getEffectiveDate())){
42  					oldHrObj.setActive(false);
43  					oldHrObj.setTimestamp(TKUtils.subtractOneSecondFromTimestamp(new Timestamp(TKUtils.getCurrentDate().getTime()))); 
44  				} else{
45  					
46  					oldHrObj.setTimestamp(TKUtils.subtractOneSecondFromTimestamp(new Timestamp(TKUtils.getCurrentDate().getTime())));
47  					oldHrObj.setEffectiveDate(hrObj.getEffectiveDate());
48  					oldHrObj.setActive(false);
49  					oldHrObj.setId(null);
50  				}
51  				KRADServiceLocator.getBusinessObjectService().save(oldHrObj);
52  			}
53  		}
54  		hrObj.setTimestamp(new Timestamp(System.currentTimeMillis()));
55  		hrObj.setId(null);
56  		
57  		customSaveLogic(hrObj);
58  		KRADServiceLocator.getBusinessObjectService().save(hrObj);
59  
60          
61          try {
62              String cacheName = (String)hrObj.getClass().getDeclaredField("CACHE_NAME").get(hrObj);
63              CacheUtils.flushCache(cacheName);
64          } catch (NoSuchFieldException e) {
65              
66              LOG.warn("No cache name found for object: " + hrObj.getClass().getName());
67          } catch (IllegalAccessException e) {
68              LOG.warn("No cache name found for object: " + hrObj.getClass().getName());
69          }
70      }
71  	
72  	public abstract HrBusinessObject getObjectById(String id);
73  	public void customSaveLogic(HrBusinessObject hrObj){};
74  }