1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.override.validation;
17
18 import org.apache.cxf.common.util.StringUtils;
19 import org.kuali.kpme.core.accrualcategory.AccrualCategory;
20 import org.kuali.kpme.core.principal.PrincipalHRAttributes;
21 import org.kuali.kpme.core.service.HrServiceLocator;
22 import org.kuali.kpme.tklm.leave.override.EmployeeOverride;
23 import org.kuali.rice.kns.document.MaintenanceDocument;
24 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
25 import org.kuali.rice.krad.bo.PersistableBusinessObject;
26
27 public class EmployeeOverrideRule extends MaintenanceDocumentRuleBase{
28 @Override
29 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
30 boolean valid = true;
31 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
32 if (pbo instanceof EmployeeOverride) {
33 EmployeeOverride eo = (EmployeeOverride) pbo;
34 valid &= this.validatePrincipalHRAttributes(eo);
35 valid &= this.validateAccrualCategory(eo);
36 valid &= this.validateLeavePlan(eo);
37 }
38 return valid;
39 }
40
41 boolean validateLeavePlan(EmployeeOverride eo) {
42 if(StringUtils.isEmpty(eo.getLeavePlan())) {
43 this.putFieldError("leavePlan", "error.employeeOverride.leavePlan.notfound");
44 return false;
45 } else if(eo.getEffectiveDate() != null) {
46 AccrualCategory ac = HrServiceLocator.getAccrualCategoryService().
47 getAccrualCategory(eo.getAccrualCategory(), eo.getEffectiveLocalDate());
48 PrincipalHRAttributes pha = HrServiceLocator.getPrincipalHRAttributeService().
49 getPrincipalCalendar(eo.getPrincipalId(), eo.getEffectiveLocalDate());
50 if(ac != null && pha != null && !ac.getLeavePlan().equals(pha.getLeavePlan())) {
51 this.putFieldError("leavePlan", "error.employeeOverride.leavePlan.inconsistent", eo.getAccrualCategory() );
52 return false;
53 }
54 }
55 return true;
56 }
57
58 boolean validateAccrualCategory(EmployeeOverride eo) {
59 if(eo.getAccrualCategory() != null && eo.getEffectiveDate() != null) {
60 AccrualCategory ac = HrServiceLocator.getAccrualCategoryService().
61 getAccrualCategory(eo.getAccrualCategory(), eo.getEffectiveLocalDate());
62 if(ac == null) {
63 this.putFieldError("accrualCategory", "error.employeeOverride.accrualCategory.notfound", eo.getAccrualCategory() );
64 return false;
65 }
66 }
67 return true;
68 }
69
70 boolean validatePrincipalHRAttributes(EmployeeOverride eo) {
71 if(eo.getPrincipalId() != null && eo.getEffectiveDate() != null) {
72 PrincipalHRAttributes pha = HrServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(eo.getPrincipalId(), eo.getEffectiveLocalDate());
73 if(pha == null) {
74 this.putFieldError("principalId", "error.employeeOverride.principalHRAttributes.notfound", eo.getPrincipalId() );
75 return false;
76 }
77 }
78 return true;
79 }
80
81 }