1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.accrual.validation;
17
18 import org.kuali.hr.time.accrual.TimeOffAccrual;
19 import org.kuali.hr.time.util.ValidationUtils;
20 import org.kuali.rice.kns.document.MaintenanceDocument;
21 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
22 import org.kuali.rice.krad.bo.PersistableBusinessObject;
23
24 public class TimeOffAccrualRule extends MaintenanceDocumentRuleBase {
25
26
27
28
29
30 @Override
31 protected boolean processCustomRouteDocumentBusinessRules(
32 MaintenanceDocument document) {
33 boolean valid = false;
34
35 LOG.debug("entering custom validation for ClockLocationRule");
36 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
37 if (pbo instanceof TimeOffAccrual) {
38 TimeOffAccrual tof = (TimeOffAccrual) pbo;
39 if (tof != null) {
40 valid = true;
41 valid &= this.validatePrincipalId(tof);
42 valid &= this.validateAccrualCategory(tof);
43 valid &= this.validateDuplication(tof);
44 }
45 }
46
47 return valid;
48 }
49
50 private boolean validatePrincipalId(TimeOffAccrual tof) {
51 if (tof.getPrincipalId() != null
52 && !ValidationUtils.validatePrincipalId(tof.getPrincipalId())) {
53 this.putFieldError("principalId", "error.existence",
54 "principalId '" + tof.getPrincipalId() + "'");
55 return false;
56 } else {
57 return true;
58 }
59 }
60
61 private boolean validateAccrualCategory(TimeOffAccrual tof) {
62 if (tof.getAccrualCategory() != null
63 && !ValidationUtils.validateAccrualCategory(tof
64 .getAccrualCategory(), tof.getEffectiveDate())) {
65 this.putFieldError("accrualCategory", "error.existence",
66 "accrualCategory '" + tof.getAccrualCategory() + "'");
67 return false;
68 } else {
69 return true;
70 }
71 }
72
73 private boolean validateDuplication(TimeOffAccrual tof) {
74 if(ValidationUtils.duplicateTimeOffAccrual(tof)) {
75 this.putFieldError("effectiveDate", "timeoffaccrual.duplicate.exists");
76 return false;
77 } else {
78 return true;
79 }
80 }
81
82 }