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.apache.commons.lang.StringUtils;
19 import org.kuali.hr.time.principal.PrincipalHRAttributes;
20 import org.kuali.hr.time.util.ValidationUtils;
21 import org.kuali.rice.kns.document.MaintenanceDocument;
22 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
23 import org.kuali.rice.krad.bo.PersistableBusinessObject;
24
25 public class PrincipalHRAttributesRule extends MaintenanceDocumentRuleBase {
26
27 private boolean validatePrincipalId(PrincipalHRAttributes principalHRAttr) {
28 if (principalHRAttr.getPrincipalId() != null
29 && !ValidationUtils.validatePrincipalId(principalHRAttr
30 .getPrincipalId())) {
31 this.putFieldError("principalId", "error.existence",
32 "principalId '" + principalHRAttr.getPrincipalId() + "'");
33 return false;
34 } else {
35 return true;
36 }
37 }
38
39 private boolean validatePayCalendar(PrincipalHRAttributes principalHRAttr) {
40 if (principalHRAttr.getPayCalendar() != null
41 && !ValidationUtils.validateCalendarByType(principalHRAttr.getPayCalendar(), "Pay")) {
42 this.putFieldError("payCalendar", "error.existence",
43 "Pay Calendar '" + principalHRAttr.getPayCalendar() + "'");
44 return false;
45 } else {
46 return true;
47 }
48 }
49
50 private boolean validateLeaveCalendar(PrincipalHRAttributes principalHRAttr) {
51 if (principalHRAttr.getLeaveCalendar() != null
52 && !ValidationUtils.validateCalendarByType(principalHRAttr.getLeaveCalendar(), "Leave")) {
53 this.putFieldError("leaveCalendar", "error.existence",
54 "Leave Calendar '" + principalHRAttr.getLeaveCalendar() + "'");
55 return false;
56 } else {
57 return true;
58 }
59 }
60
61
62 private boolean validateLeavePlan(PrincipalHRAttributes principalHRAttr) {
63 if (principalHRAttr.getLeavePlan() != null
64 && !ValidationUtils.validateLeavePlan(principalHRAttr.getLeavePlan(), null)) {
65 this.putFieldError("leavePlan", "error.existence",
66 "leavePlan '" + principalHRAttr.getLeavePlan() + "'");
67 return false;
68 } else {
69 return true;
70 }
71 }
72
73 private boolean validateServiceDate(PrincipalHRAttributes principalHRAttr) {
74 if (StringUtils.isNotEmpty(principalHRAttr.getLeavePlan())
75 && principalHRAttr.getServiceDate() == null) {
76 this.putFieldError("leavePlan", "validation.prerequisite", "'Service Date'");
77 return false;
78 }
79 return true;
80 }
81
82 boolean validateEffectiveDate(PrincipalHRAttributes principalHRAttr) {
83 boolean valid = true;
84 if (principalHRAttr.getEffectiveDate() != null && !ValidationUtils.validateOneYearFutureDate(principalHRAttr.getEffectiveDate())) {
85 this.putFieldError("effectiveDate", "error.date.exceed.year", "Effective Date");
86 valid = false;
87 }
88 return valid;
89 }
90
91 @Override
92 protected boolean processCustomRouteDocumentBusinessRules(
93 MaintenanceDocument document) {
94 boolean valid = false;
95
96
97 LOG.debug("entering custom validation for Job");
98 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
99 if (pbo instanceof PrincipalHRAttributes) {
100 PrincipalHRAttributes principalHRAttr = (PrincipalHRAttributes) pbo;
101 if (principalHRAttr != null) {
102 valid = true;
103 valid &= this.validatePrincipalId(principalHRAttr);
104
105
106 valid &= this.validatePayCalendar(principalHRAttr);
107 valid &= this.validateLeaveCalendar(principalHRAttr);
108 valid &= this.validateLeavePlan(principalHRAttr);
109 valid &= this.validateServiceDate(principalHRAttr);
110 }
111 }
112 return valid;
113 }
114
115 }