View Javadoc
1   /*
2    * Copyright 2008 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 static org.kuali.ole.fp.document.validation.impl.AuxiliaryVoucherDocumentRuleConstants.RESTRICTED_PERIOD_CODES;
19  import static org.kuali.ole.sys.OLEConstants.ACCOUNTING_PERIOD_ACTIVE_INDICATOR_FIELD;
20  import static org.kuali.ole.sys.OLEKeyConstants.AuxiliaryVoucher.ERROR_ACCOUNTING_PERIOD_OUT_OF_RANGE;
21  
22  import org.kuali.ole.coa.businessobject.AccountingPeriod;
23  import org.kuali.ole.coa.service.AccountingPeriodService;
24  import org.kuali.ole.fp.document.AuxiliaryVoucherDocument;
25  import org.kuali.ole.sys.context.SpringContext;
26  import org.kuali.ole.sys.document.validation.GenericValidation;
27  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
28  import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
29  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
30  import org.kuali.rice.krad.util.GlobalVariables;
31  
32  /**
33   * A validation for the Auxiliary Voucher document, this checks that the given accounting period on
34   * the document is allowed by the associated system paramter.
35   */
36  public class AuxiliaryVoucherAccountingPeriodAllowedByParameterValidation extends GenericValidation {
37      private AuxiliaryVoucherDocument auxiliaryVoucherDocumentForValidation;
38      private ParameterService parameterService;
39      private AccountingPeriodService accountingPeriodService;
40  
41      /**
42       * Using the OLE-FP / AuxiliaryVoucherDocument / RestrictedPeriodCodes parameter, checks that the accounting period specified on the document is valid.
43       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
44       */
45      public boolean validate(AttributedDocumentEvent event) {
46          boolean valid = true;
47          AccountingPeriod acctPeriod = getAccountingPeriodService().getByPeriod(auxiliaryVoucherDocumentForValidation.getPostingPeriodCode(), auxiliaryVoucherDocumentForValidation.getPostingYear());
48  
49          valid = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(AuxiliaryVoucherDocument.class, RESTRICTED_PERIOD_CODES, auxiliaryVoucherDocumentForValidation.getPostingPeriodCode()).evaluationSucceeds();
50          if (!valid) {
51              GlobalVariables.getMessageMap().putError(ACCOUNTING_PERIOD_ACTIVE_INDICATOR_FIELD, ERROR_ACCOUNTING_PERIOD_OUT_OF_RANGE);
52          }
53          
54          return valid;
55      }
56  
57      /**
58       * Gets the auxiliaryVoucherDocumentForValidation attribute. 
59       * @return Returns the auxiliaryVoucherDocumentForValidation.
60       */
61      public AuxiliaryVoucherDocument getAuxiliaryVoucherDocumentForValidation() {
62          return auxiliaryVoucherDocumentForValidation;
63      }
64  
65      /**
66       * Sets the auxiliaryVoucherDocumentForValidation attribute value.
67       * @param auxiliaryVoucherDocumentForValidation The auxiliaryVoucherDocumentForValidation to set.
68       */
69      public void setAuxiliaryVoucherDocumentForValidation(AuxiliaryVoucherDocument auxiliaryVoucherDocumentForValidation) {
70          this.auxiliaryVoucherDocumentForValidation = auxiliaryVoucherDocumentForValidation;
71      }
72  
73      /**
74       * Gets the parameterService attribute. 
75       * @return Returns the parameterService.
76       */
77      public ParameterService getParameterService() {
78          return parameterService;
79      }
80  
81      /**
82       * Sets the parameterService attribute value.
83       * @param parameterService The parameterService to set.
84       */
85      public void setParameterService(ParameterService parameterService) {
86          this.parameterService = parameterService;
87      }
88  
89      /**
90       * Gets the accountingPeriodService attribute. 
91       * @return Returns the accountingPeriodService.
92       */
93      public AccountingPeriodService getAccountingPeriodService() {
94          return accountingPeriodService;
95      }
96  
97      /**
98       * Sets the accountingPeriodService attribute value.
99       * @param accountingPeriodService The accountingPeriodService to set.
100      */
101     public void setAccountingPeriodService(AccountingPeriodService accountingPeriodService) {
102         this.accountingPeriodService = accountingPeriodService;
103     }
104 }