001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.time.accrual.validation; 017 018 import org.kuali.hr.time.accrual.TimeOffAccrual; 019 import org.kuali.hr.time.util.ValidationUtils; 020 import org.kuali.rice.kns.document.MaintenanceDocument; 021 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase; 022 import org.kuali.rice.krad.bo.PersistableBusinessObject; 023 024 public class TimeOffAccrualRule extends MaintenanceDocumentRuleBase { 025 026 /** 027 * It looks like the method that calls this class doesn't actually care 028 * about the return type. 029 */ 030 @Override 031 protected boolean processCustomRouteDocumentBusinessRules( 032 MaintenanceDocument document) { 033 boolean valid = false; 034 035 LOG.debug("entering custom validation for ClockLocationRule"); 036 PersistableBusinessObject pbo = (PersistableBusinessObject) this.getNewBo(); 037 if (pbo instanceof TimeOffAccrual) { 038 TimeOffAccrual tof = (TimeOffAccrual) pbo; 039 if (tof != null) { 040 valid = true; 041 valid &= this.validatePrincipalId(tof); 042 valid &= this.validateAccrualCategory(tof); 043 } 044 } 045 046 return valid; 047 } 048 049 private boolean validatePrincipalId(TimeOffAccrual tof) { 050 if (tof.getPrincipalId() != null 051 && !ValidationUtils.validatePrincipalId(tof.getPrincipalId())) { 052 this.putFieldError("principalId", "error.existence", 053 "principalId '" + tof.getPrincipalId() + "'"); 054 return false; 055 } else { 056 return true; 057 } 058 } 059 060 private boolean validateAccrualCategory(TimeOffAccrual tof) { 061 if (tof.getAccrualCategory() != null 062 && !ValidationUtils.validateAccrualCategory(tof 063 .getAccrualCategory(), tof.getEffectiveDate())) { 064 this.putFieldError("accrualCategory", "error.existence", 065 "accrualCategory '" + tof.getAccrualCategory() + "'"); 066 return false; 067 } else { 068 return true; 069 } 070 } 071 072 }