View Javadoc

1   /**
2    * Copyright 2004-2012 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.principal.validation;
17  
18  import org.kuali.hr.time.principal.PrincipalHRAttributes;
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 PrincipalHRAttributesRule extends MaintenanceDocumentRuleBase {
25  
26  	private boolean validatePrincipalId(PrincipalHRAttributes principalHRAttr) {
27  		if (principalHRAttr.getPrincipalId() != null
28  				&& !ValidationUtils.validatePrincipalId(principalHRAttr
29  						.getPrincipalId())) {
30  			this.putFieldError("principalId", "error.existence",
31  					"principalId '" + principalHRAttr.getPrincipalId() + "'");
32  			return false;
33  		} else {
34  			return true;
35  		}
36  	}
37  	
38  	private boolean validatePayCalendar(PrincipalHRAttributes principalHRAttr) {
39  		if (principalHRAttr.getPayCalendar() != null
40  				&& !ValidationUtils.validateCalendarByType(principalHRAttr.getPayCalendar(), "Pay")) {
41  			this.putFieldError("payCalendar", "error.existence",
42  					"Pay Calendar '" + principalHRAttr.getPayCalendar() + "'");
43  			return false;
44  		} else {
45  			return true;
46  		}
47  	}
48  
49  	
50  	boolean validateEffectiveDate(PrincipalHRAttributes principalHRAttr) {
51  		boolean valid = true;
52  		if (principalHRAttr.getEffectiveDate() != null && !ValidationUtils.validateOneYearFutureDate(principalHRAttr.getEffectiveDate())) {
53  			this.putFieldError("effectiveDate", "error.date.exceed.year", "Effective Date");
54  			valid = false;
55  		}
56  		return valid;
57  	}
58  	
59  	@Override
60  	protected boolean processCustomRouteDocumentBusinessRules(
61  			MaintenanceDocument document) {
62  		boolean valid = false;
63  
64  		LOG.debug("entering custom validation for Job");
65  		PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
66  		if (pbo instanceof PrincipalHRAttributes) {
67  			PrincipalHRAttributes principalHRAttr = (PrincipalHRAttributes) pbo;
68  			if (principalHRAttr != null) {
69  				valid = true;
70  				valid &= this.validatePrincipalId(principalHRAttr);
71  				// KPME-1442 Kagata
72  				//valid &= this.validateEffectiveDate(principalHRAttr);
73  				valid &= this.validatePayCalendar(principalHRAttr);
74  			}
75  		}
76  		return valid;
77  	}
78  
79  }