View Javadoc

1   /**
2    * Copyright 2004-2013 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.hr.time.accrual.validation;
17  
18  import org.kuali.hr.time.accrual.TimeOffAccrual;
19  import org.kuali.hr.time.util.ValidationUtils;
20  import org.kuali.rice.kns.document.MaintenanceDocument;
21  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
22  import org.kuali.rice.krad.bo.PersistableBusinessObject;
23  
24  public class TimeOffAccrualRule extends MaintenanceDocumentRuleBase {
25  
26  	/**
27  	 * It looks like the method that calls this class doesn't actually care
28  	 * about the return type.
29  	 */
30  	@Override
31  	protected boolean processCustomRouteDocumentBusinessRules(
32  			MaintenanceDocument document) {
33  		boolean valid = false;
34  
35  		LOG.debug("entering custom validation for ClockLocationRule");
36  		PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
37  		if (pbo instanceof TimeOffAccrual) {
38  			TimeOffAccrual tof = (TimeOffAccrual) pbo;
39  			if (tof != null) {
40  				valid = true;
41  				valid &= this.validatePrincipalId(tof);
42  				valid &= this.validateAccrualCategory(tof);
43  			}
44  		}
45  
46  		return valid;
47  	}
48  
49  	private boolean validatePrincipalId(TimeOffAccrual tof) {
50  		if (tof.getPrincipalId() != null
51  				&& !ValidationUtils.validatePrincipalId(tof.getPrincipalId())) {
52  			this.putFieldError("principalId", "error.existence",
53  					"principalId '" + tof.getPrincipalId() + "'");
54  			return false;
55  		} else {
56  			return true;
57  		}
58  	}
59  
60  	private boolean validateAccrualCategory(TimeOffAccrual tof) {
61  		if (tof.getAccrualCategory() != null
62  				&& !ValidationUtils.validateAccrualCategory(tof
63  						.getAccrualCategory(), tof.getEffectiveDate())) {
64  			this.putFieldError("accrualCategory", "error.existence",
65  					"accrualCategory '" + tof.getAccrualCategory() + "'");
66  			return false;
67  		} else {
68  			return true;
69  		}
70  	}
71  
72  }