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.principal.validation;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.hr.time.principal.PrincipalHRAttributes;
20  import org.kuali.hr.time.util.ValidationUtils;
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  public class PrincipalHRAttributesRule extends MaintenanceDocumentRuleBase {
26  
27  	private boolean validatePrincipalId(PrincipalHRAttributes principalHRAttr) {
28  		if (principalHRAttr.getPrincipalId() != null
29  				&& !ValidationUtils.validatePrincipalId(principalHRAttr
30  						.getPrincipalId())) {
31  			this.putFieldError("principalId", "error.existence",
32  					"principalId '" + principalHRAttr.getPrincipalId() + "'");
33  			return false;
34  		} else {
35  			return true;
36  		}
37  	}
38  	
39  	private boolean validatePayCalendar(PrincipalHRAttributes principalHRAttr) {
40  		if (principalHRAttr.getPayCalendar() != null
41  				&& !ValidationUtils.validateCalendarByType(principalHRAttr.getPayCalendar(), "Pay")) {
42  			this.putFieldError("payCalendar", "error.existence",
43  					"Pay Calendar '" + principalHRAttr.getPayCalendar() + "'");
44  			return false;
45  		} else {
46  			return true;
47  		}
48  	}
49  	
50  	private boolean validateLeaveCalendar(PrincipalHRAttributes principalHRAttr) {
51  		if (principalHRAttr.getLeaveCalendar() != null
52  				&& !ValidationUtils.validateCalendarByType(principalHRAttr.getLeaveCalendar(), "Leave")) {
53  			this.putFieldError("leaveCalendar", "error.existence",
54  					"Leave Calendar '" + principalHRAttr.getLeaveCalendar() + "'");
55  			return false;
56  		} else {
57  			return true;
58  		}
59  	}
60  	
61  	
62  	private boolean validateLeavePlan(PrincipalHRAttributes principalHRAttr) {
63  		if (principalHRAttr.getLeavePlan() != null
64  				&& !ValidationUtils.validateLeavePlan(principalHRAttr.getLeavePlan(), null)) {
65  			this.putFieldError("leavePlan", "error.existence",
66  					"leavePlan '" + principalHRAttr.getLeavePlan() + "'");
67  			return false;
68  		} else {
69  			return true;
70  		}
71  	}
72  
73      private boolean validateServiceDate(PrincipalHRAttributes principalHRAttr) {
74          if (StringUtils.isNotEmpty(principalHRAttr.getLeavePlan())
75                  && principalHRAttr.getServiceDate() == null) {
76              this.putFieldError("leavePlan", "validation.prerequisite", "'Service Date'");
77              return false;
78          }
79          return true;
80      }
81  	
82  	boolean validateEffectiveDate(PrincipalHRAttributes principalHRAttr) {
83  		boolean valid = true;
84  		if (principalHRAttr.getEffectiveDate() != null && !ValidationUtils.validateOneYearFutureDate(principalHRAttr.getEffectiveDate())) {
85  			this.putFieldError("effectiveDate", "error.date.exceed.year", "Effective Date");
86  			valid = false;
87  		}
88  		return valid;
89  	}
90  	
91  	@Override
92  	protected boolean processCustomRouteDocumentBusinessRules(
93  			MaintenanceDocument document) {
94  		boolean valid = false;
95  
96  
97  		LOG.debug("entering custom validation for Job");
98  		PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo();
99  		if (pbo instanceof PrincipalHRAttributes) {
100 			PrincipalHRAttributes principalHRAttr = (PrincipalHRAttributes) pbo;
101 			if (principalHRAttr != null) {
102 				valid = true;
103 				valid &= this.validatePrincipalId(principalHRAttr);
104 				// KPME-1442 Kagata
105 				//valid &= this.validateEffectiveDate(principalHRAttr);
106 				valid &= this.validatePayCalendar(principalHRAttr);
107 				valid &= this.validateLeaveCalendar(principalHRAttr);
108 				valid &= this.validateLeavePlan(principalHRAttr);
109                 valid &= this.validateServiceDate(principalHRAttr);
110 			}
111 		}
112 		return valid;
113 	}
114 
115 }