001/*
002 * Copyright 2008 The Kuali Foundation
003 * 
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 * http://www.opensource.org/licenses/ecl2.php
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.ole.fp.document.validation.impl;
017
018import org.kuali.ole.fp.businessobject.CreditCardDetail;
019import org.kuali.ole.sys.OLEKeyConstants;
020import org.kuali.ole.sys.OLEPropertyConstants;
021import org.kuali.ole.sys.context.SpringContext;
022import org.kuali.ole.sys.document.validation.GenericValidation;
023import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
024import org.kuali.rice.kns.service.DataDictionaryService;
025import org.kuali.rice.kns.service.DictionaryValidationService;
026import org.kuali.rice.krad.util.GlobalVariables;
027import org.kuali.rice.krad.util.MessageMap;
028
029/**
030 * This class...
031 */
032public class CreditCardReceiptValidation extends GenericValidation {
033    private CreditCardDetail creditCardDetailForValidation;
034    /**
035     * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
036     */
037    public boolean validate(AttributedDocumentEvent event) {
038        CreditCardDetail creditCardReceipt = getCreditCardDetailForValidation();
039        MessageMap errorMap = GlobalVariables.getMessageMap();
040        int originalErrorCount = errorMap.getErrorCount();
041
042        // call the DD validation which checks basic data integrity
043        SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(creditCardReceipt);
044        boolean isValid = (errorMap.getErrorCount() == originalErrorCount);
045
046        // check that dollar amount is not zero before continuing
047        if (isValid) {
048            isValid = !creditCardReceipt.getCreditCardAdvanceDepositAmount().isZero();
049            if (!isValid) {
050                String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(CreditCardDetail.class, OLEPropertyConstants.CREDIT_CARD_ADVANCE_DEPOSIT_AMOUNT);
051                errorMap.putError(OLEPropertyConstants.CREDIT_CARD_ADVANCE_DEPOSIT_AMOUNT, OLEKeyConstants.ERROR_ZERO_AMOUNT, label);
052            }
053        }
054
055//        if (isValid) {
056//            isValid = SpringContext.getBean(DictionaryValidationService.class).validateReferenceExists(creditCardReceipt, OLEPropertyConstants.CREDIT_CARD_TYPE);
057//            if (!isValid) {
058//                String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(CreditCardDetail.class, OLEPropertyConstants.FINANCIAL_DOCUMENT_CREDIT_CARD_TYPE_CODE);
059//                errorMap.putError(OLEPropertyConstants.FINANCIAL_DOCUMENT_CREDIT_CARD_TYPE_CODE, OLEKeyConstants.ERROR_EXISTENCE, label);
060//            }
061//        }
062//        if (isValid) {
063//            isValid = SpringContext.getBean(DictionaryValidationService.class).validateReferenceExists(creditCardReceipt, OLEPropertyConstants.CREDIT_CARD_VENDOR);
064//            if (!isValid) {
065//                String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(CreditCardDetail.class, OLEPropertyConstants.FINANCIAL_DOCUMENT_CREDIT_CARD_VENDOR_NUMBER);
066//                errorMap.putError(OLEPropertyConstants.FINANCIAL_DOCUMENT_CREDIT_CARD_VENDOR_NUMBER, OLEKeyConstants.ERROR_EXISTENCE, label);
067//            }
068//        }
069
070        return isValid;
071    }
072    /**
073     * Gets the creditCardDetailForValidation attribute. 
074     * @return Returns the creditCardDetailForValidation.
075     */
076    public CreditCardDetail getCreditCardDetailForValidation() {
077        return creditCardDetailForValidation;
078    }
079    /**
080     * Sets the creditCardDetailForValidation attribute value.
081     * @param creditCardDetailForValidation The creditCardDetailForValidation to set.
082     */
083    public void setCreditCardDetailForValidation(CreditCardDetail creditCardDetailForValidation) {
084        this.creditCardDetailForValidation = creditCardDetailForValidation;
085    }
086    
087
088}