View Javadoc
1   /*
2    * Copyright 2010 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.purap.document.validation.impl;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.module.purap.PurapKeyConstants;
20  import org.kuali.ole.module.purap.businessobject.NegativePaymentRequestApprovalLimit;
21  import org.kuali.ole.sys.OLEPropertyConstants;
22  import org.kuali.rice.kns.document.MaintenanceDocument;
23  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
24  
25  /**
26   * Business rules for the NegativePaymentRequestApprovalLimit maintenance document
27   */
28  public class NegativePaymentRequestApprovalLimitRule extends MaintenanceDocumentRuleBase {
29  
30      /**
31       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomApproveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
32       */
33      @Override
34      protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
35          boolean result = super.processCustomApproveDocumentBusinessRules(document);
36          final NegativePaymentRequestApprovalLimit limit = (NegativePaymentRequestApprovalLimit) getNewBo();
37          result &= checkExclusiveOrganizationCodeAndAccountNumber(limit);
38          return result;
39      }
40  
41      /**
42       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
43       */
44      @Override
45      protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
46          boolean result = super.processCustomRouteDocumentBusinessRules(document);
47          final NegativePaymentRequestApprovalLimit limit = (NegativePaymentRequestApprovalLimit) getNewBo();
48          result &= checkExclusiveOrganizationCodeAndAccountNumber(limit);
49          return result;
50      }
51  
52      /**
53       * Checks that organization code and account number aren't both specified on a new NegativePaymentRequestApprovalLimit
54       *
55       * @param limit the NegativePaymentRequestApprovalLimit to check
56       * @return true if the rule passed, false otherwise (with error message added)
57       */
58      protected boolean checkExclusiveOrganizationCodeAndAccountNumber(NegativePaymentRequestApprovalLimit limit) {
59          if (!StringUtils.isBlank(limit.getOrganizationCode()) && !StringUtils.isBlank(limit.getAccountNumber())) {
60              putFieldError(OLEPropertyConstants.ORGANIZATION_CODE, PurapKeyConstants.ERROR_NEGATIVE_PAYMENT_REQUEST_APPROVAL_LIMIT_ORG_AND_ACCOUNT_EXCLUSIVE, new String[]{});
61              putFieldError(OLEPropertyConstants.ACCOUNT_NUMBER, PurapKeyConstants.ERROR_NEGATIVE_PAYMENT_REQUEST_APPROVAL_LIMIT_ORG_AND_ACCOUNT_EXCLUSIVE, new String[]{});
62              return false;
63          }
64          return true;
65      }
66  
67  }