View Javadoc
1   /*
2    * Copyright 2008-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.module.purap.PurapConstants;
19  import org.kuali.ole.module.purap.PurapKeyConstants;
20  import org.kuali.ole.module.purap.document.InvoiceDocument;
21  import org.kuali.ole.module.purap.document.service.PurapService;
22  import org.kuali.ole.sys.OLEPropertyConstants;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.kns.util.KNSGlobalVariables;
26  import org.kuali.rice.kns.util.MessageList;
27  import org.kuali.rice.krad.util.GlobalVariables;
28  import org.kuali.rice.krad.util.ObjectUtils;
29  
30  public class InvoicePayDateNotOverThresholdDaysAwayValidation extends GenericValidation {
31  
32      private PurapService purapService;
33  
34      /**
35       * This method side-effects a warning, and consequently should not be used in such a way as to cause validation to fail. Returns
36       * a boolean for ease of testing. If the threshold days value is positive, the method will test future dates accurately. If the
37       * the threshold days value is negative, the method will test past dates.
38       */
39      public boolean validate(AttributedDocumentEvent event) {
40          InvoiceDocument document = (InvoiceDocument) event.getDocument();
41          GlobalVariables.getMessageMap().clearErrorPath();
42          GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
43  
44          int thresholdDays = PurapConstants.PREQ_PAY_DATE_DAYS_BEFORE_WARNING;
45          if ((document.getInvoicePayDate() != null) && purapService.isDateMoreThanANumberOfDaysAway(document.getInvoicePayDate(), thresholdDays)) {
46              if (ObjectUtils.isNull(KNSGlobalVariables.getMessageList())) {
47                  KNSGlobalVariables.setMessageList(new MessageList());
48              }
49              if (!KNSGlobalVariables.getMessageList().contains(PurapKeyConstants.WARNING_PAYMENT_REQUEST_PAYDATE_OVER_THRESHOLD_DAYS)) {
50                  KNSGlobalVariables.getMessageList().add(PurapKeyConstants.WARNING_PAYMENT_REQUEST_PAYDATE_OVER_THRESHOLD_DAYS);
51              }
52          }
53  
54          GlobalVariables.getMessageMap().clearErrorPath();
55  
56          //always returns true, as this is a warning, not an error
57          return true;
58      }
59  
60      public PurapService getPurapService() {
61          return purapService;
62      }
63  
64      public void setPurapService(PurapService purapService) {
65          this.purapService = purapService;
66      }
67  
68  }