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 static org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX; 019 020 import org.kuali.kfs.sys.KFSPropertyConstants; 021 import org.kuali.kfs.sys.KFSKeyConstants.CashReceipt; 022 import org.kuali.kfs.sys.document.AccountingDocument; 023 import org.kuali.kfs.sys.document.validation.GenericValidation; 024 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 025 import org.kuali.rice.kns.util.GlobalVariables; 026 027 /** 028 * Validation for the Cash Receipt family of documents which validates the sum amount of all 029 * accounting lines on the document. 030 */ 031 public class CashReceiptFamilyAccountingLineTotalValidation extends GenericValidation { 032 private AccountingDocument accountingDocumentForValidation; 033 034 /** 035 * Return true if source total is non-zero 036 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent) 037 */ 038 public boolean validate(AttributedDocumentEvent event) { 039 boolean isValid = true; 040 041 if (getAccountingDocumentForValidation().getSourceTotal().isZero()) { 042 String errorProperty = DOCUMENT_ERROR_PREFIX + KFSPropertyConstants.SOURCE_ACCOUNTING_LINES; 043 044 isValid = false; 045 GlobalVariables.getMessageMap().putError(errorProperty, CashReceipt.ERROR_ZERO_TOTAL, "Accounting Line Total"); 046 } 047 048 return isValid; 049 } 050 051 /** 052 * Gets the accountingDocumentForValidation attribute. 053 * @return Returns the accountingDocumentForValidation. 054 */ 055 public AccountingDocument getAccountingDocumentForValidation() { 056 return accountingDocumentForValidation; 057 } 058 059 /** 060 * Sets the accountingDocumentForValidation attribute value. 061 * @param accountingDocumentForValidation The accountingDocumentForValidation to set. 062 */ 063 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) { 064 this.accountingDocumentForValidation = accountingDocumentForValidation; 065 } 066 }