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