1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.validation.impl;
17
18 import org.kuali.ole.module.purap.PurapKeyConstants;
19 import org.kuali.ole.module.purap.PurapPropertyConstants;
20 import org.kuali.ole.module.purap.document.PaymentRequestDocument;
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.kew.api.WorkflowDocument;
26 import org.kuali.rice.krad.service.BusinessObjectService;
27 import org.kuali.rice.krad.service.PersistenceService;
28 import org.kuali.rice.krad.util.GlobalVariables;
29 import org.kuali.rice.krad.util.ObjectUtils;
30
31 import java.util.Map;
32
33 public class PaymentRequestPayDateNotPastValidation extends GenericValidation {
34
35 private PurapService purapService;
36 private PersistenceService persistenceService;
37 private BusinessObjectService businessObjectService;
38
39
40
41
42 public boolean validate(AttributedDocumentEvent event) {
43 boolean valid = true;
44 PaymentRequestDocument document = (PaymentRequestDocument) event.getDocument();
45 GlobalVariables.getMessageMap().clearErrorPath();
46 GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
47
48 java.sql.Date paymentRequestPayDate = document.getPaymentRequestPayDate();
49 if (ObjectUtils.isNotNull(paymentRequestPayDate) && purapService.isDateInPast(paymentRequestPayDate)) {
50
51 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
52 if (workflowDocument.isInitiated() || workflowDocument.isSaved()) {
53
54
55 valid &= false;
56 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PAYMENT_REQUEST_PAY_DATE, PurapKeyConstants.ERROR_INVALID_PAY_DATE);
57 } else {
58
59
60
61 PaymentRequestDocument paymentRequestDocumentFromDatabase = retrievePaymentRequestDocumentFromDatabase(document);
62
63 if (ObjectUtils.isNull(paymentRequestDocumentFromDatabase)) {
64
65 throw new NullPointerException("Unable to find payment request document " + document.getDocumentNumber() + " from database");
66 }
67
68 java.sql.Date paymentRequestPayDateFromDatabase = paymentRequestDocumentFromDatabase.getPaymentRequestPayDate();
69 if (ObjectUtils.isNull(paymentRequestPayDateFromDatabase) || !paymentRequestPayDateFromDatabase.equals(paymentRequestPayDate)) {
70 valid &= false;
71 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PAYMENT_REQUEST_PAY_DATE, PurapKeyConstants.ERROR_INVALID_PAY_DATE);
72 }
73 }
74 }
75
76 GlobalVariables.getMessageMap().clearErrorPath();
77
78 return valid;
79 }
80
81
82
83
84
85
86
87 protected PaymentRequestDocument retrievePaymentRequestDocumentFromDatabase(PaymentRequestDocument document) {
88 Map primaryKeyValues = persistenceService.getPrimaryKeyFieldValues(document);
89 return (PaymentRequestDocument) businessObjectService.findByPrimaryKey(document.getClass(), primaryKeyValues);
90 }
91
92 public PurapService getPurapService() {
93 return purapService;
94 }
95
96 public void setPurapService(PurapService purapService) {
97 this.purapService = purapService;
98 }
99
100 public PersistenceService getPersistenceService() {
101 return persistenceService;
102 }
103
104 public void setPersistenceService(PersistenceService persistenceService) {
105 this.persistenceService = persistenceService;
106 }
107
108 public BusinessObjectService getBusinessObjectService() {
109 return businessObjectService;
110 }
111
112 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
113 this.businessObjectService = businessObjectService;
114 }
115
116 }