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 org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.fp.businessobject.DisbursementVoucherPayeeDetail;
20 import org.kuali.ole.fp.document.DisbursementVoucherDocument;
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.ole.sys.document.AccountingDocument;
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.util.GlobalVariables;
29 import org.kuali.rice.krad.util.MessageMap;
30 import org.kuali.rice.krad.util.ObjectUtils;
31
32 public class DisbursementVoucherPayeeAddressValidation extends GenericValidation {
33 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherPayeeAddressValidation.class);
34
35 private AccountingDocument accountingDocumentForValidation;
36
37
38
39
40 public boolean validate(AttributedDocumentEvent event) {
41 LOG.debug("validate start");
42 boolean isValid = true;
43
44 DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
45 DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
46
47 MessageMap errors = GlobalVariables.getMessageMap();
48 errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
49
50 DataDictionaryService dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
51
52 String stateCode = payeeDetail.getDisbVchrPayeeStateCode();
53 if (StringUtils.isNotBlank(stateCode) && ObjectUtils.isNull(payeeDetail.getDisbVchrPayeeState())) {
54 String label = dataDictionaryService.getAttributeLabel(DisbursementVoucherPayeeDetail.class, OLEPropertyConstants.DISB_VCHR_PAYEE_STATE_CODE);
55 String propertyPath = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYEE_STATE_CODE;
56 errors.putError(propertyPath, OLEKeyConstants.ERROR_EXISTENCE, label);
57 isValid = false;
58 }
59
60 String zipCode = payeeDetail.getDisbVchrPayeeZipCode();
61 if (StringUtils.isNotBlank(zipCode) && ObjectUtils.isNull(payeeDetail.getDisbVchrPayeePostalZipCode())) {
62 String label = dataDictionaryService.getAttributeLabel(DisbursementVoucherPayeeDetail.class, OLEPropertyConstants.DISB_VCHR_PAYEE_ZIP_CODE);
63 String propertyPath = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYEE_ZIP_CODE;
64 errors.putError(propertyPath, OLEKeyConstants.ERROR_EXISTENCE, label);
65 isValid = false;
66 }
67
68 String countryCode = payeeDetail.getDisbVchrPayeeCountryCode();
69 if (StringUtils.isNotBlank(countryCode) && ObjectUtils.isNull(payeeDetail.getDisbVchrPayeeCountry())) {
70 String label = dataDictionaryService.getAttributeLabel(DisbursementVoucherPayeeDetail.class, OLEPropertyConstants.DISB_VCHR_PAYEE_COUNTRY_CODE);
71 String propertyPath = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYEE_COUNTRY_CODE;
72 errors.putError(propertyPath, OLEKeyConstants.ERROR_EXISTENCE, label);
73 isValid = false;
74 }
75
76 errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
77
78 return isValid;
79 }
80
81
82
83
84
85
86 public AccountingDocument getAccountingDocumentForValidation() {
87 return accountingDocumentForValidation;
88 }
89
90
91
92
93
94
95
96 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
97 this.accountingDocumentForValidation = accountingDocumentForValidation;
98 }
99 }