View Javadoc
1   /*
2    * Copyright 2009 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.module.purap.document.validation.impl;
17  
18  import org.kuali.ole.gl.batch.ScrubberStep;
19  import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
20  import org.kuali.ole.module.purap.businessobject.PurApItem;
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.ole.sys.OLEKeyConstants;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.core.api.datetime.DateTimeService;
26  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
27  import org.kuali.rice.kns.util.KNSGlobalVariables;
28  
29  import java.util.Date;
30  import java.util.List;
31  
32  public class PaymentRequestExpiredAccountWarningValidation extends GenericValidation {
33  
34      private PurApItem itemForValidation;
35      private DateTimeService dateTimeService;
36      private ParameterService parameterService;
37  
38      public boolean validate(AttributedDocumentEvent event) {
39          boolean valid = true;
40          List<PurApAccountingLine> accountingLines = itemForValidation.getSourceAccountingLines();
41          for (PurApAccountingLine accountingLine : accountingLines) {
42              if (accountingLine.getAccount().isExpired()) {
43                  Date current = dateTimeService.getCurrentDate();
44                  Date accountExpirationDate = accountingLine.getAccount().getAccountExpirationDate();
45                  String expirationExtensionDays = parameterService.getParameterValueAsString(ScrubberStep.class, OLEConstants.SystemGroupParameterNames.GL_SCRUBBER_VALIDATION_DAYS_OFFSET);
46                  int expirationExtensionDaysInt = 3 * 30; // default to 90 days (approximately 3 months)
47  
48                  if (expirationExtensionDays.trim().length() > 0) {
49  
50                      expirationExtensionDaysInt = new Integer(expirationExtensionDays).intValue();
51                  }
52  
53                  if (!accountingLine.getAccount().isForContractsAndGrants() ||
54                          dateTimeService.dateDiff(accountExpirationDate, current, false) < expirationExtensionDaysInt) {
55                      KNSGlobalVariables.getMessageList().add(OLEKeyConstants.ERROR_ACCOUNT_EXPIRED);
56                      valid &= false;
57                      break;
58                  }
59              }
60          }
61          return valid;
62      }
63  
64      public DateTimeService getDateTimeService() {
65          return dateTimeService;
66      }
67  
68      public void setDateTimeService(DateTimeService dateTimeService) {
69          this.dateTimeService = dateTimeService;
70      }
71  
72      public PurApItem getItemForValidation() {
73          return itemForValidation;
74      }
75  
76      public void setItemForValidation(PurApItem itemForValidation) {
77          this.itemForValidation = itemForValidation;
78      }
79  
80      public ParameterService getParameterService() {
81          return parameterService;
82      }
83  
84      public void setParameterService(ParameterService parameterService) {
85          this.parameterService = parameterService;
86      }
87  
88  }