1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 }