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.sys.document.validation.impl;
17  
18  import static org.kuali.ole.sys.OLEConstants.ACCOUNTING_LINE_ERRORS;
19  import static org.kuali.ole.sys.OLEKeyConstants.ERROR_DOCUMENT_OPTIONAL_ONE_SIDED_DOCUMENT_REQUIRED_NUMBER_OF_ACCOUNTING_LINES_NOT_MET;
20  
21  import org.kuali.ole.sys.document.AccountingDocument;
22  import org.kuali.ole.sys.document.validation.GenericValidation;
23  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24  import org.kuali.rice.krad.util.GlobalVariables;
25  
26  /**
27   * Validation which checks a one-sided accounting document (ie, an accounting document which only uses source accounting lines, not target)
28   * has a required number of accounting lines.
29   */
30  public class OptionalOneSidedDocumentAccountingLinesCountValidation extends GenericValidation {
31      private AccountingDocument accountingDocumentForValidation;
32  
33      /**
34       * Some double-sided documents also allow for one sided entries for correcting - so if one side is empty, the other side must
35       * have at least two lines in it. The balancing rules take care of validation of amounts.
36       * 
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          int sourceSectionSize = getAccountingDocumentForValidation().getSourceAccountingLines().size();
41          int targetSectionSize = getAccountingDocumentForValidation().getTargetAccountingLines().size();
42  
43          if ((sourceSectionSize == 0 && targetSectionSize < 2) || (targetSectionSize == 0 && sourceSectionSize < 2)) {
44              GlobalVariables.getMessageMap().putError(ACCOUNTING_LINE_ERRORS, ERROR_DOCUMENT_OPTIONAL_ONE_SIDED_DOCUMENT_REQUIRED_NUMBER_OF_ACCOUNTING_LINES_NOT_MET);
45  
46              return false;
47          }
48  
49          return true;
50      }
51  
52      /**
53       * Gets the accountingDocumentForValdation attribute. 
54       * @return Returns the accountingDocumentForValdation.
55       */
56      public AccountingDocument getAccountingDocumentForValidation() {
57          return accountingDocumentForValidation;
58      }
59  
60      /**
61       * Sets the accountingDocumentForValdation attribute value.
62       * @param accountingDocumentForValdation The accountingDocumentForValdation to set.
63       */
64      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
65          this.accountingDocumentForValidation = accountingDocumentForValidation;
66      }
67  
68      
69  }