001/* 002 * Copyright 2008 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 */ 016package org.kuali.ole.fp.document.validation.impl; 017 018import static org.kuali.ole.fp.document.validation.impl.AuxiliaryVoucherDocumentRuleConstants.RESTRICTED_PERIOD_CODES; 019import static org.kuali.ole.sys.OLEConstants.ACCOUNTING_PERIOD_ACTIVE_INDICATOR_FIELD; 020import static org.kuali.ole.sys.OLEKeyConstants.AuxiliaryVoucher.ERROR_ACCOUNTING_PERIOD_OUT_OF_RANGE; 021 022import org.kuali.ole.coa.businessobject.AccountingPeriod; 023import org.kuali.ole.coa.service.AccountingPeriodService; 024import org.kuali.ole.fp.document.AuxiliaryVoucherDocument; 025import org.kuali.ole.sys.context.SpringContext; 026import org.kuali.ole.sys.document.validation.GenericValidation; 027import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent; 028import org.kuali.rice.core.api.parameter.ParameterEvaluatorService; 029import org.kuali.rice.coreservice.framework.parameter.ParameterService; 030import org.kuali.rice.krad.util.GlobalVariables; 031 032/** 033 * A validation for the Auxiliary Voucher document, this checks that the given accounting period on 034 * the document is allowed by the associated system paramter. 035 */ 036public class AuxiliaryVoucherAccountingPeriodAllowedByParameterValidation extends GenericValidation { 037 private AuxiliaryVoucherDocument auxiliaryVoucherDocumentForValidation; 038 private ParameterService parameterService; 039 private AccountingPeriodService accountingPeriodService; 040 041 /** 042 * Using the OLE-FP / AuxiliaryVoucherDocument / RestrictedPeriodCodes parameter, checks that the accounting period specified on the document is valid. 043 * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent) 044 */ 045 public boolean validate(AttributedDocumentEvent event) { 046 boolean valid = true; 047 AccountingPeriod acctPeriod = getAccountingPeriodService().getByPeriod(auxiliaryVoucherDocumentForValidation.getPostingPeriodCode(), auxiliaryVoucherDocumentForValidation.getPostingYear()); 048 049 valid = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(AuxiliaryVoucherDocument.class, RESTRICTED_PERIOD_CODES, auxiliaryVoucherDocumentForValidation.getPostingPeriodCode()).evaluationSucceeds(); 050 if (!valid) { 051 GlobalVariables.getMessageMap().putError(ACCOUNTING_PERIOD_ACTIVE_INDICATOR_FIELD, ERROR_ACCOUNTING_PERIOD_OUT_OF_RANGE); 052 } 053 054 return valid; 055 } 056 057 /** 058 * Gets the auxiliaryVoucherDocumentForValidation attribute. 059 * @return Returns the auxiliaryVoucherDocumentForValidation. 060 */ 061 public AuxiliaryVoucherDocument getAuxiliaryVoucherDocumentForValidation() { 062 return auxiliaryVoucherDocumentForValidation; 063 } 064 065 /** 066 * Sets the auxiliaryVoucherDocumentForValidation attribute value. 067 * @param auxiliaryVoucherDocumentForValidation The auxiliaryVoucherDocumentForValidation to set. 068 */ 069 public void setAuxiliaryVoucherDocumentForValidation(AuxiliaryVoucherDocument auxiliaryVoucherDocumentForValidation) { 070 this.auxiliaryVoucherDocumentForValidation = auxiliaryVoucherDocumentForValidation; 071 } 072 073 /** 074 * Gets the parameterService attribute. 075 * @return Returns the parameterService. 076 */ 077 public ParameterService getParameterService() { 078 return parameterService; 079 } 080 081 /** 082 * Sets the parameterService attribute value. 083 * @param parameterService The parameterService to set. 084 */ 085 public void setParameterService(ParameterService parameterService) { 086 this.parameterService = parameterService; 087 } 088 089 /** 090 * Gets the accountingPeriodService attribute. 091 * @return Returns the accountingPeriodService. 092 */ 093 public AccountingPeriodService getAccountingPeriodService() { 094 return accountingPeriodService; 095 } 096 097 /** 098 * Sets the accountingPeriodService attribute value. 099 * @param accountingPeriodService The accountingPeriodService to set. 100 */ 101 public void setAccountingPeriodService(AccountingPeriodService accountingPeriodService) { 102 this.accountingPeriodService = accountingPeriodService; 103 } 104}