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.businessobject.PurchaseOrderVendorQuote;
22 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
23 import org.kuali.ole.sys.OLEKeyConstants;
24 import org.kuali.ole.sys.document.validation.GenericValidation;
25 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26 import org.kuali.ole.vnd.businessobject.VendorDetail;
27 import org.kuali.ole.vnd.document.service.VendorService;
28 import org.kuali.rice.krad.util.GlobalVariables;
29
30
31
32
33 public class PurchaseOrderAddQuoteToVendorValidation extends GenericValidation {
34
35 private PurchaseOrderDocument accountingDocumentForValidation;
36 private PurchaseOrderVendorQuote vendorQuote;
37 private VendorService vendorService;
38
39
40
41
42
43
44
45 public boolean validate(AttributedDocumentEvent event) {
46 boolean valid = true;
47 valid &= isVendorQuoteActiveNotDebarredVendor(vendorQuote.getVendorHeaderGeneratedIdentifier(), vendorQuote.getVendorDetailAssignedIdentifier());
48 valid &= vendorQuoteHasRequiredFields(vendorQuote);
49 return valid;
50 }
51
52 protected boolean isVendorQuoteActiveNotDebarredVendor(Integer vendorHeaderGeneratedIdentifier, Integer vendorDetailAssignedIdentifer) {
53 VendorDetail vendorDetail = vendorService.getVendorDetail(vendorHeaderGeneratedIdentifier, vendorDetailAssignedIdentifer);
54 if (vendorDetail != null) {
55 if (!vendorDetail.isActiveIndicator()) {
56 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_INACTIVE_VENDOR);
57 return false;
58 } else if (vendorDetail.isVendorDebarred()) {
59 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_DEBARRED_VENDOR);
60 return false;
61 }
62 }
63 return true;
64 }
65
66 protected boolean vendorQuoteHasRequiredFields(PurchaseOrderVendorQuote vendorQuote) {
67 boolean valid = true;
68 if (StringUtils.isBlank(vendorQuote.getVendorName())) {
69 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_NAME, OLEKeyConstants.ERROR_REQUIRED, "Vendor Name");
70 valid = false;
71 }
72 if (StringUtils.isBlank(vendorQuote.getVendorLine1Address())) {
73 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_LINE_1_ADDR, OLEKeyConstants.ERROR_REQUIRED, "Vendor Line 1 Address");
74 valid = false;
75 }
76 if (StringUtils.isBlank(vendorQuote.getVendorCityName())) {
77 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_CITY_NAME, OLEKeyConstants.ERROR_REQUIRED, "Vendor City Name");
78 valid = false;
79 }
80 return valid;
81 }
82
83 public PurchaseOrderDocument getAccountingDocumentForValidation() {
84 return accountingDocumentForValidation;
85 }
86
87 public void setAccountingDocumentForValidation(PurchaseOrderDocument accountingDocumentForValidation) {
88 this.accountingDocumentForValidation = accountingDocumentForValidation;
89 }
90
91 public PurchaseOrderVendorQuote getVendorQuote() {
92 return vendorQuote;
93 }
94
95 public void setVendorQuote(PurchaseOrderVendorQuote vendorQuote) {
96 this.vendorQuote = vendorQuote;
97 }
98
99 public VendorService getVendorService() {
100 return vendorService;
101 }
102
103 public void setVendorService(VendorService vendorService) {
104 this.vendorService = vendorService;
105 }
106
107 }
108