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.module.purap.document.validation.impl;
017
018 import java.util.Date;
019 import java.util.List;
020
021 import org.kuali.kfs.gl.batch.ScrubberStep;
022 import org.kuali.kfs.module.purap.businessobject.PurApAccountingLine;
023 import org.kuali.kfs.module.purap.businessobject.PurApItem;
024 import org.kuali.kfs.sys.KFSConstants;
025 import org.kuali.kfs.sys.KFSKeyConstants;
026 import org.kuali.kfs.sys.document.validation.GenericValidation;
027 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
028 import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
029 import org.kuali.rice.kns.service.DateTimeService;
030 import org.kuali.rice.kns.service.ParameterService;
031 import org.kuali.rice.kns.util.GlobalVariables;
032
033 public class PaymentRequestExpiredAccountWarningValidation extends GenericValidation {
034
035 private PurApItem itemForValidation;
036 private DateTimeService dateTimeService;
037 private ParameterService parameterService;
038
039 public boolean validate(AttributedDocumentEvent event) {
040 boolean valid = true;
041 List<PurApAccountingLine> accountingLines = itemForValidation.getSourceAccountingLines();
042 for (PurApAccountingLine accountingLine : accountingLines) {
043 if (accountingLine.getAccount().isExpired()) {
044 Date current = dateTimeService.getCurrentDate();
045 Date accountExpirationDate = accountingLine.getAccount().getAccountExpirationDate();
046 String expirationExtensionDays = parameterService.getParameterValue(ScrubberStep.class, KFSConstants.SystemGroupParameterNames.GL_SCRUBBER_VALIDATION_DAYS_OFFSET);
047 int expirationExtensionDaysInt = 3 * 30; // default to 90 days (approximately 3 months)
048
049 if (expirationExtensionDays.trim().length() > 0) {
050
051 expirationExtensionDaysInt = new Integer(expirationExtensionDays).intValue();
052 }
053
054 if (!accountingLine.getAccount().isForContractsAndGrants() ||
055 dateTimeService.dateDiff(accountExpirationDate, current, false) < expirationExtensionDaysInt) {
056 GlobalVariables.getMessageList().add(KFSKeyConstants.ERROR_ACCOUNT_EXPIRED);
057 valid &= false;
058 break;
059 }
060 }
061 }
062 return valid;
063 }
064
065 public DateTimeService getDateTimeService() {
066 return dateTimeService;
067 }
068
069 public void setDateTimeService(DateTimeService dateTimeService) {
070 this.dateTimeService = dateTimeService;
071 }
072
073 public PurApItem getItemForValidation() {
074 return itemForValidation;
075 }
076
077 public void setItemForValidation(PurApItem itemForValidation) {
078 this.itemForValidation = itemForValidation;
079 }
080
081 public ParameterService getParameterService() {
082 return parameterService;
083 }
084
085 public void setParameterService(ParameterService parameterService) {
086 this.parameterService = parameterService;
087 }
088
089 }