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 java.util.List;
019    
020    import org.kuali.kfs.module.cam.CamsKeyConstants;
021    import org.kuali.kfs.module.cam.businessobject.AssetPaymentAssetDetail;
022    import org.kuali.kfs.module.cam.document.AssetPaymentDocument;
023    import org.kuali.kfs.module.cam.document.service.AssetPaymentService;
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.ObjectUtils;
028    
029    /**
030     * 
031     * This class validates if asset# typed in the asset textbox isn't blank, and validate its wasn't already added in the collection
032     *  
033     */
034    public class AssetPaymentAddAssetValidation extends GenericValidation {
035        private AssetPaymentService assetPaymentService;
036        private AssetPaymentAssetDetail assetPaymentAssetDetailForValidation;
037        
038        /**
039         *  
040         * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
041         */
042        public boolean validate(AttributedDocumentEvent event) {
043            String errorPath = event.getErrorPathPrefix();
044            
045            //Validating the asset exists in the asset table.
046            if (ObjectUtils.isNull(this.getAssetPaymentAssetDetailForValidation().getAsset())) {
047                GlobalVariables.getMessageMap().putError(errorPath, CamsKeyConstants.AssetLocationGlobal.ERROR_INVALID_CAPITAL_ASSET_NUMBER, this.getAssetPaymentAssetDetailForValidation().getCapitalAssetNumber().toString());
048                return false;
049            }
050            return this.getAssetPaymentService().validateAssets(errorPath, this.getAssetPaymentAssetDetailForValidation().getAsset());
051        }
052    
053        public AssetPaymentAssetDetail getAssetPaymentAssetDetailForValidation() {
054            return assetPaymentAssetDetailForValidation;
055        }
056    
057        public void setAssetPaymentAssetDetailForValidation(AssetPaymentAssetDetail assetPaymentAssetDetailForValidation) {
058            this.assetPaymentAssetDetailForValidation = assetPaymentAssetDetailForValidation;
059        }
060        
061        public AssetPaymentService getAssetPaymentService() {
062            return assetPaymentService;
063        }
064    
065        public void setAssetPaymentService(AssetPaymentService assetPaymentService) {
066            this.assetPaymentService = assetPaymentService;
067        }    
068    }