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