1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.syslunch.service;
17
18 import java.sql.Timestamp;
19
20 import org.kuali.hr.core.cache.CacheUtils;
21 import org.kuali.hr.time.service.base.TkServiceLocator;
22 import org.kuali.hr.time.syslunch.rule.SystemLunchRule;
23 import org.kuali.hr.time.util.TKUtils;
24 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
25 import org.kuali.rice.krad.service.KRADServiceLocator;
26
27 public class SystemLunchRuleMaintainableImpl extends KualiMaintainableImpl {
28
29
30
31 private static final long serialVersionUID = 1L;
32
33 @Override
34 public void saveBusinessObject() {
35 SystemLunchRule sysLunchRule = (SystemLunchRule)this.getBusinessObject();
36 if(sysLunchRule.getTkSystemLunchRuleId()!=null && sysLunchRule.isActive()){
37 SystemLunchRule oldSystemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(sysLunchRule.getTkSystemLunchRuleId());
38 if(sysLunchRule.getEffectiveDate().equals(oldSystemLunchRule.getEffectiveDate())){
39 sysLunchRule.setTimestamp(null);
40 } else{
41 if(oldSystemLunchRule!=null){
42 oldSystemLunchRule.setActive(false);
43
44 oldSystemLunchRule.setTimestamp(TKUtils.subtractOneSecondFromTimestamp(new Timestamp(System.currentTimeMillis())));
45 oldSystemLunchRule.setEffectiveDate(sysLunchRule.getEffectiveDate());
46 KRADServiceLocator.getBusinessObjectService().save(oldSystemLunchRule);
47 }
48 sysLunchRule.setTimestamp(new Timestamp(System.currentTimeMillis()));
49 sysLunchRule.setTkSystemLunchRuleId(null);
50 }
51 }
52
53 KRADServiceLocator.getBusinessObjectService().save(sysLunchRule);
54 CacheUtils.flushCache(SystemLunchRule.CACHE_NAME);
55 }
56 }