1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
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  
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  
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                  
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  
61  
62  
63      public AccountingLine getAccountingLineForValidation() {
64          return accountingLineForValidation;
65      }
66  
67      
68  
69  
70  
71      public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
72          this.accountingLineForValidation = accountingLineForValidation;
73      }
74      
75  }