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 org.kuali.kfs.module.cam.CamsKeyConstants;
019    import org.kuali.kfs.module.cam.CamsPropertyConstants;
020    import org.kuali.kfs.module.cam.document.AssetPaymentDocument;
021    import org.kuali.kfs.sys.KFSConstants;
022    import org.kuali.kfs.sys.document.validation.GenericValidation;
023    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
024    import org.kuali.rice.kns.util.GlobalVariables;
025    
026    
027    /**
028     * This class validates to make sure that at least one payment line is available for the document
029     */
030    public class AssetPaymentAssetCountValidation extends GenericValidation {
031    
032        /**
033         * Validate accounting line count to ensure minimum of one line
034         * 
035         * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
036         */
037        public boolean validate(AttributedDocumentEvent event) {
038            boolean valid = true;
039            AssetPaymentDocument assetPaymentDocument = (AssetPaymentDocument) event.getDocument();
040    
041            //IF no assets found in document, then....
042            if (assetPaymentDocument.getAssetPaymentAssetDetail().size() == 0) {
043                GlobalVariables.getMessageMap().putErrorForSectionId(CamsPropertyConstants.COMMON_ERROR_SECTION_ID,CamsKeyConstants.Payment.ERROR_NON_ASSETS_IN_DOCUMENT);
044                valid = false;
045            }
046            
047            return valid;
048        }
049    }