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