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.module.cam.document.validation.impl;
017    
018    import static org.kuali.kfs.sys.KFSConstants.AMOUNT_PROPERTY_NAME;
019    import static org.kuali.kfs.sys.KFSKeyConstants.ERROR_ZERO_AMOUNT;
020    
021    import org.kuali.kfs.module.cam.document.AssetPaymentDocument;
022    import org.kuali.kfs.sys.businessobject.AccountingLine;
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    import org.kuali.rice.kns.util.KualiDecimal;
027    
028    /**
029     * This class validates asset zero amount condition
030     */
031    public class AssetPaymentZeroAmountValidation extends GenericValidation {
032        private AccountingLine accountingLineForValidation;
033    
034        /**
035         * Asset payment amount should be a non-zero value
036         * 
037         * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
038         */
039        public boolean validate(AttributedDocumentEvent event) {
040            // skip check if accounting line is from CAB
041            AssetPaymentDocument assetPaymentDocument = (AssetPaymentDocument) event.getDocument();
042            if (assetPaymentDocument.isCapitalAssetBuilderOriginIndicator()) {
043                return true;
044            }
045            
046            KualiDecimal amount = accountingLineForValidation.getAmount();
047            if (amount.isZero()) {
048                GlobalVariables.getMessageMap().putError(AMOUNT_PROPERTY_NAME, ERROR_ZERO_AMOUNT, "an accounting line");
049                return false;
050            }
051            return true;
052        }
053    
054        public AccountingLine getAccountingLineForValidation() {
055            return accountingLineForValidation;
056        }
057    
058        public void setAccountingLineForValidation(AccountingLine accountingLine) {
059            this.accountingLineForValidation = accountingLine;
060        }
061    
062    }