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.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX;
19  
20  import org.kuali.ole.sys.OLEKeyConstants;
21  import org.kuali.ole.sys.OLEPropertyConstants;
22  import org.kuali.ole.sys.document.AccountingDocument;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  /**
28   * Validation which checks a one-sided accounting document (ie, an accounting document which only uses source accounting lines, not target)
29   * has a required number of accounting lines.
30   */
31  public class OneSidedRequiredAccountingLinesCountValidation extends GenericValidation {
32      private AccountingDocument accountingDocumentForValidation;
33      private int requiredMinimumCount = 1; // default - you need at least one accounting line
34  
35      /**
36       * Validates that the accountingDocumentForValidation has at least the requiredMinimumCount accounting lines
37       * in its sourceAccountingLines (yep, it's assumed that one-sided accounting docs *always* use source...isn't that dumb?)
38       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
39       */
40      public boolean validate(AttributedDocumentEvent event) {
41          if (getAccountingDocumentForValidation().getSourceAccountingLines().size() < getRequiredMinimumCount()) {
42              GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + OLEPropertyConstants.SOURCE_ACCOUNTING_LINES, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNTING_LINES_NO_SINGLE_SECTION_ACCOUNTING_LINES);
43              return false;
44          }
45          return true;
46      }
47  
48      /**
49       * Gets the accountingDocumentForValdation attribute. 
50       * @return Returns the accountingDocumentForValdation.
51       */
52      public AccountingDocument getAccountingDocumentForValidation() {
53          return accountingDocumentForValidation;
54      }
55  
56      /**
57       * Sets the accountingDocumentForValdation attribute value.
58       * @param accountingDocumentForValdation The accountingDocumentForValdation to set.
59       */
60      public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
61          this.accountingDocumentForValidation = accountingDocumentForValidation;
62      }
63  
64      /**
65       * Gets the requiredMinimumCount attribute. 
66       * @return Returns the requiredMinimumCount.
67       */
68      public int getRequiredMinimumCount() {
69          return requiredMinimumCount;
70      }
71  
72      /**
73       * Sets the requiredMinimumCount attribute value.
74       * @param requiredMinimumCount The requiredMinimumCount to set.
75       */
76      public void setRequiredMinimumCount(int requiredCount) {
77          this.requiredMinimumCount = requiredCount;
78      }
79  }