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.purap.document.validation.impl; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.kfs.module.purap.PurapConstants; 020 import org.kuali.kfs.module.purap.PurapKeyConstants; 021 import org.kuali.kfs.module.purap.PurapConstants.PaymentRequestStatuses; 022 import org.kuali.kfs.module.purap.businessobject.PurApAccountingLine; 023 import org.kuali.kfs.module.purap.businessobject.PurApItem; 024 import org.kuali.kfs.module.purap.document.PaymentRequestDocument; 025 import org.kuali.kfs.sys.document.validation.GenericValidation; 026 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 027 import org.kuali.rice.kns.util.GlobalVariables; 028 import org.kuali.rice.kns.util.ObjectUtils; 029 030 public class PaymentRequestNonZeroAccountingLineAmountValidation extends GenericValidation { 031 032 private PurApItem itemForValidation; 033 034 public boolean validate(AttributedDocumentEvent event) { 035 boolean valid = true; 036 String status = ((PaymentRequestDocument)event.getDocument()).getStatusCode(); 037 038 //Do this for AFOA only 039 if (StringUtils.equals(PaymentRequestStatuses.AWAITING_FISCAL_REVIEW, status)) { 040 041 for (PurApAccountingLine acct : itemForValidation.getSourceAccountingLines()) { 042 043 //if amount is null or zero, throw an error. 044 if(ObjectUtils.isNull(acct.getAmount()) || (ObjectUtils.isNotNull(acct.getAmount()) && acct.getAmount().isZero())){ 045 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_ACCOUNTING_AMOUNT_INVALID, itemForValidation.getItemIdentifierString()); 046 valid &= false; 047 } 048 } 049 } 050 051 return valid; 052 } 053 054 public PurApItem getItemForValidation() { 055 return itemForValidation; 056 } 057 058 public void setItemForValidation(PurApItem itemForValidation) { 059 this.itemForValidation = itemForValidation; 060 } 061 062 }