001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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: */
016: package org.kuali.module.financial.rules;
017:
018: import org.kuali.core.service.DataDictionaryService;
019: import org.kuali.core.service.DictionaryValidationService;
020: import org.kuali.core.util.ErrorMap;
021: import org.kuali.core.util.GlobalVariables;
022: import org.kuali.kfs.KFSKeyConstants;
023: import org.kuali.kfs.KFSPropertyConstants;
024: import org.kuali.kfs.context.SpringContext;
025: import org.kuali.module.financial.bo.AdvanceDepositDetail;
026:
027: /**
028: * Common Advance Deposit Document rule utilities.
029: */
030: public class AdvanceDepositDocumentRuleUtil {
031: /**
032: * This method method will invoke the data dictionary validation for a AdvanceDepositDetail bo instance, in addition to checking
033: * existence of the Bank and BankAccount attributes that hang off of it. This method assumes that the document hierarchy for the
034: * error map path is managed outside of this call.
035: *
036: * @param advanceDeposit advanceDeposit object being validated
037: * @return boolean returns true if dollar amount is not 0 and bank-related references (i.e. bank and bank account) are valid
038: */
039: public static boolean validateAdvanceDeposit(
040: AdvanceDepositDetail advanceDeposit) {
041: ErrorMap errorMap = GlobalVariables.getErrorMap();
042: int originalErrorCount = errorMap.getErrorCount();
043:
044: // call the DD validation which checks basic data integrity
045: SpringContext.getBean(DictionaryValidationService.class)
046: .validateBusinessObject(advanceDeposit);
047: boolean isValid = (errorMap.getErrorCount() == originalErrorCount);
048:
049: // check that dollar amount is not zero before continuing
050: if (isValid) {
051: isValid = !advanceDeposit
052: .getFinancialDocumentAdvanceDepositAmount()
053: .isZero();
054: if (!isValid) {
055: String label = SpringContext.getBean(
056: DataDictionaryService.class).getAttributeLabel(
057: AdvanceDepositDetail.class,
058: KFSPropertyConstants.ADVANCE_DEPOSIT_AMOUNT);
059: errorMap
060: .putError(
061: KFSPropertyConstants.ADVANCE_DEPOSIT_AMOUNT,
062: KFSKeyConstants.AdvanceDeposit.ERROR_DOCUMENT_ADVANCE_DEPOSIT_ZERO_AMOUNT,
063: label);
064: }
065: }
066:
067: if (isValid) {
068: isValid = SpringContext
069: .getBean(DictionaryValidationService.class)
070: .validateReferenceExists(
071: advanceDeposit,
072: KFSPropertyConstants.FINANCIAL_DOCUMENT_BANK);
073: if (!isValid) {
074: String label = SpringContext
075: .getBean(DataDictionaryService.class)
076: .getAttributeLabel(
077: AdvanceDepositDetail.class,
078: KFSPropertyConstants.FINANCIAL_DOCUMENT_BANK_CODE);
079: errorMap
080: .putError(
081: KFSPropertyConstants.FINANCIAL_DOCUMENT_BANK_CODE,
082: KFSKeyConstants.ERROR_EXISTENCE, label);
083: }
084: }
085: if (isValid) {
086: isValid = SpringContext
087: .getBean(DictionaryValidationService.class)
088: .validateReferenceExists(
089: advanceDeposit,
090: KFSPropertyConstants.FINANCIAL_DOCUMENT_BANK_ACCOUNT);
091: if (!isValid) {
092: String label = SpringContext
093: .getBean(DataDictionaryService.class)
094: .getAttributeLabel(
095: AdvanceDepositDetail.class,
096: KFSPropertyConstants.FINANCIAL_DOCUMENT_BANK_ACCOUNT_NUMBER);
097: errorMap
098: .putError(
099: KFSPropertyConstants.FINANCIAL_DOCUMENT_BANK_ACCOUNT_NUMBER,
100: KFSKeyConstants.ERROR_EXISTENCE, label);
101: }
102: }
103:
104: return isValid;
105: }
106: }
|