001 /* 002 * Copyright 2011 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.kfs.fp.document.validation.impl; 017 018 import org.kuali.kfs.sys.KFSConstants; 019 import org.kuali.kfs.sys.KFSKeyConstants; 020 import org.kuali.kfs.sys.businessobject.AccountingLine; 021 import org.kuali.kfs.sys.document.validation.GenericValidation; 022 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 023 import org.kuali.rice.kns.util.GlobalVariables; 024 import org.kuali.rice.kns.util.KualiDecimal; 025 026 /** 027 * Validates that the amount on a given accounting line is not zero 028 */ 029 public class AccountingLineAmountNonZeroValidation extends GenericValidation { 030 private AccountingLine accountingLineForValidation; 031 032 /** 033 * Validates that the amount of the given accounting line is not zero 034 * <strong>the accounting document must be the first parameter, the accounting line must be the second parameter</strong> 035 * @see org.kuali.kfs.sys.document.validation.GenericValidation#validate(java.lang.Object[]) 036 */ 037 public boolean validate(AttributedDocumentEvent event) { 038 KualiDecimal amount = accountingLineForValidation.getAmount(); 039 040 if (KualiDecimal.ZERO.compareTo(amount) == 0) { // amount == 0 041 GlobalVariables.getMessageMap().putError(KFSConstants.AMOUNT_PROPERTY_NAME, KFSKeyConstants.ERROR_ZERO_AMOUNT, "an accounting line"); 042 return false; 043 } 044 045 return true; 046 } 047 048 /** 049 * Gets the accountingLineForValidation attribute. 050 * @return Returns the accountingLineForValidation. 051 */ 052 public AccountingLine getAccountingLineForValidation() { 053 return accountingLineForValidation; 054 } 055 056 /** 057 * Sets the accountingLineForValidation attribute value. 058 * @param accountingLineForValidation The accountingLineForValidation to set. 059 */ 060 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) { 061 this.accountingLineForValidation = accountingLineForValidation; 062 } 063 }