View Javadoc
1   /*
2    * Copyright 2006 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.kuali.ole.fp.businessobject.AdvanceDepositDetail;
19  import org.kuali.ole.sys.OLEKeyConstants;
20  import org.kuali.ole.sys.OLEPropertyConstants;
21  import org.kuali.ole.sys.context.SpringContext;
22  import org.kuali.ole.sys.document.validation.impl.BankCodeValidation;
23  import org.kuali.rice.kns.service.DataDictionaryService;
24  import org.kuali.rice.kns.service.DictionaryValidationService;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  import org.kuali.rice.krad.util.MessageMap;
27  
28  /**
29   * Common Advance Deposit Document rule utilities.
30   */
31  public class AdvanceDepositDocumentRuleUtil {
32      /**
33       * This method method will invoke the data dictionary validation for a AdvanceDepositDetail bo instance, in addition to checking
34       * existence of the Bank and BankAccount attributes that hang off of it. This method assumes that the document hierarchy for the
35       * error map path is managed outside of this call.
36       * 
37       * @param advanceDeposit advanceDeposit object being validated
38       * @return boolean returns true if dollar amount is not 0 and bank-related references (i.e. bank and bank account) are valid
39       */
40      public static boolean validateAdvanceDeposit(AdvanceDepositDetail advanceDeposit) {
41          MessageMap errorMap = GlobalVariables.getMessageMap();
42          int originalErrorCount = errorMap.getErrorCount();
43  
44          // call the DD validation which checks basic data integrity
45          SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(advanceDeposit);
46          boolean isValid = (errorMap.getErrorCount() == originalErrorCount);
47  
48          // check that dollar amount is not zero before continuing
49          if (isValid) {
50              isValid = !advanceDeposit.getFinancialDocumentAdvanceDepositAmount().isZero();
51              if (!isValid) {
52                  String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(AdvanceDepositDetail.class, OLEPropertyConstants.ADVANCE_DEPOSIT_AMOUNT);
53                  errorMap.putError(OLEPropertyConstants.ADVANCE_DEPOSIT_AMOUNT, OLEKeyConstants.AdvanceDeposit.ERROR_DOCUMENT_ADVANCE_DEPOSIT_ZERO_AMOUNT, label);
54              }
55          }
56  
57          if (isValid) {
58              isValid = BankCodeValidation.validate(advanceDeposit.getFinancialDocumentBankCode(), OLEPropertyConstants.FINANCIAL_DOCUMENT_BANK_CODE, true, false);
59          }
60  
61          return isValid;
62      }
63  }