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.PurapConstants;
20 import org.kuali.ole.module.purap.PurapConstants.PODocumentsStrings;
21 import org.kuali.ole.module.purap.PurapKeyConstants;
22 import org.kuali.ole.module.purap.PurapPropertyConstants;
23 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
24 import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
25 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26 import org.kuali.ole.vnd.VendorConstants.VendorTypes;
27 import org.kuali.ole.vnd.VendorPropertyConstants;
28 import org.kuali.ole.vnd.businessobject.VendorDetail;
29 import org.kuali.rice.kns.service.DataDictionaryService;
30 import org.kuali.rice.krad.util.GlobalVariables;
31 import org.kuali.rice.krad.util.MessageMap;
32 import org.kuali.rice.krad.util.ObjectUtils;
33
34 public class PurchaseOrderProcessVendorValidation extends PurchasingProcessVendorValidation {
35
36 private DataDictionaryService dataDictionaryService;
37
38
39
40
41
42
43
44 public boolean validate(AttributedDocumentEvent event) {
45 boolean valid = super.validate(event);
46 PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) event.getDocument();
47 PurchaseOrderDocument poDocument = (PurchaseOrderDocument) purapDocument;
48 MessageMap errorMap = GlobalVariables.getMessageMap();
49 errorMap.clearErrorPath();
50 errorMap.addToErrorPath(PurapConstants.VENDOR_ERRORS);
51
52
53 Integer vendorHeaderID = poDocument.getVendorHeaderGeneratedIdentifier();
54 if (ObjectUtils.isNull(vendorHeaderID)) {
55 valid = false;
56 errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_NONEXIST_VENDOR);
57 }
58
59
60 VendorDetail vendorDetail = super.getVendorService().getVendorDetail(poDocument.getVendorHeaderGeneratedIdentifier(), poDocument.getVendorDetailAssignedIdentifier());
61 if (ObjectUtils.isNull(vendorDetail))
62 return valid;
63
64
65 if (!vendorDetail.isActiveIndicator()) {
66 valid &= false;
67 errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_INACTIVE_VENDOR);
68 }
69
70
71 super.getPostalCodeValidationService().validateAddress(poDocument.getVendorCountryCode(), poDocument.getVendorStateCode(), poDocument.getVendorPostalCode(), PurapPropertyConstants.VENDOR_STATE_CODE, PurapPropertyConstants.VENDOR_POSTAL_CODE);
72
73
74 Integer alternateVendorHdrGeneratedId = poDocument.getAlternateVendorHeaderGeneratedIdentifier();
75 Integer alternateVendorHdrDetailAssignedId = poDocument.getAlternateVendorDetailAssignedIdentifier();
76
77 VendorDetail alternateVendor = super.getVendorService().getVendorDetail(alternateVendorHdrGeneratedId, alternateVendorHdrDetailAssignedId);
78
79 if (alternateVendor != null) {
80 if (alternateVendor.isVendorDebarred()) {
81 errorMap.putError(PurapPropertyConstants.ALTERNATE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_DEBARRED);
82 valid &= false;
83 }
84 if (StringUtils.equals(alternateVendor.getVendorHeader().getVendorTypeCode(), VendorTypes.DISBURSEMENT_VOUCHER)) {
85 errorMap.putError(PurapPropertyConstants.ALTERNATE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_DV_TYPE);
86 valid &= false;
87 }
88 if (!alternateVendor.isActiveIndicator()) {
89 errorMap.putError(PurapPropertyConstants.ALTERNATE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_INACTIVE, PODocumentsStrings.ALTERNATE_PAYEE_VENDOR);
90 valid &= false;
91 }
92 }
93
94 errorMap.clearErrorPath();
95 return valid;
96 }
97
98 public DataDictionaryService getDataDictionaryService() {
99 return dataDictionaryService;
100 }
101
102 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
103 this.dataDictionaryService = dataDictionaryService;
104 }
105 }