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  				valid &= this.validateDuplication(tof);
44  			}
45  		}
46  
47  		return valid;
48  	}
49  
50  	private boolean validatePrincipalId(TimeOffAccrual tof) {
51  		if (tof.getPrincipalId() != null
52  				&& !ValidationUtils.validatePrincipalId(tof.getPrincipalId())) {
53  			this.putFieldError("principalId", "error.existence",
54  					"principalId '" + tof.getPrincipalId() + "'");
55  			return false;
56  		} else {
57  			return true;
58  		}
59  	}
60  
61  	private boolean validateAccrualCategory(TimeOffAccrual tof) {
62  		if (tof.getAccrualCategory() != null
63  				&& !ValidationUtils.validateAccrualCategory(tof
64  						.getAccrualCategory(), tof.getEffectiveDate())) {
65  			this.putFieldError("accrualCategory", "error.existence",
66  					"accrualCategory '" + tof.getAccrualCategory() + "'");
67  			return false;
68  		} else {
69  			return true;
70  		}
71  	}
72  
73  	private boolean validateDuplication(TimeOffAccrual tof) {
74  		if(ValidationUtils.duplicateTimeOffAccrual(tof)) {
75  			this.putFieldError("effectiveDate", "timeoffaccrual.duplicate.exists");
76  			return false;
77  		} else {
78  			return true;
79  		}
80  	}
81  
82  }