1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.shiftdiff.rule.validation;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.hr.time.shiftdiff.rule.ShiftDifferentialRule;
20 import org.kuali.hr.time.util.TkConstants;
21 import org.kuali.hr.time.util.ValidationUtils;
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 TkConstants.WILDCARD_CHARACTER)
33 && !ValidationUtils.validateSalGroup(shiftDifferentialRule
34 .getHrSalGroup(), shiftDifferentialRule
35 .getEffectiveDate())) {
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 .getEffectiveDate())) {
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 TkConstants.WILDCARD_CHARACTER)
61 && !ValidationUtils.validateLocation(shiftDifferentialRule
62 .getLocation(), shiftDifferentialRule
63 .getEffectiveDate())) {
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 TkConstants.WILDCARD_CHARACTER)
76 && !ValidationUtils.validatePayGrade(shiftDifferentialRule
77 .getPayGrade(), shiftDifferentialRule
78 .getEffectiveDate())) {
79 this.putFieldError("payGrade", "error.existence", "pay grade '"
80 + shiftDifferentialRule.getPayGrade() + "'");
81 return false;
82 } else {
83 return true;
84 }
85 }
86
87
88
89
90
91 @Override
92 protected boolean processCustomRouteDocumentBusinessRules(
93 MaintenanceDocument document) {
94 boolean valid = false;
95 LOG.debug("entering custom validation for TimeCollectionRule");
96 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
97 if (pbo instanceof ShiftDifferentialRule) {
98 ShiftDifferentialRule shiftDifferentialRule = (ShiftDifferentialRule) pbo;
99 shiftDifferentialRule.setUserPrincipalId(GlobalVariables
100 .getUserSession().getLoggedInUserPrincipalName());
101 if (shiftDifferentialRule != null) {
102 valid = true;
103 valid &= this.validateLocation(shiftDifferentialRule);
104 valid &= this.validateSalGroup(shiftDifferentialRule);
105 valid &= this.validatePayGrade(shiftDifferentialRule);
106 valid &= this.validateEarnCode(shiftDifferentialRule);
107 }
108 }
109
110 return valid;
111 }
112
113 }