View Javadoc

1   /*
2    * Copyright 2007 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.pdp.document.validation.impl;
17  
18  import org.kuali.ole.pdp.PdpConstants;
19  import org.kuali.ole.pdp.businessobject.ACHBank;
20  import org.kuali.ole.sys.OLEKeyConstants;
21  import org.kuali.rice.kns.document.MaintenanceDocument;
22  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
23  import org.kuali.rice.krad.util.ObjectUtils;
24  
25  public class AchBankRule extends MaintenanceDocumentRuleBase {
26  
27      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ACHBank.class);
28  
29      protected ACHBank oldAchBank;
30      protected ACHBank newAchBank;
31  
32      /**
33       * This method sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and
34       * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
35       * all sub-objects from the DB by their primary keys, if available.
36       * 
37       * @param document - the maintenanceDocument being evaluated
38       */
39      public void setupConvenienceObjects() {
40  
41          LOG.info("setupConvenienceObjects called");
42  
43          // setup oldAchBank convenience objects, make sure all possible sub-objects are populated
44          oldAchBank = (ACHBank) super.getOldBo();
45  
46          // setup newAchBank convenience objects, make sure all possible sub-objects are populated
47          newAchBank = (ACHBank) super.getNewBo();
48      }
49  
50      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
51  
52          LOG.info("processCustomSaveDocumentBusinessRules called");
53          // call the route rules to report all of the messages, but ignore the result
54          processCustomRouteDocumentBusinessRules(document);
55          
56          // Save always succeeds, even if there are business rule failures
57          return true;
58      }
59  
60      protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
61  
62          boolean validEntry = true;
63  
64          LOG.info("processCustomRouteDocumentBusinessRules called");
65          setupConvenienceObjects();
66  
67          String officeCode = newAchBank.getBankOfficeCode();
68          if ((ObjectUtils.isNotNull(officeCode)) && !officeCode.equals(PdpConstants.AchBankOfficeCodes.AchBankOfficeCode_O) && !officeCode.equals(PdpConstants.AchBankOfficeCodes.AchBankOfficeCode_B)) {
69              putFieldError("bankOfficeCode", OLEKeyConstants.ERROR_DOCUMENT_ACHBANKMAINT_INVALID_OFFICE_CODE);
70              validEntry = false;
71          }
72  
73          String typeCode = newAchBank.getBankTypeCode();
74          if ((typeCode != null) && !typeCode.equals(PdpConstants.AchBankTypeCodes.AchBankTypeCode_0) && !typeCode.equals(PdpConstants.AchBankTypeCodes.AchBankTypeCode_1) && !typeCode.equals(PdpConstants.AchBankTypeCodes.AchBankTypeCode_2)) {
75              putFieldError("bankTypeCode", OLEKeyConstants.ERROR_DOCUMENT_ACHBANKMAINT_INVALID_TYPE_CODE);
76              validEntry = false;
77          }
78  
79          String bankInstitutionStatusCode = newAchBank.getBankInstitutionStatusCode();
80          if ((ObjectUtils.isNotNull(bankInstitutionStatusCode) ) && !bankInstitutionStatusCode.equals(PdpConstants.ACH_BANK_INSTITUTION_CODE_DEFAULT)) {
81              putFieldError("bankInstitutionStatusCode", OLEKeyConstants.ERROR_DOCUMENT_ACHBANKMAINT_INVALID_INST_STATUS_CODE);
82              validEntry = false;
83          }
84  
85          String bankDataViewCode = newAchBank.getBankDataViewCode();
86          if ((ObjectUtils.isNotNull(bankDataViewCode) ) && !bankDataViewCode.equals(PdpConstants.ACH_BANK_DATA_VIEW_CODE_DEFAULT)) {
87              putFieldError("bankDataViewCode", OLEKeyConstants.ERROR_DOCUMENT_ACHBANKMAINT_INVALID_DATA_VIEW_CODE);
88              validEntry = false;
89          }
90  
91          return validEntry;
92      }
93     
94  }