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.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapKeyConstants;
20 import org.kuali.ole.module.purap.PurapPropertyConstants;
21 import org.kuali.ole.module.purap.document.VendorCreditMemoDocument;
22 import org.kuali.ole.module.purap.document.service.PaymentRequestService;
23 import org.kuali.ole.select.document.OleVendorCreditMemoDocument;
24 import org.kuali.ole.sys.OLEKeyConstants;
25 import org.kuali.ole.sys.document.validation.GenericValidation;
26 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
27 import org.kuali.rice.kns.service.DataDictionaryService;
28 import org.kuali.rice.krad.bo.BusinessObject;
29 import org.kuali.rice.krad.util.GlobalVariables;
30 import org.kuali.rice.krad.util.ObjectUtils;
31
32 public class VendorCreditMemoInitTabRequiredFieldsValidation extends GenericValidation {
33
34 private DataDictionaryService dataDictionaryService;
35 private PaymentRequestService paymentRequestService;
36
37
38
39
40
41 public boolean validate(AttributedDocumentEvent event) {
42 OleVendorCreditMemoDocument cmDocument = (OleVendorCreditMemoDocument) event.getDocument();
43
44 boolean valid = true;
45 if(cmDocument.getInvoiceIdentifier() == null || cmDocument.getInvoiceIdentifier().compareTo(new Integer(0)) == 0) {
46 valid = validateRequiredField(cmDocument, PurapPropertyConstants.CREDIT_MEMO_NUMBER);
47 }
48
49
50 valid = valid && validateRequiredField(cmDocument, PurapPropertyConstants.CREDIT_MEMO_AMOUNT);
51 boolean creditMemoDateExist = validateRequiredField(cmDocument, PurapPropertyConstants.CREDIT_MEMO_DATE);
52
53 if (creditMemoDateExist) {
54 if (paymentRequestService.isInvoiceDateAfterToday(cmDocument.getCreditMemoDate())) {
55 String label = dataDictionaryService.getAttributeErrorLabel(VendorCreditMemoDocument.class, PurapPropertyConstants.CREDIT_MEMO_DATE);
56 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.CREDIT_MEMO_DATE, PurapKeyConstants.ERROR_INVALID_INVOICE_DATE, label);
57 valid = false;
58 }
59 }
60
61 return valid;
62
63 }
64
65
66
67
68
69
70
71
72
73 protected boolean validateRequiredField(BusinessObject businessObject, String fieldName) {
74 boolean valid = true;
75
76 Object fieldValue = ObjectUtils.getPropertyValue(businessObject, fieldName);
77 if (fieldValue == null || (fieldValue instanceof String && StringUtils.isBlank(fieldName))) {
78 String label = dataDictionaryService.getAttributeErrorLabel(businessObject.getClass(), fieldName);
79 GlobalVariables.getMessageMap().putError(fieldName, OLEKeyConstants.ERROR_REQUIRED, label);
80 valid = false;
81 }
82
83 return valid;
84 }
85
86 public DataDictionaryService getDataDictionaryService() {
87 return dataDictionaryService;
88 }
89
90 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
91 this.dataDictionaryService = dataDictionaryService;
92 }
93
94 public PaymentRequestService getPaymentRequestService() {
95 return paymentRequestService;
96 }
97
98 public void setPaymentRequestService(PaymentRequestService paymentRequestService) {
99 this.paymentRequestService = paymentRequestService;
100 }
101
102 }