1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.principal.validation;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.kpme.core.principal.PrincipalHRAttributes;
20 import org.kuali.kpme.core.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 private boolean validateLeavePlan(PrincipalHRAttributes principalHRAttr) {
62 if (principalHRAttr.getLeavePlan() != null
63 && !ValidationUtils.validateLeavePlan(principalHRAttr.getLeavePlan(), null)) {
64 this.putFieldError("leavePlan", "error.existence",
65 "leavePlan '" + principalHRAttr.getLeavePlan() + "'");
66 return false;
67 } else {
68 return true;
69 }
70 }
71
72 private boolean validateServiceDate(PrincipalHRAttributes principalHRAttr) {
73 if (StringUtils.isNotEmpty(principalHRAttr.getLeavePlan())
74 && principalHRAttr.getServiceDate() == null) {
75 this.putFieldError("leavePlan", "validation.prerequisite", "'Service Date'");
76 return false;
77 }
78 return true;
79 }
80
81 private boolean validateLeavefields(PrincipalHRAttributes principalHRAttr){
82 if (StringUtils.isNotEmpty(principalHRAttr.getLeavePlan()) ||
83 StringUtils.isNotEmpty(principalHRAttr.getLeaveCalendar()) ||
84 principalHRAttr.getServiceDate() != null) {
85 if (StringUtils.isNotEmpty(principalHRAttr.getLeavePlan()) &&
86 StringUtils.isNotEmpty(principalHRAttr.getLeaveCalendar()) &&
87 principalHRAttr.getServiceDate() != null) {
88 return true;
89 } else {
90 if (!StringUtils.isNotEmpty(principalHRAttr.getLeavePlan())){
91 this.putFieldError("leavePlan","error.principalHrAttibutes.leavePlan.notPresent");
92 }
93 if (!StringUtils.isNotEmpty(principalHRAttr.getLeaveCalendar())){
94 this.putFieldError("leaveCalendar","error.principalHrAttibutes.leaveCalendar.notPresent");
95 }
96 if (principalHRAttr.getServiceDate() == null){
97 this.putFieldError("serviceDate","error.principalHrAttibutes.serviceDate.notPresent");
98 }
99 return false;
100 }
101 } else {
102 return true;
103 }
104 }
105
106 boolean validateEffectiveDate(PrincipalHRAttributes principalHRAttr) {
107 boolean valid = true;
108 if (principalHRAttr.getEffectiveDate() != null && !ValidationUtils.validateOneYearFutureDate(principalHRAttr.getEffectiveLocalDate())) {
109 this.putFieldError("effectiveDate", "error.date.exceed.year", "Effective Date");
110 valid = false;
111 }
112 return valid;
113 }
114
115 @Override
116 protected boolean processCustomRouteDocumentBusinessRules(
117 MaintenanceDocument document) {
118 boolean valid = false;
119
120
121 LOG.debug("entering custom validation for Job");
122 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
123 if (pbo instanceof PrincipalHRAttributes) {
124 PrincipalHRAttributes principalHRAttr = (PrincipalHRAttributes) pbo;
125 if (principalHRAttr != null) {
126 valid = true;
127 valid &= this.validatePrincipalId(principalHRAttr);
128
129
130 valid &= this.validatePayCalendar(principalHRAttr);
131 valid &= this.validateLeaveCalendar(principalHRAttr);
132 valid &= this.validateLeavePlan(principalHRAttr);
133
134 valid &= this.validateLeavefields(principalHRAttr);
135 }
136 }
137 return valid;
138 }
139
140 }