001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.fp.document.validation.impl;
017
018 import org.kuali.kfs.fp.document.AdvanceDepositDocument;
019 import org.kuali.kfs.sys.KFSConstants;
020 import org.kuali.kfs.sys.KFSKeyConstants;
021 import org.kuali.kfs.sys.businessobject.AccountingLine;
022 import org.kuali.kfs.sys.document.validation.GenericValidation;
023 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
024 import org.kuali.kfs.sys.service.ElectronicPaymentClaimingService;
025 import org.kuali.rice.kns.util.GlobalVariables;
026
027 /**
028 * Validates that if the given advance deposit document has any electronic fund accounting lines,
029 * that all accounting lines on the document go to the electronic funds account
030 */
031 public class AdvanceDepositIfAnyElectronicFundAccountingLineAllElectronicFundValidation extends GenericValidation {
032 private AdvanceDepositDocument advanceDepositDocumentForValidation;
033 private ElectronicPaymentClaimingService electronicPaymentClaimingService;
034
035 /**
036 * Validates the advance deposit document, that if it has one eft accounting line, all accounting lines represent electronic funds
037 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
038 */
039 public boolean validate(AttributedDocumentEvent event) {
040 boolean result = true; // assume that the document works just fine
041 if (anyAccountingLinesRepresentElectronicPayments() && !allAccountingLinesRepresentElectronicPayments()) {
042 GlobalVariables.getMessageMap().putError(KFSConstants.ACCOUNTING_LINE_ERRORS, KFSKeyConstants.AdvanceDeposit.ERROR_DOCUMENT_ADVANCE_DEPOSIT_INCORRECT_ELECTRONIC_PAYMENT_STATE, new String[] {});
043 result = false; // oh you document! you've disappointed me!
044 }
045 return result;
046 }
047
048 /**
049 * Determines if any of the accounting lines on the document represent electronic payments
050 * @return true if the document contains an electronic transfer accounting line, false if none do
051 */
052 protected boolean anyAccountingLinesRepresentElectronicPayments() {
053 for (Object accountingLineAsObject : getAdvanceDepositDocumentForValidation().getSourceAccountingLines()) {
054 final AccountingLine accountingLine = (AccountingLine)accountingLineAsObject;
055 if (getElectronicPaymentClaimingService().representsElectronicFundAccount(accountingLine)) {
056 return true;
057 }
058 }
059 return false;
060 }
061
062 /**
063 * Determines if all of the accounting lines on the document represent electronic payments
064 * @return true if the document contains all electronic transfer accounting line, false if any accounting line does not represent an electronic payment
065 */
066 protected boolean allAccountingLinesRepresentElectronicPayments() {
067 for (Object accountingLineAsObject : getAdvanceDepositDocumentForValidation().getSourceAccountingLines()) {
068 final AccountingLine accountingLine = (AccountingLine)accountingLineAsObject;
069 if (!getElectronicPaymentClaimingService().representsElectronicFundAccount(accountingLine)) {
070 return false;
071 }
072 }
073 return true;
074 }
075
076 /**
077 * Gets the advanceDepositDocumentForValidation attribute.
078 * @return Returns the advanceDepositDocumentForValidation.
079 */
080 public AdvanceDepositDocument getAdvanceDepositDocumentForValidation() {
081 return advanceDepositDocumentForValidation;
082 }
083
084 /**
085 * Sets the advanceDepositDocumentForValidation attribute value.
086 * @param advanceDepositDocumentForValidation The advanceDepositDocumentForValidation to set.
087 */
088 public void setAdvanceDepositDocumentForValidation(AdvanceDepositDocument documentForValidation) {
089 this.advanceDepositDocumentForValidation = documentForValidation;
090 }
091
092 /**
093 * Gets the electronicPaymentClaimingService attribute.
094 * @return Returns the electronicPaymentClaimingService.
095 */
096 public ElectronicPaymentClaimingService getElectronicPaymentClaimingService() {
097 return electronicPaymentClaimingService;
098 }
099
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 }