View Javadoc
1   /*
2    * Copyright 2007 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.cg.document.validation.impl;
17  
18  import java.sql.Date;
19  
20  import org.kuali.ole.module.cg.document.ProposalAwardCloseDocument;
21  import org.kuali.ole.sys.OLEKeyConstants;
22  import org.kuali.ole.sys.OLEPropertyConstants;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.rice.core.api.datetime.DateTimeService;
25  import org.kuali.rice.kns.rules.TransactionalDocumentRuleBase;
26  import org.kuali.rice.kns.service.DataDictionaryService;
27  import org.kuali.rice.krad.document.Document;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  
30  /**
31   * Rules for handling Closes.
32   */
33  public class CloseDocumentRule extends TransactionalDocumentRuleBase {
34  
35      @Override
36      public boolean processCustomRouteDocumentBusinessRules(Document document) {
37          ProposalAwardCloseDocument closeDocument = (ProposalAwardCloseDocument) document;
38          Date today = SpringContext.getBean(DateTimeService.class).getCurrentSqlDateMidnight();
39          Date closeDate = closeDocument.getUserInitiatedCloseDate();
40          Date closeOnOrBeforeDate = closeDocument.getCloseOnOrBeforeDate();
41          DataDictionaryService dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
42  
43          boolean isValid = true;
44          boolean closeDateIsNotNull = true;
45          boolean closeDateIsTodayOrLater = true;
46          boolean closeOnOrBeforeDateIsNotNull = true;
47          boolean closeOnOrBeforeDateIsTodayOrLater = true;
48          boolean closeOnOrBeforeDateIsCloseDateOrEarlier = true;
49  
50          String closeDateLabel = dataDictionaryService.getAttributeLabel(ProposalAwardCloseDocument.class, "userInitiatedCloseDate");
51          String closeOnOrBeforeDateLabel = dataDictionaryService.getAttributeLabel(ProposalAwardCloseDocument.class, "closeOnOrBeforeDate");
52  
53          GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
54          if (closeDate == null) {
55              closeDateIsNotNull = false;
56              String label = dataDictionaryService.getAttributeLabel(ProposalAwardCloseDocument.class, "userInitiatedCloseDate");
57          } else if (today.getTime() > closeDate.getTime()) {
58              closeDateIsTodayOrLater = false;
59              GlobalVariables.getMessageMap().putError("userInitiatedCloseDate", OLEKeyConstants.ContractsAndGrants.USER_INITIATED_DATE_TOO_EARLY, closeDateLabel);
60          }
61          if (closeOnOrBeforeDate == null) {
62              closeOnOrBeforeDateIsNotNull = false;
63          } else if (today.getTime() > closeOnOrBeforeDate.getTime()) {
64              closeOnOrBeforeDateIsTodayOrLater = false;
65              GlobalVariables.getMessageMap().putError("closeOnOrBeforeDate", OLEKeyConstants.ContractsAndGrants.CLOSE_ON_OR_BEFORE_DATE_TOO_EARLY, closeOnOrBeforeDateLabel);
66          } else if (closeOnOrBeforeDate.getTime() > closeDate.getTime()) {
67              closeOnOrBeforeDateIsCloseDateOrEarlier = false;
68              GlobalVariables.getMessageMap().putError("closeOnOrBeforeDate", OLEKeyConstants.ContractsAndGrants.CLOSE_ON_OR_BEFORE_DATE_TOO_LATE, closeOnOrBeforeDateLabel, closeDateLabel);
69          }
70          GlobalVariables.getMessageMap().removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
71  
72          isValid = closeDateIsNotNull && closeDateIsTodayOrLater && closeOnOrBeforeDateIsNotNull && closeOnOrBeforeDateIsTodayOrLater && closeOnOrBeforeDateIsCloseDateOrEarlier;
73          return isValid;
74      }
75  
76  }