1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leaveadjustment.validation;
17
18 import java.math.BigDecimal;
19 import java.sql.Date;
20
21 import org.kuali.hr.lm.leaveadjustment.LeaveAdjustment;
22 import org.kuali.hr.time.earncode.EarnCode;
23 import org.kuali.hr.time.service.base.TkServiceLocator;
24 import org.kuali.hr.time.util.ValidationUtils;
25 import org.kuali.rice.kns.document.MaintenanceDocument;
26 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
27 import org.kuali.rice.krad.bo.PersistableBusinessObject;
28
29 public class LeaveAdjustmentValidation extends MaintenanceDocumentRuleBase{
30
31 boolean validateLeavePlan(String leavePlan, Date asOfDate) {
32 boolean valid = true;
33 if (!ValidationUtils.validateLeavePlan(leavePlan, asOfDate)) {
34 this.putFieldError("leavePlan", "error.existence", "leavePlan '"
35 + leavePlan + "'");
36 valid = false;
37 }
38 return valid;
39 }
40
41 boolean validateEarnCode(String earnCode, String accrualCategory, Date asOfDate) {
42 boolean valid = true;
43 if (!ValidationUtils.validateEarnCodeOfAccrualCategory(earnCode, accrualCategory, asOfDate)) {
44 this.putFieldError("earnCode", "error.earnCode.accrualCategory.mismatch",
45 earnCode);
46 valid = false;
47 }
48 return valid;
49 }
50
51 boolean validatePrincipal(String principalId) {
52 boolean valid = true;
53 if (!ValidationUtils.validatePrincipalId(principalId)) {
54 this.putFieldError("principalId", "error.existence",
55 "principalId '" + principalId + "'");
56 valid = false;
57 }
58 return valid;
59 }
60
61 boolean validateAccrualCategory(String accrualCategory, Date asOfDate, String principalId) {
62 boolean valid = true;
63 if (!ValidationUtils.validateAccCategory(accrualCategory, principalId, asOfDate)) {
64 this.putFieldError("accrualCategory", "error.existence", "accrualCategory '"
65 + accrualCategory + "'");
66 valid = false;
67 }
68 return valid;
69 }
70
71 private boolean validateFraction(String earnCode, BigDecimal amount, Date asOfDate) {
72 boolean valid = true;
73 if (!ValidationUtils.validateEarnCodeFraction(earnCode, amount, asOfDate)) {
74 EarnCode ec = TkServiceLocator.getEarnCodeService().getEarnCode(earnCode, asOfDate);
75 if(ec != null && ec.getFractionalTimeAllowed() != null) {
76 BigDecimal fracAllowed = new BigDecimal(ec.getFractionalTimeAllowed());
77 String[] parameters = new String[2];
78 parameters[0] = earnCode;
79 parameters[1] = Integer.toString(fracAllowed.scale());
80 this.putFieldError("adjustmentAmount", "error.amount.fraction", parameters);
81 valid = false;
82 }
83 }
84 return valid;
85 }
86
87 @Override
88 protected boolean processCustomRouteDocumentBusinessRules(
89 MaintenanceDocument document) {
90 boolean valid = false;
91
92 LOG.debug("entering custom validation for LeaveAdjustment");
93 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
94 if (pbo instanceof LeaveAdjustment) {
95 LeaveAdjustment leaveAdjustment = (LeaveAdjustment) pbo;
96
97 if (leaveAdjustment != null) {
98 valid = true;
99 if(leaveAdjustment.getPrincipalId() != null) {
100 valid &= this.validatePrincipal(leaveAdjustment.getPrincipalId());
101 }
102 if(leaveAdjustment.getAccrualCategory() != null) {
103 valid &= this.validateAccrualCategory(leaveAdjustment.getAccrualCategory(),leaveAdjustment.getEffectiveDate(), leaveAdjustment.getPrincipalId());
104 }
105 if(leaveAdjustment.getLeavePlan() != null) {
106 valid &= this.validateLeavePlan(leaveAdjustment.getLeavePlan(), leaveAdjustment.getEffectiveDate());
107 }
108 if(leaveAdjustment.getEarnCode() != null) {
109 valid &= this.validateEarnCode(leaveAdjustment.getEarnCode(), leaveAdjustment.getAccrualCategory(), leaveAdjustment.getEffectiveDate());
110 if(leaveAdjustment.getAdjustmentAmount() != null) {
111 valid &= this.validateFraction(leaveAdjustment.getEarnCode(), leaveAdjustment.getAdjustmentAmount(), leaveAdjustment.getEffectiveDate());
112 }
113 }
114 }
115 }
116
117 return valid;
118 }
119
120 }