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.CamsPropertyConstants; 022 import org.kuali.kfs.module.cam.businessobject.AssetPaymentAssetDetail; 023 import org.kuali.kfs.module.cam.document.AssetPaymentDocument; 024 import org.kuali.kfs.module.cam.document.service.AssetPaymentService; 025 import org.kuali.kfs.sys.KFSConstants; 026 import org.kuali.kfs.sys.document.validation.GenericValidation; 027 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 028 import org.kuali.rice.kns.util.GlobalVariables; 029 import org.kuali.rice.kns.util.KualiDecimal; 030 031 /** 032 * This class validates if asset is locked by other document, if so return false 033 */ 034 public class AssetPaymentAssetValidation extends GenericValidation { 035 private AssetPaymentService assetPaymentService; 036 037 /** 038 * Validates asset to ensure it is not locked by any other document 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 AssetPaymentDocument assetPaymentDocument = (AssetPaymentDocument) event.getDocument(); 044 List<AssetPaymentAssetDetail> assetPaymentAssetDetails =assetPaymentDocument.getAssetPaymentAssetDetail(); 045 046 boolean valid=true; 047 048 int zeroCostAssetCount=0; 049 int nonZeroCostAssetCount=0; 050 051 int position_a=-1; 052 for(AssetPaymentAssetDetail assetPaymentAssetDetail:assetPaymentAssetDetails) { 053 position_a++; 054 String errorPath = KFSConstants.DOCUMENT_PROPERTY_NAME + "."+CamsPropertyConstants.AssetPaymentDocument.ASSET_PAYMENT_ASSET_DETAIL + "["+position_a+"]."+ CamsPropertyConstants.Asset.CAPITAL_ASSET_NUMBER; 055 056 if (assetPaymentAssetDetail.getAsset().getTotalCostAmount()!= null && assetPaymentAssetDetail.getAsset().getTotalCostAmount().compareTo(new KualiDecimal(0)) != 0) 057 nonZeroCostAssetCount++; 058 else 059 zeroCostAssetCount++; 060 061 valid &= this.getAssetPaymentService().validateAssets(errorPath, assetPaymentAssetDetail.getAsset()); 062 } 063 064 if (zeroCostAssetCount > 0 && (nonZeroCostAssetCount > 0)) { 065 GlobalVariables.getMessageMap().putErrorForSectionId(CamsPropertyConstants.COMMON_ERROR_SECTION_ID,CamsKeyConstants.Payment.ERROR_NON_ZERO_COST_ASSETS_ALLOWED); 066 valid &= false; 067 } 068 return valid; 069 } 070 071 public AssetPaymentService getAssetPaymentService() { 072 return assetPaymentService; 073 } 074 075 public void setAssetPaymentService(AssetPaymentService assetPaymentService) { 076 this.assetPaymentService = assetPaymentService; 077 } 078 }