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.coa.businessobject.Account;
20  import org.kuali.ole.fp.businessobject.BudgetAdjustmentAccountingLine;
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.ole.sys.OLEKeyConstants;
23  import org.kuali.ole.sys.OLEPropertyConstants;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.ole.sys.document.validation.GenericValidation;
26  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
27  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  import org.kuali.rice.krad.util.ObjectUtils;
30  
31  /**
32   * Validation that checks Budget Adjustment accounting lines to make sure that non-zero adjustments have related income stream accounts.
33   */
34  public class BudgetAdjustmentAccountingLineAccountIncomeStreamValidation extends GenericValidation {
35      private BudgetAdjustmentAccountingLine accountingLineForValidation;
36  
37      /**
38       * Validate that, if current adjustment amount is non zero, account has an associated income stream chart and account
39       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
40       */
41      public boolean validate(AttributedDocumentEvent event) {
42          boolean accountNumberAllowed = true;
43          if (getAccountingLineForValidation().getCurrentBudgetAdjustmentAmount().isNonZero()) {
44              getAccountingLineForValidation().refreshReferenceObject("account");
45              
46              if (!ObjectUtils.isNull(getAccountingLineForValidation().getAccount())) {
47                  //KFSMI-4877: if fund group is in system parameter values then income stream account number must exist.
48                  String fundGroupCode = getAccountingLineForValidation().getAccount().getSubFundGroup().getFundGroupCode();
49                  String incomeStreamRequiringFundGroupCode = SpringContext.getBean(ParameterService.class).getParameterValueAsString(Account.class, OLEConstants.ChartApcParms.INCOME_STREAM_ACCOUNT_REQUIRING_FUND_GROUPS);
50                  if (StringUtils.containsIgnoreCase(fundGroupCode, incomeStreamRequiringFundGroupCode)) {
51                      if (ObjectUtils.isNull(getAccountingLineForValidation().getAccount().getIncomeStreamAccount())) {
52                          GlobalVariables.getMessageMap().putError(OLEPropertyConstants.ACCOUNT_NUMBER, OLEKeyConstants.ERROR_DOCUMENT_BA_NO_INCOME_STREAM_ACCOUNT, getAccountingLineForValidation().getAccountNumber());
53                          accountNumberAllowed = false;
54                      }
55                  }
56              }
57          }
58          
59          return accountNumberAllowed;
60      }
61  
62      /**
63       * Gets the accountingLineForValidation attribute. 
64       * @return Returns the accountingLineForValidation.
65       */
66      public BudgetAdjustmentAccountingLine getAccountingLineForValidation() {
67          return accountingLineForValidation;
68      }
69  
70      /**
71       * Sets the accountingLineForValidation attribute value.
72       * @param accountingLineForValidation The accountingLineForValidation to set.
73       */
74      public void setAccountingLineForValidation(BudgetAdjustmentAccountingLine accountingLineForValidation) {
75          this.accountingLineForValidation = accountingLineForValidation;
76      }
77  }