View Javadoc
1   /*
2    * Copyright 2008-2009 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 java.text.MessageFormat;
19  
20  import org.kuali.ole.fp.businessobject.Deposit;
21  import org.kuali.ole.fp.document.CashManagementDocument;
22  import org.kuali.ole.sys.OLEConstants;
23  import org.kuali.ole.sys.OLEKeyConstants;
24  import org.kuali.ole.sys.OLEPropertyConstants;
25  import org.kuali.ole.sys.businessobject.Bank;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.ole.sys.service.BankService;
28  import org.kuali.rice.core.api.config.property.ConfigurationService;
29  import org.kuali.rice.kns.rules.PromptBeforeValidationBase;
30  import org.kuali.rice.krad.document.Document;
31  
32  /**
33   * Performs warning checks and prompts for CashManagement.
34   */
35  public class CashManagementDocumentPreRules extends PromptBeforeValidationBase {
36  
37      @Override
38      public boolean doPrompts(Document document) {
39          boolean preRulesOK = true;
40  
41          CashManagementDocument cmDocument = (CashManagementDocument) document;
42  
43          preRulesOK &= checkBankCodeActive(cmDocument);
44  
45          return preRulesOK;
46      }
47  
48      /**
49       * If bank specification is enabled, prompts user to use the continuation bank code when the given bank code is inactive
50       * 
51       * @param cmDocument document containing bank code
52       * @return true
53       */
54      protected boolean checkBankCodeActive(CashManagementDocument cmDocument) {
55          boolean continueRules = true;
56  
57          // if bank specification is not enabled, no need to validate bank
58          if (!SpringContext.getBean(BankService.class).isBankSpecificationEnabled()) {
59              return continueRules;
60          }
61  
62          int questionIndex = 0;
63          for (Deposit deposit : cmDocument.getDeposits()) {
64              questionIndex++;
65  
66              // refresh bank reference so continuation bank can be checked for active status
67              deposit.refreshReferenceObject(OLEPropertyConstants.BANK);
68              Bank bank = deposit.getBank();
69  
70              // if bank is inactive and continuation is active, prompt user to use continuation bank
71              if (bank != null && !bank.isActive() && bank.getContinuationBank().isActive()) {
72                  String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.QUESTION_BANK_INACTIVE);
73                  questionText = MessageFormat.format(questionText, deposit.getDepositBankCode(), bank.getContinuationBankCode());
74  
75                  boolean useContinuation = super.askOrAnalyzeYesNoQuestion(OLEConstants.USE_CONTINUATION_BANK_QUESTION + questionIndex, questionText);
76                  if (useContinuation) {
77                      deposit.setDepositBankCode(bank.getContinuationBankCode());
78                  }
79              }
80          }
81  
82          return continueRules;
83      }
84  
85  }