001: /*
002: * Copyright 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.pdp.rules;
017:
018: import org.kuali.core.document.MaintenanceDocument;
019: import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
020: import org.kuali.kfs.KFSKeyConstants;
021: import org.kuali.module.pdp.bo.AchBank;
022:
023: public class AchBankRule extends MaintenanceDocumentRuleBase {
024:
025: protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
026: .getLogger(AchBank.class);
027:
028: private AchBank oldAchBank;
029: private AchBank newAchBank;
030:
031: /**
032: * This method sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and
033: * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
034: * all sub-objects from the DB by their primary keys, if available.
035: *
036: * @param document - the maintenanceDocument being evaluated
037: */
038: public void setupConvenienceObjects() {
039:
040: LOG.info("setupConvenienceObjects called");
041:
042: // setup oldAchBank convenience objects, make sure all possible sub-objects are populated
043: oldAchBank = (AchBank) super .getOldBo();
044:
045: // setup newAchBank convenience objects, make sure all possible sub-objects are populated
046: newAchBank = (AchBank) super .getNewBo();
047: }
048:
049: protected boolean processCustomSaveDocumentBusinessRules(
050: MaintenanceDocument document) {
051:
052: LOG.info("processCustomSaveDocumentBusinessRules called");
053: // call the route rules to report all of the messages, but ignore the result
054: processCustomRouteDocumentBusinessRules(document);
055:
056: // Save always succeeds, even if there are business rule failures
057: return true;
058: }
059:
060: protected boolean processCustomRouteDocumentBusinessRules(
061: MaintenanceDocument document) {
062:
063: boolean validEntry = true;
064:
065: LOG.info("processCustomRouteDocumentBusinessRules called");
066: setupConvenienceObjects();
067:
068: String officeCode = newAchBank.getBankOfficeCode();
069: if ((officeCode != null) && !officeCode.equals("O")
070: && !officeCode.equals("B")) {
071: putFieldError(
072: "bankOfficeCode",
073: KFSKeyConstants.ERROR_DOCUMENT_ACHBANKMAINT_INVALID_OFFICE_CODE);
074: validEntry = false;
075: }
076:
077: String typeCode = newAchBank.getBankTypeCode();
078: if ((typeCode != null) && !typeCode.equals("0")
079: && !typeCode.equals("1") && !typeCode.equals("2")) {
080: putFieldError(
081: "bankTypeCode",
082: KFSKeyConstants.ERROR_DOCUMENT_ACHBANKMAINT_INVALID_TYPE_CODE);
083: validEntry = false;
084: }
085:
086: String bankInstitutionStatusCode = newAchBank
087: .getBankInstitutionStatusCode();
088: if ((bankInstitutionStatusCode != null)
089: && !bankInstitutionStatusCode.equals("1")) {
090: putFieldError(
091: "bankInstitutionStatusCode",
092: KFSKeyConstants.ERROR_DOCUMENT_ACHBANKMAINT_INVALID_INST_STATUS_CODE);
093: validEntry = false;
094: }
095:
096: String bankDataViewCode = newAchBank.getBankDataViewCode();
097: if ((bankDataViewCode != null) && !bankDataViewCode.equals("1")) {
098: putFieldError(
099: "bankDataViewCode",
100: KFSKeyConstants.ERROR_DOCUMENT_ACHBANKMAINT_INVALID_DATA_VIEW_CODE);
101: validEntry = false;
102: }
103:
104: return validEntry;
105: }
106:
107: }
|