1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.principal.validation;
17
18 import org.kuali.hr.time.principal.PrincipalHRAttributes;
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 PrincipalHRAttributesRule extends MaintenanceDocumentRuleBase {
25
26 private boolean validatePrincipalId(PrincipalHRAttributes principalHRAttr) {
27 if (principalHRAttr.getPrincipalId() != null
28 && !ValidationUtils.validatePrincipalId(principalHRAttr
29 .getPrincipalId())) {
30 this.putFieldError("principalId", "error.existence",
31 "principalId '" + principalHRAttr.getPrincipalId() + "'");
32 return false;
33 } else {
34 return true;
35 }
36 }
37
38 private boolean validatePayCalendar(PrincipalHRAttributes principalHRAttr) {
39 if (principalHRAttr.getPayCalendar() != null
40 && !ValidationUtils.validateCalendarByType(principalHRAttr.getPayCalendar(), "Pay")) {
41 this.putFieldError("payCalendar", "error.existence",
42 "Pay Calendar '" + principalHRAttr.getPayCalendar() + "'");
43 return false;
44 } else {
45 return true;
46 }
47 }
48
49
50 boolean validateEffectiveDate(PrincipalHRAttributes principalHRAttr) {
51 boolean valid = true;
52 if (principalHRAttr.getEffectiveDate() != null && !ValidationUtils.validateOneYearFutureDate(principalHRAttr.getEffectiveDate())) {
53 this.putFieldError("effectiveDate", "error.date.exceed.year", "Effective Date");
54 valid = false;
55 }
56 return valid;
57 }
58
59 @Override
60 protected boolean processCustomRouteDocumentBusinessRules(
61 MaintenanceDocument document) {
62 boolean valid = false;
63
64 LOG.debug("entering custom validation for Job");
65 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
66 if (pbo instanceof PrincipalHRAttributes) {
67 PrincipalHRAttributes principalHRAttr = (PrincipalHRAttributes) pbo;
68 if (principalHRAttr != null) {
69 valid = true;
70 valid &= this.validatePrincipalId(principalHRAttr);
71
72
73 valid &= this.validatePayCalendar(principalHRAttr);
74 }
75 }
76 return valid;
77 }
78
79 }