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.IndirectCostRecoveryAccount;
20  import org.kuali.ole.sys.OLEKeyConstants;
21  import org.kuali.ole.sys.OLEPropertyConstants;
22  import org.kuali.ole.sys.businessobject.AccountingLine;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  import org.kuali.rice.krad.util.ObjectUtils;
27  
28  /**
29   * This class...
30   */
31  public class IndirectCostAdjustmentAccountValidation extends GenericValidation {
32      protected AccountingLine accountingLineForValidation;
33      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(IndirectCostAdjustmentAccountValidation.class);
34      
35      /**
36       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
37       */
38      public boolean validate(AttributedDocumentEvent event) {
39          AccountingLine accountingLine = getAccountingLineForValidation();
40          boolean isValid = true;
41          if (accountingLine.isSourceAccountingLine()) {
42              accountingLine.refreshReferenceObject(OLEPropertyConstants.ACCOUNT);
43              if (ObjectUtils.isNotNull(accountingLine.getAccount())) {
44                  for (IndirectCostRecoveryAccount icrAccount : accountingLine.getAccount().getActiveIndirectCostRecoveryAccounts()){
45                      isValid &= StringUtils.isNotBlank(icrAccount.getIndirectCostRecoveryAccountNumber());
46                  }
47                  //not valid if ICR collection is empty or any of the account number is blank
48                  if (!isValid) {
49                      GlobalVariables.getMessageMap().putError(OLEPropertyConstants.ACCOUNT_NUMBER, OLEKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_GRANT_INVALID_ACCOUNT, accountingLine.getAccountNumber());
50                      if (LOG.isDebugEnabled()) {
51                          LOG.debug("rule failure: " + OLEKeyConstants.IndirectCostAdjustment.ERROR_DOCUMENT_ICA_GRANT_INVALID_ACCOUNT + " / " + accountingLine.getAccountNumber() );
52                      }
53                  }
54              }
55          }
56          return isValid;
57      }
58  
59      /**
60       * Gets the accountingLineForValidation attribute. 
61       * @return Returns the accountingLineForValidation.
62       */
63      public AccountingLine getAccountingLineForValidation() {
64          return accountingLineForValidation;
65      }
66  
67      /**
68       * Sets the accountingLineForValidation attribute value.
69       * @param accountingLineForValidation The accountingLineForValidation to set.
70       */
71      public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
72          this.accountingLineForValidation = accountingLineForValidation;
73      }
74      
75  }