/* * The Kuali Financial System, a comprehensive financial management system for higher education. * * Copyright 2005-2014 The Kuali Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.kuali.kfs.module.cam.document.validation.impl; import static org.kuali.kfs.sys.KFSConstants.AMOUNT_PROPERTY_NAME; import static org.kuali.kfs.sys.KFSKeyConstants.ERROR_BLANK_AMOUNT; import static org.kuali.kfs.sys.KFSKeyConstants.ERROR_ZERO_AMOUNT; import org.kuali.kfs.module.cam.document.AssetPaymentDocument; import org.kuali.kfs.sys.businessobject.AccountingLine; import org.kuali.kfs.sys.document.validation.GenericValidation; import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; import org.kuali.rice.core.api.util.type.KualiDecimal; import org.kuali.rice.krad.util.GlobalVariables; import org.kuali.rice.krad.util.ObjectUtils; /** * This class validates asset zero amount condition */ public class AssetPaymentZeroAmountValidation extends GenericValidation { private AccountingLine accountingLineForValidation; /** * Asset payment amount should be a non-zero value * * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent) */ @Override public boolean validate(AttributedDocumentEvent event) { // skip check if accounting line is from CAB AssetPaymentDocument assetPaymentDocument = (AssetPaymentDocument) event.getDocument(); if (assetPaymentDocument.isCapitalAssetBuilderOriginIndicator()) { return true; } KualiDecimal amount = accountingLineForValidation.getAmount(); if(ObjectUtils.isNull(amount)) { GlobalVariables.getMessageMap().putError(AMOUNT_PROPERTY_NAME,ERROR_BLANK_AMOUNT,""); return false; } else if (amount.isZero()) { GlobalVariables.getMessageMap().putError(AMOUNT_PROPERTY_NAME, ERROR_ZERO_AMOUNT, "an accounting line"); return false; } return true; } public AccountingLine getAccountingLineForValidation() { return accountingLineForValidation; } public void setAccountingLineForValidation(AccountingLine accountingLine) { this.accountingLineForValidation = accountingLine; } }