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 import java.util.List;
21
22 import org.kuali.hr.core.cache.CacheUtils;
23 import org.kuali.hr.time.HrBusinessObject;
24 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
25 import org.kuali.rice.krad.service.KRADServiceLocator;
26 import sun.util.LocaleServiceProviderPool;
27
28 public abstract class HrBusinessObjectMaintainableImpl extends KualiMaintainableImpl {
29 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HrBusinessObjectMaintainableImpl.class);
30
31
32
33 private static final long serialVersionUID = 1L;
34
35 @Override
36 public void saveBusinessObject() {
37 HrBusinessObject hrObj = (HrBusinessObject) this.getBusinessObject();
38 if(hrObj.getId()!=null){
39 HrBusinessObject oldHrObj = this.getObjectById(hrObj.getId());
40 if(oldHrObj!= null){
41
42 if(hrObj.getEffectiveDate().equals(oldHrObj.getEffectiveDate())){
43 oldHrObj.setActive(false);
44 oldHrObj.setTimestamp(TKUtils.subtractOneSecondFromTimestamp(new Timestamp(TKUtils.getCurrentDate().getTime())));
45 } else{
46
47 oldHrObj.setTimestamp(TKUtils.subtractOneSecondFromTimestamp(new Timestamp(TKUtils.getCurrentDate().getTime())));
48 oldHrObj.setEffectiveDate(hrObj.getEffectiveDate());
49 oldHrObj.setActive(false);
50 oldHrObj.setId(null);
51 }
52 KRADServiceLocator.getBusinessObjectService().save(oldHrObj);
53 }
54 }
55 hrObj.setTimestamp(new Timestamp(System.currentTimeMillis()));
56 hrObj.setId(null);
57
58 customSaveLogic(hrObj);
59 KRADServiceLocator.getBusinessObjectService().save(hrObj);
60
61
62 try {
63 List<String> cacheNames = (List<String>)hrObj.getClass().getDeclaredField("CACHE_FLUSH").get(hrObj);
64 CacheUtils.flushCaches(cacheNames);
65 } catch (NoSuchFieldException e) {
66 try {
67 String cacheName = (String)hrObj.getClass().getDeclaredField("CACHE_NAME").get(hrObj);
68 CacheUtils.flushCache(cacheName);
69 } catch (NoSuchFieldException ex) {
70
71 LOG.warn("No cache name found for object: " + hrObj.getClass().getName());
72 } catch (IllegalAccessException ex) {
73 LOG.warn("No cache name found for object: " + hrObj.getClass().getName());
74 }
75
76
77 } catch (IllegalAccessException e) {
78 LOG.warn("No caches found for object: " + hrObj.getClass().getName());
79 }
80 }
81
82 public abstract HrBusinessObject getObjectById(String id);
83 public void customSaveLogic(HrBusinessObject hrObj){};
84 }