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.sys.document.validation.impl; 017 018 import static org.kuali.kfs.sys.KFSConstants.AMOUNT_PROPERTY_NAME; 019 import static org.kuali.kfs.sys.KFSKeyConstants.ERROR_INVALID_NEGATIVE_AMOUNT_NON_CORRECTION; 020 import static org.kuali.kfs.sys.KFSKeyConstants.ERROR_ZERO_AMOUNT; 021 022 import org.kuali.kfs.sys.businessobject.AccountingLine; 023 import org.kuali.kfs.sys.document.AccountingDocument; 024 import org.kuali.kfs.sys.document.validation.GenericValidation; 025 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 026 import org.kuali.rice.kns.util.GlobalVariables; 027 import org.kuali.rice.kns.util.KualiDecimal; 028 029 /** 030 * Validates an accounting line that, if the line is not a correction document, the line amount is a positive amount 031 */ 032 public class AccountingLineAmountPositiveValidation extends GenericValidation { 033 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountingLineAmountPositiveValidation.class); 034 035 private AccountingDocument accountingDocumentForValidation; 036 private AccountingLine accountingLineForValidation; 037 038 /** 039 * Check for zero amount, or negative on original (non-correction) document; no sign check for documents that are 040 * corrections to previous documents 041 * <strong>the accounting document must be the first parameter, the accounting line must be the second parameter</strong> 042 * @see org.kuali.kfs.sys.document.validation.GenericValidation#validate(java.lang.Object[]) 043 */ 044 public boolean validate(AttributedDocumentEvent event) { 045 KualiDecimal amount = accountingLineForValidation.getAmount(); 046 String correctsDocumentId = accountingDocumentForValidation.getDocumentHeader().getFinancialDocumentInErrorNumber(); 047 048 if (KualiDecimal.ZERO.compareTo(amount) == 0) { // amount == 0 049 GlobalVariables.getMessageMap().putError(AMOUNT_PROPERTY_NAME, ERROR_ZERO_AMOUNT, "an accounting line"); 050 return false; 051 } 052 else { 053 if (null == correctsDocumentId && KualiDecimal.ZERO.compareTo(amount) == 1) { // amount < 0 054 GlobalVariables.getMessageMap().putError(AMOUNT_PROPERTY_NAME, ERROR_INVALID_NEGATIVE_AMOUNT_NON_CORRECTION); 055 return false; 056 } 057 } 058 059 return true; 060 } 061 062 /** 063 * Gets the accountingDocumentForValidation attribute. 064 * @return Returns the accountingDocumentForValidation. 065 */ 066 public AccountingDocument getAccountingDocumentForValidation() { 067 return accountingDocumentForValidation; 068 } 069 070 /** 071 * Sets the accountingDocumentForValidation attribute value. 072 * @param accountingDocumentForValidation The accountingDocumentForValidation to set. 073 */ 074 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) { 075 this.accountingDocumentForValidation = accountingDocumentForValidation; 076 } 077 078 /** 079 * Gets the accountingLineForValidation attribute. 080 * @return Returns the accountingLineForValidation. 081 */ 082 public AccountingLine getAccountingLineForValidation() { 083 return accountingLineForValidation; 084 } 085 086 /** 087 * Sets the accountingLineForValidation attribute value. 088 * @param accountingLineForValidation The accountingLineForValidation to set. 089 */ 090 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) { 091 this.accountingLineForValidation = accountingLineForValidation; 092 } 093 }