1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.rules.shiftdifferential.validation;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.kpme.core.util.HrConstants;
20 import org.kuali.kpme.core.util.ValidationUtils;
21 import org.kuali.kpme.tklm.time.rules.shiftdifferential.ShiftDifferentialRule;
22 import org.kuali.rice.kns.document.MaintenanceDocument;
23 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
24 import org.kuali.rice.krad.bo.PersistableBusinessObject;
25 import org.kuali.rice.krad.util.GlobalVariables;
26
27 public class ShiftDifferentialRuleRule extends MaintenanceDocumentRuleBase {
28
29 boolean validateSalGroup(ShiftDifferentialRule shiftDifferentialRule) {
30 if (shiftDifferentialRule.getHrSalGroup() != null
31 && !StringUtils.equals(shiftDifferentialRule.getHrSalGroup(),
32 HrConstants.WILDCARD_CHARACTER)
33 && !ValidationUtils.validateSalGroup(shiftDifferentialRule
34 .getHrSalGroup(), shiftDifferentialRule
35 .getEffectiveLocalDate())) {
36 this.putFieldError("hrSalGroup", "error.existence", "Salgroup '"
37 + shiftDifferentialRule.getHrSalGroup() + "'");
38 return false;
39 } else {
40 return true;
41 }
42 }
43
44 boolean validateEarnCode(ShiftDifferentialRule shiftDifferentialRule) {
45 if (shiftDifferentialRule.getEarnCode() != null
46 && !ValidationUtils.validateEarnCode(shiftDifferentialRule
47 .getEarnCode(), shiftDifferentialRule
48 .getEffectiveLocalDate())) {
49 this.putFieldError("earnCode", "error.existence", "earnCode '"
50 + shiftDifferentialRule.getEarnCode() + "'");
51 return false;
52 } else {
53 return true;
54 }
55 }
56
57 boolean validateLocation(ShiftDifferentialRule shiftDifferentialRule) {
58 if (shiftDifferentialRule.getLocation() != null
59 && !StringUtils.equals(shiftDifferentialRule.getLocation(),
60 HrConstants.WILDCARD_CHARACTER)
61 && !ValidationUtils.validateLocation(shiftDifferentialRule
62 .getLocation(), shiftDifferentialRule
63 .getEffectiveLocalDate())) {
64 this.putFieldError("location", "error.existence", "location '"
65 + shiftDifferentialRule.getLocation() + "'");
66 return false;
67 } else {
68 return true;
69 }
70 }
71
72 boolean validatePayGrade(ShiftDifferentialRule shiftDifferentialRule) {
73 if (shiftDifferentialRule.getPayGrade() != null
74 && !StringUtils.equals(shiftDifferentialRule.getPayGrade(),
75 HrConstants.WILDCARD_CHARACTER)
76 && !ValidationUtils.validatePayGrade(shiftDifferentialRule
77 .getPayGrade(), shiftDifferentialRule.getHrSalGroup(), shiftDifferentialRule
78 .getEffectiveLocalDate())) {
79 this.putFieldError("payGrade", "error.existence", "pay grade '"
80 + shiftDifferentialRule.getPayGrade() + "'");
81 return false;
82 } else {
83 return true;
84 }
85 }
86
87 boolean validateLocationWithSalaryGroup(ShiftDifferentialRule shiftDifferentialRule) {
88
89 if (shiftDifferentialRule.getLocation() != null
90 && !StringUtils.equals(shiftDifferentialRule.getLocation(),
91 HrConstants.WILDCARD_CHARACTER)
92 && !StringUtils.equals(shiftDifferentialRule.getHrSalGroup(),
93 HrConstants.WILDCARD_CHARACTER)
94 && !ValidationUtils.validateLocationWithSalaryGroup(shiftDifferentialRule.getHrSalGroup(),
95 shiftDifferentialRule.getLocation(),
96 shiftDifferentialRule.getEffectiveLocalDate())) {
97
98 this.putFieldError("location", "error.location.salaryGroupLocation.nomatch", shiftDifferentialRule.getLocation());
99 return false;
100 } else {
101 return true;
102 }
103 }
104
105 boolean validateDays(ShiftDifferentialRule shiftDifferentialRule) {
106
107 if (shiftDifferentialRule.isSunday() ||
108 shiftDifferentialRule.isMonday() ||
109 shiftDifferentialRule.isTuesday() ||
110 shiftDifferentialRule.isWednesday() ||
111 shiftDifferentialRule.isThursday() ||
112 shiftDifferentialRule.isFriday() ||
113 shiftDifferentialRule.isSaturday()) {
114 return true;
115 } else {
116
117 this.putFieldError("sunday", "day.required");
118 return false;
119 }
120 }
121
122
123
124
125
126 @Override
127 protected boolean processCustomRouteDocumentBusinessRules(
128 MaintenanceDocument document) {
129 boolean valid = false;
130 LOG.debug("entering custom validation for ShiftDifferentialRule");
131 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
132 if (pbo instanceof ShiftDifferentialRule) {
133 ShiftDifferentialRule shiftDifferentialRule = (ShiftDifferentialRule) pbo;
134 shiftDifferentialRule.setUserPrincipalId(GlobalVariables
135 .getUserSession().getLoggedInUserPrincipalName());
136 if (shiftDifferentialRule != null) {
137 valid = true;
138 valid &= this.validateLocation(shiftDifferentialRule);
139 valid &= this.validateSalGroup(shiftDifferentialRule);
140 valid &= this.validatePayGrade(shiftDifferentialRule);
141 valid &= this.validateEarnCode(shiftDifferentialRule);
142 valid &= this.validateLocationWithSalaryGroup(shiftDifferentialRule);
143 valid &= this.validateDays(shiftDifferentialRule);
144 }
145 }
146
147 return valid;
148 }
149
150 }