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.tklm.time.rules.graceperiod.validation;
17  
18  import java.math.BigDecimal;
19  
20  import org.kuali.kpme.tklm.time.rules.graceperiod.GracePeriodRule;
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  @SuppressWarnings("deprecation")
26  public class GracePeriodRuleValidation extends MaintenanceDocumentRuleBase{
27  	@Override
28  	protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document){
29  		boolean valid = false;
30  		LOG.debug("entering custom validation for Grace Period Rule");
31  		PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
32  		if (pbo instanceof GracePeriodRule) {
33  			GracePeriodRule gracePeriodRule = (GracePeriodRule)this.getNewBo();
34  			if (gracePeriodRule != null) {
35  				valid = true;
36  				//Confirm that hour factor is greater than 0 and less than 1
37  				if(gracePeriodRule.getHourFactor() != null 
38  					&& (gracePeriodRule.getHourFactor().compareTo(BigDecimal.ZERO) <= 0 
39  						|| gracePeriodRule.getHourFactor().compareTo(new BigDecimal(60)) > 0)){
40  					this.putFieldError("hourFactor", "graceperiod.hour.factor.invalid", gracePeriodRule.getHourFactor()+"");
41  					valid = false;
42  				}
43  			}
44  		}
45  		return valid;
46  	}
47  }