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.sys.document.validation.impl;
017
018 import static org.kuali.kfs.sys.KFSConstants.ACCOUNTING_LINE_ERRORS;
019 import static org.kuali.kfs.sys.KFSKeyConstants.ERROR_DOCUMENT_OPTIONAL_ONE_SIDED_DOCUMENT_REQUIRED_NUMBER_OF_ACCOUNTING_LINES_NOT_MET;
020 import static org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX;
021
022 import org.kuali.kfs.sys.KFSKeyConstants;
023 import org.kuali.kfs.sys.KFSPropertyConstants;
024 import org.kuali.kfs.sys.document.AccountingDocument;
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.util.GlobalVariables;
028
029 /**
030 * Validation which checks a one-sided accounting document (ie, an accounting document which only uses source accounting lines, not target)
031 * has a required number of accounting lines.
032 */
033 public class OptionalOneSidedDocumentAccountingLinesCountValidation extends GenericValidation {
034 private AccountingDocument accountingDocumentForValidation;
035
036 /**
037 * Some double-sided documents also allow for one sided entries for correcting - so if one side is empty, the other side must
038 * have at least two lines in it. The balancing rules take care of validation of amounts.
039 *
040 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
041 */
042 public boolean validate(AttributedDocumentEvent event) {
043 int sourceSectionSize = getAccountingDocumentForValidation().getSourceAccountingLines().size();
044 int targetSectionSize = getAccountingDocumentForValidation().getTargetAccountingLines().size();
045
046 if ((sourceSectionSize == 0 && targetSectionSize < 2) || (targetSectionSize == 0 && sourceSectionSize < 2)) {
047 GlobalVariables.getMessageMap().putError(ACCOUNTING_LINE_ERRORS, ERROR_DOCUMENT_OPTIONAL_ONE_SIDED_DOCUMENT_REQUIRED_NUMBER_OF_ACCOUNTING_LINES_NOT_MET);
048
049 return false;
050 }
051
052 return true;
053 }
054
055 /**
056 * Gets the accountingDocumentForValdation attribute.
057 * @return Returns the accountingDocumentForValdation.
058 */
059 public AccountingDocument getAccountingDocumentForValidation() {
060 return accountingDocumentForValidation;
061 }
062
063 /**
064 * Sets the accountingDocumentForValdation attribute value.
065 * @param accountingDocumentForValdation The accountingDocumentForValdation to set.
066 */
067 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
068 this.accountingDocumentForValidation = accountingDocumentForValidation;
069 }
070
071
072 }