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.sys.OLEConstants.DOCUMENT_ERRORS;
19  import static org.kuali.ole.sys.OLEKeyConstants.ERROR_DOCUMENT_ACCOUNTING_PERIOD_CLOSED;
20  
21  import org.kuali.ole.coa.businessobject.AccountingPeriod;
22  import org.kuali.ole.coa.service.AccountingPeriodService;
23  import org.kuali.ole.fp.document.AuxiliaryVoucherDocument;
24  import org.kuali.ole.sys.document.validation.GenericValidation;
25  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  
28  /**
29   * Validates that the accounting period given by the document is currently open
30   */
31  public class AuxiliaryVoucherAccountingPeriodOpenValidation extends GenericValidation {
32      private AuxiliaryVoucherDocument auxliaryVoucherDocumentForValidation;
33      private AccountingPeriodService accountingPeriodService;
34  
35      /**
36       * Uses the accounting period service to get the accounting period for the document and checks that it's open
37       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
38       */
39      public boolean validate(AttributedDocumentEvent event) {
40          AccountingPeriod acctPeriod = getAccountingPeriodService().getByPeriod(auxliaryVoucherDocumentForValidation.getPostingPeriodCode(), auxliaryVoucherDocumentForValidation.getPostingYear());
41          
42          //  can't post into a closed period
43          if (acctPeriod == null || acctPeriod.isActive()) {
44              GlobalVariables.getMessageMap().putError(DOCUMENT_ERRORS, ERROR_DOCUMENT_ACCOUNTING_PERIOD_CLOSED);
45              return false;
46          }
47          
48          return true;
49      }
50  
51      /**
52       * Gets the accountingPeriodService attribute. 
53       * @return Returns the accountingPeriodService.
54       */
55      public AccountingPeriodService getAccountingPeriodService() {
56          return accountingPeriodService;
57      }
58  
59      /**
60       * Sets the accountingPeriodService attribute value.
61       * @param accountingPeriodService The accountingPeriodService to set.
62       */
63      public void setAccountingPeriodService(AccountingPeriodService accountingPeriodService) {
64          this.accountingPeriodService = accountingPeriodService;
65      }
66  
67      /**
68       * Gets the auxliaryVoucherDocumentForValidation attribute. 
69       * @return Returns the auxliaryVoucherDocumentForValidation.
70       */
71      public AuxiliaryVoucherDocument getAuxliaryVoucherDocumentForValidation() {
72          return auxliaryVoucherDocumentForValidation;
73      }
74  
75      /**
76       * Sets the auxliaryVoucherDocumentForValidation attribute value.
77       * @param auxliaryVoucherDocumentForValidation The auxliaryVoucherDocumentForValidation to set.
78       */
79      public void setAuxliaryVoucherDocumentForValidation(AuxiliaryVoucherDocument auxliaryVoucherDocumentForValidation) {
80          this.auxliaryVoucherDocumentForValidation = auxliaryVoucherDocumentForValidation;
81      }
82  }