1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.validation.impl;
17
18 import static org.kuali.ole.fp.document.validation.impl.CreditCardReceiptDocumentRuleConstants.CREDIT_CARD_RECEIPT_PREFIX;
19 import static org.kuali.ole.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX;
20
21 import org.kuali.ole.fp.document.CreditCardReceiptDocument;
22 import org.kuali.ole.sys.OLEKeyConstants;
23 import org.kuali.ole.sys.OLEKeyConstants.CashReceipt;
24 import org.kuali.ole.sys.OLEPropertyConstants;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.ole.sys.document.validation.GenericValidation;
27 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
28 import org.kuali.rice.core.api.util.type.KualiDecimal;
29 import org.kuali.rice.kns.service.DataDictionaryService;
30 import org.kuali.rice.kns.service.DictionaryValidationService;
31 import org.kuali.rice.krad.util.GlobalVariables;
32
33
34
35
36 public class CreditCardReceiptCashTotalsValidation extends GenericValidation {
37 private CreditCardReceiptDocument accountingDocumentForValidation;
38
39
40
41 public boolean validate(AttributedDocumentEvent event) {
42 CreditCardReceiptDocument ccrDocument = getAccountingDocumentForValidation();
43 KualiDecimal totalAmount = ccrDocument.getTotalDollarAmount();
44 String propertyName = OLEPropertyConstants.CREDIT_CARD_RECEIPTS_TOTAL;
45 String documentEntryName = ccrDocument.getDocumentHeader().getWorkflowDocument().getDocumentTypeName();
46
47 boolean isValid = true;
48 String errorProperty = CREDIT_CARD_RECEIPT_PREFIX + propertyName;
49
50
51 DataDictionaryService dds = SpringContext.getBean(DataDictionaryService.class);
52 String errorLabel = dds.getAttributeLabel(documentEntryName, propertyName);
53 if ((totalAmount == null) || totalAmount.isZero()) {
54 GlobalVariables.getMessageMap().putError(errorProperty, CashReceipt.ERROR_ZERO_TOTAL, errorLabel);
55
56 isValid = false;
57 }
58 else {
59 int precount = GlobalVariables.getMessageMap().getNumberOfPropertiesWithErrors();
60
61 DictionaryValidationService dvs = SpringContext.getBean(DictionaryValidationService.class);
62 dvs.validateDocumentAttribute(ccrDocument, propertyName, DOCUMENT_ERROR_PREFIX);
63
64
65 GlobalVariables.getMessageMap().replaceError(errorProperty, OLEKeyConstants.ERROR_MAX_LENGTH, CashReceipt.ERROR_EXCESSIVE_TOTAL, errorLabel);
66
67 int postcount = GlobalVariables.getMessageMap().getNumberOfPropertiesWithErrors();
68 isValid = (postcount == precount);
69 }
70
71 return isValid;
72 }
73
74
75
76
77 public CreditCardReceiptDocument getAccountingDocumentForValidation() {
78 return accountingDocumentForValidation;
79 }
80
81
82
83
84 public void setAccountingDocumentForValidation(CreditCardReceiptDocument accountingDocumentForValidation) {
85 this.accountingDocumentForValidation = accountingDocumentForValidation;
86 }
87
88 }