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.fp.document.validation.impl;
017
018 import org.kuali.kfs.sys.KFSConstants;
019 import org.kuali.kfs.sys.KFSKeyConstants;
020 import org.kuali.kfs.sys.KFSPropertyConstants;
021 import org.kuali.kfs.sys.document.AccountingDocument;
022 import org.kuali.kfs.sys.document.validation.GenericValidation;
023 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
024 import org.kuali.rice.kns.util.GlobalVariables;
025 import org.kuali.rice.kns.util.MessageMap;
026
027 public class DisbursementVoucherAccountingLineCountValidation extends GenericValidation {
028 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherAccountingLineCountValidation.class);
029
030 private AccountingDocument accountingDocumentForValidation;
031
032 /**
033 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
034 */
035 public boolean validate(AttributedDocumentEvent event) {
036 LOG.debug("validate start");
037 boolean isValid = true;
038
039 MessageMap errors = GlobalVariables.getMessageMap();
040 errors.addToErrorPath(KFSPropertyConstants.DOCUMENT);
041
042 if (accountingDocumentForValidation.getSourceAccountingLines().size() < 1) {
043 errors.putErrorWithoutFullErrorPath(KFSConstants.ACCOUNTING_LINE_ERRORS, KFSKeyConstants.ERROR_NO_ACCOUNTING_LINES);
044 isValid = false;
045 }
046
047 errors.removeFromErrorPath(KFSPropertyConstants.DOCUMENT);
048
049 return isValid;
050 }
051
052 /**
053 * Sets the accountingDocumentForValidation attribute value.
054 *
055 * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
056 */
057 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
058 this.accountingDocumentForValidation = accountingDocumentForValidation;
059 }
060
061 /**
062 * Gets the accountingDocumentForValidation attribute.
063 * @return Returns the accountingDocumentForValidation.
064 */
065 public AccountingDocument getAccountingDocumentForValidation() {
066 return accountingDocumentForValidation;
067 }
068
069 }