001 /**
002 * Copyright 2004-2012 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 valid &= this.validateDuplication(tof);
044 }
045 }
046
047 return valid;
048 }
049
050 private boolean validatePrincipalId(TimeOffAccrual tof) {
051 if (tof.getPrincipalId() != null
052 && !ValidationUtils.validatePrincipalId(tof.getPrincipalId())) {
053 this.putFieldError("principalId", "error.existence",
054 "principalId '" + tof.getPrincipalId() + "'");
055 return false;
056 } else {
057 return true;
058 }
059 }
060
061 private boolean validateAccrualCategory(TimeOffAccrual tof) {
062 if (tof.getAccrualCategory() != null
063 && !ValidationUtils.validateAccrualCategory(tof
064 .getAccrualCategory(), tof.getEffectiveDate())) {
065 this.putFieldError("accrualCategory", "error.existence",
066 "accrualCategory '" + tof.getAccrualCategory() + "'");
067 return false;
068 } else {
069 return true;
070 }
071 }
072
073 private boolean validateDuplication(TimeOffAccrual tof) {
074 if(ValidationUtils.duplicateTimeOffAccrual(tof)) {
075 this.putFieldError("effectiveDate", "timeoffaccrual.duplicate.exists");
076 return false;
077 } else {
078 return true;
079 }
080 }
081
082 }