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.fp.businessobject.Check;
019    import org.kuali.kfs.sys.KFSKeyConstants;
020    import org.kuali.kfs.sys.KFSPropertyConstants;
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    
025    /**
026     * Validation that makes sure a check amount is positive.
027     */
028    public class CashReceiptCheckAmountPositiveValidation extends GenericValidation {
029        private Check checkForValidation;
030    
031        /**
032         * Verifies that the amount on the check is not negative.
033         * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
034         */
035        public boolean validate(AttributedDocumentEvent event) {
036            if (getCheckForValidation().getAmount().isNegative()) {
037                GlobalVariables.getMessageMap().putError(KFSPropertyConstants.CHECK_AMOUNT, KFSKeyConstants.CashReceipt.ERROR_NEGATIVE_CHECK_AMOUNT, KFSPropertyConstants.CHECKS);
038                return false;
039            }
040            return true;
041        }
042    
043        /**
044         * Gets the checkForValidation attribute. 
045         * @return Returns the checkForValidation.
046         */
047        public Check getCheckForValidation() {
048            return checkForValidation;
049        }
050    
051        /**
052         * Sets the checkForValidation attribute value.
053         * @param checkForValidation The checkForValidation to set.
054         */
055        public void setCheckForValidation(Check checkForValidation) {
056            this.checkForValidation = checkForValidation;
057        }
058    }