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 static org.kuali.kfs.sys.KFSPropertyConstants.REVERSAL_DATE;
019 import static org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX;
020
021 import org.kuali.kfs.fp.document.JournalVoucherDocument;
022 import org.kuali.kfs.sys.KFSKeyConstants;
023 import org.kuali.kfs.sys.context.SpringContext;
024 import org.kuali.kfs.sys.document.validation.GenericValidation;
025 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
026 import org.kuali.rice.kns.service.DateTimeService;
027 import org.kuali.rice.kns.util.GlobalVariables;
028
029 /**
030 * A validation of the reversal date on a Journal Voucher document
031 */
032 public class JournalVoucherReversalDateValidation extends GenericValidation {
033 private JournalVoucherDocument journalVoucherForValidation;
034
035 /**
036 * Checks that if the reveral date for the document is not null, that the reversal date has not already occurred
037 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
038 */
039 public boolean validate(AttributedDocumentEvent event) {
040 java.sql.Date today = SpringContext.getBean(DateTimeService.class).getCurrentSqlDateMidnight();
041 if (null != getJournalVoucherForValidation().getReversalDate() && getJournalVoucherForValidation().getReversalDate().before(today)) {
042 GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + REVERSAL_DATE, KFSKeyConstants.ERROR_DOCUMENT_INCORRECT_REVERSAL_DATE);
043 return false;
044 }
045 return true;
046 }
047
048 /**
049 * Gets the journalVoucherForValidation attribute.
050 * @return Returns the journalVoucherForValidation.
051 */
052 public JournalVoucherDocument getJournalVoucherForValidation() {
053 return journalVoucherForValidation;
054 }
055
056 /**
057 * Sets the journalVoucherForValidation attribute value.
058 * @param journalVoucherForValidation The journalVoucherForValidation to set.
059 */
060 public void setJournalVoucherForValidation(JournalVoucherDocument journalVoucherForDocument) {
061 this.journalVoucherForValidation = journalVoucherForDocument;
062 }
063 }