1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.rules.timecollection.validation;
17
18 import org.apache.cxf.common.util.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.timecollection.TimeCollectionRule;
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 TimeCollectionRuleValidation extends MaintenanceDocumentRuleBase {
28
29 boolean validateWorkArea(TimeCollectionRule ruleObj) {
30 if (!ValidationUtils.validateWorkArea(ruleObj.getWorkArea(), ruleObj.getDept(), ruleObj.getEffectiveLocalDate())) {
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.getEffectiveLocalDate())) {
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(HrConstants.WILDCARD_CHARACTER)) {
50 return true;
51 }
52 if (!ValidationUtils.validatePayType(ruleObj.getPayType(), ruleObj.getEffectiveLocalDate())) {
53 this.putFieldError("payType", "error.existence", "payType '" + ruleObj.getPayType() + "'");
54 return false;
55 } else {
56 return true;
57 }
58 }
59
60
61
62
63
64 @Override
65 protected boolean processCustomRouteDocumentBusinessRules(
66 MaintenanceDocument document) {
67 boolean valid = false;
68 LOG.debug("entering custom validation for TimeCollectionRule");
69 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
70
71
72
73 if (pbo instanceof TimeCollectionRule) {
74 TimeCollectionRule timeCollectionRule = (TimeCollectionRule) pbo;
75 timeCollectionRule.setUserPrincipalId(GlobalVariables.getUserSession().getLoggedInUserPrincipalName());
76 if (timeCollectionRule != null) {
77 valid = true;
78 valid &= this.validateDepartment(timeCollectionRule);
79 valid &= this.validateWorkArea(timeCollectionRule);
80 valid &= this.validatePayType(timeCollectionRule);
81 }
82 }
83
84 return valid;
85 }
86
87 }