View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.fp.document.validation.impl;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.sys.OLEKeyConstants;
20  import org.kuali.ole.sys.OLEPropertyConstants;
21  import org.kuali.ole.sys.businessobject.AccountingLine;
22  import org.kuali.ole.sys.document.validation.GenericValidation;
23  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24  import org.kuali.rice.krad.util.GlobalVariables;
25  
26  public class IndirectCostAdjustmentChartOfAccountsValidation extends GenericValidation {
27      protected AccountingLine accountingLineForValidation;
28      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(IndirectCostAdjustmentChartOfAccountsValidation.class);
29      
30      /**
31       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
32       */
33      public boolean validate(AttributedDocumentEvent event) {
34          boolean isValid = true;
35          AccountingLine accountingLine = getAccountingLineForValidation();
36  
37          if (accountingLine.isSourceAccountingLine()) {
38              String icrExpense = accountingLine.getChart().getIcrExpenseFinancialObjectCd();
39              isValid &= StringUtils.isNotBlank(icrExpense);
40              if (!isValid) {
41                  GlobalVariables.getMessageMap().putError(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, OLEKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_GRANT_INVALID_CHART_OF_ACCOUNTS, accountingLine.getChartOfAccountsCode());
42                  if (LOG.isDebugEnabled()) {
43                      LOG.debug("rule failure: " + OLEKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_GRANT_INVALID_CHART_OF_ACCOUNTS + " / " + accountingLine.getChartOfAccountsCode() );
44                  }
45              }
46          }
47          else {
48              String icrIncome = accountingLine.getChart().getIcrIncomeFinancialObjectCode();
49              isValid &= StringUtils.isNotBlank(icrIncome);
50              if (!isValid) {
51                  GlobalVariables.getMessageMap().putError(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, OLEKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_RECEIPT_INVALID_CHART_OF_ACCOUNTS, accountingLine.getChartOfAccountsCode());
52                  if (LOG.isDebugEnabled()) {
53                      LOG.debug("rule failure: " + OLEKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_RECEIPT_INVALID_CHART_OF_ACCOUNTS + " / " + accountingLine.getChartOfAccountsCode() );
54                  }
55              }
56          }
57  
58          return isValid;
59      }
60  
61      /**
62       * Gets the accountingLineForValidation attribute. 
63       * @return Returns the accountingLineForValidation.
64       */
65      public AccountingLine getAccountingLineForValidation() {
66          return accountingLineForValidation;
67      }
68  
69      /**
70       * Sets the accountingLineForValidation attribute value.
71       * @param accountingLineForValidation The accountingLineForValidation to set.
72       */
73      public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
74          this.accountingLineForValidation = accountingLineForValidation;
75      }
76      
77  }