1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.earncode.validation;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.hr.time.earncode.EarnCode;
20 import org.kuali.hr.time.service.base.TkServiceLocator;
21 import org.kuali.hr.time.timeblock.TimeBlock;
22 import org.kuali.hr.time.util.TkConstants;
23 import org.kuali.hr.time.util.ValidationUtils;
24 import org.kuali.rice.kns.document.MaintenanceDocument;
25 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
26
27 import java.math.BigDecimal;
28 import java.sql.Date;
29 import java.util.List;
30
31 public class EarnCodeValidation extends MaintenanceDocumentRuleBase{
32
33 @Override
34 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
35 EarnCode earnCode = (EarnCode)this.getNewBo();
36 EarnCode oldEarnCode = (EarnCode)this.getOldBo();
37 if ((StringUtils.equals(oldEarnCode.getEarnCode(), TkConstants.LUNCH_EARN_CODE)
38 || StringUtils.equals(oldEarnCode.getEarnCode(), TkConstants.HOLIDAY_EARN_CODE))
39 && !earnCode.isActive()) {
40 this.putFieldError("active", "earncode.inactivate.locked", earnCode
41 .getEarnCode());
42 }
43
44 if (earnCode.getHrEarnCodeId() == null) {
45 if (ValidationUtils.validateEarnCode(earnCode.getEarnCode(), null)) {
46
47
48 this.putFieldError("earnCode", "earncode.earncode.unique");
49 return false;
50 }
51 }
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 if(StringUtils.isNotEmpty(earnCode.getAccrualCategory())){
74 if (!ValidationUtils.validateAccrualCategory(earnCode.getAccrualCategory(), earnCode.getEffectiveDate())) {
75 this.putFieldError("accrualCategory", "earncode.accrualCategory.invalid", earnCode.getAccrualCategory());
76 return false;
77 }
78 }
79
80
81 int count = TkServiceLocator.getEarnCodeService().getNewerEarnCodeCount(earnCode.getEarnCode(), earnCode.getEffectiveDate());
82 if(count > 0) {
83 this.putFieldError("effectiveDate", "earncode.effectiveDate.newer.exists");
84 return false;
85 }
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 List<TimeBlock> latestEndTimestampTimeBlocks = TkServiceLocator.getTimeBlockService().getLatestEndTimestamp();
107
108 if ( !earnCode.isActive() && earnCode.getEffectiveDate().before(latestEndTimestampTimeBlocks.get(0).getEndDate()) ){
109 List<TimeBlock> activeTimeBlocks = TkServiceLocator.getTimeBlockService().getTimeBlocksWithEarnCode(earnCode.getEarnCode(), earnCode.getEffectiveDate());
110 if(activeTimeBlocks != null && !activeTimeBlocks.isEmpty()) {
111 this.putFieldError("earnCode", "earncode.earncode.inactivate", earnCode.getEarnCode());
112 return false;
113 }
114 }
115
116 return true;
117 }
118
119 }