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.document.NonCheckDisbursementDocument;
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.businessobject.Bank;
25  import org.kuali.ole.sys.context.SpringContext;
26  import org.kuali.ole.sys.service.BankService;
27  import org.kuali.rice.core.api.config.property.ConfigurationService;
28  import org.kuali.rice.kns.rules.PromptBeforeValidationBase;
29  import org.kuali.rice.krad.document.Document;
30  
31  /**
32   * Performs warning checks and prompts for NonCheckDisbursement.
33   */
34  public class NonCheckDisbursementDocumentPreRules extends PromptBeforeValidationBase {
35  
36      @Override
37      public boolean doPrompts(Document document) {
38          boolean preRulesOK = true;
39          
40          NonCheckDisbursementDocument nonCheckDocument = (NonCheckDisbursementDocument) document;
41          
42          preRulesOK &= checkBankCodeActive(nonCheckDocument);
43          
44          return preRulesOK;
45      }
46      
47      /**
48       * If bank specification is enabled, prompts user to use the continuation bank code when the
49       * given bank code is inactive
50       * 
51       * @param nonCheckDocument document containing bank code
52       * @return true
53       */
54      protected boolean checkBankCodeActive(NonCheckDisbursementDocument nonCheckDocument) {
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          // refresh bank reference so continuation bank can be checked for active status
63          nonCheckDocument.refreshReferenceObject(OLEPropertyConstants.BANK);
64          Bank bank = nonCheckDocument.getBank();
65  
66          // if bank is inactive and continuation is active, prompt user to use continuation bank
67          if (bank != null && !bank.isActive() && bank.getContinuationBank().isActive()) {
68              String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.QUESTION_BANK_INACTIVE);
69              questionText = MessageFormat.format(questionText, nonCheckDocument.getFinancialDocumentBankCode(), bank.getContinuationBankCode());
70  
71              boolean useContinuation = super.askOrAnalyzeYesNoQuestion(OLEConstants.USE_CONTINUATION_BANK_QUESTION, questionText);
72              if (useContinuation) {
73                  nonCheckDocument.setFinancialDocumentBankCode(bank.getContinuationBankCode());
74              }
75          }
76  
77          return continueRules;
78      }
79  
80  }