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.paygrade.validation;
17  
18  import org.kuali.kpme.core.paygrade.PayGrade;
19  import org.kuali.kpme.core.salarygroup.SalaryGroup;
20  import org.kuali.kpme.core.service.HrServiceLocator;
21  import org.kuali.kpme.core.util.ValidationUtils;
22  import org.kuali.rice.krad.bo.PersistableBusinessObject;
23  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
24  import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
25  
26  public class PayGradeValidation extends MaintenanceDocumentRuleBase {
27  	@Override
28  	protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
29  		boolean valid = true;
30  		LOG.debug("entering custom validation for Pay Grade");
31  		PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewDataObject();
32  		if (pbo != null && pbo instanceof PayGrade) {
33  			PayGrade aPayGrade = (PayGrade) pbo;
34  			valid &= this.validateSalGroup(aPayGrade);
35  		}
36  		return valid;
37  	}
38  	
39  	private boolean validateSalGroup(PayGrade aPayGrade){
40  		SalaryGroup aSalGroup = HrServiceLocator.getSalaryGroupService().getSalaryGroup(aPayGrade.getSalGroup(), aPayGrade.getEffectiveLocalDate()) ;
41  		String errorMes = "Salgroup '"+ aPayGrade.getSalGroup() + "'";
42  		if(aSalGroup == null) {
43  			this.putFieldError("dataObject.salGroup", "error.existence", errorMes);
44  			return false;
45  		} else {
46  			if(!ValidationUtils.wildCardMatch(aSalGroup.getInstitution(), aPayGrade.getInstitution())) {
47  				String[] params = new String[3];
48  				params[0] = aPayGrade.getInstitution();
49  				params[1] = aSalGroup.getInstitution();
50  				params[2] = errorMes;
51  				this.putFieldError("dataObject.institution", "institution.inconsistent", params);
52  				return false;
53  			}
54  			if(!ValidationUtils.wildCardMatch(aSalGroup.getLocation(), aPayGrade.getLocation())) {
55  				String[] params = new String[3];
56  				params[0] = aPayGrade.getLocation();
57  				params[1] = aSalGroup.getLocation();
58  				params[2] = errorMes;
59  				this.putFieldError("dataObject.location", "location.inconsistent", params);
60  				return false;
61  			}
62  		} 
63  		return true;
64  	}
65  }