1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.paystep.validation;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.kpme.core.api.paygrade.PayGrade;
20 import org.kuali.kpme.core.api.salarygroup.SalaryGroup;
21 import org.kuali.kpme.core.paystep.PayStepBo;
22 import org.kuali.kpme.core.service.HrServiceLocator;
23 import org.kuali.kpme.core.util.ValidationUtils;
24 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
25 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
26
27 @SuppressWarnings("deprecation")
28 public class PayStepValidation extends MaintenanceDocumentRuleBase {
29
30 @Override
31 protected boolean processCustomRouteDocumentBusinessRules(
32 MaintenanceDocument document) {
33 LOG.debug("entering custom validation for pay step");
34 boolean isValid = super.processCustomRouteDocumentBusinessRules(document);
35
36 PayStepBo payStep = (PayStepBo) this.getNewDataObject();
37
38 isValid &= validateSalaryGroup(payStep);
39 isValid &= validatePayGrade(payStep);
40 isValid &= validatePayGradeInSalaryGroup(payStep);
41
42 return isValid;
43 }
44
45 private boolean validatePayGrade(PayStepBo payStep) {
46 PayGrade aPayGrade = HrServiceLocator.getPayGradeService().getPayGrade(payStep.getPayGrade(), payStep.getSalaryGroup(), payStep.getEffectiveLocalDate());
47 String errorMes = "Pay Grade '" + payStep.getPayGrade() + "'";
48 if(aPayGrade == null) {
49 this.putFieldError("dataObject.payGrade", "error.existence", errorMes);
50 return false;
51 } else {
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 }
72 return true;
73 }
74
75 private boolean validateSalaryGroup(PayStepBo payStep) {
76 SalaryGroup aSalGroup = HrServiceLocator.getSalaryGroupService().getSalaryGroup(payStep.getSalaryGroup(), payStep.getEffectiveLocalDate());
77 String errorMes = "SalaryGroup '" + payStep.getSalaryGroup() + "'";
78 if(aSalGroup != null) {
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 } else {
100 this.putFieldError("dataObject.salaryGroup", "error.existence", errorMes);
101 return false;
102 }
103
104 return true;
105 }
106
107 private boolean validatePayGradeInSalaryGroup(PayStepBo payStep) {
108 if(StringUtils.isNotEmpty(payStep.getSalaryGroup())
109 && ValidationUtils.validatePayGradeWithSalaryGroup(payStep.getSalaryGroup(),payStep.getPayGrade(),payStep.getEffectiveLocalDate())) {
110 return true;
111 } else {
112 String[] params = new String[2];
113 params[0] = payStep.getPayGrade();
114 params[1] = payStep.getSalaryGroup();
115
116 this.putFieldError("dataObject.payGrade", "salaryGroup.contains.payGrade", params);
117 return false;
118 }
119 }
120 }