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.commons.lang.StringUtils;
19 import org.kuali.hr.kpme.tklm.time.rules.validation.TkKeyedBusinessObjectValidation;
20 import org.kuali.kpme.core.bo.HrKeyedBusinessObject;
21 import org.kuali.kpme.core.util.HrConstants;
22 import org.kuali.kpme.core.util.ValidationUtils;
23 import org.kuali.kpme.tklm.time.rules.timecollection.TimeCollectionRule;
24 import org.kuali.rice.kns.document.MaintenanceDocument;
25 import org.kuali.rice.krad.bo.PersistableBusinessObject;
26 import org.kuali.rice.krad.util.GlobalVariables;
27
28 public class TimeCollectionRuleValidation extends TkKeyedBusinessObjectValidation {
29
30 boolean validateWorkArea(TimeCollectionRule ruleObj) {
31 if (!ValidationUtils.validateWorkArea(ruleObj.getWorkArea(), ruleObj.getDept(), ruleObj.getEffectiveLocalDate())) {
32 this.putFieldError("workArea", "error.existence", "workarea '" + ruleObj.getWorkArea() + "'");
33 return false;
34 } else {
35 return true;
36 }
37 }
38
39 boolean validateDepartment(TimeCollectionRule ruleObj) {
40 if (!ValidationUtils.validateDepartment(ruleObj.getDept(), ruleObj.getGroupKeyCode(), ruleObj.getEffectiveLocalDate())) {
41 this.putFieldError("dept", "error.existence", "department '" + ruleObj.getDept() + "'");
42 return false;
43 } else {
44 return true;
45 }
46 }
47
48
49 boolean validatePayType(TimeCollectionRule ruleObj) {
50 if(!StringUtils.isEmpty(ruleObj.getPayType()) && ruleObj.getPayType().equals(HrConstants.WILDCARD_CHARACTER)) {
51 return true;
52 }
53 if (!ValidationUtils.validatePayType(ruleObj.getPayType(), ruleObj.getEffectiveLocalDate())) {
54 this.putFieldError("payType", "error.existence", "payType '" + ruleObj.getPayType() + "'");
55 return false;
56 } else {
57 return true;
58 }
59 }
60
61
62 private boolean validateWorkAreaDeptWildcarding(TimeCollectionRule tcr) {
63 if(!HrConstants.WILDCARD_LONG.equals(tcr.getWorkArea())) {
64 return !(StringUtils.equals(tcr.getDept(), HrConstants.WILDCARD_CHARACTER));
65 }
66 return true;
67 }
68
69
70 private boolean validateGroupKeyDeptWildcarding(TimeCollectionRule tcr) {
71 if(StringUtils.equals(tcr.getGroupKeyCode(), HrConstants.WILDCARD_CHARACTER)) {
72 return StringUtils.equals(tcr.getDept(), HrConstants.WILDCARD_CHARACTER);
73 }
74 return true;
75 }
76
77 public boolean validateWildcards(TimeCollectionRule tcr) {
78
79 if(!validateWorkAreaDeptWildcarding(tcr)){
80
81 this.putFieldError("workArea", "error.wc.wadef");
82 return false;
83 }
84
85 if(!validateGroupKeyDeptWildcarding(tcr)){
86
87 this.putFieldError("groupKeyCode", "error.wc.deptdef");
88 return false;
89 }
90
91 return true;
92 }
93
94
95 @Override
96 protected boolean validateGroupKeyCode(HrKeyedBusinessObject keyedBo) {
97 if (StringUtils.equals(keyedBo.getGroupKeyCode(), HrConstants.WILDCARD_CHARACTER))
98 {
99 return true;
100 }
101 return super.validateGroupKeyCode(keyedBo);
102 }
103
104
105
106
107
108 @Override
109 protected boolean processCustomRouteDocumentBusinessRules(
110 MaintenanceDocument document) {
111 boolean valid = false;
112 LOG.debug("entering custom validation for TimeCollectionRule");
113 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
114
115
116 if (pbo instanceof TimeCollectionRule) {
117 TimeCollectionRule timeCollectionRule = (TimeCollectionRule) pbo;
118 timeCollectionRule.setUserPrincipalId(GlobalVariables.getUserSession().getLoggedInUserPrincipalName());
119 if (timeCollectionRule != null) {
120 valid = true;
121 valid &= this.validateWildcards(timeCollectionRule);
122 valid &= this.validateDepartment(timeCollectionRule);
123 valid &= this.validateWorkArea(timeCollectionRule);
124 valid &= this.validatePayType(timeCollectionRule);
125 valid &= this.validateGroupKeyCode(timeCollectionRule);
126 }
127 }
128
129 return valid;
130 }
131
132 }