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.module.purap.document.validation.impl;
017    
018    import org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument;
019    import org.kuali.kfs.module.purap.service.PurapAccountingLineRuleHelperService;
020    import org.kuali.kfs.sys.businessobject.AccountingLine;
021    import org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService;
022    import org.kuali.kfs.sys.document.validation.GenericValidation;
023    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
024    
025    /**
026     * A validation which uses the AccountingLineRuleHelperService to validate the values on an accounting line
027     */
028    public class PurapAccountingLineDataDictionaryValidation extends GenericValidation {
029        private PurapAccountingLineRuleHelperService ruleHelperService; 
030        private AccountingLine accountingLineForValidation;
031    
032        /**
033         * Okay, okay, so yeah, I could have handled this through a bunch of DD validations.  But it's late Thursday afternoon
034         * and someone has already written this code for me...
035         * <strong>Expects an accounting line as the first parameter</strong>
036         * @see org.kuali.kfs.sys.document.validation.Validation#validate(java.lang.Object[])
037         */
038        public boolean validate(AttributedDocumentEvent event) {
039            ruleHelperService.setDocument((PurchasingAccountsPayableDocument)event.getDocument());
040            return ruleHelperService.validateAccountingLine(accountingLineForValidation);
041        }
042    
043        /**
044         * Sets the ruleHelperService attribute value.
045         * @param ruleHelperService The ruleHelperService to set.
046         */
047        public void setAccountingLineRuleHelperService(PurapAccountingLineRuleHelperService ruleHelperService) {
048            this.ruleHelperService = ruleHelperService;
049        }
050    
051        /**
052         * Gets the accountingLineForValidation attribute. 
053         * @return Returns the accountingLineForValidation.
054         */
055        public AccountingLine getAccountingLineForValidation() {
056            return accountingLineForValidation;
057        }
058    
059        /**
060         * Sets the accountingLineForValidation attribute value.
061         * @param accountingLineForValidation The accountingLineForValidation to set.
062         */
063        public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
064            this.accountingLineForValidation = accountingLineForValidation;
065        }
066    }