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.overtime.weekly.rule;
17  
18  import org.apache.commons.lang.StringUtils;
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 WeeklyOvertimeRuleValidation extends MaintenanceDocumentRuleBase {
25  
26      private static final String ADD_LINE_LOCATION = "add.lstWeeklyOvertimeRules.";
27  
28      @Override
29      public boolean processCustomAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject line) {
30          boolean valid = true;
31  
32          if (line instanceof WeeklyOvertimeRule) {
33              WeeklyOvertimeRule rule = (WeeklyOvertimeRule)line;
34              valid = validateWeeklyOvertimeRule(rule, ADD_LINE_LOCATION);
35          }
36  
37          return valid;
38      }
39  
40  	@Override
41  	protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
42          boolean valid = true;
43  		WeeklyOvertimeRuleGroup ruleGroup = (WeeklyOvertimeRuleGroup)this.getNewBo();
44  
45  		int index = 0;
46  		for(WeeklyOvertimeRule rule : ruleGroup.getLstWeeklyOvertimeRules()) {
47              valid &= validateWeeklyOvertimeRule(rule, "lstWeeklyOvertimeRules["+index+"].");
48  			index++;
49  		}
50  
51  		return valid;
52  	}
53  
54      boolean validateWeeklyOvertimeRule(WeeklyOvertimeRule rule, String errorFieldPrefix) {
55          boolean valid = true;
56  
57          if (errorFieldPrefix == null)
58              errorFieldPrefix = "";
59  
60          if(!StringUtils.isEmpty(rule.getMaxHoursEarnGroup())) {
61              if(!ValidationUtils.validateEarnGroup(rule.getMaxHoursEarnGroup(), rule.getEffectiveDate())) {
62                  this.putFieldError(errorFieldPrefix + "maxHoursEarnGroup", "error.existence", "maxHoursEarnGroup '" + rule.getMaxHoursEarnGroup() + "'");
63                  valid = false;
64              }
65          }
66          if(!StringUtils.isEmpty(rule.getConvertFromEarnGroup())) {
67              if(!ValidationUtils.validateEarnGroup(rule.getConvertFromEarnGroup(), rule.getEffectiveDate())) {
68                  this.putFieldError(errorFieldPrefix + "convertFromEarnGroup", "error.existence", "convertFromEarnGroup '" + rule.getConvertFromEarnGroup() + "'");
69                  valid = false;
70              }
71          }
72          
73  		if (!StringUtils.isEmpty(rule.getConvertFromEarnGroup())
74  				&& ValidationUtils.earnGroupHasOvertimeEarnCodes(rule.getConvertFromEarnGroup(), rule.getEffectiveDate())){
75  			this.putFieldError(errorFieldPrefix + "convertFromEarnGroup", "earngroup.earncode.overtime",  rule.getConvertFromEarnGroup());
76  			valid = false;;
77  		}
78  
79          if(!StringUtils.isEmpty(rule.getConvertToEarnCode())) {
80              if(!ValidationUtils.validateEarnCode(rule.getConvertToEarnCode(), rule.getEffectiveDate())) {
81                  this.putFieldError(errorFieldPrefix + "convertToEarnCode", "error.existence", "convertToEarnCode '" + rule.getConvertToEarnCode() + "'");
82                  valid = false;
83              } else if (!ValidationUtils.validateEarnCode(rule.getConvertToEarnCode(), true, rule.getEffectiveDate())) {
84                  this.putFieldError(errorFieldPrefix + "convertToEarnCode", "earncode.ovt.required", rule.getConvertToEarnCode());
85                  valid = false;
86              }
87          }
88  
89          return valid;
90      }
91  
92  }