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