View Javadoc

1   /*
2    * Copyright 2009 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.fp.document.validation.impl;
17  
18  import org.kuali.ole.fp.document.AdvanceDepositDocument;
19  import org.kuali.ole.sys.OLEConstants;
20  import org.kuali.ole.sys.OLEKeyConstants;
21  import org.kuali.ole.sys.businessobject.AccountingLine;
22  import org.kuali.ole.sys.document.validation.GenericValidation;
23  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24  import org.kuali.ole.sys.service.ElectronicPaymentClaimingService;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  /**
28   * Validates that if the given advance deposit document has any electronic fund accounting lines,
29   * that all accounting lines on the document go to the electronic funds account
30   */
31  public class AdvanceDepositIfAnyElectronicFundAccountingLineAllElectronicFundValidation extends GenericValidation {
32      private AdvanceDepositDocument advanceDepositDocumentForValidation;
33      private ElectronicPaymentClaimingService electronicPaymentClaimingService;
34  
35      /**
36       * Validates the advance deposit document, that if it has one eft accounting line, all accounting lines represent electronic funds
37       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
38       */
39      public boolean validate(AttributedDocumentEvent event) {
40          boolean result = true; // assume that the document works just fine
41          if (anyAccountingLinesRepresentElectronicPayments() && !allAccountingLinesRepresentElectronicPayments()) {
42              GlobalVariables.getMessageMap().putError(OLEConstants.ACCOUNTING_LINE_ERRORS, OLEKeyConstants.AdvanceDeposit.ERROR_DOCUMENT_ADVANCE_DEPOSIT_INCORRECT_ELECTRONIC_PAYMENT_STATE, new String[] {});
43              result = false; // oh you document! you've disappointed me!
44          }
45          return result;
46      }
47      
48      /**
49       * Determines if any of the accounting lines on the document represent electronic payments
50       * @return true if the document contains an electronic transfer accounting line, false if none do
51       */
52      protected boolean anyAccountingLinesRepresentElectronicPayments() {
53          for (Object accountingLineAsObject : getAdvanceDepositDocumentForValidation().getSourceAccountingLines()) {
54              final AccountingLine accountingLine = (AccountingLine)accountingLineAsObject;
55              if (getElectronicPaymentClaimingService().representsElectronicFundAccount(accountingLine)) {
56                  return true;
57              }
58          }
59          return false;
60      }
61      
62      /**
63       * Determines if all of the accounting lines on the document represent electronic payments
64       * @return true if the document contains all electronic transfer accounting line, false if any accounting line does not represent an electronic payment
65       */
66      protected boolean allAccountingLinesRepresentElectronicPayments() {
67          for (Object accountingLineAsObject : getAdvanceDepositDocumentForValidation().getSourceAccountingLines()) {
68              final AccountingLine accountingLine = (AccountingLine)accountingLineAsObject;
69              if (!getElectronicPaymentClaimingService().representsElectronicFundAccount(accountingLine)) {
70                  return false;
71              }
72          }
73          return true;
74      }
75  
76      /**
77       * Gets the advanceDepositDocumentForValidation attribute. 
78       * @return Returns the advanceDepositDocumentForValidation.
79       */
80      public AdvanceDepositDocument getAdvanceDepositDocumentForValidation() {
81          return advanceDepositDocumentForValidation;
82      }
83  
84      /**
85       * Sets the advanceDepositDocumentForValidation attribute value.
86       * @param advanceDepositDocumentForValidation The advanceDepositDocumentForValidation to set.
87       */
88      public void setAdvanceDepositDocumentForValidation(AdvanceDepositDocument documentForValidation) {
89          this.advanceDepositDocumentForValidation = documentForValidation;
90      }
91  
92      /**
93       * Gets the electronicPaymentClaimingService attribute. 
94       * @return Returns the electronicPaymentClaimingService.
95       */
96      public ElectronicPaymentClaimingService getElectronicPaymentClaimingService() {
97          return electronicPaymentClaimingService;
98      }
99  
100     /**
101      * Sets the electronicPaymentClaimingService attribute value.
102      * @param electronicPaymentClaimingService The electronicPaymentClaimingService to set.
103      */
104     public void setElectronicPaymentClaimingService(ElectronicPaymentClaimingService electronicPaymentClaimingService) {
105         this.electronicPaymentClaimingService = electronicPaymentClaimingService;
106     }
107 }