View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.core.paystep.validation;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.kpme.core.api.paygrade.PayGrade;
20  import org.kuali.kpme.core.api.salarygroup.SalaryGroup;
21  import org.kuali.kpme.core.paystep.PayStepBo;
22  import org.kuali.kpme.core.service.HrServiceLocator;
23  import org.kuali.kpme.core.util.ValidationUtils;
24  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
25  import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
26  
27  @SuppressWarnings("deprecation")
28  public class PayStepValidation extends MaintenanceDocumentRuleBase {
29  
30  	@Override
31  	protected boolean processCustomRouteDocumentBusinessRules(
32  			MaintenanceDocument document) {
33  		LOG.debug("entering custom validation for pay step");
34  		boolean isValid = super.processCustomRouteDocumentBusinessRules(document);
35  
36  		PayStepBo payStep = (PayStepBo) this.getNewDataObject();
37  		
38  		isValid &= validateSalaryGroup(payStep);
39  		isValid &= validatePayGrade(payStep);
40  		isValid &= validatePayGradeInSalaryGroup(payStep);
41  		
42  		return isValid;
43  	}
44  
45  	private boolean validatePayGrade(PayStepBo payStep) {
46  		PayGrade aPayGrade = HrServiceLocator.getPayGradeService().getPayGrade(payStep.getPayGrade(), payStep.getSalaryGroup(), payStep.getEffectiveLocalDate());
47  		String errorMes = "Pay Grade '" + payStep.getPayGrade() + "'";
48  		if(aPayGrade == null) {
49  			this.putFieldError("dataObject.payGrade", "error.existence", errorMes);
50  			return false;
51  		} else {
52  			// TODO
53  			// Figure out how to handle this validation once a collection of group keys gets added to Salary Group
54  			/*
55  			if(!ValidationUtils.wildCardMatch(aPayGrade.getInstitution(), payStep.getInstitution())) {
56  				String[] params = new String[3];
57  				params[0] = payStep.getInstitution();
58  				params[1] = aPayGrade.getInstitution();
59  				params[2] = errorMes;
60  				this.putFieldError("dataObject.institution", "institution.inconsistent", params);
61  				return false;
62  			}
63  			if(!ValidationUtils.wildCardMatch(aPayGrade.getLocation(), payStep.getLocation())) {
64  				String[] params = new String[3];
65  				params[0] = payStep.getLocation();
66  				params[1] = aPayGrade.getLocation();
67  				params[2] = errorMes;
68  				this.putFieldError("dataObject.location", "location.inconsistent", params);
69  				return false;
70  			}*/
71  		}
72  		return true;
73  	}
74  
75  	private boolean validateSalaryGroup(PayStepBo payStep) {
76  		SalaryGroup aSalGroup = HrServiceLocator.getSalaryGroupService().getSalaryGroup(payStep.getSalaryGroup(), payStep.getEffectiveLocalDate());
77  		String errorMes = "SalaryGroup '" + payStep.getSalaryGroup() + "'";
78  		if(aSalGroup != null) {
79  			// TODO
80  			// Figure out how to handle this validation once a collection of group keys gets added to Salary Group
81  			/*
82  			if(!ValidationUtils.wildCardMatch(aSalGroup.getInstitution(), payStep.getInstitution())) {
83  				String[] params = new String[3];
84  				params[0] = payStep.getInstitution();
85  				params[1] = aSalGroup.getInstitution();
86  				params[2] = errorMes;
87  				this.putFieldError("dataObject.institution", "institution.inconsistent", params);
88  				return false;
89  			}
90  			if(!ValidationUtils.wildCardMatch(aSalGroup.getLocation(), payStep.getLocation())) {
91  				String[] params = new String[3];
92  				params[0] = payStep.getLocation();
93  				params[1] = aSalGroup.getLocation();
94  				params[2] = errorMes;
95  				this.putFieldError("dataObject.location", "location.inconsistent", params);
96  				return false;
97  			}*/
98  			
99  		} else {
100 			this.putFieldError("dataObject.salaryGroup", "error.existence", errorMes);
101 			return false;
102 		}
103 		
104 		return true;
105 	}
106 	
107 	private boolean validatePayGradeInSalaryGroup(PayStepBo payStep) {
108 		if(StringUtils.isNotEmpty(payStep.getSalaryGroup())
109 				&& ValidationUtils.validatePayGradeWithSalaryGroup(payStep.getSalaryGroup(),payStep.getPayGrade(),payStep.getEffectiveLocalDate())) {
110 			return true;
111 		} else {
112 			String[] params = new String[2];
113 			params[0] = payStep.getPayGrade();
114 			params[1] = payStep.getSalaryGroup();
115 			
116 			this.putFieldError("dataObject.payGrade", "salaryGroup.contains.payGrade", params);
117 			return false;
118 		}
119 	}
120 }