1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.timecollection.rule.service;
17
18 import java.sql.Timestamp;
19 import java.util.Map;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.hr.core.cache.CacheUtils;
23 import org.kuali.hr.time.collection.rule.TimeCollectionRule;
24 import org.kuali.hr.time.service.base.TkServiceLocator;
25 import org.kuali.hr.time.util.TKUtils;
26 import org.kuali.rice.kns.document.MaintenanceDocument;
27 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
28 import org.kuali.rice.krad.service.KRADServiceLocator;
29 import org.kuali.rice.krad.util.GlobalVariables;
30
31 public class TimeCollectionRuleMaintainableImpl extends KualiMaintainableImpl {
32
33
34
35 private static final long serialVersionUID = 1L;
36
37 @Override
38 public void processAfterNew(MaintenanceDocument document, Map<String, String[]> parameters) {
39 super.processAfterNew(document, parameters);
40 }
41
42 @Override
43 public void processAfterPost(MaintenanceDocument document, Map<String, String[]> parameters) {
44 TimeCollectionRule timeCollectionRule = (TimeCollectionRule) document.getNewMaintainableObject().getBusinessObject();
45 timeCollectionRule.setUserPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
46 super.processAfterPost(document, parameters);
47 }
48
49 @Override
50 public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> parameters) {
51 TimeCollectionRule timeCollectionRule = (TimeCollectionRule) document.getNewMaintainableObject().getBusinessObject();
52 timeCollectionRule.setUserPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
53 super.processAfterEdit(document, parameters);
54 }
55
56 @Override
57 public void saveBusinessObject() {
58 TimeCollectionRule timeCollectionRule = (TimeCollectionRule) this.getBusinessObject();
59
60
61 if(timeCollectionRule.getTkTimeCollectionRuleId()!=null && timeCollectionRule.isActive()){
62 TimeCollectionRule oldTimeCollectRule = TkServiceLocator.getTimeCollectionRuleService().getTimeCollectionRule(timeCollectionRule.getTkTimeCollectionRuleId());
63 if(timeCollectionRule.getEffectiveDate().equals(oldTimeCollectRule.getEffectiveDate())){
64 timeCollectionRule.setTimestamp(null);
65 } else{
66 if(oldTimeCollectRule!=null){
67 oldTimeCollectRule.setActive(false);
68
69 oldTimeCollectRule.setTimestamp(TKUtils.subtractOneSecondFromTimestamp(new Timestamp(System.currentTimeMillis())));
70 oldTimeCollectRule.setEffectiveDate(timeCollectionRule.getEffectiveDate());
71 KRADServiceLocator.getBusinessObjectService().save(oldTimeCollectRule);
72 }
73 timeCollectionRule.setTimestamp(new Timestamp(System.currentTimeMillis()));
74 timeCollectionRule.setTkTimeCollectionRuleId(null);
75 }
76 }
77
78 KRADServiceLocator.getBusinessObjectService().save(timeCollectionRule);
79 CacheUtils.flushCache(TimeCollectionRule.CACHE_NAME);
80 }
81
82
83 @Override
84 public Map populateBusinessObject(Map<String, String> fieldValues, MaintenanceDocument maintenanceDocument, String methodToCall) {
85 if (fieldValues.containsKey("workArea") && StringUtils.equals(fieldValues.get("workArea"), "%")) {
86 fieldValues.put("workArea", "-1");
87 }
88 if (fieldValues.containsKey("jobNumber") && StringUtils.equals(fieldValues.get("jobNumber"), "%")) {
89 fieldValues.put("jobNumber", "-1");
90 }
91 return super.populateBusinessObject(fieldValues, maintenanceDocument, methodToCall);
92 }
93 }