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.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.GenericValidation;
23  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24  import org.kuali.ole.sys.document.validation.impl.BankCodeValidation;
25  import org.kuali.rice.kns.service.DataDictionaryService;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  
28  /**
29   * This class...
30   */
31  public class AdvanceDepositValidation extends GenericValidation {
32      protected AdvanceDepositDetail advanceDepositDetailForValidation;
33      /**
34       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
35       */
36      public boolean validate(AttributedDocumentEvent event) {
37          
38          AdvanceDepositDetail advanceDeposit = getAdvanceDepositDetailForValidation();
39          boolean isValid = true;
40  
41          // check that dollar amount is not zero before continuing
42          if (isValid) {
43              isValid = !advanceDeposit.getFinancialDocumentAdvanceDepositAmount().isZero();
44              if (!isValid) {
45                  String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(AdvanceDepositDetail.class, OLEPropertyConstants.ADVANCE_DEPOSIT_AMOUNT);
46                  GlobalVariables.getMessageMap().putError(OLEPropertyConstants.ADVANCE_DEPOSIT_AMOUNT, OLEKeyConstants.AdvanceDeposit.ERROR_DOCUMENT_ADVANCE_DEPOSIT_ZERO_AMOUNT, label);
47              }
48          }
49  
50          if (isValid) {
51              isValid = BankCodeValidation.validate(advanceDeposit.getFinancialDocumentBankCode(), OLEPropertyConstants.FINANCIAL_DOCUMENT_BANK_CODE, true, false);
52          }
53  
54          return isValid;
55      }
56      /**
57       * Gets the advanceDepositDetailForValidation attribute. 
58       * @return Returns the advanceDepositDetailForValidation.
59       */
60      public AdvanceDepositDetail getAdvanceDepositDetailForValidation() {
61          return advanceDepositDetailForValidation;
62      }
63      /**
64       * Sets the advanceDepositDetailForValidation attribute value.
65       * @param advanceDepositDetailForValidation The advanceDepositDetailForValidation to set.
66       */
67      public void setAdvanceDepositDetailForValidation(AdvanceDepositDetail advanceDepositDetailForValidation) {
68          this.advanceDepositDetailForValidation = advanceDepositDetailForValidation;
69      }
70  }