1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.collection.rule.validation;
17
18 import org.apache.cxf.common.util.StringUtils;
19 import org.kuali.hr.time.collection.rule.TimeCollectionRule;
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 TimeCollectionRuleRule extends MaintenanceDocumentRuleBase {
28
29 boolean validateWorkArea(TimeCollectionRule ruleObj) {
30 if (!ValidationUtils.validateWorkArea(ruleObj.getWorkArea(), ruleObj.getDept(), ruleObj.getEffectiveDate())) {
31 this.putFieldError("workArea", "error.existence", "workarea '" + ruleObj.getWorkArea() + "'");
32 return false;
33 } else {
34 return true;
35 }
36 }
37
38 boolean validateDepartment(TimeCollectionRule ruleObj) {
39 if (!ValidationUtils.validateDepartment(ruleObj.getDept(), ruleObj.getEffectiveDate())) {
40 this.putFieldError("dept", "error.existence", "department '" + ruleObj.getDept() + "'");
41 return false;
42 } else {
43 return true;
44 }
45 }
46
47
48 boolean validatePayType(TimeCollectionRule ruleObj) {
49 if(!StringUtils.isEmpty(ruleObj.getPayType()) && ruleObj.getPayType().equals(TkConstants.WILDCARD_CHARACTER)) {
50 return true;
51 }
52 if (!ValidationUtils.validatePayType(ruleObj.getPayType(), ruleObj.getEffectiveDate())) {
53 this.putFieldError("payType", "error.existence", "payType '" + ruleObj.getPayType() + "'");
54 return false;
55 } else {
56 return true;
57 }
58 }
59
60 boolean validateClockUserAndHrsDistFlags(TimeCollectionRule ruleObj) {
61 if (!ruleObj.isClockUserFl() && ruleObj.isHrsDistributionF()) {
62 this.putFieldError("hrsDistributionF", "timecollRule.hrDistribution.invalid");
63 return false;
64 }
65 return true;
66 }
67
68
69
70
71
72 @Override
73 protected boolean processCustomRouteDocumentBusinessRules(
74 MaintenanceDocument document) {
75 boolean valid = false;
76 LOG.debug("entering custom validation for TimeCollectionRule");
77 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
78
79
80
81 if (pbo instanceof TimeCollectionRule) {
82 TimeCollectionRule timeCollectionRule = (TimeCollectionRule) pbo;
83 timeCollectionRule.setUserPrincipalId(GlobalVariables.getUserSession().getLoggedInUserPrincipalName());
84 if (timeCollectionRule != null) {
85 valid = true;
86 valid &= this.validateDepartment(timeCollectionRule);
87 valid &= this.validateWorkArea(timeCollectionRule);
88 valid &= this.validatePayType(timeCollectionRule);
89 valid &= this.validateClockUserAndHrsDistFlags(timeCollectionRule);
90 }
91 }
92
93 return valid;
94 }
95
96 }