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.CreditCardDetail;
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.rice.kns.service.DataDictionaryService;
25  import org.kuali.rice.kns.service.DictionaryValidationService;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  import org.kuali.rice.krad.util.MessageMap;
28  
29  /**
30   * This class...
31   */
32  public class CreditCardReceiptValidation extends GenericValidation {
33      private CreditCardDetail creditCardDetailForValidation;
34      /**
35       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
36       */
37      public boolean validate(AttributedDocumentEvent event) {
38          CreditCardDetail creditCardReceipt = getCreditCardDetailForValidation();
39          MessageMap errorMap = GlobalVariables.getMessageMap();
40          int originalErrorCount = errorMap.getErrorCount();
41  
42          // call the DD validation which checks basic data integrity
43          SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(creditCardReceipt);
44          boolean isValid = (errorMap.getErrorCount() == originalErrorCount);
45  
46          // check that dollar amount is not zero before continuing
47          if (isValid) {
48              isValid = !creditCardReceipt.getCreditCardAdvanceDepositAmount().isZero();
49              if (!isValid) {
50                  String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(CreditCardDetail.class, OLEPropertyConstants.CREDIT_CARD_ADVANCE_DEPOSIT_AMOUNT);
51                  errorMap.putError(OLEPropertyConstants.CREDIT_CARD_ADVANCE_DEPOSIT_AMOUNT, OLEKeyConstants.ERROR_ZERO_AMOUNT, label);
52              }
53          }
54  
55  //        if (isValid) {
56  //            isValid = SpringContext.getBean(DictionaryValidationService.class).validateReferenceExists(creditCardReceipt, OLEPropertyConstants.CREDIT_CARD_TYPE);
57  //            if (!isValid) {
58  //                String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(CreditCardDetail.class, OLEPropertyConstants.FINANCIAL_DOCUMENT_CREDIT_CARD_TYPE_CODE);
59  //                errorMap.putError(OLEPropertyConstants.FINANCIAL_DOCUMENT_CREDIT_CARD_TYPE_CODE, OLEKeyConstants.ERROR_EXISTENCE, label);
60  //            }
61  //        }
62  //        if (isValid) {
63  //            isValid = SpringContext.getBean(DictionaryValidationService.class).validateReferenceExists(creditCardReceipt, OLEPropertyConstants.CREDIT_CARD_VENDOR);
64  //            if (!isValid) {
65  //                String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(CreditCardDetail.class, OLEPropertyConstants.FINANCIAL_DOCUMENT_CREDIT_CARD_VENDOR_NUMBER);
66  //                errorMap.putError(OLEPropertyConstants.FINANCIAL_DOCUMENT_CREDIT_CARD_VENDOR_NUMBER, OLEKeyConstants.ERROR_EXISTENCE, label);
67  //            }
68  //        }
69  
70          return isValid;
71      }
72      /**
73       * Gets the creditCardDetailForValidation attribute. 
74       * @return Returns the creditCardDetailForValidation.
75       */
76      public CreditCardDetail getCreditCardDetailForValidation() {
77          return creditCardDetailForValidation;
78      }
79      /**
80       * Sets the creditCardDetailForValidation attribute value.
81       * @param creditCardDetailForValidation The creditCardDetailForValidation to set.
82       */
83      public void setCreditCardDetailForValidation(CreditCardDetail creditCardDetailForValidation) {
84          this.creditCardDetailForValidation = creditCardDetailForValidation;
85      }
86      
87  
88  }