001/*
002 * Copyright 2008 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 */
016package org.kuali.ole.fp.document.validation.impl;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.ole.sys.OLEKeyConstants;
020import org.kuali.ole.sys.OLEPropertyConstants;
021import org.kuali.ole.sys.businessobject.AccountingLine;
022import org.kuali.ole.sys.document.validation.GenericValidation;
023import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
024import org.kuali.rice.krad.util.GlobalVariables;
025
026public class IndirectCostAdjustmentChartOfAccountsValidation extends GenericValidation {
027    protected AccountingLine accountingLineForValidation;
028    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(IndirectCostAdjustmentChartOfAccountsValidation.class);
029    
030    /**
031     * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
032     */
033    public boolean validate(AttributedDocumentEvent event) {
034        boolean isValid = true;
035        AccountingLine accountingLine = getAccountingLineForValidation();
036
037        if (accountingLine.isSourceAccountingLine()) {
038            String icrExpense = accountingLine.getChart().getIcrExpenseFinancialObjectCd();
039            isValid &= StringUtils.isNotBlank(icrExpense);
040            if (!isValid) {
041                GlobalVariables.getMessageMap().putError(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, OLEKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_GRANT_INVALID_CHART_OF_ACCOUNTS, accountingLine.getChartOfAccountsCode());
042                if (LOG.isDebugEnabled()) {
043                    LOG.debug("rule failure: " + OLEKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_GRANT_INVALID_CHART_OF_ACCOUNTS + " / " + accountingLine.getChartOfAccountsCode() );
044                }
045            }
046        }
047        else {
048            String icrIncome = accountingLine.getChart().getIcrIncomeFinancialObjectCode();
049            isValid &= StringUtils.isNotBlank(icrIncome);
050            if (!isValid) {
051                GlobalVariables.getMessageMap().putError(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, OLEKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_RECEIPT_INVALID_CHART_OF_ACCOUNTS, accountingLine.getChartOfAccountsCode());
052                if (LOG.isDebugEnabled()) {
053                    LOG.debug("rule failure: " + OLEKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_RECEIPT_INVALID_CHART_OF_ACCOUNTS + " / " + accountingLine.getChartOfAccountsCode() );
054                }
055            }
056        }
057
058        return isValid;
059    }
060
061    /**
062     * Gets the accountingLineForValidation attribute. 
063     * @return Returns the accountingLineForValidation.
064     */
065    public AccountingLine getAccountingLineForValidation() {
066        return accountingLineForValidation;
067    }
068
069    /**
070     * Sets the accountingLineForValidation attribute value.
071     * @param accountingLineForValidation The accountingLineForValidation to set.
072     */
073    public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
074        this.accountingLineForValidation = accountingLineForValidation;
075    }
076    
077}